File indexing completed on 2025-01-18 10:04:35
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_OccAllocator.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 Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup);
0034
0035
0036 Standard_EXPORT Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode);
0037
0038
0039 Standard_EXPORT Standard_Boolean 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
0070 Standard_EXPORT OpenGl_RaytraceMaterial();
0071
0072
0073 const Standard_ShortReal* Packed()
0074 {
0075 return reinterpret_cast<Standard_ShortReal*> (this);
0076 }
0077 };
0078
0079
0080 struct OpenGl_RaytraceLight
0081 {
0082
0083 BVH_Vec4f Emission;
0084 BVH_Vec4f Position;
0085
0086 public:
0087
0088
0089 OpenGl_RaytraceLight() { }
0090
0091
0092 Standard_EXPORT OpenGl_RaytraceLight (const BVH_Vec4f& theEmission,
0093 const BVH_Vec4f& thePosition);
0094
0095
0096 const Standard_ShortReal* Packed()
0097 {
0098 return reinterpret_cast<Standard_ShortReal*> (this);
0099 }
0100 };
0101
0102
0103 typedef opencascade::handle<BVH_Tree<Standard_ShortReal, 3, BVH_QuadTree> > QuadBvhHandle;
0104 typedef BVH_Triangulation<Standard_ShortReal, 3> OpenGl_BVHTriangulation3f;
0105
0106
0107 class OpenGl_TriangleSet : public OpenGl_BVHTriangulation3f
0108 {
0109 DEFINE_STANDARD_RTTIEXT(OpenGl_TriangleSet, OpenGl_BVHTriangulation3f)
0110 public:
0111
0112
0113 static const Standard_Integer INVALID_MATERIAL = -1;
0114
0115 public:
0116
0117
0118 Standard_EXPORT OpenGl_TriangleSet (const Standard_Size theArrayID,
0119 const opencascade::handle<BVH_Builder<Standard_ShortReal, 3> >& theBuilder);
0120
0121
0122 Standard_Size AssociatedPArrayID() const
0123 {
0124 return myArrayID;
0125 }
0126
0127
0128 Standard_Integer MaterialIndex() const
0129 {
0130 if (Elements.size() == 0)
0131 {
0132 return INVALID_MATERIAL;
0133 }
0134
0135 return Elements.front().w();
0136 }
0137
0138
0139 void SetMaterialIndex (Standard_Integer theMatID)
0140 {
0141 for (Standard_Size anIdx = 0; anIdx < Elements.size(); ++anIdx)
0142 {
0143 Elements[anIdx].w() = theMatID;
0144 }
0145 }
0146
0147
0148 virtual BVH_BoxNt Box() const Standard_OVERRIDE;
0149
0150
0151 using BVH_Triangulation<Standard_ShortReal, 3>::Box;
0152
0153
0154 Standard_EXPORT virtual Standard_ShortReal Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE;
0155
0156
0157 Standard_EXPORT const QuadBvhHandle& QuadBVH();
0158
0159 public:
0160
0161 BVH_Array3f Normals;
0162 BVH_Array2f TexCrds;
0163
0164 private:
0165
0166 Standard_Size myArrayID;
0167
0168 QuadBvhHandle myQuadBVH;
0169
0170 };
0171
0172
0173 class OpenGl_RaytraceGeometry : public BVH_Geometry<Standard_ShortReal, 3>
0174 {
0175 public:
0176
0177
0178 static const Standard_Integer INVALID_OFFSET = -1;
0179
0180
0181
0182
0183
0184 static const Standard_Integer MAX_TEX_NUMBER = 32;
0185
0186 public:
0187
0188
0189 std::vector<OpenGl_RaytraceLight,
0190 NCollection_OccAllocator<OpenGl_RaytraceLight> > Sources;
0191
0192
0193 std::vector<OpenGl_RaytraceMaterial,
0194 NCollection_OccAllocator<OpenGl_RaytraceMaterial> > Materials;
0195
0196
0197 BVH_Vec4f Ambient;
0198
0199 public:
0200
0201
0202 OpenGl_RaytraceGeometry()
0203 : BVH_Geometry<Standard_ShortReal, 3>(),
0204 myTopLevelTreeDepth (0),
0205 myBotLevelTreeDepth (0)
0206 {
0207
0208 }
0209
0210
0211 ~OpenGl_RaytraceGeometry()
0212 {
0213
0214 }
0215
0216
0217 void ClearMaterials()
0218 {
0219 std::vector<OpenGl_RaytraceMaterial,
0220 NCollection_OccAllocator<OpenGl_RaytraceMaterial> > anEmptyMaterials;
0221
0222 Materials.swap (anEmptyMaterials);
0223
0224 myTextures.Clear();
0225 }
0226
0227
0228 Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
0229
0230 public:
0231
0232
0233 Standard_EXPORT Standard_Boolean ProcessAcceleration();
0234
0235
0236
0237
0238 Standard_EXPORT Standard_Integer AccelerationOffset (Standard_Integer theNodeIdx);
0239
0240
0241
0242
0243 Standard_EXPORT Standard_Integer VerticesOffset (Standard_Integer theNodeIdx);
0244
0245
0246
0247
0248 Standard_EXPORT Standard_Integer ElementsOffset (Standard_Integer theNodeIdx);
0249
0250
0251
0252
0253 Standard_EXPORT OpenGl_TriangleSet* TriangleSet (Standard_Integer theNodeIdx);
0254
0255
0256 Standard_EXPORT const QuadBvhHandle& QuadBVH();
0257
0258 public:
0259
0260
0261 Standard_Boolean HasTextures() const
0262 {
0263 return !myTextures.IsEmpty();
0264 }
0265
0266
0267 Standard_EXPORT Standard_Integer AddTexture (const Handle(OpenGl_Texture)& theTexture);
0268
0269
0270 Standard_EXPORT Standard_Boolean UpdateTextureHandles (const Handle(OpenGl_Context)& theContext);
0271
0272
0273 Standard_EXPORT Standard_Boolean AcquireTextures (const Handle(OpenGl_Context)& theContext);
0274
0275
0276 Standard_EXPORT Standard_Boolean ReleaseTextures (const Handle(OpenGl_Context)& theContext) const;
0277
0278
0279 const std::vector<GLuint64>& TextureHandles() const
0280 {
0281 return myTextureHandles;
0282 }
0283
0284
0285 void ReleaseResources (const Handle(OpenGl_Context)& )
0286 {
0287
0288 }
0289
0290 public:
0291
0292
0293 Standard_Integer TopLevelTreeDepth() const
0294 {
0295 return myTopLevelTreeDepth;
0296 }
0297
0298
0299 Standard_Integer BotLevelTreeDepth() const
0300 {
0301 return myBotLevelTreeDepth;
0302 }
0303
0304 protected:
0305
0306 NCollection_Vector<Handle(OpenGl_Texture)> myTextures;
0307 std::vector<GLuint64> myTextureHandles;
0308 Standard_Integer myTopLevelTreeDepth;
0309 Standard_Integer myBotLevelTreeDepth;
0310
0311 QuadBvhHandle myQuadBVH;
0312
0313 };
0314
0315 #endif