1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0025017: Visualization - materials in Raytracing are messed up

This commit is contained in:
duv 2014-07-11 16:39:29 +04:00 committed by bugmaster
parent 3c64852756
commit 8d3f219f5d
7 changed files with 38 additions and 19 deletions

View File

@ -335,11 +335,16 @@ private:
public: public:
//! State counter for OpenGl structures.
OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; } OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
//! Returns unique ID for primitive arrays.
const Standard_Size GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); }
private: private:
mutable OpenGl_StateCounter myStateCounter; mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
}; };

View File

@ -195,7 +195,10 @@ void OpenGl_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theTy
return; 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); AddElement (anArray);
Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax); Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax);

View File

@ -707,15 +707,18 @@ void OpenGl_PrimitiveArray::DrawMarkers (const Handle(OpenGl_Workspace)& theWork
// function : OpenGl_PrimitiveArray // function : OpenGl_PrimitiveArray
// purpose : // 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_IndexBuffer)& theIndices,
const Handle(Graphic3d_Buffer)& theAttribs, const Handle(Graphic3d_Buffer)& theAttribs,
const Handle(Graphic3d_BoundBuffer)& theBounds) const Handle(Graphic3d_BoundBuffer)& theBounds)
: myIndices (theIndices), : myIndices (theIndices),
myAttribs (theAttribs), myAttribs (theAttribs),
myBounds (theBounds), myBounds (theBounds),
myDrawMode (DRAW_MODE_NONE), myDrawMode (DRAW_MODE_NONE),
myIsVboInit (Standard_False) myIsVboInit (Standard_False),
myUID (theDriver->GetNextPrimitiveArrayUID())
{ {
if (!myIndices.IsNull() if (!myIndices.IsNull()
&& myIndices->NbElements < 1) && myIndices->NbElements < 1)

View File

@ -27,6 +27,8 @@
#include <OpenGl_Element.hxx> #include <OpenGl_Element.hxx>
class OpenGl_GraphicDriver;
class OpenGl_PrimitiveArray : public OpenGl_Element class OpenGl_PrimitiveArray : public OpenGl_Element
{ {
public: public:
@ -39,7 +41,8 @@ public:
}; };
//! Default constructor //! 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_IndexBuffer)& theIndices,
const Handle(Graphic3d_Buffer)& theAttribs, const Handle(Graphic3d_Buffer)& theAttribs,
const Handle(Graphic3d_BoundBuffer)& theBounds); const Handle(Graphic3d_BoundBuffer)& theBounds);
@ -61,6 +64,9 @@ public:
//! @return bounds array //! @return bounds array
const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; } const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; }
//! Returns unique ID of primitive array.
const Standard_Size GetUID() const { return myUID; }
private: private:
//! VBO initialization procedures //! VBO initialization procedures
@ -98,6 +104,8 @@ protected:
GLint myDrawMode; GLint myDrawMode;
mutable Standard_Boolean myIsVboInit; mutable Standard_Boolean myIsVboInit;
Standard_Size myUID; //!< Unique ID of primitive array.
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC

View File

@ -135,9 +135,9 @@ public:
public: public:
//! Creates new OpenGL element triangulation. //! Creates new OpenGL element triangulation.
OpenGl_TriangleSet (const OpenGl_PrimitiveArray* theArray = NULL) OpenGl_TriangleSet (const Standard_Size theArrayID)
: BVH_Triangulation<Standard_ShortReal, 4>(), : BVH_Triangulation<Standard_ShortReal, 4>(),
myArray (theArray) myArrayID (theArrayID)
{ {
// //
} }
@ -148,10 +148,10 @@ public:
// //
} }
//! Returns associated OpenGl structure. //! Returns Id of associated primitive array.
const OpenGl_PrimitiveArray* AssociatedPArray() const const Standard_Size AssociatedPArrayID() const
{ {
return myArray; return myArrayID;
} }
//! Returns material index of triangle set. //! Returns material index of triangle set.
@ -192,7 +192,7 @@ public:
private: private:
const OpenGl_PrimitiveArray* myArray; //!< Reference to associated OpenGl structure. Standard_Size myArrayID; //!< Id of associated primitive array.
}; };

View File

@ -629,7 +629,7 @@ protected: //! @name fields related to ray-tracing
std::map<const OpenGl_Structure*, Standard_Size> myStructureStates; std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
//! PrimitiveArray to TriangleSet map for scene partial update. //! PrimitiveArray to TriangleSet map for scene partial update.
std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*> myArrayToTrianglesMap; std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
//! Cached locations of frequently used uniform variables. //! Cached locations of frequently used uniform variables.
Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables]; Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];

View File

@ -86,7 +86,7 @@ Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (GeomUpdateMode theMod
std::set<const OpenGl_Structure*> anElements; std::set<const OpenGl_Structure*> anElements;
// Set of all currently visible and "raytracable" primitive arrays. // Set of all currently visible and "raytracable" primitive arrays.
std::set<const OpenGl_PrimitiveArray*> anArrays; std::set<Standard_Size> anArrayIDs;
const OpenGl_LayerList& aList = myView->LayerList(); const OpenGl_LayerList& aList = myView->LayerList();
@ -132,7 +132,7 @@ Standard_Boolean OpenGl_Workspace::UpdateRaytraceGeometry (GeomUpdateMode theMod
if (aPrimArray != NULL) if (aPrimArray != NULL)
{ {
// Collect all primitive arrays in scene. // 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 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 // 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. // 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)); 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<OpenGl_PrimitiveArray*> (aNode->elem); OpenGl_PrimitiveArray* aPrimArray = dynamic_cast<OpenGl_PrimitiveArray*> (aNode->elem);
std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*>::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray);
if (aPrimArray != NULL) if (aPrimArray != NULL)
{ {
std::map<Standard_Size, OpenGl_TriangleSet*>::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray->GetUID());
if (aSetIter != myArrayToTrianglesMap.end()) if (aSetIter != myArrayToTrianglesMap.end())
{ {
OpenGl_TriangleSet* aSet = aSetIter->second; OpenGl_TriangleSet* aSet = aSetIter->second;
@ -480,7 +480,7 @@ OpenGl_TriangleSet* OpenGl_Workspace::AddRaytracePrimitiveArray (const OpenGl_Pr
} }
#endif #endif
OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray); OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray->GetUID());
{ {
aSet->Vertices.reserve (anAttribs->NbElements); aSet->Vertices.reserve (anAttribs->NbElements);
aSet->Normals .reserve (anAttribs->NbElements); aSet->Normals .reserve (anAttribs->NbElements);