1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_Workspace_Header
17 #define _OpenGl_Workspace_Header
22 #include <Handle_OpenGl_Workspace.hxx>
23 #include <OpenGl_Window.hxx>
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>
34 #include <Aspect_CLayer2d.hxx>
35 #include <Aspect_Handle.hxx>
36 #include <Aspect_PrintAlgo.hxx>
37 #include <Aspect_PolygonOffsetMode.hxx>
39 #include <InterfaceGraphic_Graphic3d.hxx>
40 #include <InterfaceGraphic_Visual3d.hxx>
42 #include <NCollection_Sequence.hxx>
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>
55 #include <Handle_OpenGl_View.hxx>
56 #include <Handle_OpenGl_Texture.hxx>
58 #include <OpenGl_ShaderObject.hxx>
59 #include <OpenGl_ShaderProgram.hxx>
60 #include <OpenGl_TextureBufferArb.hxx>
62 class OpenGl_AspectLine;
63 class OpenGl_AspectMarker;
64 class OpenGl_AspectText;
65 class OpenGl_FrameBuffer;
66 class OpenGl_Structure;
67 class OpenGl_TriangleSet;
71 //! OpenGL material definition
72 struct OpenGl_Material
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
81 Standard_ShortReal Shine() const { return Params.x(); }
82 Standard_ShortReal& ChangeShine() { return Params.x(); }
84 Standard_ShortReal Transparency() const { return Params.y(); }
85 Standard_ShortReal& ChangeTransparency() { return Params.y(); }
87 //! Initialize material
88 void Init (const OPENGL_SURF_PROP& theProps);
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; }
96 DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
98 //! Graphical ray-tracing filter.
99 //! Filters out all raytracable structures.
100 class OpenGl_RaytraceFilter : public OpenGl_RenderFilter
104 //! Default constructor.
105 OpenGl_RaytraceFilter() {}
107 //! Remembers the previously set filter.
108 inline void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
110 myPrevRenderFilter = theFilter;
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);
120 Handle(OpenGl_RenderFilter) myPrevRenderFilter;
124 DEFINE_STANDARD_RTTI(OpenGl_RaytraceFilter)
127 //! Represents window with GL context.
128 //! Provides methods to render primitives and maintain GL state.
129 class OpenGl_Workspace : public OpenGl_Window
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);
141 virtual ~OpenGl_Workspace();
143 void SetActiveView (const Handle(OpenGl_View)& theView,
144 const Standard_Integer theViewId)
147 myViewId = theViewId;
150 const Handle(OpenGl_View)& ActiveView() const { return myView; }
152 Standard_Integer ActiveViewId() const { return myViewId; }
154 //! Redraw the window.
155 void Redraw (const Graphic3d_CView& theCView,
156 const Aspect_CLayer2d& theCUnderLayer,
157 const Aspect_CLayer2d& theCOverLayer);
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);
164 void Invalidate (const Graphic3d_CView& /*theCView*/)
166 myBackBufferRestored = Standard_False;
169 //! Special method to perform printing.
170 //! System-specific and currently only Win platform implemented.
171 Standard_Boolean Print (const Handle(OpenGl_PrinterContext)& thePrintContext,
172 const Graphic3d_CView& theCView,
173 const Aspect_CLayer2d& theCUnderLayer,
174 const Aspect_CLayer2d& theCOverLayer,
175 const Aspect_Handle theHPrintDC,
176 const Standard_Boolean theToShowBackground,
177 const Standard_CString theFileName,
178 const Aspect_PrintAlgo thePrintAlgorithm,
179 const Standard_Real theScaleFactor);
181 const Handle(OpenGl_PrinterContext)& PrinterContext() const
183 return myPrintContext;
186 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
188 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
189 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
190 Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr,
191 Image_PixMap& theImage,
192 const Graphic3d_BufferType& theBufferType);
194 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
195 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
196 Standard_Boolean& UseGLLight() { return myUseGLLight; }
198 Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; }
200 //// RELATED TO STATUS ////
202 Standard_Integer NamedStatus;
204 const TEL_COLOUR* HighlightColor;
206 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
207 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
208 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
209 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
211 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
213 //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
214 Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
215 Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
216 Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
217 Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
218 inline const OpenGl_TextParam* AspectTextParams() const
220 return TextParam_applied;
223 //! Clear the applied aspect state.
224 void ResetAppliedAspect();
226 Standard_EXPORT Handle(OpenGl_Texture) DisableTexture();
227 Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture,
228 const Handle(Graphic3d_TextureParams)& theParams = NULL);
229 const Handle(OpenGl_Texture)& ActiveTexture() const { return myTextureBound; }
231 //! Set filter for restricting rendering of particular elements.
232 //! Filter can be applied for rendering passes used by recursive
233 //! rendering algorithms for rendering elements of groups.
234 //! @param theFilter [in] the filter instance.
235 inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
237 myRenderFilter = theFilter;
240 //! Get rendering filter.
241 //! @return filter instance.
242 inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const
244 return myRenderFilter;
247 //! @return applied view matrix.
248 inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
250 //! @return applied model structure matrix.
251 inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
253 //! Sets and applies current polygon offset.
254 void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits);
256 //! Returns currently applied polygon offset params.
257 const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; }
259 //! @return true if clipping algorithm enabled
260 inline Standard_Boolean IsCullingEnabled() const { return myIsCullingEnabled; }
262 //! Returns a flag whether to redraw the scene using OpenGL rasterization
263 Standard_Boolean ToRedrawGL() const { return myToRedrawGL; }
267 //! Copy content of Back buffer to the Front buffer
268 void copyBackToFront();
270 virtual Standard_Boolean Activate();
272 void redraw1 (const Graphic3d_CView& theCView,
273 const Aspect_CLayer2d& theCUnderLayer,
274 const Aspect_CLayer2d& theCOverLayer);
276 //! Blit snapshot containing main scene (myResultFBO or BackBuffer)
277 //! into presentation buffer (myResultFBO->offscreen FBO or myResultFBO->BackBuffer or BackBuffer->FrontBuffer),
278 //! and redraw immediate structures on top.
280 //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
281 //! the first step (blitting) will be skipped.
283 //! @return false if immediate structures has been rendered directly into FrontBuffer and Buffer Swap should not be called.
284 bool redrawImmediate (const Graphic3d_CView& theCView,
285 const Aspect_CLayer2d& theCUnderLayer,
286 const Aspect_CLayer2d& theCOverLayer,
287 OpenGl_FrameBuffer* theTargetFBO,
288 const Standard_Boolean theIsPartialUpdate = Standard_False);
290 void updateMaterial (const int theFlag);
292 void setTextureParams (Handle(OpenGl_Texture)& theTexture,
293 const Handle(Graphic3d_TextureParams)& theParams);
297 //! Result of OpenGL shaders initialization.
298 enum RaytraceInitStatus
305 //! Describes update mode (state).
308 OpenGl_GUM_CHECK, //!< check if geometry update is necessary
309 OpenGl_GUM_PREPARE, //!< collect unchanged objects
310 OpenGl_GUM_UPDATE //!< update raytracing data, rebuild changed objects
313 //! Defines frequently used shader variables.
314 enum ShaderVariableIndex
326 OpenGl_RT_uUnviewMat,
330 OpenGl_RT_uLightAmbnt,
331 OpenGl_RT_uLightCount,
333 OpenGl_RT_uShadEnabled,
334 OpenGl_RT_uReflEnabled,
335 OpenGl_RT_uEnvMapEnable,
345 OpenGl_RT_NbVariables // special field
348 //! Defines texture samplers.
349 enum ShaderSamplerNames
351 OpenGl_RT_SceneNodeInfoTexture = 0,
352 OpenGl_RT_SceneMinPointTexture = 1,
353 OpenGl_RT_SceneMaxPointTexture = 2,
354 OpenGl_RT_SceneTransformTexture = 3,
356 OpenGl_RT_GeometryVertexTexture = 4,
357 OpenGl_RT_GeometryNormalTexture = 5,
358 OpenGl_RT_GeometryTexCrdTexture = 6,
359 OpenGl_RT_GeometryTriangTexture = 7,
361 OpenGl_RT_EnvironmentMapTexture = 8,
363 OpenGl_RT_RaytraceMaterialTexture = 9,
364 OpenGl_RT_RaytraceLightSrcTexture = 10,
366 OpenGl_RT_FSAAInputTexture = 11,
368 OpenGl_RT_OpenGlColorTexture = 12,
369 OpenGl_RT_OpenGlDepthTexture = 13
372 //! Tool class for management of shader sources.
377 //! Creates new uninitialized shader source.
383 //! Creates new shader source from specified file.
384 ShaderSource (const TCollection_AsciiString& theFileName)
386 Load (&theFileName, 1);
391 //! Returns prefix to insert before the source.
392 const TCollection_AsciiString& Prefix() const
397 //! Sets prefix to insert before the source.
398 void SetPrefix (const TCollection_AsciiString& thePrefix)
400 myPrefix = thePrefix;
403 //! Returns shader source combined with prefix.
404 TCollection_AsciiString Source() const;
406 //! Loads shader source from specified files.
407 void Load (const TCollection_AsciiString* theFileNames, const Standard_Integer theCount);
411 TCollection_AsciiString mySource; //!< Source string of the shader object
412 TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
416 //! Default ray-tracing depth.
417 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
419 //! Default size of traversal stack.
420 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
422 //! Compile-time ray-tracing parameters.
423 struct RaytracingParams
425 //! Actual size of traversal stack in shader program.
426 Standard_Integer StackSize;
428 //! Actual ray-tracing depth (number of ray bounces).
429 Standard_Integer NbBounces;
431 //! Sets light propagation through transparent media.
432 Standard_Boolean TransparentShadows;
434 //! Creates default compile-time ray-tracing parameters.
436 : StackSize (THE_DEFAULT_STACK_SIZE),
437 NbBounces (THE_DEFAULT_NB_BOUNCES),
438 TransparentShadows (Standard_False)
444 protected: //! @name methods related to ray-tracing
446 //! Updates 3D scene geometry for ray-tracing.
447 Standard_Boolean UpdateRaytraceGeometry (GeomUpdateMode theMode);
449 //! Checks to see if the structure is modified.
450 Standard_Boolean CheckRaytraceStructure (const OpenGl_Structure* theStructure);
452 //! Creates ray-tracing material properties.
453 Standard_Boolean CreateMaterial (const OpenGl_AspectFace* theAspect, OpenGl_RaytraceMaterial& theMaterial);
455 //! Updates 3D scene light sources for ray-tracing.
456 Standard_Boolean UpdateRaytraceLightSources (const OpenGl_Mat4& theInvModelView);
458 //! Updates environment map for ray-tracing.
459 Standard_Boolean UpdateRaytraceEnvironmentMap();
461 //! Adds OpenGL structure to ray-traced scene geometry.
462 Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure, std::set<const OpenGl_Structure*>& theElements);
464 //! Adds OpenGL groups to ray-traced scene geometry.
465 Standard_Boolean AddRaytraceGroups (const OpenGl_Structure* theStructure,
466 const Standard_Integer theStructMatId,
467 const Standard_ShortReal* theTransform);
469 //! Adds OpenGL primitive array to ray-traced scene geometry.
470 OpenGl_TriangleSet* AddRaytracePrimitiveArray (
471 const OpenGl_PrimitiveArray* theArray, int theMatID, const OpenGl_Mat4* theTrans);
473 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
474 Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
475 const OpenGl_PrimitiveArray& theArray,
476 Standard_Integer theOffset,
477 Standard_Integer theCount,
478 Standard_Integer theMatID);
480 //! Adds OpenGL triangle array to ray-traced scene geometry.
481 Standard_Boolean AddRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
482 const Handle(Graphic3d_IndexBuffer)& theIndices,
483 Standard_Integer theOffset,
484 Standard_Integer theCount,
485 Standard_Integer theMatID);
487 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
488 Standard_Boolean AddRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
489 const Handle(Graphic3d_IndexBuffer)& theIndices,
490 Standard_Integer theOffset,
491 Standard_Integer theCount,
492 Standard_Integer theMatID);
494 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
495 Standard_Boolean AddRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
496 const Handle(Graphic3d_IndexBuffer)& theIndices,
497 Standard_Integer theOffset,
498 Standard_Integer theCount,
499 Standard_Integer theMatID);
501 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
502 Standard_Boolean AddRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
503 const Handle(Graphic3d_IndexBuffer)& theIndices,
504 Standard_Integer theOffset,
505 Standard_Integer theCount,
506 Standard_Integer theMatID);
508 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
509 Standard_Boolean AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
510 const Handle(Graphic3d_IndexBuffer)& theIndices,
511 Standard_Integer theOffset,
512 Standard_Integer theCount,
513 Standard_Integer theMatID);
515 //! Adds OpenGL polygon array to ray-traced scene geometry.
516 Standard_Boolean AddRaytracePolygonArray (OpenGl_TriangleSet& theSet,
517 const Handle(Graphic3d_IndexBuffer)& theIndices,
518 Standard_Integer theOffset,
519 Standard_Integer theCount,
520 Standard_Integer theMatID);
522 //! Loads and compiles shader object from specified source.
523 Handle(OpenGl_ShaderObject) LoadShader (const ShaderSource& theSource, GLenum theType);
525 //! Performs safe exit when shaders initialization fails.
526 Standard_Boolean SafeFailBack (const TCollection_ExtendedString& theMessage);
528 //! Generates shader prefix based on current ray-tracing options.
529 TCollection_AsciiString GenerateShaderPrefix();
531 //! Initializes OpenGL/GLSL shader programs.
532 Standard_Boolean InitRaytraceResources (const Graphic3d_CView& theCView);
534 //! Releases OpenGL/GLSL shader programs.
535 void ReleaseRaytraceResources();
537 //! Uploads ray-trace data to the GPU.
538 Standard_Boolean UploadRaytraceData();
540 //! Resizes OpenGL frame buffers.
541 Standard_Boolean ResizeRaytraceBuffers (const Standard_Integer theSizeX,
542 const Standard_Integer theSizeY);
544 //! Generates viewing rays for corners of screen quad.
545 void UpdateCamera (const OpenGl_Mat4& theOrientation,
546 const OpenGl_Mat4& theViewMapping,
547 OpenGl_Vec3 theOrigins[4],
548 OpenGl_Vec3 theDirects[4],
549 OpenGl_Mat4& theInvModelProj);
551 //! Sets uniform state for the given ray-tracing shader program.
552 Standard_Boolean SetUniformState (const Graphic3d_CView& theCView,
553 const Standard_Integer theSizeX,
554 const Standard_Integer theSizeY,
555 const OpenGl_Vec3* theOrigins,
556 const OpenGl_Vec3* theDirects,
557 const OpenGl_Mat4& theUnviewMat,
558 const Standard_Integer theProgramIndex,
559 Handle(OpenGl_ShaderProgram)& theRaytraceProgram);
561 //! Runs ray-tracing shader programs.
562 Standard_Boolean RunRaytraceShaders (const Graphic3d_CView& theCView,
563 const Standard_Integer theSizeX,
564 const Standard_Integer theSizeY,
565 const OpenGl_Vec3 theOrigins[4],
566 const OpenGl_Vec3 theDirects[4],
567 const OpenGl_Mat4& theUnviewMat,
568 OpenGl_FrameBuffer* theFrameBuffer);
570 //! Redraws the window using OpenGL/GLSL ray-tracing.
571 Standard_Boolean Raytrace (const Graphic3d_CView& theCView,
572 const Standard_Integer theSizeX,
573 const Standard_Integer theSizeY,
574 const Aspect_CLayer2d& theCOverLayer,
575 const Aspect_CLayer2d& theCUnderLayer,
576 OpenGl_FrameBuffer* theFrameBuffer);
578 protected: //! @name fields related to ray-tracing
580 //! Result of shaders initialization.
581 RaytraceInitStatus myComputeInitStatus;
583 //! Is geometry data valid?
584 Standard_Boolean myIsRaytraceDataValid;
586 //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
587 Standard_Boolean myIsRaytraceWarnTextures;
589 //! 3D scene geometry data for ray-tracing.
590 OpenGl_RaytraceGeometry myRaytraceGeometry;
592 //! Radius of bounding sphere of the scene.
593 Standard_ShortReal myRaytraceSceneRadius;
594 //! Scene epsilon to prevent self-intersections.
595 Standard_ShortReal myRaytraceSceneEpsilon;
597 //! Compile-time ray-tracing parameters.
598 RaytracingParams myRaytraceParameters;
600 //! OpenGL/GLSL source of ray-tracing fragment shader.
601 ShaderSource myRaytraceShaderSource;
602 //! OpenGL/GLSL source of adaptive-AA fragment shader.
603 ShaderSource myPostFSAAShaderSource;
605 //! OpenGL/GLSL ray-tracing fragment shader.
606 Handle(OpenGl_ShaderObject) myRaytraceShader;
607 //! OpenGL/GLSL adaptive-AA fragment shader.
608 Handle(OpenGl_ShaderObject) myPostFSAAShader;
610 //! OpenGL/GLSL ray-tracing shader program.
611 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
612 //! OpenGL/GLSL adaptive-AA shader program.
613 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
615 //! Texture buffer of data records of bottom-level BVH nodes.
616 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
617 //! Texture buffer of minimum points of bottom-level BVH nodes.
618 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
619 //! Texture buffer of maximum points of bottom-level BVH nodes.
620 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
621 //! Texture buffer of transformations of high-level BVH nodes.
622 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
624 //! Texture buffer of vertex coords.
625 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
626 //! Texture buffer of vertex normals.
627 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
628 //! Texture buffer of vertex UV coords.
629 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
630 //! Texture buffer of triangle indices.
631 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
633 //! Texture buffer of material properties.
634 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
635 //! Texture buffer of light source properties.
636 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
638 //! Vertex buffer (VBO) for drawing dummy quad.
639 OpenGl_VertexBuffer myRaytraceScreenQuad;
641 //! Framebuffer (FBO) to perform adaptive FSAA.
642 Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
643 //! Framebuffer (FBO) to perform adaptive FSAA.
644 Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
645 //! Framebuffer (FBO) for pre-raytrace rendering by OpenGL.
646 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
648 //! Framebuffer stores cached main presentation of the view (without presentation of immediate layers).
649 Handle(OpenGl_FrameBuffer) myResultFBO;
650 //! Special flag which is invalidated when myResultFBO can not be blitted for some reason (e.g. driver bugs).
651 Standard_Boolean myHasFboBlit;
653 //! Vertices for full-screen quad rendering.
654 OpenGl_VertexBuffer myFullScreenQuad;
656 //! State of OpenGL view.
657 Standard_Size myViewModificationStatus;
658 //! State of OpenGL layer list.
659 Standard_Size myLayersModificationStatus;
661 //! State of OpenGL structures reflected to ray-tracing.
662 std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
664 //! PrimitiveArray to TriangleSet map for scene partial update.
665 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
667 //! Cached locations of frequently used uniform variables.
668 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
670 //! Graphical ray-tracing filter to filter out all raytracable structures.
671 Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
673 //! Redraw the scene using OpenGL rasterization or ray-tracing?
674 Standard_Boolean myToRedrawGL;
676 protected: //! @name protected fields
678 Handle(OpenGl_PrinterContext) myPrintContext;
679 Handle(OpenGl_View) myView;
680 Handle(OpenGl_LineAttributes) myLineAttribs;
681 Standard_Integer myViewId;
682 Standard_Integer myAntiAliasingMode;
683 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
684 Standard_Boolean myBackBufferRestored;
685 Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data
686 Standard_Boolean myUseZBuffer;
687 Standard_Boolean myUseDepthTest;
688 Standard_Boolean myUseGLLight;
689 Standard_Boolean myIsCullingEnabled; //!< frustum culling flag
691 unsigned int myFrameCounter; //!< redraw counter, for debugging
693 protected: //! @name fields related to status
695 Handle(OpenGl_RenderFilter) myRenderFilter;
696 Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture)
697 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
698 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
699 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
700 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
702 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
704 const OpenGl_Matrix* ViewMatrix_applied;
705 const OpenGl_Matrix* StructureMatrix_applied;
707 OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates)
708 OpenGl_Material myMatBack; //!< current back material state
709 OpenGl_Material myMatTmp; //!< temporary variable
710 TelCullMode myCullingMode; //!< back face culling mode, applied from face aspect
712 OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
714 TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset.
716 OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
718 public: //! @name type definition
720 DEFINE_STANDARD_RTTI(OpenGl_Workspace)
721 DEFINE_STANDARD_ALLOC
725 #endif // _OpenGl_Workspace_Header