c5b7f16c9ecc76ec90982612d4b0110ca8e39a37
[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_Element;
68 class Image_PixMap;
69
70 //! OpenGL material definition
71 struct OpenGl_Material
72 {
73
74   OpenGl_Vec4 Ambient;  //!< ambient reflection coefficient
75   OpenGl_Vec4 Diffuse;  //!< diffuse reflection coefficient
76   OpenGl_Vec4 Specular; //!< glossy  reflection coefficient
77   OpenGl_Vec4 Emission; //!< material emission
78   OpenGl_Vec4 Params;   //!< extra packed parameters
79
80   Standard_ShortReal  Shine()              const { return Params.x(); }
81   Standard_ShortReal& ChangeShine()              { return Params.x(); }
82
83   Standard_ShortReal  Transparency()       const { return Params.y(); }
84   Standard_ShortReal& ChangeTransparency()       { return Params.y(); }
85
86   //! Initialize material
87   void Init (const OPENGL_SURF_PROP& theProps);
88
89   //! Returns packed (serialized) representation of material properties
90   const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
91   static Standard_Integer NbOfVec4() { return 5; }
92
93 };
94
95 //! Represents window with GL context.
96 //! Provides methods to render primitives and maintain GL state.
97 class OpenGl_Workspace : public OpenGl_Window
98 {
99 public:
100
101   //! Main constructor - prepare GL context for specified window.
102   OpenGl_Workspace (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
103                     const CALL_DEF_WINDOW&        theCWindow,
104                     Aspect_RenderingContext       theGContext,
105                     const Handle(OpenGl_Caps)&    theCaps,
106                     const Handle(OpenGl_Context)& theShareCtx);
107
108   //! Destructor
109   virtual ~OpenGl_Workspace();
110
111   void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
112   const Handle(OpenGl_View)& ActiveView () const { return myView; }
113
114   //! Redraw the window.
115   void Redraw (const Graphic3d_CView& theCView,
116                const Aspect_CLayer2d& theCUnderLayer,
117                const Aspect_CLayer2d& theCOverLayer);
118
119   Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer);
120   void RedrawImmediate (const Graphic3d_CView& theCView,
121                         const Aspect_CLayer2d& theCUnderLayer,
122                         const Aspect_CLayer2d& theCOverLayer,
123                         const Standard_Boolean theToForce = Standard_False);
124
125   void Invalidate (const Graphic3d_CView& /*theCView*/)
126   {
127     myBackBufferRestored = Standard_False;
128   }
129
130   //! Special method to perform printing.
131   //! System-specific and currently only Win platform implemented.
132   Standard_Boolean Print (const Handle(OpenGl_PrinterContext)& thePrintContext,
133                           const Graphic3d_CView& theCView,
134                           const Aspect_CLayer2d& theCUnderLayer,
135                           const Aspect_CLayer2d& theCOverLayer,
136                           const Aspect_Handle    theHPrintDC,
137                           const Standard_Boolean theToShowBackground,
138                           const Standard_CString theFileName,
139                           const Aspect_PrintAlgo thePrintAlgorithm,
140                           const Standard_Real    theScaleFactor);
141
142   const Handle(OpenGl_PrinterContext)& PrinterContext() const
143   {
144     return myPrintContext;
145   }
146
147   void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
148
149   Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
150   void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
151   Standard_Boolean BufferDump (OpenGl_FrameBuffer*         theFBOPtr,
152                                Image_PixMap&               theImage,
153                                const Graphic3d_BufferType& theBufferType);
154
155   void UseTransparency (const Standard_Boolean theFlag);
156   Standard_Boolean& UseZBuffer()   { return myUseZBuffer; }
157   Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
158   Standard_Boolean& UseGLLight()   { return myUseGLLight; }
159
160   Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; }
161
162   //// RELATED TO STATUS ////
163
164   Standard_Integer   NamedStatus;
165
166   const TEL_COLOUR* HighlightColor;
167
168   const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
169   const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix*, bool aRevert = false);
170
171   //! Updates current model-view matrix
172   //! replacing it with StructureMatrixT*ViewMatrix from the workspace.
173   const void UpdateModelViewMatrix();
174
175   const OpenGl_AspectLine*   SetAspectLine   (const OpenGl_AspectLine*   theAspect);
176   const OpenGl_AspectFace*   SetAspectFace   (const OpenGl_AspectFace*   theAspect);
177   const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
178   const OpenGl_AspectText*   SetAspectText   (const OpenGl_AspectText*   theAspect);
179
180   void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
181
182   //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
183   Standard_EXPORT const OpenGl_AspectLine*   AspectLine   (const Standard_Boolean theWithApply);
184   Standard_EXPORT const OpenGl_AspectFace*   AspectFace   (const Standard_Boolean theWithApply);
185   Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
186   Standard_EXPORT const OpenGl_AspectText*   AspectText   (const Standard_Boolean theWithApply);
187   inline const OpenGl_TextParam* AspectTextParams() const
188   {
189     return TextParam_applied;
190   }
191
192   //! Clear the applied aspect state.
193   void ResetAppliedAspect();
194
195   Standard_EXPORT Handle(OpenGl_Texture) DisableTexture();
196   Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)&          theTexture,
197                                                         const Handle(Graphic3d_TextureParams)& theParams = NULL);
198
199   //! Set filter for restricting rendering of particular elements.
200   //! Filter can be applied for rendering passes used by recursive
201   //! rendering algorithms for rendering elements of groups.
202   //! @param theFilter [in] the filter instance.
203   inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
204   {
205     myRenderFilter = theFilter;
206   }
207
208   //! Get rendering filter.
209   //! @return filter instance.
210   inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const
211   {
212     return myRenderFilter;
213   }
214
215   //! @return applied view matrix.
216   inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
217
218   //! @return applied model structure matrix.
219   inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
220
221   //! Sets and applies current polygon offset.
222   void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits);
223
224   //! Returns currently applied polygon offset params.
225   const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; }
226
227 protected:
228
229   //! Copy content of Back buffer to the Front buffer
230   void copyBackToFront();
231
232   virtual Standard_Boolean Activate();
233
234   void redraw1 (const Graphic3d_CView& theCView,
235                 const Aspect_CLayer2d& theCUnderLayer,
236                 const Aspect_CLayer2d& theCOverLayer,
237                 const int              theToSwap);
238
239   void updateMaterial (const int theFlag);
240
241   void setTextureParams (Handle(OpenGl_Texture)&                theTexture,
242                          const Handle(Graphic3d_TextureParams)& theParams);
243
244 protected:
245
246   //! Result of OpenGL shaders initialization.
247   enum RaytraceInitStatus
248   {
249     OpenGl_RT_NONE,
250     OpenGl_RT_INIT,
251     OpenGl_RT_FAIL
252   };
253
254   //! Describes update mode (state).
255   enum GeomUpdateMode
256   {
257     OpenGl_GUM_CHECK,   //!< check if geometry update is necessary
258     OpenGl_GUM_PREPARE, //!< collect unchanged objects
259     OpenGl_GUM_UPDATE   //!< update raytracing data, rebuild changed objects
260   };
261
262   //! Defines frequently used shader variables.
263   enum ShaderVariableIndex
264   {
265     OpenGl_RT_aPosition,
266
267     OpenGl_RT_uOriginLT,
268     OpenGl_RT_uOriginLB,
269     OpenGl_RT_uOriginRT,
270     OpenGl_RT_uOriginRB,
271
272     OpenGl_RT_uDirectLT,
273     OpenGl_RT_uDirectLB,
274     OpenGl_RT_uDirectRT,
275     OpenGl_RT_uDirectRB,
276     
277     OpenGl_RT_uSceneRad,
278     OpenGl_RT_uSceneEps,
279
280     OpenGl_RT_uLightAmbnt,
281     OpenGl_RT_uLightCount,
282
283     OpenGl_RT_uShadEnabled,
284     OpenGl_RT_uReflEnabled,
285     
286     OpenGl_RT_uInputTexture,
287
288     OpenGl_RT_uOffsetX,
289     OpenGl_RT_uOffsetY,
290     OpenGl_RT_uSamples,
291
292     OpenGl_RT_uEnvironmentEnable,
293
294     OpenGl_RT_NbVariables // special field
295   };
296
297   //! Defines texture samplers.
298   enum ShaderSamplerNames
299   {
300     OpenGl_RT_SceneNodeInfoTexture = 0,
301     OpenGl_RT_SceneMinPointTexture = 1,
302     OpenGl_RT_SceneMaxPointTexture = 2,
303
304     OpenGl_RT_ObjectNodeInfoTexture = 3,
305     OpenGl_RT_ObjectMinPointTexture = 4,
306     OpenGl_RT_ObjectMaxPointTexture = 5,
307
308     OpenGl_RT_GeometryVertexTexture = 6,
309     OpenGl_RT_GeometryNormalTexture = 7,
310     OpenGl_RT_GeometryTriangTexture = 8,
311
312     OpenGl_RT_EnvironmentMapTexture = 9,
313
314     OpenGl_RT_RaytraceMaterialTexture = 10,
315     OpenGl_RT_RaytraceLightSrcTexture = 11,
316
317     OpenGl_RT_FSAAInputTexture = 12,
318
319     OpenGl_RT_SceneTransformTexture = 13
320   };
321
322   //! Tool class for management of shader sources.
323   class ShaderSource
324   {
325   public:
326
327     //! Creates new uninitialized shader source.
328     ShaderSource()
329     {
330       //
331     }
332
333     //! Creates new shader source from specified file.
334     ShaderSource (const TCollection_AsciiString& theFileName)
335     {
336       Load (&theFileName, 1);
337     }
338
339   public:
340
341     //! Returns prefix to insert before the source.
342     const TCollection_AsciiString& Prefix() const
343     {
344       return myPrefix;
345     }
346
347     //! Sets prefix to insert before the source.
348     void SetPrefix (const TCollection_AsciiString& thePrefix)
349     {
350       myPrefix = thePrefix;
351     }
352
353     //! Returns shader source combined with prefix.
354     TCollection_AsciiString Source() const;
355
356     //! Loads shader source from specified files.
357     void Load (const TCollection_AsciiString* theFileNames, const Standard_Integer theCount);
358
359   private:
360
361     TCollection_AsciiString mySource; //!< Source string of the shader object
362     TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
363
364   };
365
366   //! Default size of traversal stack.
367   static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
368
369 protected: //! @name methods related to ray-tracing
370
371   //! Updates 3D scene geometry for ray-tracing.
372   Standard_Boolean UpdateRaytraceGeometry (GeomUpdateMode theMode);
373
374   //! Checks to see if the structure is modified.
375   Standard_Boolean CheckRaytraceStructure (const OpenGl_Structure* theStructure);
376
377   //! Updates 3D scene light sources for ray-tracing.
378   Standard_Boolean UpdateRaytraceLightSources (const GLdouble theInvModelView[16]);
379
380   //! Updates environment map for ray-tracing.
381   Standard_Boolean UpdateRaytraceEnvironmentMap();
382
383   //! Adds OpenGL structure to ray-traced scene geometry.
384   Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure,
385     const Standard_ShortReal* theTransform, std::set<const OpenGl_Structure*>& theElements);
386
387   //! Adds OpenGL primitive array to ray-traced scene geometry.
388   OpenGl_TriangleSet* AddRaytracePrimitiveArray (
389     const OpenGl_PrimitiveArray* theArray, int theMatID, const Standard_ShortReal* theTrans);
390
391   //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
392   Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet&          theSet,
393                                              const OpenGl_PrimitiveArray& theArray,
394                                              Standard_Integer             theOffset,
395                                              Standard_Integer             theCount,
396                                              Standard_Integer             theMatID);
397
398   //! Adds OpenGL triangle array to ray-traced scene geometry.
399   Standard_Boolean AddRaytraceTriangleArray (OpenGl_TriangleSet&                  theSet,
400                                              const Handle(Graphic3d_IndexBuffer)& theIndices,
401                                              Standard_Integer                     theOffset,
402                                              Standard_Integer                     theCount,
403                                              Standard_Integer                     theMatID);
404
405   //! Adds OpenGL triangle fan array to ray-traced scene geometry.
406   Standard_Boolean AddRaytraceTriangleFanArray (OpenGl_TriangleSet&                  theSet,
407                                                 const Handle(Graphic3d_IndexBuffer)& theIndices,
408                                                 Standard_Integer                     theOffset,
409                                                 Standard_Integer                     theCount,
410                                                 Standard_Integer                     theMatID);
411
412   //! Adds OpenGL triangle strip array to ray-traced scene geometry.
413   Standard_Boolean AddRaytraceTriangleStripArray (OpenGl_TriangleSet&                  theSet,
414                                                   const Handle(Graphic3d_IndexBuffer)& theIndices,
415                                                   Standard_Integer                     theOffset,
416                                                   Standard_Integer                     theCount,
417                                                   Standard_Integer                     theMatID);
418
419   //! Adds OpenGL quadrangle array to ray-traced scene geometry.
420   Standard_Boolean AddRaytraceQuadrangleArray (OpenGl_TriangleSet&                  theSet,
421                                                const Handle(Graphic3d_IndexBuffer)& theIndices,
422                                                Standard_Integer                     theOffset,
423                                                Standard_Integer                     theCount,
424                                                Standard_Integer                     theMatID);
425
426   //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
427   Standard_Boolean AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet&                  theSet,
428                                                     const Handle(Graphic3d_IndexBuffer)& theIndices,
429                                                     Standard_Integer                     theOffset,
430                                                     Standard_Integer                     theCount,
431                                                     Standard_Integer                     theMatID);
432
433   //! Adds OpenGL polygon array to ray-traced scene geometry.
434   Standard_Boolean AddRaytracePolygonArray (OpenGl_TriangleSet&                  theSet,
435                                             const Handle(Graphic3d_IndexBuffer)& theIndices,
436                                             Standard_Integer                     theOffset,
437                                             Standard_Integer                     theCount,
438                                             Standard_Integer                     theMatID);
439
440   //! Loads and compiles shader object from specified source.
441   Handle(OpenGl_ShaderObject) LoadShader (const ShaderSource& theSource, GLenum theType);
442
443   //! Performs safe exit when shaders initialization fails.
444   Standard_Boolean SafeFailBack (const TCollection_ExtendedString& theMessage);
445
446   //! Initializes OpenGL/GLSL shader programs.
447   Standard_Boolean InitRaytraceResources();
448
449   //! Releases OpenGL/GLSL shader programs.
450   void ReleaseRaytraceResources();
451
452   //! Uploads ray-trace data to the GPU.
453   Standard_Boolean UploadRaytraceData();
454
455   //! Resizes OpenGL frame buffers.
456   Standard_Boolean ResizeRaytraceBuffers (const Standard_Integer theSizeX,
457                                           const Standard_Integer theSizeY);
458
459   //! Generates viewing rays for corners of screen quad.
460   void UpdateCamera (const NCollection_Mat4<GLdouble>& theOrientation,
461                      const NCollection_Mat4<GLdouble>& theViewMapping,
462                      OpenGl_Vec3                       theOrigins[4],
463                      OpenGl_Vec3                       theDirects[4]);
464
465   //! Runs ray-tracing shader programs.
466   Standard_Boolean RunRaytraceShaders (const Graphic3d_CView& theCView,
467                                        const Standard_Integer theSizeX,
468                                        const Standard_Integer theSizeY,
469                                        const OpenGl_Vec3      theOrigins[4],
470                                        const OpenGl_Vec3      theDirects[4],
471                                        OpenGl_FrameBuffer*    theFrameBuffer);
472
473   //! Redraws the window using OpenGL/GLSL ray-tracing.
474   Standard_Boolean Raytrace (const Graphic3d_CView& theCView,
475                              const Standard_Integer theSizeX,
476                              const Standard_Integer theSizeY,
477                              const Standard_Boolean theToSwap,
478                              OpenGl_FrameBuffer*    theFrameBuffer);
479
480 protected: //! @name fields related to ray-tracing
481
482   //! Result of shaders initialization.
483   RaytraceInitStatus myComputeInitStatus;
484
485   //! Is geometry data valid?
486   Standard_Boolean myIsRaytraceDataValid;
487
488   //! 3D scene geometry data for ray-tracing.
489   OpenGl_RaytraceGeometry myRaytraceGeometry;
490
491   //! Radius of bounding sphere of the scene.
492   Standard_ShortReal myRaytraceSceneRadius;
493   //! Scene epsilon to prevent self-intersections.
494   Standard_ShortReal myRaytraceSceneEpsilon;
495
496   //! Actual size of traversal stack in shader program.
497   Standard_Integer myTraversalStackSize;
498
499   //! OpenGL/GLSL source of ray-tracing fragment shader.
500   ShaderSource myRaytraceShaderSource;
501   //! OpenGL/GLSL source of adaptive-AA fragment shader.
502   ShaderSource myPostFSAAShaderSource;
503
504   //! OpenGL/GLSL ray-tracing fragment shader.
505   Handle(OpenGl_ShaderObject) myRaytraceShader;
506   //! OpenGL/GLSL adaptive-AA fragment shader.
507   Handle(OpenGl_ShaderObject) myPostFSAAShader;
508
509   //! OpenGL/GLSL ray-tracing shader program.
510   Handle(OpenGl_ShaderProgram) myRaytraceProgram;
511   //! OpenGL/GLSL adaptive-AA shader program.
512   Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
513
514   //! Texture buffer of data records of high-level BVH nodes.
515   Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
516   //! Texture buffer of minimum points of high-level BVH nodes.
517   Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
518   //! Texture buffer of maximum points of high-level BVH nodes.
519   Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
520   //! Texture buffer of transformations of high-level BVH nodes.
521   Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
522
523   //! Texture buffer of data records of bottom-level BVH nodes.
524   Handle(OpenGl_TextureBufferArb) myObjectNodeInfoTexture;
525   //! Texture buffer of minimum points of bottom-level BVH nodes.
526   Handle(OpenGl_TextureBufferArb) myObjectMinPointTexture;
527   //! Texture buffer of maximum points of bottom-level BVH nodes.
528   Handle(OpenGl_TextureBufferArb) myObjectMaxPointTexture;
529
530   //! Texture buffer of vertex coords.
531   Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
532   //! Texture buffer of vertex normals.
533   Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
534   //! Texture buffer of triangle indices.
535   Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
536   
537   //! Texture buffer of material properties.
538   Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
539   //! Texture buffer of light source properties.
540   Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
541
542   //! Vertex buffer (VBO) for drawing dummy quad.
543   OpenGl_VertexBuffer myRaytraceScreenQuad;
544
545   //! Framebuffer (FBO) to perform adaptive FSAA.
546   Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
547   //! Framebuffer (FBO) to perform adaptive FSAA.
548   Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
549
550   //! State of OpenGL view.
551   Standard_Size myViewModificationStatus;
552   //! State of OpenGL layer list.
553   Standard_Size myLayersModificationStatus;
554
555   //! State of OpenGL structures reflected to ray-tracing.
556   std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
557
558   //! PrimitiveArray to TriangleSet map for scene partial update.
559   std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*> myArrayToTrianglesMap;
560
561   //! Cached locations of frequently used uniform variables.
562   Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
563
564 protected: //! @name protected fields
565
566   Handle(OpenGl_PrinterContext) myPrintContext;
567   Handle(OpenGl_View)           myView;
568   Handle(OpenGl_LineAttributes) myLineAttribs;
569   Standard_Integer       myAntiAliasingMode;
570   Standard_Boolean       myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
571   Standard_Boolean       myBackBufferRestored;
572   Standard_Boolean       myIsImmediateDrawn;     //!< flag indicates that immediate mode buffer contains some data
573   Standard_Boolean       myUseTransparency;
574   Standard_Boolean       myUseZBuffer;
575   Standard_Boolean       myUseDepthTest;
576   Standard_Boolean       myUseGLLight;
577
578 protected: //! @name fields related to status
579
580   Handle(OpenGl_RenderFilter) myRenderFilter;
581   Handle(OpenGl_Texture) myTextureBound;    //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture)
582   const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
583   const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
584   const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
585   const OpenGl_AspectText *AspectText_set, *AspectText_applied;
586
587   const OpenGl_TextParam *TextParam_set, *TextParam_applied;
588
589   const OpenGl_Matrix* ViewMatrix_applied;
590   const OpenGl_Matrix* StructureMatrix_applied;
591
592   OpenGl_Material myMatFront;    //!< current front material state (cached to reduce GL context updates)
593   OpenGl_Material myMatBack;     //!< current back  material state
594   OpenGl_Material myMatTmp;      //!< temporary variable
595   TelCullMode     myCullingMode; //!< back face culling mode, applied from face aspect
596
597   OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
598
599   TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset.
600
601   OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
602
603 public: //! @name type definition
604
605   DEFINE_STANDARD_RTTI(OpenGl_Workspace)
606   DEFINE_STANDARD_ALLOC
607
608 };
609
610 #endif // _OpenGl_Workspace_Header