Coding - Optimize container usage and add regression GTests (#1102)

Refactor several hot paths in TKBO/TKOffset/TKOpenGl to reduce redundant
lookups/copies and align containers with OCCT collection types.

Changes:
- TKBO:
  - Switch BOPTools_Set storage from NCollection_List to NCollection_Vector.
  - Replace unsafe C-style edge cast with TopoDS::Edge().
  - Apply small lookup/copy optimizations in BOPAlgo_Builder and
    BOPAlgo_PaveFiller (Seek() usage, const refs, reduced temporaries).
- TKOffset:
  - Reduce repeated vertex/tolerance extraction in BRepOffset_Inter2d.
  - Cache MinLoc transformation in ExtentEdge().
- TKMesh:
  - Simplify IMeshData_Face surface adaptor initialization.
  - Add BRepMesh_FaceChecker_Test and register it in GTests/FILES.cmake.
- TKOpenGl:
  - Replace std::map/std::set with NCollection_DataMap/NCollection_Map in
    ray-tracing scene update state.
  - Simplify texture transform and shader prefix string construction.
  - Add OpenGl_View_Raytrace_TextureTransform_Test and register it in
    GTests/FILES.cmake.
This commit is contained in:
Pasukhin Dmitry
2026-02-20 22:36:43 +00:00
committed by GitHub
parent e384f0bb93
commit 82303a99a3
9 changed files with 128 additions and 158 deletions
@@ -586,11 +586,19 @@ void BOPAlgo_Builder::BuildBOP(const NCollection_List<TopoDS_Shape>& theObjects,
NCollection_List<TopoDS_Shape>::Iterator itLFIm(*pLFIm);
for (; itLFIm.More(); itLFIm.Next())
{
TopoDS_Face aFIm = TopoDS::Face(itLFIm.Value());
if (BOPTools_AlgoTools::IsSplitToReverse(aFIm, aF, myContext))
const TopoDS_Face& aFImRef = TopoDS::Face(itLFIm.Value());
if (BOPTools_AlgoTools::IsSplitToReverse(aFImRef, aF, myContext))
{
TopoDS_Face aFIm = aFImRef;
aFIm.Reverse();
aMapOri.Add(aFIm);
aMap.Add(aFIm);
aMapOri.Add(aFIm);
aMap.Add(aFIm);
}
else
{
aMapOri.Add(aFImRef);
aMap.Add(aFImRef);
}
}
}
else
@@ -647,7 +655,7 @@ void BOPAlgo_Builder::BuildBOP(const NCollection_List<TopoDS_Shape>& theObjects,
const int aNbF = aMap.Extent();
for (int j = 1; j <= aNbF; ++j)
{
TopoDS_Shape aFIm = aMap(j);
const TopoDS_Shape& aFIm = aMap(j);
bool isIN = anINMap.Contains(aFIm);
bool isINOpposite = anOppositeINMap.Contains(aFIm);
@@ -783,7 +791,7 @@ void BOPAlgo_Builder::BuildBOP(const NCollection_List<TopoDS_Shape>& theObjects,
// Add faces of the block to the shell
TopExp_Explorer anExpF(aCB, TopAbs_FACE);
for (; anExpF.More(); anExpF.Next())
aBB.Add(aShell, TopoDS::Face(anExpF.Current()));
aBB.Add(aShell, anExpF.Current());
BOPTools_AlgoTools::OrientFacesOnShell(aShell);
// Make solid out of the shell
@@ -46,6 +46,9 @@
#include <Standard_Real.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopoDS_Shape.hxx>
#include <utility>
class IntTools_Context;
class BOPDS_PaveBlock;
class gp_Pnt;
@@ -120,6 +123,9 @@ public:
//! Sets the arguments for operation
void SetArguments(const NCollection_List<TopoDS_Shape>& theLS) { myArguments = theLS; }
//! Sets the arguments for operation (move semantics)
void SetArguments(NCollection_List<TopoDS_Shape>&& theLS) { myArguments = std::move(theLS); }
//! Adds the argument for operation
void AddArgument(const TopoDS_Shape& theShape) { myArguments.Append(theShape); }
@@ -4066,7 +4066,8 @@ void BOPAlgo_PaveFiller::CorrectToleranceOfSE()
//
const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
double aTolV = BRep_Tool::Tolerance(aV);
double aMaxTol = aMVITol.IsBound(nV) ? aMVITol.Find(nV) : 0.;
const double* pMaxTol = aMVITol.Seek(nV);
double aMaxTol = pMaxTol ? *pMaxTol : 0.;
// it makes no sense to compute the real tolerance if it is
// impossible to reduce the tolerance at least 0.1% of the current value
if (aTolV - aMaxTol < 0.001 * aTolV)
@@ -15,6 +15,7 @@
#include <BOPTools_Set.hxx>
#include <BRep_Tool.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Shape.hxx>
#include <TopTools_ShapeMapHasher.hxx>
@@ -26,7 +27,7 @@ static size_t NormalizedIds(const size_t aId, const int aDiv);
BOPTools_Set::BOPTools_Set()
: myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
myShapes(myAllocator)
myShapes(256, myAllocator)
{
myNbShapes = 0;
mySum = 0;
@@ -37,7 +38,7 @@ BOPTools_Set::BOPTools_Set()
BOPTools_Set::BOPTools_Set(const occ::handle<NCollection_BaseAllocator>& theAllocator)
: myAllocator(theAllocator),
myShapes(myAllocator)
myShapes(256, myAllocator)
{
myNbShapes = 0;
mySum = 0;
@@ -48,16 +49,12 @@ BOPTools_Set::BOPTools_Set(const occ::handle<NCollection_BaseAllocator>& theAllo
BOPTools_Set::BOPTools_Set(const BOPTools_Set& theOther)
: myAllocator(theOther.myAllocator),
myShapes(theOther.myShapes),
myShape(theOther.myShape),
myNbShapes(theOther.myNbShapes),
mySum(theOther.mySum),
myUpper(theOther.myUpper)
{
for (NCollection_List<TopoDS_Shape>::Iterator aIt(theOther.myShapes); aIt.More(); aIt.Next())
{
const TopoDS_Shape& aShape = aIt.Value();
myShapes.Append(aShape);
}
}
//=================================================================================================
@@ -87,21 +84,12 @@ int BOPTools_Set::NbShapes() const
BOPTools_Set& BOPTools_Set::Assign(const BOPTools_Set& theOther)
{
NCollection_List<TopoDS_Shape>::Iterator aIt;
//
myShape = theOther.myShape;
myNbShapes = theOther.myNbShapes;
mySum = theOther.mySum;
myUpper = theOther.myUpper;
myAllocator = theOther.myAllocator;
//
myShapes.Clear();
aIt.Initialize(theOther.myShapes);
for (; aIt.More(); aIt.Next())
{
const TopoDS_Shape& aSx = aIt.Value();
myShapes.Append(aSx);
}
myShapes = theOther.myShapes;
return *this;
}
@@ -116,36 +104,27 @@ const TopoDS_Shape& BOPTools_Set::Shape() const
bool BOPTools_Set::IsEqual(const BOPTools_Set& theOther) const
{
bool bRet;
//
bRet = false;
//
if (theOther.myNbShapes != myNbShapes)
{
return bRet;
return false;
}
//
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aM1;
NCollection_List<TopoDS_Shape>::Iterator aIt;
//
aIt.Initialize(myShapes);
for (; aIt.More(); aIt.Next())
for (int i = 0; i < myShapes.Size(); ++i)
{
const TopoDS_Shape& aSx1 = aIt.Value();
aM1.Add(aSx1);
aM1.Add(myShapes(i));
}
//
aIt.Initialize(theOther.myShapes);
for (; aIt.More(); aIt.Next())
for (int i = 0; i < theOther.myShapes.Size(); ++i)
{
const TopoDS_Shape& aSx2 = aIt.Value();
if (!aM1.Contains(aSx2))
if (!aM1.Contains(theOther.myShapes(i)))
{
return bRet;
return false;
}
}
//
return !bRet;
return true;
}
//=================================================================================================
@@ -167,7 +146,7 @@ void BOPTools_Set::Add(const TopoDS_Shape& theS, const TopAbs_ShapeEnum theType)
const TopoDS_Shape& aSx = aExp.Current();
if (theType == TopAbs_EDGE)
{
const TopoDS_Edge& aEx = *((TopoDS_Edge*)&aSx);
const TopoDS_Edge& aEx = TopoDS::Edge(aSx);
if (BRep_Tool::Degenerated(aEx))
{
continue;
@@ -193,18 +172,15 @@ void BOPTools_Set::Add(const TopoDS_Shape& theS, const TopAbs_ShapeEnum theType)
}
}
//
myNbShapes = myShapes.Extent();
myNbShapes = myShapes.Size();
if (!myNbShapes)
{
return;
}
//
NCollection_List<TopoDS_Shape>::Iterator aIt;
//
aIt.Initialize(myShapes);
for (; aIt.More(); aIt.Next())
for (int i = 0; i < myShapes.Size(); ++i)
{
const TopoDS_Shape& aSx = aIt.Value();
const TopoDS_Shape& aSx = myShapes(i);
aId = TopTools_ShapeMapHasher{}(aSx) % myUpper + 1;
aIdN = NormalizedIds(aId, myNbShapes);
mySum += aIdN;
@@ -22,7 +22,7 @@
#include <TopoDS_Shape.hxx>
#include <Standard_Integer.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <NCollection_List.hxx>
#include <NCollection_Vector.hxx>
class BOPTools_Set
{
@@ -57,7 +57,7 @@ protected:
Standard_EXPORT void Clear();
occ::handle<NCollection_BaseAllocator> myAllocator;
NCollection_List<TopoDS_Shape> myShapes;
NCollection_Vector<TopoDS_Shape> myShapes;
TopoDS_Shape myShape;
int myNbShapes;
size_t mySum;
@@ -66,8 +66,7 @@ protected:
IMeshData_Face(const TopoDS_Face& theFace)
: IMeshData_TessellatedShape(theFace)
{
BRepAdaptor_Surface aSurfAdaptor(GetFace(), false);
mySurface = new BRepAdaptor_Surface(aSurfAdaptor);
mySurface = new BRepAdaptor_Surface(GetFace(), false);
}
private:
@@ -608,7 +608,6 @@ static void EdgeInter(
// There can be doubles
//----------------------------------
NCollection_List<TopoDS_Shape>::Iterator it1LV1, it1LV2, it2LV1;
gp_Pnt P1, P2;
bool Purge = true;
while (Purge)
@@ -618,21 +617,19 @@ static void EdgeInter(
for (it1LV1.Initialize(LV1), it1LV2.Initialize(LV2); it1LV1.More();
it1LV1.Next(), it1LV2.Next())
{
const TopoDS_Vertex& aV1 = TopoDS::Vertex(it1LV1.Value());
const gp_Pnt P1 = BRep_Tool::Pnt(aV1);
const double aTol1 = BRep_Tool::Tolerance(aV1);
j = 1;
it2LV1.Initialize(LV1);
while (j < i)
{
P1 = BRep_Tool::Pnt(TopoDS::Vertex(it1LV1.Value()));
P2 = BRep_Tool::Pnt(TopoDS::Vertex(it2LV1.Value()));
// Modified by skv - Thu Jan 22 18:19:04 2004 OCC4455 Begin
// if (P1.IsEqual(P2,10*Tol)) {
double aTol;
aTol = std::max(BRep_Tool::Tolerance(TopoDS::Vertex(it1LV1.Value())),
BRep_Tool::Tolerance(TopoDS::Vertex(it2LV1.Value())));
const TopoDS_Vertex& aV2 = TopoDS::Vertex(it2LV1.Value());
const gp_Pnt P2 = BRep_Tool::Pnt(aV2);
const double aTol = std::max(aTol1, BRep_Tool::Tolerance(aV2));
if (P1.IsEqual(P2, aTol))
{
// Modified by skv - Thu Jan 22 18:19:05 2004 OCC4455 End
LV1.Remove(it1LV1);
LV2.Remove(it1LV2);
if (AffichPurge)
@@ -1321,14 +1318,15 @@ bool BRepOffset_Inter2d::ExtentEdge(const TopoDS_Edge& E, TopoDS_Edge& NE, const
l -= 0.05 * (l - f);
else
{
f = FirstParOnPC;
l = LastParOnPC;
f = FirstParOnPC;
l = LastParOnPC;
const gp_Trsf aMinLocTrsf = MinLoc.Transformation();
GeomAPI_ProjectPointOnCurve Projector;
if (!Precision::IsInfinite(FirstParOnPC))
{
gp_Pnt2d P2d1 = MinPC->Value(FirstParOnPC);
gp_Pnt P1 = MinSurf->Value(P2d1.X(), P2d1.Y());
P1.Transform(MinLoc.Transformation());
P1.Transform(aMinLocTrsf);
Projector.Init(P1, C3d);
if (Projector.NbPoints() > 0)
f = Projector.LowerDistanceParameter();
@@ -1341,7 +1339,7 @@ bool BRepOffset_Inter2d::ExtentEdge(const TopoDS_Edge& E, TopoDS_Edge& NE, const
{
gp_Pnt2d P2d2 = MinPC->Value(LastParOnPC);
gp_Pnt P2 = MinSurf->Value(P2d2.X(), P2d2.Y());
P2.Transform(MinLoc.Transformation());
P2.Transform(aMinLocTrsf);
Projector.Init(P2, C3d);
if (Projector.NbPoints() > 0)
l = Projector.LowerDistanceParameter();
@@ -29,8 +29,8 @@
#include <OpenGl_TileSampler.hxx>
#include <TCollection_AsciiString.hxx>
#include <map>
#include <set>
#include <NCollection_DataMap.hxx>
#include <NCollection_Map.hxx>
class OpenGl_BackgroundArray;
class OpenGl_DepthPeeling;
@@ -1063,13 +1063,13 @@ protected: //! @name fields related to ray-tracing
int myUniformLocations[2][OpenGl_RT_NbVariables];
//! State of OpenGL structures reflected to ray-tracing.
std::map<const OpenGl_Structure*, StructState> myStructureStates;
NCollection_DataMap<const OpenGl_Structure*, StructState> myStructureStates;
//! PrimitiveArray to TriangleSet map for scene partial update.
std::map<size_t, OpenGl_TriangleSet*> myArrayToTrianglesMap;
NCollection_DataMap<size_t, OpenGl_TriangleSet*> myArrayToTrianglesMap;
//! Set of IDs of non-raytracable elements (to detect updates).
std::set<int> myNonRaytraceStructureIDs;
NCollection_Map<int> myNonRaytraceStructureIDs;
//! Marks if environment map should be updated.
bool myToUpdateEnvironmentMap;
@@ -26,6 +26,8 @@
#include <OpenGl_GlCore44.hxx>
#include <OSD_Protection.hxx>
#include <OSD_File.hxx>
#include <NCollection_MapAlgo.hxx>
#include <NCollection_Vector.hxx>
#include "../../TKService/Shaders/Shaders_RaytraceBase_vs.pxx"
#include "../../TKService/Shaders/Shaders_RaytraceBase_fs.pxx"
@@ -87,7 +89,7 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
{
myRaytraceGeometry.ClearMaterials();
myArrayToTrianglesMap.clear();
myArrayToTrianglesMap.Clear();
myIsRaytraceDataValid = false;
}
@@ -95,15 +97,15 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
// 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;
NCollection_Map<const OpenGl_Structure*> anElements;
// Set to store all currently visible OpenGL primitive arrays
// applicable for ray-tracing
std::set<size_t> anArrayIDs;
NCollection_Map<size_t> anArrayIDs;
// Set to store all non-raytracable elements allowing tracking
// of changes in OpenGL scene (only for path tracing)
std::set<int> aNonRaytraceIDs;
NCollection_Map<int> aNonRaytraceIDs;
for (NCollection_List<occ::handle<Graphic3d_Layer>>::Iterator aLayerIter(myZLayers.Layers());
aLayerIter.More();
@@ -135,8 +137,8 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
}
else if (aStructure->IsVisible() && myRaytraceParameters.GlobalIllumination)
{
aNonRaytraceIDs.insert(aStructure->highlight ? aStructure->Identification()
: -aStructure->Identification());
aNonRaytraceIDs.Add(aStructure->highlight ? aStructure->Identification()
: -aStructure->Identification());
}
}
else if (theMode == OpenGl_GUM_PREPARE)
@@ -163,7 +165,7 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
if (aPrimArray != nullptr)
{
anArrayIDs.insert(aPrimArray->GetUID());
anArrayIDs.Add(aPrimArray->GetUID());
}
}
}
@@ -176,7 +178,7 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
}
else if (addRaytraceStructure(aStructure, theGlContext))
{
anElements.insert(aStructure); // structure was processed
anElements.Add(aStructure); // structure was processed
}
}
}
@@ -199,11 +201,11 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
continue;
}
if (anArrayIDs.find(aTriangleSet->AssociatedPArrayID()) != anArrayIDs.end())
if (anArrayIDs.Contains(aTriangleSet->AssociatedPArrayID()))
{
anUnchangedObjects.Append(myRaytraceGeometry.Objects().Value(anObjIdx));
myArrayToTrianglesMap[aTriangleSet->AssociatedPArrayID()] = aTriangleSet;
myArrayToTrianglesMap.Bind(aTriangleSet->AssociatedPArrayID(), aTriangleSet);
}
}
@@ -214,19 +216,24 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
else if (theMode == OpenGl_GUM_REBUILD)
{
// Actualize the hash map of structures - remove out-of-date records
std::map<const OpenGl_Structure*, StructState>::iterator anIter = myStructureStates.begin();
while (anIter != myStructureStates.end())
NCollection_Vector<const OpenGl_Structure*> aKeysToRemove(
myStructureStates.Extent() > 0 ? myStructureStates.Extent() : 1);
for (NCollection_DataMap<const OpenGl_Structure*, StructState>::Iterator anIter(
myStructureStates);
anIter.More();
anIter.Next())
{
if (anElements.find(anIter->first) == anElements.end())
if (!anElements.Contains(anIter.Key()))
{
myStructureStates.erase(anIter++);
}
else
{
++anIter;
aKeysToRemove.Append(anIter.Key());
}
}
for (NCollection_Vector<const OpenGl_Structure*>::Iterator aKeyIter(aKeysToRemove);
aKeyIter.More();
aKeyIter.Next())
{
myStructureStates.UnBind(aKeyIter.Value());
}
// Actualize OpenGL layer list state
myRaytraceLayerListState = myZLayers.ModificationStateOfRaytracable();
@@ -247,24 +254,12 @@ bool OpenGl_View::updateRaytraceGeometry(const RaytraceUpdateMode theM
if (myRaytraceParameters.GlobalIllumination)
{
bool toRestart = aNonRaytraceIDs.size() != myNonRaytraceStructureIDs.size();
for (std::set<int>::iterator anID = aNonRaytraceIDs.begin();
anID != aNonRaytraceIDs.end() && !toRestart;
++anID)
{
if (myNonRaytraceStructureIDs.find(*anID) == myNonRaytraceStructureIDs.end())
{
toRestart = true;
}
}
if (toRestart)
if (!NCollection_MapAlgo::IsEqual(myNonRaytraceStructureIDs, aNonRaytraceIDs))
{
myAccumFrames = 0;
}
myNonRaytraceStructureIDs = aNonRaytraceIDs;
myNonRaytraceStructureIDs.Exchange(aNonRaytraceIDs);
}
return true;
@@ -288,18 +283,15 @@ bool OpenGl_View::toUpdateStructure(const OpenGl_Structure* theStructure)
return false; // did not contain ray-trace elements
}
std::map<const OpenGl_Structure*, StructState>::iterator aStructState =
myStructureStates.find(theStructure);
const StructState* aStructState = myStructureStates.Seek(theStructure);
if (aStructState == myStructureStates.end()
|| aStructState->second.StructureState != theStructure->ModificationState())
if (aStructState == nullptr || aStructState->StructureState != theStructure->ModificationState())
{
return true;
}
else if (theStructure->InstancedStructure() != nullptr)
{
return aStructState->second.InstancedState
!= theStructure->InstancedStructure()->ModificationState();
return aStructState->InstancedState != theStructure->InstancedStructure()->ModificationState();
}
return false;
@@ -319,33 +311,21 @@ void buildTextureTransform(const occ::handle<Graphic3d_TextureParams>& theParams
}
// Apply scaling
const NCollection_Vec2<float>& aScale = theParams->Scale();
const float aScaleX = theParams->Scale().x();
const float aScaleY = theParams->Scale().y();
theMatrix.ChangeValue(0, 0) *= aScale.x();
theMatrix.ChangeValue(1, 0) *= aScale.x();
theMatrix.ChangeValue(2, 0) *= aScale.x();
theMatrix.ChangeValue(3, 0) *= aScale.x();
theMatrix.ChangeValue(0, 1) *= aScale.y();
theMatrix.ChangeValue(1, 1) *= aScale.y();
theMatrix.ChangeValue(2, 1) *= aScale.y();
theMatrix.ChangeValue(3, 1) *= aScale.y();
theMatrix.ChangeValue(0, 0) = aScaleX;
theMatrix.ChangeValue(1, 1) = aScaleY;
// Apply translation
const NCollection_Vec2<float> aTrans = -theParams->Translation();
theMatrix.ChangeValue(0, 3) =
theMatrix.GetValue(0, 0) * aTrans.x() + theMatrix.GetValue(0, 1) * aTrans.y();
theMatrix.ChangeValue(1, 3) =
theMatrix.GetValue(1, 0) * aTrans.x() + theMatrix.GetValue(1, 1) * aTrans.y();
theMatrix.ChangeValue(2, 3) =
theMatrix.GetValue(2, 0) * aTrans.x() + theMatrix.GetValue(2, 1) * aTrans.y();
theMatrix.ChangeValue(0, 3) = aScaleX * aTrans.x();
theMatrix.ChangeValue(1, 3) = aScaleY * aTrans.y();
// Apply rotation
const float aSin = std::sin(-theParams->Rotation() * static_cast<float>(M_PI / 180.0));
const float aCos = std::cos(-theParams->Rotation() * static_cast<float>(M_PI / 180.0));
const float aAngle = -theParams->Rotation() * static_cast<float>(M_PI / 180.0);
const float aSin = std::sin(aAngle);
const float aCos = std::cos(aAngle);
BVH_Mat4f aRotationMat;
aRotationMat.SetValue(0, 0, aCos);
@@ -492,7 +472,7 @@ bool OpenGl_View::addRaytraceStructure(const OpenGl_Structure* theStr
{
if (!theStructure->IsVisible())
{
myStructureStates[theStructure] = StructState(theStructure);
myStructureStates.Bind(theStructure, StructState(theStructure));
return true;
}
@@ -513,7 +493,7 @@ bool OpenGl_View::addRaytraceStructure(const OpenGl_Structure* theStr
theGlContext);
}
myStructureStates[theStructure] = StructState(theStructure);
myStructureStates.Bind(theStructure, StructState(theStructure));
return aResult;
}
@@ -528,6 +508,11 @@ bool OpenGl_View::addRaytraceGroups(const OpenGl_Structure* theStruct
const occ::handle<OpenGl_Context>& theGlContext)
{
NCollection_Mat4<float> aMat4;
const bool hasTrsf = !theTrsf.IsNull();
if (hasTrsf)
{
theTrsf->Trsf().GetMat4(aMat4);
}
for (OpenGl_Structure::GroupIterator aGroupIter(theStructure->Groups()); aGroupIter.More();
aGroupIter.Next())
{
@@ -564,16 +549,14 @@ bool OpenGl_View::addRaytraceGroups(const OpenGl_Structure* theStruct
if (aPrimArray != nullptr)
{
std::map<size_t, OpenGl_TriangleSet*>::iterator aSetIter =
myArrayToTrianglesMap.find(aPrimArray->GetUID());
OpenGl_TriangleSet** aSetPtr = myArrayToTrianglesMap.ChangeSeek(aPrimArray->GetUID());
if (aSetIter != myArrayToTrianglesMap.end())
if (aSetPtr != nullptr)
{
OpenGl_TriangleSet* aSet = aSetIter->second;
OpenGl_TriangleSet* aSet = *aSetPtr;
opencascade::handle<BVH_Transform<float, 4>> aTransform = new BVH_Transform<float, 4>();
if (!theTrsf.IsNull())
if (hasTrsf)
{
theTrsf->Trsf().GetMat4(aMat4);
aTransform->SetTransform(aMat4);
}
@@ -591,9 +574,8 @@ bool OpenGl_View::addRaytraceGroups(const OpenGl_Structure* theStruct
{
opencascade::handle<BVH_Transform<float, 4>> aTransform =
new BVH_Transform<float, 4>();
if (!theTrsf.IsNull())
if (hasTrsf)
{
theTrsf->Trsf().GetMat4(aMat4);
aTransform->SetTransform(aMat4);
}
@@ -1158,54 +1140,54 @@ bool OpenGl_View::ShaderSource::LoadFromStrings(const TCollection_AsciiString* t
TCollection_AsciiString OpenGl_View::generateShaderPrefix(
const occ::handle<OpenGl_Context>& theGlContext) const
{
TCollection_AsciiString aPrefixString = TCollection_AsciiString("#define STACK_SIZE ")
+ TCollection_AsciiString(myRaytraceParameters.StackSize)
+ "\n" + TCollection_AsciiString("#define NB_BOUNCES ")
+ TCollection_AsciiString(myRaytraceParameters.NbBounces);
TCollection_AsciiString aPrefixString("#define STACK_SIZE ");
aPrefixString += TCollection_AsciiString(myRaytraceParameters.StackSize);
aPrefixString += "\n#define NB_BOUNCES ";
aPrefixString += TCollection_AsciiString(myRaytraceParameters.NbBounces);
if (myRaytraceParameters.IsZeroToOneDepth)
{
aPrefixString += TCollection_AsciiString("\n#define THE_ZERO_TO_ONE_DEPTH");
aPrefixString += "\n#define THE_ZERO_TO_ONE_DEPTH";
}
if (myRaytraceParameters.TransparentShadows)
{
aPrefixString += TCollection_AsciiString("\n#define TRANSPARENT_SHADOWS");
aPrefixString += "\n#define TRANSPARENT_SHADOWS";
}
if (!theGlContext->ToRenderSRGB())
{
aPrefixString += TCollection_AsciiString("\n#define THE_SHIFT_sRGB");
aPrefixString += "\n#define THE_SHIFT_sRGB";
}
// If OpenGL driver supports bindless textures and texturing
// is actually used, activate texturing in ray-tracing mode
if (myRaytraceParameters.UseBindlessTextures && theGlContext->arbTexBindless != nullptr)
{
aPrefixString += TCollection_AsciiString("\n#define USE_TEXTURES")
+ TCollection_AsciiString("\n#define MAX_TEX_NUMBER ")
+ TCollection_AsciiString(OpenGl_RaytraceGeometry::MAX_TEX_NUMBER);
aPrefixString += "\n#define USE_TEXTURES";
aPrefixString += "\n#define MAX_TEX_NUMBER ";
aPrefixString += TCollection_AsciiString(OpenGl_RaytraceGeometry::MAX_TEX_NUMBER);
}
if (myRaytraceParameters.GlobalIllumination) // path tracing activated
{
aPrefixString += TCollection_AsciiString("\n#define PATH_TRACING");
aPrefixString += "\n#define PATH_TRACING";
if (myRaytraceParameters.AdaptiveScreenSampling) // adaptive screen sampling requested
{
if (theGlContext->IsGlGreaterEqual(4, 4))
{
aPrefixString += TCollection_AsciiString("\n#define ADAPTIVE_SAMPLING");
aPrefixString += "\n#define ADAPTIVE_SAMPLING";
if (myRaytraceParameters.AdaptiveScreenSamplingAtomic
&& theGlContext->CheckExtension("GL_NV_shader_atomic_float"))
{
aPrefixString += TCollection_AsciiString("\n#define ADAPTIVE_SAMPLING_ATOMIC");
aPrefixString += "\n#define ADAPTIVE_SAMPLING_ATOMIC";
}
}
}
if (myRaytraceParameters.TwoSidedBsdfModels) // two-sided BSDFs requested
{
aPrefixString += TCollection_AsciiString("\n#define TWO_SIDED_BXDF");
aPrefixString += "\n#define TWO_SIDED_BXDF";
}
switch (myRaytraceParameters.ToneMappingMethod)
@@ -1213,24 +1195,24 @@ TCollection_AsciiString OpenGl_View::generateShaderPrefix(
case Graphic3d_ToneMappingMethod_Disabled:
break;
case Graphic3d_ToneMappingMethod_Filmic:
aPrefixString += TCollection_AsciiString("\n#define TONE_MAPPING_FILMIC");
aPrefixString += "\n#define TONE_MAPPING_FILMIC";
break;
}
}
if (myRaytraceParameters.ToIgnoreNormalMap)
{
aPrefixString += TCollection_AsciiString("\n#define IGNORE_NORMAL_MAP");
aPrefixString += "\n#define IGNORE_NORMAL_MAP";
}
if (myRaytraceParameters.CubemapForBack)
{
aPrefixString += TCollection_AsciiString("\n#define BACKGROUND_CUBEMAP");
aPrefixString += "\n#define BACKGROUND_CUBEMAP";
}
if (myRaytraceParameters.DepthOfField)
{
aPrefixString += TCollection_AsciiString("\n#define DEPTH_OF_FIELD");
aPrefixString += "\n#define DEPTH_OF_FIELD";
}
return aPrefixString;