0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[occt.git] / src / OpenGl / OpenGl_SceneGeometry.hxx
CommitLineData
e276548b 1// Created on: 2013-08-27
2// Created by: Denis BOGOLEPOV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
e276548b 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
e276548b 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
e276548b 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
e276548b 15
16#ifndef _OpenGl_SceneGeometry_Header
17#define _OpenGl_SceneGeometry_Header
18
265d4508 19#include <BVH_Geometry.hxx>
20#include <BVH_Triangulation.hxx>
21#include <NCollection_StdAllocator.hxx>
e276548b 22#include <OpenGl_PrimitiveArray.hxx>
265d4508 23#include <OpenGl_Structure.hxx>
e276548b 24
25namespace OpenGl_Raytrace
26{
27 //! Checks to see if the group contains ray-trace geometry.
28 Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup);
29
30 //! Checks to see if the element contains ray-trace geometry.
31 Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode);
32
33 //! Checks to see if the structure contains ray-trace geometry.
34 Standard_Boolean IsRaytracedStructure (const OpenGl_Structure* theStructure);
35}
36
37//! Stores properties of surface material.
38class OpenGl_RaytraceMaterial
39{
40public:
41
42 //! Ambient reflection coefficient.
265d4508 43 BVH_Vec4f Ambient;
e276548b 44
45 //! Diffuse reflection coefficient.
265d4508 46 BVH_Vec4f Diffuse;
e276548b 47
48 //! Glossy reflection coefficient.
265d4508 49 BVH_Vec4f Specular;
e276548b 50
51 //! Material emission.
265d4508 52 BVH_Vec4f Emission;
e276548b 53
54 //! Specular reflection coefficient.
265d4508 55 BVH_Vec4f Reflection;
e276548b 56
57 //! Specular refraction coefficient.
265d4508 58 BVH_Vec4f Refraction;
e276548b 59
60 //! Material transparency.
265d4508 61 BVH_Vec4f Transparency;
e276548b 62
63public:
64
65 //! Creates new default material.
66 OpenGl_RaytraceMaterial();
67
68 //! Creates new material with specified properties.
265d4508 69 OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
70 const BVH_Vec4f& theDiffuse,
71 const BVH_Vec4f& theSpecular);
e276548b 72
73 //! Creates new material with specified properties.
265d4508 74 OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
75 const BVH_Vec4f& theDiffuse,
76 const BVH_Vec4f& theSpecular,
77 const BVH_Vec4f& theEmission,
78 const BVH_Vec4f& theTranspar);
e276548b 79
80 //! Creates new material with specified properties.
265d4508 81 OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
82 const BVH_Vec4f& theDiffuse,
83 const BVH_Vec4f& theSpecular,
84 const BVH_Vec4f& theEmission,
85 const BVH_Vec4f& theTranspar,
86 const BVH_Vec4f& theReflection,
87 const BVH_Vec4f& theRefraction);
e276548b 88
89 //! Returns packed (serialized) representation of material.
265d4508 90 const Standard_ShortReal* Packed()
91 {
92 return reinterpret_cast<Standard_ShortReal*> (this);
93 }
e276548b 94};
95
96//! Stores properties of OpenGL light source.
97class OpenGl_RaytraceLight
98{
99public:
100
265d4508 101 //! Diffuse intensity (in terms of OpenGL).
102 BVH_Vec4f Diffuse;
e276548b 103
104 //! Position of light source (in terms of OpenGL).
265d4508 105 BVH_Vec4f Position;
e276548b 106
107public:
108
109 //! Creates new light source.
265d4508 110 OpenGl_RaytraceLight (const BVH_Vec4f& theDiffuse,
111 const BVH_Vec4f& thePosition);
e276548b 112
113 //! Returns packed (serialized) representation of light source.
265d4508 114 const Standard_ShortReal* Packed()
115 {
116 return reinterpret_cast<Standard_ShortReal*> (this);
117 }
e276548b 118};
119
265d4508 120//! Triangulation of single OpenGL primitive array.
121class OpenGl_TriangleSet : public BVH_Triangulation<Standard_ShortReal, 4>
e276548b 122{
265d4508 123public:
e276548b 124
fc73a202 125 BVH_Array4f Normals; //!< Array of vertex normals
e276548b 126
127public:
128
265d4508 129 //! Creates new OpenGL element triangulation.
130 OpenGl_TriangleSet()
fc73a202 131 : BVH_Triangulation<Standard_ShortReal, 4>()
265d4508 132 {
133 //
134 }
135
136 //! Releases resources of OpenGL element triangulation.
137 ~OpenGl_TriangleSet()
138 {
139 //
140 }
e276548b 141};
142
265d4508 143//! Stores geometry of ray-tracing scene.
144class OpenGl_RaytraceGeometry : public BVH_Geometry<Standard_ShortReal, 4>
e276548b 145{
146public:
147
265d4508 148 //! Value of invalid offset to return in case of errors.
149 static const Standard_Integer INVALID_OFFSET = -1;
e276548b 150
e276548b 151public:
152
265d4508 153 //! Array of properties of light sources.
154 std::vector<OpenGl_RaytraceLight,
155 NCollection_StdAllocator<OpenGl_RaytraceLight> > Sources;
e276548b 156
265d4508 157 //! Array of 'front' material properties.
158 std::vector<OpenGl_RaytraceMaterial,
159 NCollection_StdAllocator<OpenGl_RaytraceMaterial> > Materials;
e276548b 160
265d4508 161 //! Global ambient from all light sources.
fc73a202 162 BVH_Vec4f Ambient;
e276548b 163
265d4508 164public:
e276548b 165
265d4508 166 //! Creates uninitialized ray-tracing geometry.
167 OpenGl_RaytraceGeometry()
fc73a202 168 : BVH_Geometry<Standard_ShortReal, 4>(),
169 myHighLevelTreeDepth (0),
170 myBottomLevelTreeDepth (0)
265d4508 171 {
172 //
173 }
e276548b 174
265d4508 175 //! Releases resources of ray-tracing geometry.
176 ~OpenGl_RaytraceGeometry()
177 {
178 //
179 }
e276548b 180
265d4508 181 //! Clears ray-tracing geometry.
182 void Clear();
e276548b 183
265d4508 184public:
e276548b 185
265d4508 186 //! Performs post-processing of high-level scene BVH.
187 Standard_Boolean ProcessAcceleration();
e276548b 188
265d4508 189 //! Returns offset of bottom-level BVH for given leaf node.
190 //! If the node index is not valid the function returns -1.
191 //! @note Can be used after processing acceleration structure.
192 Standard_Integer AccelerationOffset (Standard_Integer theNodeIdx);
e276548b 193
265d4508 194 //! Returns offset of triangulation vertices for given leaf node.
195 //! If the node index is not valid the function returns -1.
196 //! @note Can be used after processing acceleration structure.
197 Standard_Integer VerticesOffset (Standard_Integer theNodeIdx);
e276548b 198
265d4508 199 //! Returns offset of triangulation elements for given leaf node.
200 //! If the node index is not valid the function returns -1.
201 //! @note Can be used after processing acceleration structure.
202 Standard_Integer ElementsOffset (Standard_Integer theNodeIdx);
e276548b 203
265d4508 204 //! Returns triangulation data for given leaf node.
205 //! If the node index is not valid the function returns NULL.
206 //! @note Can be used after processing acceleration structure.
207 OpenGl_TriangleSet* TriangleSet (Standard_Integer theNodeIdx);
fc73a202 208
209 //! Returns depth of high-level scene BVH from last build.
210 Standard_Integer HighLevelTreeDepth() const
211 {
212 return myHighLevelTreeDepth;
213 }
214
215 //! Returns maximum depth of bottom-level scene BVHs from last build.
216 Standard_Integer BottomLevelTreeDepth() const
217 {
218 return myBottomLevelTreeDepth;
219 }
220
221protected:
222
223 Standard_Integer myHighLevelTreeDepth; //!< Depth of high-level scene BVH from last build
224 Standard_Integer myBottomLevelTreeDepth; //!< Maximum depth of bottom-level scene BVHs from last build
225
e276548b 226};
227
228#endif