File indexing completed on 2026-09-16 09:18:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef OpenGl_SceneGeometry_HeaderFile
0017 #define OpenGl_SceneGeometry_HeaderFile
0018
0019 #include <BVH_Geometry.hxx>
0020 #include <BVH_Triangulation.hxx>
0021 #include <BVH_BinnedBuilder.hxx>
0022 #include <NCollection_LinearVector.hxx>
0023 #include <OpenGl_Texture.hxx>
0024 #include <OpenGl_Sampler.hxx>
0025
0026 class OpenGl_Element;
0027 struct OpenGl_ElementNode;
0028 class OpenGl_Group;
0029
0030 namespace OpenGl_Raytrace
0031 {
0032
0033 Standard_EXPORT bool IsRaytracedGroup(const OpenGl_Group* theGroup);
0034
0035
0036 Standard_EXPORT bool IsRaytracedElement(const OpenGl_ElementNode* theNode);
0037
0038
0039 Standard_EXPORT bool IsRaytracedElement(const OpenGl_Element* theElement);
0040 }
0041
0042
0043 struct OpenGl_RaytraceMaterial
0044 {
0045 BVH_Vec4f Ambient;
0046 BVH_Vec4f Diffuse;
0047 BVH_Vec4f Specular;
0048 BVH_Vec4f Emission;
0049 BVH_Vec4f Reflection;
0050 BVH_Vec4f Refraction;
0051 BVH_Vec4f Transparency;
0052 BVH_Mat4f TextureTransform;
0053
0054
0055 struct Physical
0056 {
0057 BVH_Vec4f Kc;
0058 BVH_Vec4f Kd;
0059 BVH_Vec4f Ks;
0060 BVH_Vec4f Kt;
0061 BVH_Vec4f Le;
0062 BVH_Vec4f FresnelCoat;
0063 BVH_Vec4f FresnelBase;
0064 BVH_Vec4f Absorption;
0065 } BSDF;
0066
0067 public:
0068
0069 Standard_EXPORT OpenGl_RaytraceMaterial();
0070
0071
0072 const float* Packed() { return reinterpret_cast<float*>(this); }
0073 };
0074
0075
0076 struct OpenGl_RaytraceLight
0077 {
0078
0079 BVH_Vec4f Emission;
0080 BVH_Vec4f Position;
0081
0082 public:
0083
0084 OpenGl_RaytraceLight() = default;
0085
0086
0087 Standard_EXPORT OpenGl_RaytraceLight(const BVH_Vec4f& theEmission, const BVH_Vec4f& thePosition);
0088
0089
0090 const float* Packed() { return reinterpret_cast<float*>(this); }
0091 };
0092
0093
0094 typedef opencascade::handle<BVH_Tree<float, 3, BVH_QuadTree>> QuadBvhHandle;
0095 typedef BVH_Triangulation<float, 3> OpenGl_BVHTriangulation3f;
0096
0097
0098 class OpenGl_TriangleSet : public OpenGl_BVHTriangulation3f
0099 {
0100 DEFINE_STANDARD_RTTIEXT(OpenGl_TriangleSet, OpenGl_BVHTriangulation3f)
0101 public:
0102
0103 static const int INVALID_MATERIAL = -1;
0104
0105 public:
0106
0107 Standard_EXPORT OpenGl_TriangleSet(const size_t theArrayID,
0108 const opencascade::handle<BVH_Builder<float, 3>>& theBuilder);
0109
0110
0111 size_t AssociatedPArrayID() const { return myArrayID; }
0112
0113
0114 int MaterialIndex() const
0115 {
0116 if (Elements.IsEmpty())
0117 {
0118 return INVALID_MATERIAL;
0119 }
0120
0121 return Elements.First().w();
0122 }
0123
0124
0125 void SetMaterialIndex(int theMatID)
0126 {
0127 for (size_t anIdx = 0; anIdx < Elements.Size(); ++anIdx)
0128 {
0129 Elements[anIdx].w() = theMatID;
0130 }
0131 }
0132
0133
0134 BVH_BoxNt Box() const override;
0135
0136
0137 using BVH_Triangulation<float, 3>::Box;
0138
0139
0140 Standard_EXPORT float Center(const int theIndex, const int theAxis) const override;
0141
0142
0143 Standard_EXPORT const QuadBvhHandle& QuadBVH();
0144
0145 public:
0146 BVH_Array3f Normals;
0147 BVH_Array2f TexCrds;
0148
0149 private:
0150 size_t myArrayID;
0151
0152 QuadBvhHandle myQuadBVH;
0153 };
0154
0155
0156 class OpenGl_RaytraceGeometry : public BVH_Geometry<float, 3>
0157 {
0158 public:
0159
0160 static const int INVALID_OFFSET = -1;
0161
0162
0163
0164
0165
0166 static const int MAX_TEX_NUMBER = 32;
0167
0168 public:
0169
0170 NCollection_LinearVector<OpenGl_RaytraceLight> Sources;
0171
0172
0173 NCollection_LinearVector<OpenGl_RaytraceMaterial> Materials;
0174
0175
0176 BVH_Vec4f Ambient;
0177
0178 public:
0179
0180 OpenGl_RaytraceGeometry()
0181 : myTopLevelTreeDepth(0),
0182 myBotLevelTreeDepth(0)
0183 {
0184
0185 }
0186
0187
0188 ~OpenGl_RaytraceGeometry() override
0189 {
0190
0191 }
0192
0193
0194 void ClearMaterials()
0195 {
0196 Materials.Clear(true);
0197 myTextures.Clear();
0198 }
0199
0200
0201 Standard_EXPORT void Clear() override;
0202
0203 public:
0204
0205 Standard_EXPORT bool ProcessAcceleration();
0206
0207
0208
0209
0210 Standard_EXPORT int AccelerationOffset(int theNodeIdx);
0211
0212
0213
0214
0215 Standard_EXPORT int VerticesOffset(int theNodeIdx);
0216
0217
0218
0219
0220 Standard_EXPORT int ElementsOffset(int theNodeIdx);
0221
0222
0223
0224
0225 Standard_EXPORT OpenGl_TriangleSet* TriangleSet(int theNodeIdx);
0226
0227
0228 Standard_EXPORT const QuadBvhHandle& QuadBVH();
0229
0230 public:
0231
0232 bool HasTextures() const { return !myTextures.IsEmpty(); }
0233
0234
0235 Standard_EXPORT int AddTexture(const occ::handle<OpenGl_Texture>& theTexture);
0236
0237
0238 Standard_EXPORT bool UpdateTextureHandles(const occ::handle<OpenGl_Context>& theContext);
0239
0240
0241 Standard_EXPORT bool AcquireTextures(const occ::handle<OpenGl_Context>& theContext);
0242
0243
0244 Standard_EXPORT bool ReleaseTextures(const occ::handle<OpenGl_Context>& theContext) const;
0245
0246
0247 const NCollection_LinearVector<GLuint64>& TextureHandles() const { return myTextureHandles; }
0248
0249
0250 void ReleaseResources(const occ::handle<OpenGl_Context>&)
0251 {
0252
0253 }
0254
0255 public:
0256
0257 int TopLevelTreeDepth() const { return myTopLevelTreeDepth; }
0258
0259
0260 int BotLevelTreeDepth() const { return myBotLevelTreeDepth; }
0261
0262 protected:
0263
0264 NCollection_DynamicArray<occ::handle<OpenGl_Texture>> myTextures;
0265 NCollection_LinearVector<GLuint64> myTextureHandles;
0266 int myTopLevelTreeDepth;
0267 int myBotLevelTreeDepth;
0268
0269
0270 QuadBvhHandle myQuadBVH;
0271 };
0272
0273 #endif