// function : UpdateRaytraceGeometry
// purpose : Updates 3D scene geometry for ray tracing
// =======================================================================
-Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (Standard_Boolean theCheck)
+Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (GeomUpdateMode theMode)
{
if (myView.IsNull())
return Standard_False;
- // Note: In 'check' mode the scene geometry is analyzed for modifications
+ // Note: In 'check' mode (OpenGl_GUM_CHECK) the scene geometry is analyzed for modifications
// This is light-weight procedure performed for each frame
- if (!theCheck)
+ if (theMode == OpenGl_GUM_CHECK)
{
- myRaytraceGeometry.Clear();
+ if (myLayersModificationStatus != myView->LayerList().ModificationState())
+ {
+ return UpdateRaytraceGeometry (OpenGl_GUM_PREPARE);
+ }
+ }
+ else if (theMode == OpenGl_GUM_PREPARE)
+ {
+ myRaytraceGeometry.ClearMaterials();
+ myArrayToTrianglesMap.clear();
myIsRaytraceDataValid = Standard_False;
}
- else
- {
- if (myLayersModificationStatus != myView->LayerList().ModificationState())
- {
- return UpdateRaytraceGeometry (Standard_False);
- }
- }
-
- Standard_ShortReal* aTransform (NULL);
// The set of processed structures (reflected to ray-tracing)
// This set is used to remove out-of-date records from the
// hash map of structures
std::set<const OpenGl_Structure*> anElements;
+ // Set of all currently visible and "raytracable" primitive arrays.
+ std::set<const OpenGl_PrimitiveArray*> anArrays;
+
const OpenGl_LayerList& aList = myView->LayerList();
for (OpenGl_SequenceOfLayers::Iterator anLayerIt (aList.Layers()); anLayerIt.More(); anLayerIt.Next())
{
- const OpenGl_PriorityList& aPriorityList = anLayerIt.Value();
+ const OpenGl_PriorityList& aPriorityList = anLayerIt.Value().PriorityList();
if (aPriorityList.NbStructures() == 0)
continue;
for (aStructIt.Init (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next())
{
+ Standard_ShortReal* aTransform (NULL);
+
const OpenGl_Structure* aStructure = aStructIt.Value();
- if (theCheck)
+ if (theMode == OpenGl_GUM_CHECK)
{
if (CheckRaytraceStructure (aStructure))
{
- return UpdateRaytraceGeometry (Standard_False);
+ return UpdateRaytraceGeometry (OpenGl_GUM_PREPARE);
}
- }
- else
+ }
+ else if (theMode == OpenGl_GUM_PREPARE)
+ {
+ if (!aStructure->IsRaytracable()
+ || !aStructure->IsVisible())
+ continue;
+
+ for (OpenGl_Structure::GroupIterator aGroupIter (aStructure->DrawGroups()); aGroupIter.More(); aGroupIter.Next())
+ {
+ // OpenGL elements from group (extract primitives arrays)
+ for (const OpenGl_ElementNode* aNode = aGroupIter.Value()->FirstNode(); aNode != NULL; aNode = aNode->next)
+ {
+ OpenGl_PrimitiveArray* aPrimArray = dynamic_cast<OpenGl_PrimitiveArray*> (aNode->elem);
+
+ if (aPrimArray != NULL)
+ {
+ // Collect all primitive arrays in scene.
+ anArrays.insert (aPrimArray);
+ }
+ }
+ }
+ }
+ else if (theMode == OpenGl_GUM_UPDATE)
{
if (!aStructure->IsRaytracable())
continue;
AddRaytraceStructure (aStructure, aTransform, anElements);
}
+
+ delete [] aTransform;
}
}
}
- if (!theCheck)
+ if (theMode == OpenGl_GUM_PREPARE)
+ {
+ BVH_ObjectSet<Standard_ShortReal, 4>::BVH_ObjectList anUnchangedObjects;
+
+ // Leave only unchanged objects in myRaytraceGeometry so only their transforms and materials will be updated
+ // Objects which not in myArrayToTrianglesMap will be built from scratch.
+ for (Standard_Integer anObjectIdx = 0; anObjectIdx < myRaytraceGeometry.Objects().Size(); ++anObjectIdx)
+ {
+ OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
+ myRaytraceGeometry.Objects().ChangeValue (anObjectIdx).operator->());
+
+ // If primitive array of object not in "anArrays" set then it was hided or deleted.
+ // If primitive array present in "anArrays" set but we don't have associated object yet, then
+ // the object is new and still has to be built.
+ if ((aTriangleSet != NULL) && ((anArrays.find (aTriangleSet->AssociatedPArray())) != anArrays.end()))
+ {
+ anUnchangedObjects.Append (myRaytraceGeometry.Objects().Value (anObjectIdx));
+
+ myArrayToTrianglesMap[aTriangleSet->AssociatedPArray()] = aTriangleSet;
+ }
+ }
+
+ myRaytraceGeometry.Objects() = anUnchangedObjects;
+
+ return UpdateRaytraceGeometry (OpenGl_GUM_UPDATE);
+ }
+
+ if (theMode == OpenGl_GUM_UPDATE)
{
// Actualize the hash map of structures -- remove out-of-date records
std::map<const OpenGl_Structure*, Standard_Size>::iterator anIter = myStructureStates.begin();
const BVH_Vec4f aSize = myRaytraceGeometry.Box().Size();
- myRaytraceSceneEpsilon = Max (1e-4f, 1e-4f * sqrtf (
+ myRaytraceSceneEpsilon = Max (1e-7f, 1e-4f * sqrtf (
aSize.x() * aSize.x() + aSize.y() * aSize.y() + aSize.z() * aSize.z()));
return UploadRaytraceData();
}
- delete [] aTransform;
-
return Standard_True;
}
// to produce realistic-looking transparency effect
theMaterial.Transparency = BVH_Vec4f (powf (theProp.trans, 0.75f),
1.f - theProp.trans,
- 1.f,
- 1.f);
+ theProp.index == 0 ? 1.f : theProp.index,
+ theProp.index == 0 ? 1.f : 1.f / theProp.index);
const float aMaxRefl = Max (theMaterial.Diffuse.x() + theMaterial.Specular.x(),
Max (theMaterial.Diffuse.y() + theMaterial.Specular.y(),
else
{
OpenGl_PrimitiveArray* aPrimArray = dynamic_cast<OpenGl_PrimitiveArray*> (aNode->elem);
+
+ std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*>::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray);
+
if (aPrimArray != NULL)
{
- NCollection_Handle<BVH_Object<Standard_ShortReal, 4> > aSet =
- AddRaytracePrimitiveArray (aPrimArray->PArray(), aMatID, theTransform);
+ if (aSetIter != myArrayToTrianglesMap.end())
+ {
+ OpenGl_TriangleSet* aSet = aSetIter->second;
+
+ BVH_Transform<Standard_ShortReal, 4>* aTransform = new BVH_Transform<Standard_ShortReal, 4>();
+
+ if (theTransform != NULL)
+ {
+ aTransform->SetTransform (*(reinterpret_cast<const BVH_Mat4f*> (theTransform)));
+ }
+
+ aSet->SetProperties (aTransform);
+
+ if (aSet->MaterialIndex() != OpenGl_TriangleSet::INVALID_MATERIAL && aSet->MaterialIndex() != aMatID )
+ {
+ aSet->SetMaterialIndex (aMatID);
+ }
+ }
+ else
+ {
+ NCollection_Handle<BVH_Object<Standard_ShortReal, 4> > aSet =
+ AddRaytracePrimitiveArray (aPrimArray, aMatID, 0);
+
+ if (!aSet.IsNull())
+ {
+ BVH_Transform<Standard_ShortReal, 4>* aTransform = new BVH_Transform<Standard_ShortReal, 4>;
- if (!aSet.IsNull())
- myRaytraceGeometry.Objects().Append (aSet);
+ if (theTransform != NULL)
+ {
+ aTransform->SetTransform (*(reinterpret_cast<const BVH_Mat4f*> (theTransform)));
+ }
+
+ aSet->SetProperties (aTransform);
+
+ myRaytraceGeometry.Objects().Append (aSet);
+ }
+ }
}
}
}
}
- Standard_ShortReal* aTransform (NULL);
+ Standard_ShortReal* aTransform = NULL;
// Process all connected OpenGL structures
for (OpenGl_ListOfStructure::Iterator anIts (theStructure->ConnectedStructures()); anIts.More(); anIts.Next())
{
if (anIts.Value()->Transformation()->mat != NULL)
{
- Standard_ShortReal* aTransform = new Standard_ShortReal[16];
+ if (aTransform == NULL)
+ aTransform = new Standard_ShortReal[16];
for (Standard_Integer i = 0; i < 4; ++i)
for (Standard_Integer j = 0; j < 4; ++j)
// function : AddRaytracePrimitiveArray
// purpose : Adds OpenGL primitive array to ray-traced scene geometry
// =======================================================================
-OpenGl_TriangleSet* OpenGl_Workspace::AddRaytracePrimitiveArray (
- const CALL_DEF_PARRAY* theArray, Standard_Integer theMatID, const Standard_ShortReal* theTransform)
+OpenGl_TriangleSet* OpenGl_Workspace::AddRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
+ Standard_Integer theMatID,
+ const Standard_ShortReal* theTransform)
{
- if (theArray->type != TelPolygonsArrayType &&
- theArray->type != TelTrianglesArrayType &&
- theArray->type != TelQuadranglesArrayType &&
- theArray->type != TelTriangleFansArrayType &&
- theArray->type != TelTriangleStripsArrayType &&
- theArray->type != TelQuadrangleStripsArrayType)
+ const Handle(Graphic3d_IndexBuffer)& anIndices = theArray->Indices();
+ const Handle(Graphic3d_Buffer)& anAttribs = theArray->Attributes();
+ const Handle(Graphic3d_BoundBuffer)& aBounds = theArray->Bounds();
+ if (theArray->DrawMode() < GL_TRIANGLES
+ || theArray->DrawMode() > GL_POLYGON
+ || anAttribs.IsNull())
{
return NULL;
}
- if (theArray->vertices == NULL)
- return NULL;
-
#ifdef RAY_TRACE_PRINT_INFO
- switch (theArray->type)
- {
- case TelPolygonsArrayType:
- std::cout << "\tAdding TelPolygonsArrayType" << std::endl; break;
- case TelTrianglesArrayType:
- std::cout << "\tAdding TelTrianglesArrayType" << std::endl; break;
- case TelQuadranglesArrayType:
- std::cout << "\tAdding TelQuadranglesArrayType" << std::endl; break;
- case TelTriangleFansArrayType:
- std::cout << "\tAdding TelTriangleFansArrayType" << std::endl; break;
- case TelTriangleStripsArrayType:
- std::cout << "\tAdding TelTriangleStripsArrayType" << std::endl; break;
- case TelQuadrangleStripsArrayType:
- std::cout << "\tAdding TelQuadrangleStripsArrayType" << std::endl; break;
+ switch (theArray->DrawMode())
+ {
+ case GL_POLYGON: std::cout << "\tAdding GL_POLYGON\n"; break;
+ case GL_TRIANGLES: std::cout << "\tAdding GL_TRIANGLES\n"; break;
+ case GL_QUADS: std::cout << "\tAdding GL_QUADS\n"; break;
+ case GL_TRIANGLE_FAN: std::cout << "\tAdding GL_TRIANGLE_FAN\n"; break;
+ case GL_TRIANGLE_STRIP: std::cout << "\tAdding GL_TRIANGLE_STRIP\n"; break;
+ case GL_QUAD_STRIP: std::cout << "\tAdding GL_QUAD_STRIP\n"; break;
}
#endif
- OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet;
-
+ OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray);
{
- aSet->Vertices.reserve (theArray->num_vertexs);
-
- for (Standard_Integer aVert = 0; aVert < theArray->num_vertexs; ++aVert)
+ aSet->Vertices.reserve (anAttribs->NbElements);
+ aSet->Normals .reserve (anAttribs->NbElements);
+ const size_t aVertFrom = aSet->Vertices.size();
+ for (Standard_Integer anAttribIter = 0; anAttribIter < anAttribs->NbAttributes; ++anAttribIter)
{
- BVH_Vec4f aVertex (theArray->vertices[aVert].xyz[0],
- theArray->vertices[aVert].xyz[1],
- theArray->vertices[aVert].xyz[2],
- 1.f);
- if (theTransform)
- aVertex = MatVecMult (theTransform, aVertex);
-
- aSet->Vertices.push_back (aVertex);
+ const Graphic3d_Attribute& anAttrib = anAttribs->Attribute (anAttribIter);
+ const size_t anOffset = anAttribs->AttributeOffset (anAttribIter);
+ if (anAttrib.Id == Graphic3d_TOA_POS)
+ {
+ if (anAttrib.DataType == Graphic3d_TOD_VEC3
+ || anAttrib.DataType == Graphic3d_TOD_VEC4)
+ {
+ for (Standard_Integer aVertIter = 0; aVertIter < anAttribs->NbElements; ++aVertIter)
+ {
+ const Graphic3d_Vec3& aVert = *reinterpret_cast<const Graphic3d_Vec3* >(anAttribs->value (aVertIter) + anOffset);
+ aSet->Vertices.push_back (BVH_Vec4f (aVert.x(), aVert.y(), aVert.z(), 1.0f));
+ }
+ }
+ else if (anAttrib.DataType == Graphic3d_TOD_VEC2)
+ {
+ for (Standard_Integer aVertIter = 0; aVertIter < anAttribs->NbElements; ++aVertIter)
+ {
+ const Graphic3d_Vec2& aVert = *reinterpret_cast<const Graphic3d_Vec2* >(anAttribs->value (aVertIter) + anOffset);
+ aSet->Vertices.push_back (BVH_Vec4f (aVert.x(), aVert.y(), 0.0f, 1.0f));
+ }
+ }
+ }
+ else if (anAttrib.Id == Graphic3d_TOA_NORM)
+ {
+ if (anAttrib.DataType == Graphic3d_TOD_VEC3
+ || anAttrib.DataType == Graphic3d_TOD_VEC4)
+ {
+ for (Standard_Integer aVertIter = 0; aVertIter < anAttribs->NbElements; ++aVertIter)
+ {
+ const Graphic3d_Vec3& aNorm = *reinterpret_cast<const Graphic3d_Vec3* >(anAttribs->value (aVertIter) + anOffset);
+ aSet->Normals.push_back (BVH_Vec4f (aNorm.x(), aNorm.y(), aNorm.z(), 0.0f));
+ }
+ }
+ }
}
- aSet->Normals.reserve (theArray->num_vertexs);
-
- for (Standard_Integer aNorm = 0; aNorm < theArray->num_vertexs; ++aNorm)
+ if (aSet->Normals.size() != aSet->Vertices.size())
{
- BVH_Vec4f aNormal;
-
- // Note: In case of absence of normals, the
- // renderer uses generated geometric normals
-
- if (theArray->vnormals != NULL)
+ for (Standard_Integer aVertIter = 0; aVertIter < anAttribs->NbElements; ++aVertIter)
{
- aNormal = BVH_Vec4f (theArray->vnormals[aNorm].xyz[0],
- theArray->vnormals[aNorm].xyz[1],
- theArray->vnormals[aNorm].xyz[2],
- 0.f);
-
- if (theTransform)
- aNormal = MatVecMult (theTransform, aNormal);
+ aSet->Normals.push_back (BVH_Vec4f());
}
+ }
- aSet->Normals.push_back (aNormal);
+ if (theTransform)
+ {
+ for (size_t aVertIter = aVertFrom; aVertIter < aSet->Vertices.size(); ++aVertIter)
+ {
+ BVH_Vec4f& aVertex = aSet->Vertices[aVertIter];
+ aVertex = MatVecMult (theTransform, aVertex);
+ }
+ for (size_t aVertIter = aVertFrom; aVertIter < aSet->Normals.size(); ++aVertIter)
+ {
+ BVH_Vec4f& aNorm = aSet->Normals[aVertIter];
+ aNorm = MatVecMult (theTransform, aNorm);
+ }
}
- if (theArray->num_bounds > 0)
+ if (!aBounds.IsNull())
{
#ifdef RAY_TRACE_PRINT_INFO
- std::cout << "\tNumber of bounds = " << theArray->num_bounds << std::endl;
+ std::cout << "\tNumber of bounds = " << aBounds->NbBounds << std::endl;
#endif
Standard_Integer aBoundStart = 0;
-
- for (Standard_Integer aBound = 0; aBound < theArray->num_bounds; ++aBound)
+ for (Standard_Integer aBound = 0; aBound < aBounds->NbBounds; ++aBound)
{
- const Standard_Integer aVertNum = theArray->bounds[aBound];
+ const Standard_Integer aVertNum = aBounds->Bounds[aBound];
#ifdef RAY_TRACE_PRINT_INFO
std::cout << "\tAdding indices from bound " << aBound << ": " <<
aBoundStart << " .. " << aVertNum << std::endl;
#endif
- if (!AddRaytraceVertexIndices (aSet, theArray, aBoundStart, aVertNum, theMatID))
+ if (!AddRaytraceVertexIndices (*aSet, *theArray, aBoundStart, aVertNum, theMatID))
{
delete aSet;
return NULL;
}
else
{
- const Standard_Integer aVertNum = theArray->num_edges > 0 ? theArray->num_edges : theArray->num_vertexs;
+ const Standard_Integer aVertNum = !anIndices.IsNull() ? anIndices->NbElements : anAttribs->NbElements;
#ifdef RAY_TRACE_PRINT_INFO
std::cout << "\tAdding indices from array: " << aVertNum << std::endl;
#endif
- if (!AddRaytraceVertexIndices (aSet, theArray, 0, aVertNum, theMatID))
+ if (!AddRaytraceVertexIndices (*aSet, *theArray, 0, aVertNum, theMatID))
{
delete aSet;
return NULL;
// function : AddRaytraceVertexIndices
// purpose : Adds vertex indices to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceVertexIndices (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
+ const OpenGl_PrimitiveArray& theArray,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
- switch (theArray->type)
+ switch (theArray.DrawMode())
{
- case TelTrianglesArrayType:
- return AddRaytraceTriangleArray (theSet, theArray, theOffset, theCount, theMatID);
-
- case TelQuadranglesArrayType:
- return AddRaytraceQuadrangleArray (theSet, theArray, theOffset, theCount, theMatID);
-
- case TelTriangleFansArrayType:
- return AddRaytraceTriangleFanArray (theSet, theArray, theOffset, theCount, theMatID);
-
- case TelTriangleStripsArrayType:
- return AddRaytraceTriangleStripArray (theSet, theArray, theOffset, theCount, theMatID);
-
- case TelQuadrangleStripsArrayType:
- return AddRaytraceQuadrangleStripArray (theSet, theArray, theOffset, theCount, theMatID);
-
- default:
- return AddRaytracePolygonArray (theSet, theArray, theOffset, theCount, theMatID);
+ case GL_TRIANGLES: return AddRaytraceTriangleArray (theSet, theArray.Indices(), theOffset, theCount, theMatID);
+ case GL_QUADS: return AddRaytraceQuadrangleArray (theSet, theArray.Indices(), theOffset, theCount, theMatID);
+ case GL_TRIANGLE_FAN: return AddRaytraceTriangleFanArray (theSet, theArray.Indices(), theOffset, theCount, theMatID);
+ case GL_TRIANGLE_STRIP: return AddRaytraceTriangleStripArray (theSet, theArray.Indices(), theOffset, theCount, theMatID);
+ case GL_QUAD_STRIP: return AddRaytraceQuadrangleStripArray (theSet, theArray.Indices(), theOffset, theCount, theMatID);
+ case GL_POLYGON: return AddRaytracePolygonArray (theSet, theArray.Indices(), theOffset, theCount, theMatID);
}
+ return Standard_False;
}
// =======================================================================
// function : AddRaytraceTriangleArray
// purpose : Adds OpenGL triangle array to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleArray (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
if (theCount < 3)
return Standard_True;
- theSet->Elements.reserve (theSet->Elements.size() + theCount / 3);
+ theSet.Elements.reserve (theSet.Elements.size() + theCount / 3);
- if (theArray->num_edges > 0)
+ if (!theIndices.IsNull())
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 2; aVert += 3)
{
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[aVert + 0],
- theArray->edges[aVert + 1],
- theArray->edges[aVert + 2],
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (aVert + 0),
+ theIndices->Index (aVert + 1),
+ theIndices->Index (aVert + 2),
+ theMatID));
}
}
else
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 2; aVert += 3)
{
- theSet->Elements.push_back (BVH_Vec4i (aVert + 0,
- aVert + 1,
- aVert + 2,
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (aVert + 0, aVert + 1, aVert + 2,
+ theMatID));
}
}
// function : AddRaytraceTriangleFanArray
// purpose : Adds OpenGL triangle fan array to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleFanArray (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
if (theCount < 3)
return Standard_True;
- theSet->Elements.reserve (theSet->Elements.size() + theCount - 2);
+ theSet.Elements.reserve (theSet.Elements.size() + theCount - 2);
- if (theArray->num_edges > 0)
+ if (!theIndices.IsNull())
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 2; ++aVert)
{
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[theOffset],
- theArray->edges[aVert + 1],
- theArray->edges[aVert + 2],
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (theOffset),
+ theIndices->Index (aVert + 1),
+ theIndices->Index (aVert + 2),
+ theMatID));
}
}
else
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 2; ++aVert)
{
- theSet->Elements.push_back (BVH_Vec4i (theOffset,
- aVert + 1,
- aVert + 2,
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theOffset,
+ aVert + 1,
+ aVert + 2,
+ theMatID));
}
}
// function : AddRaytraceTriangleStripArray
// purpose : Adds OpenGL triangle strip array to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleStripArray (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
if (theCount < 3)
return Standard_True;
- theSet->Elements.reserve (theSet->Elements.size() + theCount - 2);
+ theSet.Elements.reserve (theSet.Elements.size() + theCount - 2);
- if (theArray->num_edges > 0)
+ if (!theIndices.IsNull())
{
for (Standard_Integer aVert = theOffset, aCW = 0; aVert < theOffset + theCount - 2; ++aVert, aCW = (aCW + 1) % 2)
{
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[aVert + aCW ? 1 : 0],
- theArray->edges[aVert + aCW ? 0 : 1],
- theArray->edges[aVert + 2],
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (aVert + aCW ? 1 : 0),
+ theIndices->Index (aVert + aCW ? 0 : 1),
+ theIndices->Index (aVert + 2),
+ theMatID));
}
}
else
{
for (Standard_Integer aVert = theOffset, aCW = 0; aVert < theOffset + theCount - 2; ++aVert, aCW = (aCW + 1) % 2)
{
- theSet->Elements.push_back (BVH_Vec4i (aVert + aCW ? 1 : 0,
- aVert + aCW ? 0 : 1,
- aVert + 2,
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (aVert + aCW ? 1 : 0,
+ aVert + aCW ? 0 : 1,
+ aVert + 2,
+ theMatID));
}
}
// function : AddRaytraceQuadrangleArray
// purpose : Adds OpenGL quad array to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceQuadrangleArray (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
if (theCount < 4)
return Standard_True;
- theSet->Elements.reserve (theSet->Elements.size() + theCount / 2);
+ theSet.Elements.reserve (theSet.Elements.size() + theCount / 2);
- if (theArray->num_edges > 0)
+ if (!theIndices.IsNull())
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 3; aVert += 4)
{
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[aVert + 0],
- theArray->edges[aVert + 1],
- theArray->edges[aVert + 2],
- theMatID));
-
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[aVert + 0],
- theArray->edges[aVert + 2],
- theArray->edges[aVert + 3],
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (aVert + 0),
+ theIndices->Index (aVert + 1),
+ theIndices->Index (aVert + 2),
+ theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (aVert + 0),
+ theIndices->Index (aVert + 2),
+ theIndices->Index (aVert + 3),
+ theMatID));
}
}
else
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 3; aVert += 4)
{
- theSet->Elements.push_back (BVH_Vec4i (aVert + 0,
- aVert + 1,
- aVert + 2,
- theMatID));
-
- theSet->Elements.push_back (BVH_Vec4i (aVert + 0,
- aVert + 2,
- aVert + 3,
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (aVert + 0, aVert + 1, aVert + 2,
+ theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (aVert + 0, aVert + 2, aVert + 3,
+ theMatID));
}
}
// function : AddRaytraceQuadrangleStripArray
// purpose : Adds OpenGL quad strip array to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
if (theCount < 4)
return Standard_True;
- theSet->Elements.reserve (theSet->Elements.size() + 2 * theCount - 6);
+ theSet.Elements.reserve (theSet.Elements.size() + 2 * theCount - 6);
- if (theArray->num_edges > 0)
+ if (!theIndices.IsNull())
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 3; aVert += 2)
{
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[aVert + 0],
- theArray->edges[aVert + 1],
- theArray->edges[aVert + 2],
- theMatID));
-
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[aVert + 1],
- theArray->edges[aVert + 3],
- theArray->edges[aVert + 2],
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (aVert + 0),
+ theIndices->Index (aVert + 1),
+ theIndices->Index (aVert + 2),
+ theMatID));
+
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (aVert + 1),
+ theIndices->Index (aVert + 3),
+ theIndices->Index (aVert + 2),
+ theMatID));
}
}
else
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 3; aVert += 2)
{
- theSet->Elements.push_back (BVH_Vec4i (aVert + 0,
- aVert + 1,
- aVert + 2,
- theMatID));
-
- theSet->Elements.push_back (BVH_Vec4i (aVert + 1,
- aVert + 3,
- aVert + 2,
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (aVert + 0,
+ aVert + 1,
+ aVert + 2,
+ theMatID));
+
+ theSet.Elements.push_back (BVH_Vec4i (aVert + 1,
+ aVert + 3,
+ aVert + 2,
+ theMatID));
}
}
// function : AddRaytracePolygonArray
// purpose : Adds OpenGL polygon array to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytracePolygonArray (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID)
+Standard_Boolean OpenGl_Workspace::AddRaytracePolygonArray (OpenGl_TriangleSet& theSet,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ Standard_Integer theOffset,
+ Standard_Integer theCount,
+ Standard_Integer theMatID)
{
if (theCount < 3)
return Standard_True;
- theSet->Elements.reserve (theSet->Elements.size() + theCount - 2);
+ theSet.Elements.reserve (theSet.Elements.size() + theCount - 2);
- if (theArray->num_edges > 0)
+ if (!theIndices.IsNull())
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 2; ++aVert)
{
- theSet->Elements.push_back (BVH_Vec4i (theArray->edges[theOffset],
- theArray->edges[aVert + 1],
- theArray->edges[aVert + 2],
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theIndices->Index (theOffset),
+ theIndices->Index (aVert + 1),
+ theIndices->Index (aVert + 2),
+ theMatID));
}
}
else
{
for (Standard_Integer aVert = theOffset; aVert < theOffset + theCount - 2; ++aVert)
{
- theSet->Elements.push_back (BVH_Vec4i (theOffset,
- aVert + 1,
- aVert + 2,
- theMatID));
+ theSet.Elements.push_back (BVH_Vec4i (theOffset,
+ aVert + 1,
+ aVert + 2,
+ theMatID));
}
}
if (myRaytraceGeometry.Sources.size() != 0)
{
const GLfloat* aDataPtr = myRaytraceGeometry.Sources.front().Packed();
-
- bool aResult = myRaytraceLightSrcTexture->Init (
- myGlContext, 4, myRaytraceGeometry.Sources.size() * 2, aDataPtr);
-
- if (!aResult)
+ if (!myRaytraceLightSrcTexture->Init (myGlContext, 4, GLsizei (myRaytraceGeometry.Sources.size() * 2), aDataPtr))
{
#ifdef RAY_TRACE_PRINT_INFO
std::cout << "Error: Failed to upload light source buffer" << std::endl;
myView->TextureEnv()->Bind (
myGlContext, GL_TEXTURE0 + OpenGl_RT_EnvironmentMapTexture);
- aProgram->SetUniform (myGlContext, "uEnvironmentEnable", 1);
+ aProgram->SetUniform (myGlContext,
+ myUniformLocations[anIdx][OpenGl_RT_uEnvironmentEnable], 1);
}
else
{
- aProgram->SetUniform (myGlContext, "uEnvironmentEnable", 0);
+ aProgram->SetUniform (myGlContext,
+ myUniformLocations[anIdx][OpenGl_RT_uEnvironmentEnable], 0);
}
-
- aProgram->SetSampler (myGlContext,
- "uEnvironmentMapTexture", OpenGl_RT_EnvironmentMapTexture);
}
}
// function : InitRaytraceResources
// purpose : Initializes OpenGL/GLSL shader programs
// =======================================================================
-Standard_Boolean OpenGl_Workspace::InitRaytraceResources()
+Standard_Boolean OpenGl_Workspace::InitRaytraceResources (const Graphic3d_CView& theCView)
{
Standard_Boolean aToRebuildShaders = Standard_False;
const Standard_Integer aRequiredStackSize =
myRaytraceGeometry.HighLevelTreeDepth() + myRaytraceGeometry.BottomLevelTreeDepth();
- if (myTraversalStackSize < aRequiredStackSize)
+ if (myRaytraceParameters.StackSize < aRequiredStackSize)
{
- myTraversalStackSize = Max (aRequiredStackSize, THE_DEFAULT_STACK_SIZE);
+ myRaytraceParameters.StackSize = Max (aRequiredStackSize, THE_DEFAULT_STACK_SIZE);
aToRebuildShaders = Standard_True;
}
else
{
- if (aRequiredStackSize < myTraversalStackSize)
+ if (aRequiredStackSize < myRaytraceParameters.StackSize)
{
- if (myTraversalStackSize > THE_DEFAULT_STACK_SIZE)
+ if (myRaytraceParameters.StackSize > THE_DEFAULT_STACK_SIZE)
{
- myTraversalStackSize = Max (aRequiredStackSize, THE_DEFAULT_STACK_SIZE);
-
+ myRaytraceParameters.StackSize = Max (aRequiredStackSize, THE_DEFAULT_STACK_SIZE);
aToRebuildShaders = Standard_True;
}
}
}
+ if (theCView.RenderParams.RaytracingDepth != myRaytraceParameters.TraceDepth)
+ {
+ myRaytraceParameters.TraceDepth = theCView.RenderParams.RaytracingDepth;
+ aToRebuildShaders = Standard_True;
+ }
+
+ if (theCView.RenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows)
+ {
+ myRaytraceParameters.TransparentShadows = theCView.RenderParams.IsTransparentShadowEnabled;
+ aToRebuildShaders = Standard_True;
+ }
+
if (aToRebuildShaders)
{
#ifdef RAY_TRACE_PRINT_INFO
- std::cout << "Info: Rebuild shaders with stack size: " << myTraversalStackSize << std::endl;
+ std::cout << "Info: Rebuild shaders with stack size: " << myRaytraceParameters.StackSize << std::endl;
#endif
- TCollection_AsciiString aStackSizeStr =
- TCollection_AsciiString ("#define STACK_SIZE ") + TCollection_AsciiString (myTraversalStackSize);
+ // Change state to force update all uniforms
+ ++myViewModificationStatus;
+
+ TCollection_AsciiString aPrefixString =
+ TCollection_AsciiString ("#define STACK_SIZE ") + TCollection_AsciiString (myRaytraceParameters.StackSize) + "\n" +
+ TCollection_AsciiString ("#define TRACE_DEPTH ") + TCollection_AsciiString (myRaytraceParameters.TraceDepth);
+
+ if (myRaytraceParameters.TransparentShadows)
+ {
+ aPrefixString += TCollection_AsciiString ("\n#define TRANSPARENT_SHADOWS");
+ }
+
+#ifdef RAY_TRACE_PRINT_INFO
+ std::cout << "GLSL prefix string:" << std::endl << aPrefixString << std::endl;
+#endif
- myRaytraceShaderSource.SetPrefix (aStackSizeStr);
- myPostFSAAShaderSource.SetPrefix (aStackSizeStr);
+ myRaytraceShaderSource.SetPrefix (aPrefixString);
+ myPostFSAAShaderSource.SetPrefix (aPrefixString);
if (!myRaytraceShader->LoadSource (myGlContext, myRaytraceShaderSource.Source())
|| !myPostFSAAShader->LoadSource (myGlContext, myPostFSAAShaderSource.Source()))
return Standard_False;
}
+ myRaytraceParameters.TraceDepth = theCView.RenderParams.RaytracingDepth;
+
TCollection_AsciiString aFolder = Graphic3d_ShaderProgram::ShadersFolder();
if (aFolder.IsEmpty())
if (myIsRaytraceDataValid)
{
- myTraversalStackSize = Max (THE_DEFAULT_STACK_SIZE,
+ myRaytraceParameters.StackSize = Max (THE_DEFAULT_STACK_SIZE,
myRaytraceGeometry.HighLevelTreeDepth() + myRaytraceGeometry.BottomLevelTreeDepth());
}
+ TCollection_AsciiString aPrefixString =
+ TCollection_AsciiString ("#define STACK_SIZE ") + TCollection_AsciiString (myRaytraceParameters.StackSize) + "\n" +
+ TCollection_AsciiString ("#define TRACE_DEPTH ") + TCollection_AsciiString (myRaytraceParameters.TraceDepth);
+
+ if (myRaytraceParameters.TransparentShadows)
+ {
+ aPrefixString += TCollection_AsciiString ("\n#define TRANSPARENT_SHADOWS");
+ }
+
+#ifdef RAY_TRACE_PRINT_INFO
+ std::cout << "GLSL prefix string:" << std::endl << aPrefixString << std::endl;
+#endif
+
{
Handle(OpenGl_ShaderObject) aBasicVertShader = LoadShader (
ShaderSource (aFolder + "/RaytraceBase.vs"), GL_VERTEX_SHADER);
myRaytraceShaderSource.Load (aFiles, 2);
- TCollection_AsciiString aStackSizeStr =
- TCollection_AsciiString ("#define STACK_SIZE ") + TCollection_AsciiString (myTraversalStackSize);
-
- myRaytraceShaderSource.SetPrefix (aStackSizeStr);
+ myRaytraceShaderSource.SetPrefix (aPrefixString);
myRaytraceShader = LoadShader (myRaytraceShaderSource, GL_FRAGMENT_SHADER);
myPostFSAAShaderSource.Load (aFiles, 2);
- TCollection_AsciiString aStackSizeStr =
- TCollection_AsciiString ("#define STACK_SIZE ") + TCollection_AsciiString (myTraversalStackSize);
-
- myPostFSAAShaderSource.SetPrefix (aStackSizeStr);
+ myPostFSAAShaderSource.SetPrefix (aPrefixString);
myPostFSAAShader = LoadShader (myPostFSAAShaderSource, GL_FRAGMENT_SHADER);
"uRaytraceMaterialTexture", OpenGl_RT_RaytraceMaterialTexture);
aShaderProgram->SetSampler (myGlContext,
"uRaytraceLightSrcTexture", OpenGl_RT_RaytraceLightSrcTexture);
+ aShaderProgram->SetSampler (myGlContext,
+ "uSceneTransformTexture", OpenGl_RT_SceneTransformTexture);
+ aShaderProgram->SetSampler (myGlContext,
+ "uEnvironmentMapTexture", OpenGl_RT_EnvironmentMapTexture);
if (anIndex == 1)
{
aShaderProgram->GetUniformLocation (myGlContext, "uOffsetY");
myUniformLocations[anIndex][OpenGl_RT_uSamples] =
aShaderProgram->GetUniformLocation (myGlContext, "uSamples");
+
+ myUniformLocations[anIndex][OpenGl_RT_uEnvironmentEnable] =
+ aShaderProgram->GetUniformLocation (myGlContext, "uEnvironmentEnable");
}
OpenGl_ShaderProgram::Unbind (myGlContext);
NullifyResource (myGlContext, myGeometryVertexTexture);
NullifyResource (myGlContext, myGeometryNormalTexture);
NullifyResource (myGlContext, myGeometryTriangTexture);
+ NullifyResource (myGlContext, mySceneTransformTexture);
NullifyResource (myGlContext, myRaytraceLightSrcTexture);
NullifyResource (myGlContext, myRaytraceMaterialTexture);
mySceneNodeInfoTexture = new OpenGl_TextureBufferArb;
mySceneMinPointTexture = new OpenGl_TextureBufferArb;
mySceneMaxPointTexture = new OpenGl_TextureBufferArb;
+ mySceneTransformTexture = new OpenGl_TextureBufferArb;
if (!mySceneNodeInfoTexture->Create (myGlContext)
- || !mySceneMinPointTexture->Create (myGlContext)
- || !mySceneMaxPointTexture->Create (myGlContext))
+ || !mySceneMinPointTexture->Create (myGlContext)
+ || !mySceneMaxPointTexture->Create (myGlContext)
+ || !mySceneTransformTexture->Create (myGlContext))
{
#ifdef RAY_TRACE_PRINT_INFO
std::cout << "Error: Failed to create buffers for high-level scene BVH" << std::endl;
}
/////////////////////////////////////////////////////////////////////////////
- // Write OpenGL texture buffers
+ // Write top-level BVH buffers
const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >& aBVH = myRaytraceGeometry.BVH();
bool aResult = true;
-
if (!aBVH->NodeInfoBuffer().empty())
{
- aResult &= mySceneNodeInfoTexture->Init (myGlContext, 4,
- aBVH->NodeInfoBuffer().size(), reinterpret_cast<const GLuint*> (&aBVH->NodeInfoBuffer().front()));
-
- aResult &= mySceneMinPointTexture->Init (myGlContext, 4,
- aBVH->MinPointBuffer().size(), reinterpret_cast<const GLfloat*> (&aBVH->MinPointBuffer().front()));
-
- aResult &= mySceneMaxPointTexture->Init (myGlContext, 4,
- aBVH->MaxPointBuffer().size(), reinterpret_cast<const GLfloat*> (&aBVH->MaxPointBuffer().front()));
+ aResult &= mySceneNodeInfoTexture->Init (myGlContext, 4, GLsizei (aBVH->NodeInfoBuffer().size()),
+ reinterpret_cast<const GLuint*> (&aBVH->NodeInfoBuffer().front()));
+ aResult &= mySceneMinPointTexture->Init (myGlContext, 4, GLsizei (aBVH->MinPointBuffer().size()),
+ reinterpret_cast<const GLfloat*> (&aBVH->MinPointBuffer().front()));
+ aResult &= mySceneMaxPointTexture->Init (myGlContext, 4, GLsizei (aBVH->MaxPointBuffer().size()),
+ reinterpret_cast<const GLfloat*> (&aBVH->MaxPointBuffer().front()));
}
-
if (!aResult)
{
#ifdef RAY_TRACE_PRINT_INFO
return Standard_False;
}
+ /////////////////////////////////////////////////////////////////////////////
+ // Write transform buffer
+
+ BVH_Mat4f* aNodeTransforms = new BVH_Mat4f[myRaytraceGeometry.Size()];
+ BVH_Mat4f anIdentity;
+
+ for (Standard_Integer anElemIndex = 0; anElemIndex < myRaytraceGeometry.Size(); ++anElemIndex)
+ {
+ OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
+ myRaytraceGeometry.Objects().ChangeValue (anElemIndex).operator->());
+
+ const BVH_Transform<Standard_ShortReal, 4>* aTransform =
+ dynamic_cast<const BVH_Transform<Standard_ShortReal, 4>* > (aTriangleSet->Properties().operator->());
+
+ Standard_ASSERT_RETURN (aTransform != NULL,
+ "OpenGl_TriangleSet does not contain transform", Standard_False);
+
+ aNodeTransforms[anElemIndex] = aTransform->Inversed();
+
+ }
+
+ aResult &= mySceneTransformTexture->Init (myGlContext, 4,
+ myRaytraceGeometry.Size() * 4, reinterpret_cast<const GLfloat*> (aNodeTransforms));
+
+ delete[] aNodeTransforms;
+
+ /////////////////////////////////////////////////////////////////////////////
+ // Write geometry and bottom-level BVH buffers
+
Standard_Size aTotalVerticesNb = 0;
Standard_Size aTotalElementsNb = 0;
Standard_Size aTotalBVHNodesNb = 0;
if (aTotalBVHNodesNb != 0)
{
- aResult &= myObjectNodeInfoTexture->Init (
- myGlContext, 4, aTotalBVHNodesNb, static_cast<const GLuint*> (NULL));
-
- aResult &= myObjectMinPointTexture->Init (
- myGlContext, 4, aTotalBVHNodesNb, static_cast<const GLfloat*> (NULL));
-
- aResult &= myObjectMaxPointTexture->Init (
- myGlContext, 4, aTotalBVHNodesNb, static_cast<const GLfloat*> (NULL));
+ aResult &= myObjectNodeInfoTexture->Init (myGlContext, 4, GLsizei (aTotalBVHNodesNb), static_cast<const GLuint*> (NULL));
+ aResult &= myObjectMinPointTexture->Init (myGlContext, 4, GLsizei (aTotalBVHNodesNb), static_cast<const GLfloat*> (NULL));
+ aResult &= myObjectMaxPointTexture->Init (myGlContext, 4, GLsizei (aTotalBVHNodesNb), static_cast<const GLfloat*> (NULL));
}
if (!aResult)
if (aTotalElementsNb != 0)
{
- aResult &= myGeometryTriangTexture->Init (
- myGlContext, 4, aTotalElementsNb, static_cast<const GLuint*> (NULL));
+ aResult &= myGeometryTriangTexture->Init (myGlContext, 4, GLsizei (aTotalElementsNb), static_cast<const GLuint*> (NULL));
}
if (aTotalVerticesNb != 0)
{
- aResult &= myGeometryVertexTexture->Init (
- myGlContext, 4, aTotalVerticesNb, static_cast<const GLfloat*> (NULL));
-
- aResult &= myGeometryNormalTexture->Init (
- myGlContext, 4, aTotalVerticesNb, static_cast<const GLfloat*> (NULL));
+ aResult &= myGeometryVertexTexture->Init (myGlContext, 4, GLsizei (aTotalVerticesNb), static_cast<const GLfloat*> (NULL));
+ aResult &= myGeometryNormalTexture->Init (myGlContext, 4, GLsizei (aTotalVerticesNb), static_cast<const GLfloat*> (NULL));
}
if (!aResult)
if (aBVHBuffserSize != 0)
{
- aResult &= myObjectNodeInfoTexture->SubData (myGlContext, aBVHOffset,
- aBVHBuffserSize, reinterpret_cast<const GLuint*> (&aTriangleSet->BVH()->NodeInfoBuffer().front()));
-
- aResult &= myObjectMinPointTexture->SubData (myGlContext, aBVHOffset,
- aBVHBuffserSize, reinterpret_cast<const GLfloat*> (&aTriangleSet->BVH()->MinPointBuffer().front()));
-
- aResult &= myObjectMaxPointTexture->SubData (myGlContext, aBVHOffset,
- aBVHBuffserSize, reinterpret_cast<const GLfloat*> (&aTriangleSet->BVH()->MaxPointBuffer().front()));
-
+ aResult &= myObjectNodeInfoTexture->SubData (myGlContext, aBVHOffset, GLsizei (aBVHBuffserSize),
+ reinterpret_cast<const GLuint*> (&aTriangleSet->BVH()->NodeInfoBuffer().front()));
+ aResult &= myObjectMinPointTexture->SubData (myGlContext, aBVHOffset, GLsizei (aBVHBuffserSize),
+ reinterpret_cast<const GLfloat*> (&aTriangleSet->BVH()->MinPointBuffer().front()));
+ aResult &= myObjectMaxPointTexture->SubData (myGlContext, aBVHOffset, GLsizei (aBVHBuffserSize),
+ reinterpret_cast<const GLfloat*> (&aTriangleSet->BVH()->MaxPointBuffer().front()));
if (!aResult)
{
#ifdef RAY_TRACE_PRINT_INFO
if (!aTriangleSet->Vertices.empty())
{
- aResult &= myGeometryNormalTexture->SubData (myGlContext, aVerticesOffset,
- aTriangleSet->Normals.size(), reinterpret_cast<const GLfloat*> (&aTriangleSet->Normals.front()));
-
- aResult &= myGeometryVertexTexture->SubData (myGlContext, aVerticesOffset,
- aTriangleSet->Vertices.size(), reinterpret_cast<const GLfloat*> (&aTriangleSet->Vertices.front()));
+ aResult &= myGeometryNormalTexture->SubData (myGlContext, aVerticesOffset, GLsizei (aTriangleSet->Normals.size()),
+ reinterpret_cast<const GLfloat*> (&aTriangleSet->Normals.front()));
+ aResult &= myGeometryVertexTexture->SubData (myGlContext, aVerticesOffset, GLsizei (aTriangleSet->Vertices.size()),
+ reinterpret_cast<const GLfloat*> (&aTriangleSet->Vertices.front()));
}
const Standard_Integer anElementsOffset = myRaytraceGeometry.ElementsOffset (aNodeIdx);
if (!aTriangleSet->Elements.empty())
{
- aResult &= myGeometryTriangTexture->SubData (myGlContext, anElementsOffset,
- aTriangleSet->Elements.size(), reinterpret_cast<const GLuint*> (&aTriangleSet->Elements.front()));
+ aResult &= myGeometryTriangTexture->SubData (myGlContext, anElementsOffset, GLsizei (aTriangleSet->Elements.size()),
+ reinterpret_cast<const GLuint*> (&aTriangleSet->Elements.front()));
}
if (!aResult)
if (myRaytraceGeometry.Materials.size() != 0)
{
const GLfloat* aDataPtr = myRaytraceGeometry.Materials.front().Packed();
-
- aResult &= myRaytraceMaterialTexture->Init (
- myGlContext, 4, myRaytraceGeometry.Materials.size() * 7, aDataPtr);
-
+ aResult &= myRaytraceMaterialTexture->Init (myGlContext, 4, GLsizei (myRaytraceGeometry.Materials.size() * 7), aDataPtr);
if (!aResult)
{
#ifdef RAY_TRACE_PRINT_INFO
{
NCollection_Mat4<GLdouble> aInvModelProj;
- // compute invserse model-view-projection matrix
+ // compute inverse model-view-projection matrix
(theViewMapping * theOrientation).Inverted (aInvModelProj);
Standard_Integer aOriginIndex = 0;
myGeometryTriangTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTriangTexture);
myRaytraceMaterialTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceMaterialTexture);
myRaytraceLightSrcTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceLightSrcTexture);
+ mySceneTransformTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneTransformTexture);
- if (theCView.IsAntialiasingEnabled) // render source image to FBO
+ if (theCView.RenderParams.IsAntialiasingEnabled) // render source image to FBO
{
myRaytraceFBO1->BindBuffer (myGlContext);
myRaytraceProgram->SetUniform (myGlContext,
myUniformLocations[0][OpenGl_RT_uLightAmbnt], myRaytraceGeometry.Ambient);
myRaytraceProgram->SetUniform (myGlContext,
- myUniformLocations[0][OpenGl_RT_uShadEnabled], theCView.IsShadowsEnabled);
+ myUniformLocations[0][OpenGl_RT_uShadEnabled], theCView.RenderParams.IsShadowEnabled ? 1 : 0);
myRaytraceProgram->SetUniform (myGlContext,
- myUniformLocations[0][OpenGl_RT_uReflEnabled], theCView.IsReflectionsEnabled);
+ myUniformLocations[0][OpenGl_RT_uReflEnabled], theCView.RenderParams.IsReflectionEnabled ? 1 : 0);
myGlContext->core20fwd->glEnableVertexAttribArray (
myUniformLocations[0][OpenGl_RT_aPosition]);
myGlContext->core20fwd->glDisableVertexAttribArray (
myUniformLocations[0][OpenGl_RT_aPosition]);
- if (!theCView.IsAntialiasingEnabled)
+ if (!theCView.RenderParams.IsAntialiasingEnabled)
{
myRaytraceProgram->Unbind (myGlContext);
return Standard_True;
}
- myGlContext->core20fwd->glActiveTexture (
- GL_TEXTURE0 + OpenGl_RT_FSAAInputTexture); // texture unit for FBO texture
-
- myRaytraceFBO1->BindTexture (myGlContext);
+ myRaytraceFBO1->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + OpenGl_RT_FSAAInputTexture);
myPostFSAAProgram->Bind (myGlContext);
myPostFSAAProgram->SetUniform (myGlContext,
myUniformLocations[1][OpenGl_RT_uLightAmbnt], myRaytraceGeometry.Ambient);
myPostFSAAProgram->SetUniform (myGlContext,
- myUniformLocations[1][OpenGl_RT_uShadEnabled], theCView.IsShadowsEnabled);
+ myUniformLocations[1][OpenGl_RT_uShadEnabled], theCView.RenderParams.IsShadowEnabled ? 1 : 0);
myPostFSAAProgram->SetUniform (myGlContext,
- myUniformLocations[1][OpenGl_RT_uReflEnabled], theCView.IsReflectionsEnabled);
+ myUniformLocations[1][OpenGl_RT_uReflEnabled], theCView.RenderParams.IsReflectionEnabled ? 1 : 0);
const Standard_ShortReal aMaxOffset = 0.559017f;
const Standard_ShortReal aMinOffset = 0.186339f;
myUniformLocations[1][OpenGl_RT_aPosition], 3, GL_FLOAT, GL_FALSE, 0, NULL);
// Perform multi-pass adaptive FSAA using ping-pong technique
+ // rotated grid AA always uses 4 samples
for (Standard_Integer anIt = 0; anIt < 4; ++anIt)
{
GLfloat aOffsetX = 1.f / theSizeX;
if (anIt != 3) // set input for the next pass
{
- aFramebuffer->BindTexture (myGlContext);
+ aFramebuffer->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + OpenGl_RT_FSAAInputTexture);
aFramebuffer->UnbindBuffer (myGlContext);
}
}
const Standard_Boolean theToSwap,
OpenGl_FrameBuffer* theFrameBuffer)
{
- if (!UpdateRaytraceGeometry (Standard_True))
+ if (!UpdateRaytraceGeometry (OpenGl_GUM_CHECK))
return Standard_False;
- if (!InitRaytraceResources())
+ if (!InitRaytraceResources (theCView))
return Standard_False;
if (!ResizeRaytraceBuffers (theSizeX, theSizeY))
aOrigins,
aDirects);
- // Draw background
- glPushAttrib (GL_ENABLE_BIT |
- GL_CURRENT_BIT |
- GL_COLOR_BUFFER_BIT |
- GL_DEPTH_BUFFER_BIT);
+ Standard_Boolean wasBlendingEnabled = glIsEnabled (GL_BLEND);
+ Standard_Boolean wasDepthTestEnabled = glIsEnabled (GL_DEPTH_TEST);
glDisable (GL_DEPTH_TEST);
myRaytraceScreenQuad.Unbind (myGlContext);
}
- if (theFrameBuffer != NULL)
- theFrameBuffer->UnbindBuffer (myGlContext);
+ if (!wasBlendingEnabled)
+ glDisable (GL_BLEND);
- glPopAttrib();
+ if (wasDepthTestEnabled)
+ glEnable (GL_DEPTH_TEST);
// Swap the buffers
if (theToSwap)