From: duv Date: Fri, 11 Jul 2014 12:39:29 +0000 (+0400) Subject: 0025017: Visualization - materials in Raytracing are messed up X-Git-Tag: V6_8_0_beta~206 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=8d3f219f5da131f77fb3abb991b1d863ce3dd8c9;p=occt-copy.git 0025017: Visualization - materials in Raytracing are messed up --- diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index 32ac3acb79..d2b8ea5eac 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -335,11 +335,16 @@ private: public: + //! State counter for OpenGl structures. OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; } + //! Returns unique ID for primitive arrays. + const Standard_Size GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); } + private: - mutable OpenGl_StateCounter myStateCounter; + mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures. + mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays. }; diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index 6872137fd7..c177cde377 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -195,7 +195,10 @@ void OpenGl_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theTy return; } - OpenGl_PrimitiveArray* anArray = new OpenGl_PrimitiveArray (theType, theIndices, theAttribs, theBounds); + OpenGl_Structure* aStruct = GlStruct(); + const OpenGl_GraphicDriver* aDriver = aStruct->GlDriver(); + + OpenGl_PrimitiveArray* anArray = new OpenGl_PrimitiveArray (aDriver, theType, theIndices, theAttribs, theBounds); AddElement (anArray); Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax); diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index bcb90ab13a..f9da821842 100755 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -707,15 +707,18 @@ void OpenGl_PrimitiveArray::DrawMarkers (const Handle(OpenGl_Workspace)& theWork // function : OpenGl_PrimitiveArray // purpose : // ======================================================================= -OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType, +OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver, + const Graphic3d_TypeOfPrimitiveArray theType, const Handle(Graphic3d_IndexBuffer)& theIndices, const Handle(Graphic3d_Buffer)& theAttribs, const Handle(Graphic3d_BoundBuffer)& theBounds) + : myIndices (theIndices), myAttribs (theAttribs), myBounds (theBounds), myDrawMode (DRAW_MODE_NONE), - myIsVboInit (Standard_False) + myIsVboInit (Standard_False), + myUID (theDriver->GetNextPrimitiveArrayUID()) { if (!myIndices.IsNull() && myIndices->NbElements < 1) diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index 581e5af384..1f930fa3c3 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -27,6 +27,8 @@ #include +class OpenGl_GraphicDriver; + class OpenGl_PrimitiveArray : public OpenGl_Element { public: @@ -39,7 +41,8 @@ public: }; //! Default constructor - OpenGl_PrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType, + OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver, + const Graphic3d_TypeOfPrimitiveArray theType, const Handle(Graphic3d_IndexBuffer)& theIndices, const Handle(Graphic3d_Buffer)& theAttribs, const Handle(Graphic3d_BoundBuffer)& theBounds); @@ -61,6 +64,9 @@ public: //! @return bounds array const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; } + //! Returns unique ID of primitive array. + const Standard_Size GetUID() const { return myUID; } + private: //! VBO initialization procedures @@ -98,6 +104,8 @@ protected: GLint myDrawMode; mutable Standard_Boolean myIsVboInit; + Standard_Size myUID; //!< Unique ID of primitive array. + public: DEFINE_STANDARD_ALLOC diff --git a/src/OpenGl/OpenGl_SceneGeometry.hxx b/src/OpenGl/OpenGl_SceneGeometry.hxx index 58e2e02a87..97390a706b 100755 --- a/src/OpenGl/OpenGl_SceneGeometry.hxx +++ b/src/OpenGl/OpenGl_SceneGeometry.hxx @@ -135,9 +135,9 @@ public: public: //! Creates new OpenGL element triangulation. - OpenGl_TriangleSet (const OpenGl_PrimitiveArray* theArray = NULL) + OpenGl_TriangleSet (const Standard_Size theArrayID) : BVH_Triangulation(), - myArray (theArray) + myArrayID (theArrayID) { // } @@ -148,10 +148,10 @@ public: // } - //! Returns associated OpenGl structure. - const OpenGl_PrimitiveArray* AssociatedPArray() const + //! Returns Id of associated primitive array. + const Standard_Size AssociatedPArrayID() const { - return myArray; + return myArrayID; } //! Returns material index of triangle set. @@ -192,7 +192,7 @@ public: private: - const OpenGl_PrimitiveArray* myArray; //!< Reference to associated OpenGl structure. + Standard_Size myArrayID; //!< Id of associated primitive array. }; diff --git a/src/OpenGl/OpenGl_Workspace.hxx b/src/OpenGl/OpenGl_Workspace.hxx index f9d848de24..d122e43e34 100755 --- a/src/OpenGl/OpenGl_Workspace.hxx +++ b/src/OpenGl/OpenGl_Workspace.hxx @@ -629,7 +629,7 @@ protected: //! @name fields related to ray-tracing std::map myStructureStates; //! PrimitiveArray to TriangleSet map for scene partial update. - std::map myArrayToTrianglesMap; + std::map myArrayToTrianglesMap; //! Cached locations of frequently used uniform variables. Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables]; diff --git a/src/OpenGl/OpenGl_Workspace_Raytrace.cxx b/src/OpenGl/OpenGl_Workspace_Raytrace.cxx index dbc45f8889..f336ac9ed7 100755 --- a/src/OpenGl/OpenGl_Workspace_Raytrace.cxx +++ b/src/OpenGl/OpenGl_Workspace_Raytrace.cxx @@ -86,7 +86,7 @@ Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (GeomUpdateMode theMod std::set anElements; // Set of all currently visible and "raytracable" primitive arrays. - std::set anArrays; + std::set anArrayIDs; const OpenGl_LayerList& aList = myView->LayerList(); @@ -132,7 +132,7 @@ Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (GeomUpdateMode theMod if (aPrimArray != NULL) { // Collect all primitive arrays in scene. - anArrays.insert (aPrimArray); + anArrayIDs.insert (aPrimArray->GetUID()); } } } @@ -176,11 +176,11 @@ Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (GeomUpdateMode theMod // 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())) + if ((aTriangleSet != NULL) && ((anArrayIDs.find (aTriangleSet->AssociatedPArrayID())) != anArrayIDs.end())) { anUnchangedObjects.Append (myRaytraceGeometry.Objects().Value (anObjectIdx)); - myArrayToTrianglesMap[aTriangleSet->AssociatedPArray()] = aTriangleSet; + myArrayToTrianglesMap[aTriangleSet->AssociatedPArrayID()] = aTriangleSet; } } @@ -375,10 +375,10 @@ Standard_Boolean OpenGl_Workspace::AddRaytraceStructure (const OpenGl_Structure* { OpenGl_PrimitiveArray* aPrimArray = dynamic_cast (aNode->elem); - std::map::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray); - if (aPrimArray != NULL) { + std::map::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray->GetUID()); + if (aSetIter != myArrayToTrianglesMap.end()) { OpenGl_TriangleSet* aSet = aSetIter->second; @@ -480,7 +480,7 @@ OpenGl_TriangleSet* OpenGl_Workspace::AddRaytracePrimitiveArray (const OpenGl_Pr } #endif - OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray); + OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray->GetUID()); { aSet->Vertices.reserve (anAttribs->NbElements); aSet->Normals .reserve (anAttribs->NbElements);