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