Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
1981cb22 | 3 | // Copyright (c) 2011-2013 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa SK |
16 | #ifndef _OpenGl_Workspace_Header |
17 | #define _OpenGl_Workspace_Header | |
18 | ||
fc73a202 | 19 | #include <map> |
20 | #include <set> | |
e276548b | 21 | |
2166f0fa SK |
22 | #include <Handle_OpenGl_Workspace.hxx> |
23 | #include <OpenGl_Window.hxx> | |
24 | ||
25 | #include <TColStd_Array2OfReal.hxx> | |
26 | #include <Quantity_Color.hxx> | |
bf75be98 | 27 | #include <Graphic3d_CView.hxx> |
2166f0fa | 28 | #include <Graphic3d_TypeOfComposition.hxx> |
bf75be98 | 29 | #include <Graphic3d_TypeOfTexture.hxx> |
30 | #include <Graphic3d_PtrFrameBuffer.hxx> | |
31 | #include <Graphic3d_BufferType.hxx> | |
32 | #include <Handle_Graphic3d_TextureParams.hxx> | |
2166f0fa | 33 | |
2166f0fa SK |
34 | #include <Aspect_CLayer2d.hxx> |
35 | #include <Aspect_Handle.hxx> | |
36 | #include <Aspect_PrintAlgo.hxx> | |
550f3b8b | 37 | #include <Aspect_PolygonOffsetMode.hxx> |
2166f0fa SK |
38 | |
39 | #include <InterfaceGraphic_Graphic3d.hxx> | |
40 | #include <InterfaceGraphic_Visual3d.hxx> | |
41 | ||
1981cb22 | 42 | #include <NCollection_Sequence.hxx> |
43 | ||
bf75be98 | 44 | #include <OpenGl_AspectFace.hxx> |
fc73a202 | 45 | #include <OpenGl_FrameBuffer.hxx> |
2166f0fa SK |
46 | #include <OpenGl_Matrix.hxx> |
47 | #include <OpenGl_NamedStatus.hxx> | |
a174a3c5 | 48 | #include <OpenGl_PrinterContext.hxx> |
fc73a202 | 49 | #include <OpenGl_SceneGeometry.hxx> |
2166f0fa | 50 | #include <OpenGl_TextParam.hxx> |
4269bd1b | 51 | #include <OpenGl_RenderFilter.hxx> |
0adbd30f | 52 | #include <OpenGl_Vec.hxx> |
73192b37 | 53 | #include <OpenGl_LineAttributes.hxx> |
2166f0fa SK |
54 | |
55 | #include <Handle_OpenGl_View.hxx> | |
bf75be98 | 56 | #include <Handle_OpenGl_Texture.hxx> |
2166f0fa | 57 | |
fc73a202 | 58 | #include <OpenGl_ShaderObject.hxx> |
59 | #include <OpenGl_ShaderProgram.hxx> | |
60 | #include <OpenGl_TextureBufferArb.hxx> | |
61 | ||
2166f0fa | 62 | class OpenGl_AspectLine; |
2166f0fa SK |
63 | class OpenGl_AspectMarker; |
64 | class OpenGl_AspectText; | |
65 | class OpenGl_FrameBuffer; | |
66 | class OpenGl_Structure; | |
b7cd4ba7 | 67 | class OpenGl_TriangleSet; |
4269bd1b | 68 | class OpenGl_Element; |
692613e5 | 69 | class Image_PixMap; |
2166f0fa | 70 | |
0adbd30f | 71 | //! OpenGL material definition |
72 | struct OpenGl_Material | |
73 | { | |
74 | ||
75 | OpenGl_Vec4 Ambient; //!< ambient reflection coefficient | |
76 | OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient | |
77 | OpenGl_Vec4 Specular; //!< glossy reflection coefficient | |
78 | OpenGl_Vec4 Emission; //!< material emission | |
79 | OpenGl_Vec4 Params; //!< extra packed parameters | |
80 | ||
81 | Standard_ShortReal Shine() const { return Params.x(); } | |
82 | Standard_ShortReal& ChangeShine() { return Params.x(); } | |
83 | ||
84 | Standard_ShortReal Transparency() const { return Params.y(); } | |
85 | Standard_ShortReal& ChangeTransparency() { return Params.y(); } | |
86 | ||
87 | //! Initialize material | |
88 | void Init (const OPENGL_SURF_PROP& theProps); | |
89 | ||
90 | //! Returns packed (serialized) representation of material properties | |
91 | const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); } | |
92 | static Standard_Integer NbOfVec4() { return 5; } | |
93 | ||
94 | }; | |
95 | ||
a89742cf | 96 | DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter) |
97 | ||
25ef750e | 98 | //! Graphical ray-tracing filter. |
a89742cf | 99 | //! Filters out all raytracable structures. |
100 | class OpenGl_RaytraceFilter : public OpenGl_RenderFilter | |
101 | { | |
102 | public: | |
103 | ||
104 | //! Default constructor. | |
105 | OpenGl_RaytraceFilter() {} | |
106 | ||
107 | //! Remembers the previously set filter. | |
108 | inline void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) | |
109 | { | |
110 | myPrevRenderFilter = theFilter; | |
111 | } | |
112 | ||
113 | //! Checks whether the element can be rendered or not. | |
114 | //! @param theElement [in] the element to check. | |
115 | //! @return True if element can be rendered. | |
116 | virtual Standard_Boolean CanRender (const OpenGl_Element* theElement); | |
117 | ||
118 | private: | |
119 | ||
120 | Handle(OpenGl_RenderFilter) myPrevRenderFilter; | |
121 | ||
122 | public: | |
123 | ||
124 | DEFINE_STANDARD_RTTI(OpenGl_RaytraceFilter) | |
125 | }; | |
126 | ||
e276548b | 127 | //! Represents window with GL context. |
128 | //! Provides methods to render primitives and maintain GL state. | |
2166f0fa SK |
129 | class OpenGl_Workspace : public OpenGl_Window |
130 | { | |
131 | public: | |
132 | ||
133 | //! Main constructor - prepare GL context for specified window. | |
25b97fac | 134 | OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver, |
2166f0fa | 135 | const CALL_DEF_WINDOW& theCWindow, |
5e27df78 | 136 | Aspect_RenderingContext theGContext, |
58655684 | 137 | const Handle(OpenGl_Caps)& theCaps, |
5e27df78 | 138 | const Handle(OpenGl_Context)& theShareCtx); |
2166f0fa SK |
139 | |
140 | //! Destructor | |
141 | virtual ~OpenGl_Workspace(); | |
142 | ||
143 | void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; } | |
144 | const Handle(OpenGl_View)& ActiveView () const { return myView; } | |
145 | ||
146 | //! Redraw the window. | |
147 | void Redraw (const Graphic3d_CView& theCView, | |
148 | const Aspect_CLayer2d& theCUnderLayer, | |
149 | const Aspect_CLayer2d& theCOverLayer); | |
150 | ||
679ecdee | 151 | Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer); |
152 | void RedrawImmediate (const Graphic3d_CView& theCView, | |
153 | const Aspect_CLayer2d& theCUnderLayer, | |
154 | const Aspect_CLayer2d& theCOverLayer, | |
155 | const Standard_Boolean theToForce = Standard_False); | |
156 | ||
157 | void Invalidate (const Graphic3d_CView& /*theCView*/) | |
2166f0fa | 158 | { |
679ecdee | 159 | myBackBufferRestored = Standard_False; |
2166f0fa SK |
160 | } |
161 | ||
162 | //! Special method to perform printing. | |
163 | //! System-specific and currently only Win platform implemented. | |
a174a3c5 | 164 | Standard_Boolean Print (const Handle(OpenGl_PrinterContext)& thePrintContext, |
165 | const Graphic3d_CView& theCView, | |
bf75be98 | 166 | const Aspect_CLayer2d& theCUnderLayer, |
2166f0fa SK |
167 | const Aspect_CLayer2d& theCOverLayer, |
168 | const Aspect_Handle theHPrintDC, | |
169 | const Standard_Boolean theToShowBackground, | |
170 | const Standard_CString theFileName, | |
171 | const Aspect_PrintAlgo thePrintAlgorithm, | |
172 | const Standard_Real theScaleFactor); | |
173 | ||
a174a3c5 | 174 | const Handle(OpenGl_PrinterContext)& PrinterContext() const |
175 | { | |
176 | return myPrintContext; | |
177 | } | |
178 | ||
2166f0fa SK |
179 | void DisplayCallback (const Graphic3d_CView& theCView, int theReason); |
180 | ||
2166f0fa SK |
181 | Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight); |
182 | void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr); | |
692613e5 | 183 | Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr, |
184 | Image_PixMap& theImage, | |
185 | const Graphic3d_BufferType& theBufferType); | |
2166f0fa | 186 | |
2166f0fa SK |
187 | void UseTransparency (const Standard_Boolean theFlag); |
188 | Standard_Boolean& UseZBuffer() { return myUseZBuffer; } | |
189 | Standard_Boolean& UseDepthTest() { return myUseDepthTest; } | |
190 | Standard_Boolean& UseGLLight() { return myUseGLLight; } | |
191 | ||
73192b37 | 192 | Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; } |
193 | ||
2166f0fa SK |
194 | //// RELATED TO STATUS //// |
195 | ||
196 | Standard_Integer NamedStatus; | |
197 | ||
2166f0fa SK |
198 | const TEL_COLOUR* HighlightColor; |
199 | ||
200 | const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* ); | |
30f0ad28 | 201 | const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix*, bool aRevert = false); |
2166f0fa | 202 | |
0f8c0fb8 | 203 | //! Updates current model-view matrix |
204 | //! replacing it with StructureMatrixT*ViewMatrix from the workspace. | |
205 | const void UpdateModelViewMatrix(); | |
206 | ||
2166f0fa SK |
207 | const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); |
208 | const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); | |
209 | const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); | |
210 | const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); | |
211 | ||
212 | void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; } | |
213 | ||
3946774d | 214 | //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW |
215 | Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply); | |
216 | Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply); | |
217 | Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply); | |
218 | Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply); | |
a174a3c5 | 219 | inline const OpenGl_TextParam* AspectTextParams() const |
220 | { | |
221 | return TextParam_applied; | |
222 | } | |
2166f0fa | 223 | |
34a44cbd | 224 | //! Clear the applied aspect state. |
225 | void ResetAppliedAspect(); | |
226 | ||
bf75be98 | 227 | Standard_EXPORT Handle(OpenGl_Texture) DisableTexture(); |
228 | Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture, | |
229 | const Handle(Graphic3d_TextureParams)& theParams = NULL); | |
8625ef7e | 230 | const Handle(OpenGl_Texture)& ActiveTexture() const { return myTextureBound; } |
bf75be98 | 231 | |
4269bd1b | 232 | //! Set filter for restricting rendering of particular elements. |
233 | //! Filter can be applied for rendering passes used by recursive | |
234 | //! rendering algorithms for rendering elements of groups. | |
235 | //! @param theFilter [in] the filter instance. | |
236 | inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) | |
237 | { | |
5322131b | 238 | myRenderFilter = theFilter; |
4269bd1b | 239 | } |
240 | ||
241 | //! Get rendering filter. | |
242 | //! @return filter instance. | |
5322131b | 243 | inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const |
244 | { | |
245 | return myRenderFilter; | |
4269bd1b | 246 | } |
247 | ||
248 | //! @return applied view matrix. | |
249 | inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; } | |
250 | ||
251 | //! @return applied model structure matrix. | |
252 | inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } | |
253 | ||
550f3b8b | 254 | //! Sets and applies current polygon offset. |
255 | void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits); | |
256 | ||
257 | //! Returns currently applied polygon offset params. | |
258 | const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; } | |
259 | ||
b7cd4ba7 | 260 | //! @return true if clipping algorithm enabled |
261 | inline Standard_Boolean IsCullingEnabled() const { return myIsCullingEnabled; } | |
262 | ||
a89742cf | 263 | //! Returns a flag whether to redraw the scene using OpenGL rasterization |
264 | Standard_Boolean ToRedrawGL() const { return myToRedrawGL; } | |
265 | ||
2166f0fa SK |
266 | protected: |
267 | ||
679ecdee | 268 | //! Copy content of Back buffer to the Front buffer |
269 | void copyBackToFront(); | |
2166f0fa SK |
270 | |
271 | virtual Standard_Boolean Activate(); | |
272 | ||
679ecdee | 273 | void redraw1 (const Graphic3d_CView& theCView, |
bf75be98 | 274 | const Aspect_CLayer2d& theCUnderLayer, |
2166f0fa | 275 | const Aspect_CLayer2d& theCOverLayer, |
679ecdee | 276 | const int theToSwap); |
2166f0fa | 277 | |
0adbd30f | 278 | void updateMaterial (const int theFlag); |
2166f0fa | 279 | |
bf75be98 | 280 | void setTextureParams (Handle(OpenGl_Texture)& theTexture, |
281 | const Handle(Graphic3d_TextureParams)& theParams); | |
2166f0fa | 282 | |
fc73a202 | 283 | protected: |
e276548b | 284 | |
fc73a202 | 285 | //! Result of OpenGL shaders initialization. |
286 | enum RaytraceInitStatus | |
287 | { | |
288 | OpenGl_RT_NONE, | |
289 | OpenGl_RT_INIT, | |
290 | OpenGl_RT_FAIL | |
291 | }; | |
e276548b | 292 | |
84c71f29 | 293 | //! Describes update mode (state). |
294 | enum GeomUpdateMode | |
295 | { | |
296 | OpenGl_GUM_CHECK, //!< check if geometry update is necessary | |
297 | OpenGl_GUM_PREPARE, //!< collect unchanged objects | |
298 | OpenGl_GUM_UPDATE //!< update raytracing data, rebuild changed objects | |
299 | }; | |
300 | ||
fc73a202 | 301 | //! Defines frequently used shader variables. |
302 | enum ShaderVariableIndex | |
303 | { | |
304 | OpenGl_RT_aPosition, | |
305 | ||
306 | OpenGl_RT_uOriginLT, | |
307 | OpenGl_RT_uOriginLB, | |
308 | OpenGl_RT_uOriginRT, | |
309 | OpenGl_RT_uOriginRB, | |
fc73a202 | 310 | OpenGl_RT_uDirectLT, |
311 | OpenGl_RT_uDirectLB, | |
312 | OpenGl_RT_uDirectRT, | |
313 | OpenGl_RT_uDirectRB, | |
25ef750e | 314 | OpenGl_RT_uUnviewMat, |
315 | ||
fc73a202 | 316 | OpenGl_RT_uSceneRad, |
317 | OpenGl_RT_uSceneEps, | |
fc73a202 | 318 | OpenGl_RT_uLightAmbnt, |
319 | OpenGl_RT_uLightCount, | |
320 | ||
321 | OpenGl_RT_uShadEnabled, | |
322 | OpenGl_RT_uReflEnabled, | |
25ef750e | 323 | OpenGl_RT_uEnvMapEnable, |
fc73a202 | 324 | |
325 | OpenGl_RT_uOffsetX, | |
326 | OpenGl_RT_uOffsetY, | |
327 | OpenGl_RT_uSamples, | |
328 | ||
25ef750e | 329 | OpenGl_RT_uTextures, |
84c71f29 | 330 | |
fc73a202 | 331 | OpenGl_RT_NbVariables // special field |
332 | }; | |
e276548b | 333 | |
fc73a202 | 334 | //! Defines texture samplers. |
335 | enum ShaderSamplerNames | |
336 | { | |
337 | OpenGl_RT_SceneNodeInfoTexture = 0, | |
338 | OpenGl_RT_SceneMinPointTexture = 1, | |
339 | OpenGl_RT_SceneMaxPointTexture = 2, | |
340 | ||
341 | OpenGl_RT_ObjectNodeInfoTexture = 3, | |
342 | OpenGl_RT_ObjectMinPointTexture = 4, | |
343 | OpenGl_RT_ObjectMaxPointTexture = 5, | |
344 | ||
345 | OpenGl_RT_GeometryVertexTexture = 6, | |
346 | OpenGl_RT_GeometryNormalTexture = 7, | |
25ef750e | 347 | OpenGl_RT_GeometryTexCrdTexture = 8, |
348 | OpenGl_RT_GeometryTriangTexture = 9, | |
e276548b | 349 | |
25ef750e | 350 | OpenGl_RT_EnvironmentMapTexture = 10, |
fc73a202 | 351 | |
25ef750e | 352 | OpenGl_RT_RaytraceMaterialTexture = 11, |
353 | OpenGl_RT_RaytraceLightSrcTexture = 12, | |
fc73a202 | 354 | |
25ef750e | 355 | OpenGl_RT_FSAAInputTexture = 13, |
84c71f29 | 356 | |
25ef750e | 357 | OpenGl_RT_SceneTransformTexture = 14, |
a89742cf | 358 | |
25ef750e | 359 | OpenGl_RT_OpenGlColorTexture = 15, |
360 | OpenGl_RT_OpenGlDepthTexture = 16 | |
fc73a202 | 361 | }; |
362 | ||
363 | //! Tool class for management of shader sources. | |
364 | class ShaderSource | |
e276548b | 365 | { |
fc73a202 | 366 | public: |
367 | ||
368 | //! Creates new uninitialized shader source. | |
369 | ShaderSource() | |
370 | { | |
371 | // | |
372 | } | |
373 | ||
374 | //! Creates new shader source from specified file. | |
375 | ShaderSource (const TCollection_AsciiString& theFileName) | |
376 | { | |
377 | Load (&theFileName, 1); | |
378 | } | |
379 | ||
380 | public: | |
381 | ||
382 | //! Returns prefix to insert before the source. | |
383 | const TCollection_AsciiString& Prefix() const | |
384 | { | |
385 | return myPrefix; | |
386 | } | |
387 | ||
388 | //! Sets prefix to insert before the source. | |
389 | void SetPrefix (const TCollection_AsciiString& thePrefix) | |
390 | { | |
391 | myPrefix = thePrefix; | |
392 | } | |
393 | ||
394 | //! Returns shader source combined with prefix. | |
395 | TCollection_AsciiString Source() const; | |
396 | ||
397 | //! Loads shader source from specified files. | |
398 | void Load (const TCollection_AsciiString* theFileNames, const Standard_Integer theCount); | |
399 | ||
400 | private: | |
401 | ||
402 | TCollection_AsciiString mySource; //!< Source string of the shader object | |
403 | TCollection_AsciiString myPrefix; //!< Prefix to insert before the source | |
404 | ||
e276548b | 405 | }; |
406 | ||
bc8c79bb | 407 | //! Default ray-tracing depth. |
25ef750e | 408 | static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3; |
bc8c79bb | 409 | |
fc73a202 | 410 | //! Default size of traversal stack. |
411 | static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24; | |
412 | ||
bc8c79bb | 413 | //! Compile-time ray-tracing parameters. |
414 | struct RaytracingParams | |
415 | { | |
416 | //! Actual size of traversal stack in shader program. | |
417 | Standard_Integer StackSize; | |
418 | ||
419 | //! Actual ray-tracing depth (number of ray bounces). | |
25ef750e | 420 | Standard_Integer NbBounces; |
bc8c79bb | 421 | |
422 | //! Sets light propagation through transparent media. | |
423 | Standard_Boolean TransparentShadows; | |
424 | ||
425 | //! Creates default compile-time ray-tracing parameters. | |
426 | RaytracingParams() | |
427 | : StackSize (THE_DEFAULT_STACK_SIZE), | |
25ef750e | 428 | NbBounces (THE_DEFAULT_NB_BOUNCES), |
bc8c79bb | 429 | TransparentShadows (Standard_False) |
430 | { | |
431 | // | |
432 | } | |
433 | }; | |
434 | ||
e276548b | 435 | protected: //! @name methods related to ray-tracing |
436 | ||
437 | //! Updates 3D scene geometry for ray-tracing. | |
84c71f29 | 438 | Standard_Boolean UpdateRaytraceGeometry (GeomUpdateMode theMode); |
e276548b | 439 | |
440 | //! Checks to see if the structure is modified. | |
441 | Standard_Boolean CheckRaytraceStructure (const OpenGl_Structure* theStructure); | |
442 | ||
25ef750e | 443 | //! Creates ray-tracing material properties. |
444 | Standard_Boolean CreateMaterial (const OpenGl_AspectFace* theAspect, OpenGl_RaytraceMaterial& theMaterial); | |
445 | ||
e276548b | 446 | //! Updates 3D scene light sources for ray-tracing. |
25ef750e | 447 | Standard_Boolean UpdateRaytraceLightSources (const OpenGl_Mat4& theInvModelView); |
e276548b | 448 | |
449 | //! Updates environment map for ray-tracing. | |
450 | Standard_Boolean UpdateRaytraceEnvironmentMap(); | |
5322131b | 451 | |
e276548b | 452 | //! Adds OpenGL structure to ray-traced scene geometry. |
0717ddc1 | 453 | Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure, std::set<const OpenGl_Structure*>& theElements); |
454 | ||
455 | //! Adds OpenGL groups to ray-traced scene geometry. | |
456 | Standard_Boolean AddRaytraceGroups (const OpenGl_Structure* theStructure, | |
457 | const Standard_Integer theStructMatId, | |
458 | const Standard_ShortReal* theTransform); | |
e276548b | 459 | |
460 | //! Adds OpenGL primitive array to ray-traced scene geometry. | |
265d4508 | 461 | OpenGl_TriangleSet* AddRaytracePrimitiveArray ( |
25ef750e | 462 | const OpenGl_PrimitiveArray* theArray, int theMatID, const OpenGl_Mat4* theTrans); |
e276548b | 463 | |
464 | //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry. | |
871fa103 | 465 | Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet& theSet, |
466 | const OpenGl_PrimitiveArray& theArray, | |
467 | Standard_Integer theOffset, | |
468 | Standard_Integer theCount, | |
469 | Standard_Integer theMatID); | |
e276548b | 470 | |
471 | //! Adds OpenGL triangle array to ray-traced scene geometry. | |
871fa103 | 472 | Standard_Boolean AddRaytraceTriangleArray (OpenGl_TriangleSet& theSet, |
473 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
474 | Standard_Integer theOffset, | |
475 | Standard_Integer theCount, | |
476 | Standard_Integer theMatID); | |
e276548b | 477 | |
478 | //! Adds OpenGL triangle fan array to ray-traced scene geometry. | |
871fa103 | 479 | Standard_Boolean AddRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet, |
480 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
481 | Standard_Integer theOffset, | |
482 | Standard_Integer theCount, | |
483 | Standard_Integer theMatID); | |
e276548b | 484 | |
265d4508 | 485 | //! Adds OpenGL triangle strip array to ray-traced scene geometry. |
871fa103 | 486 | Standard_Boolean AddRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet, |
487 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
488 | Standard_Integer theOffset, | |
489 | Standard_Integer theCount, | |
490 | Standard_Integer theMatID); | |
e276548b | 491 | |
492 | //! Adds OpenGL quadrangle array to ray-traced scene geometry. | |
871fa103 | 493 | Standard_Boolean AddRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet, |
494 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
495 | Standard_Integer theOffset, | |
496 | Standard_Integer theCount, | |
497 | Standard_Integer theMatID); | |
e276548b | 498 | |
499 | //! Adds OpenGL quadrangle strip array to ray-traced scene geometry. | |
871fa103 | 500 | Standard_Boolean AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet, |
501 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
502 | Standard_Integer theOffset, | |
503 | Standard_Integer theCount, | |
504 | Standard_Integer theMatID); | |
e276548b | 505 | |
506 | //! Adds OpenGL polygon array to ray-traced scene geometry. | |
871fa103 | 507 | Standard_Boolean AddRaytracePolygonArray (OpenGl_TriangleSet& theSet, |
508 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
509 | Standard_Integer theOffset, | |
510 | Standard_Integer theCount, | |
511 | Standard_Integer theMatID); | |
e276548b | 512 | |
fc73a202 | 513 | //! Loads and compiles shader object from specified source. |
514 | Handle(OpenGl_ShaderObject) LoadShader (const ShaderSource& theSource, GLenum theType); | |
515 | ||
516 | //! Performs safe exit when shaders initialization fails. | |
517 | Standard_Boolean SafeFailBack (const TCollection_ExtendedString& theMessage); | |
518 | ||
25ef750e | 519 | //! Generates shader prefix based on current ray-tracing options. |
520 | TCollection_AsciiString GenerateShaderPrefix(); | |
521 | ||
fc73a202 | 522 | //! Initializes OpenGL/GLSL shader programs. |
bc8c79bb | 523 | Standard_Boolean InitRaytraceResources (const Graphic3d_CView& theCView); |
5322131b | 524 | |
fc73a202 | 525 | //! Releases OpenGL/GLSL shader programs. |
526 | void ReleaseRaytraceResources(); | |
e276548b | 527 | |
fc73a202 | 528 | //! Uploads ray-trace data to the GPU. |
529 | Standard_Boolean UploadRaytraceData(); | |
e276548b | 530 | |
fc73a202 | 531 | //! Resizes OpenGL frame buffers. |
532 | Standard_Boolean ResizeRaytraceBuffers (const Standard_Integer theSizeX, | |
533 | const Standard_Integer theSizeY); | |
e276548b | 534 | |
fc73a202 | 535 | //! Generates viewing rays for corners of screen quad. |
25ef750e | 536 | void UpdateCamera (const OpenGl_Mat4& theOrientation, |
537 | const OpenGl_Mat4& theViewMapping, | |
538 | OpenGl_Vec3 theOrigins[4], | |
539 | OpenGl_Vec3 theDirects[4], | |
540 | OpenGl_Mat4& theInvModelProj); | |
541 | ||
542 | //! Sets uniform state for the given ray-tracing shader program. | |
543 | Standard_Boolean SetUniformState (const Graphic3d_CView& theCView, | |
544 | const OpenGl_Vec3* theOrigins, | |
545 | const OpenGl_Vec3* theDirects, | |
546 | const OpenGl_Mat4& theUnviewMat, | |
547 | const Standard_Integer theProgramIndex, | |
548 | Handle(OpenGl_ShaderProgram)& theRaytraceProgram); | |
e276548b | 549 | |
fc73a202 | 550 | //! Runs ray-tracing shader programs. |
551 | Standard_Boolean RunRaytraceShaders (const Graphic3d_CView& theCView, | |
552 | const Standard_Integer theSizeX, | |
553 | const Standard_Integer theSizeY, | |
554 | const OpenGl_Vec3 theOrigins[4], | |
555 | const OpenGl_Vec3 theDirects[4], | |
25ef750e | 556 | const OpenGl_Mat4& theUnviewMat, |
fc73a202 | 557 | OpenGl_FrameBuffer* theFrameBuffer); |
265d4508 | 558 | |
fc73a202 | 559 | //! Redraws the window using OpenGL/GLSL ray-tracing. |
e276548b | 560 | Standard_Boolean Raytrace (const Graphic3d_CView& theCView, |
fc73a202 | 561 | const Standard_Integer theSizeX, |
562 | const Standard_Integer theSizeY, | |
563 | const Standard_Boolean theToSwap, | |
a89742cf | 564 | const Aspect_CLayer2d& theCOverLayer, |
565 | const Aspect_CLayer2d& theCUnderLayer, | |
fc73a202 | 566 | OpenGl_FrameBuffer* theFrameBuffer); |
e276548b | 567 | |
568 | protected: //! @name fields related to ray-tracing | |
569 | ||
fc73a202 | 570 | //! Result of shaders initialization. |
571 | RaytraceInitStatus myComputeInitStatus; | |
e276548b | 572 | |
573 | //! Is geometry data valid? | |
574 | Standard_Boolean myIsRaytraceDataValid; | |
5322131b | 575 | |
25ef750e | 576 | //! Warning about missing extension GL_ARB_bindless_texture has been displayed? |
577 | Standard_Boolean myIsRaytraceWarnTextures; | |
578 | ||
e276548b | 579 | //! 3D scene geometry data for ray-tracing. |
265d4508 | 580 | OpenGl_RaytraceGeometry myRaytraceGeometry; |
e276548b | 581 | |
582 | //! Radius of bounding sphere of the scene. | |
265d4508 | 583 | Standard_ShortReal myRaytraceSceneRadius; |
e276548b | 584 | //! Scene epsilon to prevent self-intersections. |
265d4508 | 585 | Standard_ShortReal myRaytraceSceneEpsilon; |
e276548b | 586 | |
bc8c79bb | 587 | //! Compile-time ray-tracing parameters. |
588 | RaytracingParams myRaytraceParameters; | |
fc73a202 | 589 | |
590 | //! OpenGL/GLSL source of ray-tracing fragment shader. | |
591 | ShaderSource myRaytraceShaderSource; | |
592 | //! OpenGL/GLSL source of adaptive-AA fragment shader. | |
593 | ShaderSource myPostFSAAShaderSource; | |
594 | ||
595 | //! OpenGL/GLSL ray-tracing fragment shader. | |
596 | Handle(OpenGl_ShaderObject) myRaytraceShader; | |
597 | //! OpenGL/GLSL adaptive-AA fragment shader. | |
598 | Handle(OpenGl_ShaderObject) myPostFSAAShader; | |
599 | ||
600 | //! OpenGL/GLSL ray-tracing shader program. | |
601 | Handle(OpenGl_ShaderProgram) myRaytraceProgram; | |
602 | //! OpenGL/GLSL adaptive-AA shader program. | |
603 | Handle(OpenGl_ShaderProgram) myPostFSAAProgram; | |
604 | ||
605 | //! Texture buffer of data records of high-level BVH nodes. | |
606 | Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture; | |
607 | //! Texture buffer of minimum points of high-level BVH nodes. | |
608 | Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture; | |
609 | //! Texture buffer of maximum points of high-level BVH nodes. | |
610 | Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture; | |
84c71f29 | 611 | //! Texture buffer of transformations of high-level BVH nodes. |
612 | Handle(OpenGl_TextureBufferArb) mySceneTransformTexture; | |
fc73a202 | 613 | |
614 | //! Texture buffer of data records of bottom-level BVH nodes. | |
615 | Handle(OpenGl_TextureBufferArb) myObjectNodeInfoTexture; | |
616 | //! Texture buffer of minimum points of bottom-level BVH nodes. | |
617 | Handle(OpenGl_TextureBufferArb) myObjectMinPointTexture; | |
618 | //! Texture buffer of maximum points of bottom-level BVH nodes. | |
619 | Handle(OpenGl_TextureBufferArb) myObjectMaxPointTexture; | |
620 | ||
621 | //! Texture buffer of vertex coords. | |
622 | Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture; | |
623 | //! Texture buffer of vertex normals. | |
624 | Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture; | |
25ef750e | 625 | //! Texture buffer of vertex UV coords. |
626 | Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture; | |
fc73a202 | 627 | //! Texture buffer of triangle indices. |
628 | Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture; | |
25ef750e | 629 | |
fc73a202 | 630 | //! Texture buffer of material properties. |
631 | Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture; | |
632 | //! Texture buffer of light source properties. | |
633 | Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture; | |
634 | ||
635 | //! Vertex buffer (VBO) for drawing dummy quad. | |
636 | OpenGl_VertexBuffer myRaytraceScreenQuad; | |
637 | ||
638 | //! Framebuffer (FBO) to perform adaptive FSAA. | |
639 | Handle(OpenGl_FrameBuffer) myRaytraceFBO1; | |
640 | //! Framebuffer (FBO) to perform adaptive FSAA. | |
641 | Handle(OpenGl_FrameBuffer) myRaytraceFBO2; | |
a89742cf | 642 | //! Framebuffer (FBO) for pre-raytrace rendering by OpenGL. |
643 | Handle(OpenGl_FrameBuffer) myOpenGlFBO; | |
265d4508 | 644 | |
e276548b | 645 | //! State of OpenGL view. |
646 | Standard_Size myViewModificationStatus; | |
e276548b | 647 | //! State of OpenGL layer list. |
648 | Standard_Size myLayersModificationStatus; | |
649 | ||
265d4508 | 650 | //! State of OpenGL structures reflected to ray-tracing. |
e276548b | 651 | std::map<const OpenGl_Structure*, Standard_Size> myStructureStates; |
652 | ||
84c71f29 | 653 | //! PrimitiveArray to TriangleSet map for scene partial update. |
8d3f219f | 654 | std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap; |
84c71f29 | 655 | |
fc73a202 | 656 | //! Cached locations of frequently used uniform variables. |
657 | Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables]; | |
e276548b | 658 | |
25ef750e | 659 | //! Graphical ray-tracing filter to filter out all raytracable structures. |
a89742cf | 660 | Handle(OpenGl_RaytraceFilter) myRaytraceFilter; |
661 | ||
25ef750e | 662 | //! Redraw the scene using OpenGL rasterization or ray-tracing? |
a89742cf | 663 | Standard_Boolean myToRedrawGL; |
664 | ||
bf75be98 | 665 | protected: //! @name protected fields |
2166f0fa | 666 | |
a174a3c5 | 667 | Handle(OpenGl_PrinterContext) myPrintContext; |
73192b37 | 668 | Handle(OpenGl_View) myView; |
669 | Handle(OpenGl_LineAttributes) myLineAttribs; | |
670 | Standard_Integer myAntiAliasingMode; | |
1981cb22 | 671 | Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer) |
679ecdee | 672 | Standard_Boolean myBackBufferRestored; |
673 | Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data | |
bf75be98 | 674 | Standard_Boolean myUseTransparency; |
675 | Standard_Boolean myUseZBuffer; | |
676 | Standard_Boolean myUseDepthTest; | |
677 | Standard_Boolean myUseGLLight; | |
b7cd4ba7 | 678 | Standard_Boolean myIsCullingEnabled; //!< frustum culling flag |
2166f0fa | 679 | |
a89742cf | 680 | unsigned int myFrameCounter; //!< redraw counter, for debugging |
681 | ||
bf75be98 | 682 | protected: //! @name fields related to status |
683 | ||
4269bd1b | 684 | Handle(OpenGl_RenderFilter) myRenderFilter; |
bf75be98 | 685 | Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture) |
2166f0fa SK |
686 | const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied; |
687 | const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied; | |
688 | const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied; | |
689 | const OpenGl_AspectText *AspectText_set, *AspectText_applied; | |
690 | ||
691 | const OpenGl_TextParam *TextParam_set, *TextParam_applied; | |
692 | ||
693 | const OpenGl_Matrix* ViewMatrix_applied; | |
694 | const OpenGl_Matrix* StructureMatrix_applied; | |
695 | ||
3b1817a9 | 696 | OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates) |
697 | OpenGl_Material myMatBack; //!< current back material state | |
698 | OpenGl_Material myMatTmp; //!< temporary variable | |
699 | TelCullMode myCullingMode; //!< back face culling mode, applied from face aspect | |
0adbd30f | 700 | |
550f3b8b | 701 | OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations |
0f8c0fb8 | 702 | |
550f3b8b | 703 | TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset. |
2166f0fa | 704 | |
550f3b8b | 705 | OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect |
bf75be98 | 706 | |
707 | public: //! @name type definition | |
2166f0fa | 708 | |
bf75be98 | 709 | DEFINE_STANDARD_RTTI(OpenGl_Workspace) |
1c35b92f | 710 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
711 | |
712 | }; | |
713 | ||
bf75be98 | 714 | #endif // _OpenGl_Workspace_Header |