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