1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 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_View_Header
17 #define _OpenGl_View_Header
19 #include <Standard_Transient.hxx>
20 #include <Standard_Type.hxx>
22 #include <TColStd_Array2OfReal.hxx>
23 #include <NCollection_List.hxx>
24 #include <math_BullardGenerator.hxx>
26 #include <Quantity_NameOfColor.hxx>
27 #include <Aspect_FillMethod.hxx>
28 #include <Aspect_GradientFillMethod.hxx>
30 #include <Graphic3d_CView.hxx>
31 #include <Graphic3d_CullingTool.hxx>
32 #include <Graphic3d_GraduatedTrihedron.hxx>
33 #include <Graphic3d_SequenceOfHClipPlane.hxx>
34 #include <Graphic3d_ToneMappingMethod.hxx>
35 #include <Graphic3d_TypeOfShadingModel.hxx>
36 #include <Graphic3d_WorldViewProjState.hxx>
37 #include <Graphic3d_ZLayerSettings.hxx>
39 #include <OpenGl_Aspects.hxx>
40 #include <OpenGl_BackgroundArray.hxx>
41 #include <OpenGl_Context.hxx>
42 #include <OpenGl_FrameBuffer.hxx>
43 #include <OpenGl_FrameStatsPrs.hxx>
44 #include <OpenGl_GraduatedTrihedron.hxx>
45 #include <OpenGl_LayerList.hxx>
46 #include <OpenGl_LineAttributes.hxx>
47 #include <OpenGl_SceneGeometry.hxx>
48 #include <OpenGl_Structure.hxx>
49 #include <OpenGl_Window.hxx>
50 #include <OpenGl_Workspace.hxx>
51 #include <OpenGl_TileSampler.hxx>
58 class Graphic3d_StructureManager;
59 class OpenGl_DepthPeeling;
60 class OpenGl_GraphicDriver;
61 class OpenGl_PBREnvironment;
62 class OpenGl_StateCounter;
63 class OpenGl_ShadowMap;
64 class OpenGl_ShadowMapArray;
65 class OpenGl_TriangleSet;
66 class OpenGl_Workspace;
69 DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
71 //! Implementation of OpenGl view.
72 class OpenGl_View : public Graphic3d_CView
78 Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
79 const Handle(OpenGl_GraphicDriver)& theDriver,
80 const Handle(OpenGl_Caps)& theCaps,
81 OpenGl_StateCounter* theCounter);
83 //! Default destructor.
84 Standard_EXPORT virtual ~OpenGl_View();
86 //! Release OpenGL resources.
87 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
89 //! Deletes and erases the view.
90 Standard_EXPORT virtual void Remove() Standard_OVERRIDE;
92 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
93 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
94 //! Fast, so preferred for interactive work (used by default).
95 //! However these extra drawings will be missed in image dump since it is performed from back buffer.
96 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
97 //! in run-time (in case of slow hardware) and/or tearing may appear.
98 //! So this is strongly recommended to draw only simple (fast) structures.
99 //! 2. FALSE. Drawing immediate mode structures to the back buffer.
100 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
101 //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
102 //! from the back buffer.
103 //! @return previous mode.
104 Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
106 //! Creates and maps rendering window to the view.
107 //! @param theWindow [in] the window.
108 //! @param theContext [in] the rendering context. If NULL the context will be created internally.
109 Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
110 const Aspect_RenderingContext theContext) Standard_OVERRIDE;
112 //! Returns window associated with the view.
113 virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE
114 { return myWindow->PlatformWindow(); }
116 //! Returns True if the window associated to the view is defined.
117 virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
118 { return !myWindow.IsNull(); }
120 //! Handle changing size of the rendering window.
121 Standard_EXPORT virtual void Resized() Standard_OVERRIDE;
123 //! Redraw content of the view.
124 Standard_EXPORT virtual void Redraw() Standard_OVERRIDE;
126 //! Redraw immediate content of the view.
127 Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE;
129 //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild.
130 Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
132 //! Return true if view content cache has been invalidated.
133 virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
135 //! Dump active rendering buffer into specified memory buffer.
136 //! In Ray-Tracing allow to get a raw HDR buffer using Graphic3d_BT_RGB_RayTraceHdrLeft buffer type,
137 //! only Left view will be dumped ignoring stereoscopic parameter.
138 Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
139 const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
141 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
142 Standard_EXPORT virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
144 //! Add a layer to the view.
145 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
146 //! @param theSettings [in] new layer settings
147 //! @param theLayerAfter [in] id of layer to append new layer before
148 Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
149 const Graphic3d_ZLayerSettings& theSettings,
150 const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
152 //! Add a layer to the view.
153 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
154 //! @param theSettings [in] new layer settings
155 //! @param theLayerBefore [in] id of layer to append new layer after
156 Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
157 const Graphic3d_ZLayerSettings& theSettings,
158 const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
160 //! Remove a z layer with the given ID.
161 Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
163 //! Sets the settings for a single Z layer of specified view.
164 Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
165 const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
167 //! Returns the maximum Z layer ID.
168 //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
169 Standard_EXPORT virtual Standard_Integer ZLayerMax() const Standard_OVERRIDE;
171 //! Returns the list of layers.
172 Standard_EXPORT virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const Standard_OVERRIDE;
174 //! Returns layer with given ID or NULL if undefined.
175 Standard_EXPORT virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
177 //! Returns the bounding box of all structures displayed in the view.
178 //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
179 //! of graphical elements forming parts of infinite and other auxiliary structures.
180 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
181 //! @return computed bounding box
182 Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const Standard_OVERRIDE;
184 //! Returns pointer to an assigned framebuffer object.
185 Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
187 //! Sets framebuffer object for offscreen rendering.
188 Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
190 //! Generate offscreen FBO in the graphic library.
191 //! If not supported on hardware returns NULL.
192 Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
193 const Standard_Integer theHeight) Standard_OVERRIDE;
195 //! Remove offscreen FBO from the graphic library
196 Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
198 //! Read offscreen FBO configuration.
199 Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
200 Standard_Integer& theWidth,
201 Standard_Integer& theHeight,
202 Standard_Integer& theWidthMax,
203 Standard_Integer& theHeightMax) Standard_OVERRIDE;
205 //! Change offscreen FBO viewport.
206 Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
207 const Standard_Integer theWidth,
208 const Standard_Integer theHeight) Standard_OVERRIDE;
210 //! Returns additional buffers for depth peeling OIT.
211 const Handle(OpenGl_DepthPeeling)& DepthPeelingFbos() const { return myDepthPeelingFbos; }
215 //! Returns gradient background fill colors.
216 Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
218 //! Sets gradient background fill colors.
219 Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
221 //! Returns background image texture map.
222 virtual Handle(Graphic3d_TextureMap) BackgroundImage() Standard_OVERRIDE { return myBackgroundImage; }
224 //! Sets image texture or environment cubemap as backround.
225 //! @param theTextureMap [in] source to set a background;
226 //! should be either Graphic3d_Texture2D or Graphic3d_CubeMap
227 //! @param theToUpdatePBREnv [in] defines whether IBL maps will be generated or not
228 //! (see GeneratePBREnvironment())
229 Standard_EXPORT virtual void SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
230 Standard_Boolean theToUpdatePBREnv = Standard_True) Standard_OVERRIDE;
232 //! Returns background image fill style.
233 Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
235 //! Sets background image fill style.
236 Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE;
238 //! Returns cubemap being set last time on background.
239 Standard_EXPORT Handle(Graphic3d_CubeMap) BackgroundCubeMap() const Standard_OVERRIDE;
241 //! Generates PBR specular probe and irradiance map
242 //! in order to provide environment indirect illumination in PBR shading model (Image Based Lighting).
243 //! The source of environment data is background cubemap.
244 //! If PBR is unavailable it does nothing.
245 //! If PBR is available but there is no cubemap being set to background it clears all IBL maps (see 'ClearPBREnvironment').
246 virtual void GeneratePBREnvironment() Standard_OVERRIDE { myPBREnvRequest = OpenGl_PBREnvRequest_BAKE; }
248 //! Fills PBR specular probe and irradiance map with white color.
249 //! So that environment indirect illumination will be constant
250 //! and will be fully controlled by ambient light sources.
251 //! If PBR is unavailable it does nothing.
252 virtual void ClearPBREnvironment() Standard_OVERRIDE { myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR; }
254 //! Returns number of mipmap levels used in specular IBL map.
255 //! 0 if PBR environment is not created.
256 Standard_EXPORT unsigned int SpecIBLMapLevels() const;
258 //! Returns environment texture set for the view.
259 virtual Handle(Graphic3d_TextureEnv) TextureEnv() const Standard_OVERRIDE { return myTextureEnvData; }
261 //! Sets environment texture for the view.
262 Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
264 //! Return backfacing model used for the view.
265 virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; }
267 //! Sets backfacing model for the view.
268 virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; }
270 //! Returns local camera origin currently set for rendering, might be modified during rendering.
271 const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
273 //! Setup local camera origin currently set for rendering.
274 Standard_EXPORT void SetLocalOrigin (const gp_XYZ& theOrigin);
276 //! Returns list of lights of the view.
277 virtual const Handle(Graphic3d_LightSet)& Lights() const Standard_OVERRIDE { return myLights; }
279 //! Sets list of lights for the view.
280 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) Standard_OVERRIDE
282 myLights = theLights;
283 myCurrLightSourceState = myStateCounter->Increment();
286 //! Returns list of clip planes set for the view.
287 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
289 //! Sets list of clip planes for the view.
290 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
292 //! Fill in the dictionary with diagnostic info.
293 //! Should be called within rendering thread.
295 //! This API should be used only for user output or for creating automated reports.
296 //! The format of returned information (e.g. key-value layout)
297 //! is NOT part of this API and can be changed at any time.
298 //! Thus application should not parse returned information to weed out specific parameters.
299 Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
300 Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE;
302 //! Returns string with statistic performance info.
303 Standard_EXPORT virtual TCollection_AsciiString StatisticInformation() const Standard_OVERRIDE;
305 //! Fills in the dictionary with statistic performance info.
306 Standard_EXPORT virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const Standard_OVERRIDE;
310 //! Returns background color.
311 const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
313 //! Change graduated trihedron.
314 OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
316 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
317 const Handle(Graphic3d_TextureEnv)& theTexture);
319 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
321 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
323 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
325 //! Returns list of OpenGL Z-layers.
326 const OpenGl_LayerList& LayerList() const { return myZLayers; }
328 //! Returns OpenGL window implementation.
329 const Handle(OpenGl_Window)& GlWindow() const { return myWindow; }
331 //! Returns OpenGL environment map.
332 const Handle(OpenGl_TextureSet)& GlTextureEnv() const { return myTextureEnv; }
334 //! Returns selector for BVH tree, providing a possibility to store information
335 //! about current view volume and to detect which objects are overlapping it.
336 const Graphic3d_CullingTool& BVHTreeSelector() const { return myBVHSelector; }
338 //! Returns true if there are immediate structures to display
339 bool HasImmediateStructures() const
341 return myZLayers.NbImmediateStructures() != 0;
344 public: //! @name obsolete Graduated Trihedron functionality
346 //! Displays Graduated Trihedron.
347 Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
349 //! Erases Graduated Trihedron.
350 Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
352 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
353 //! @param theMin [in] the minimum point of scene.
354 //! @param theMax [in] the maximum point of scene.
355 Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
357 protected: //! @name Internal methods for managing GL resources
359 //! Initializes OpenGl resource for environment texture.
360 void initTextureEnv (const Handle(OpenGl_Context)& theContext);
362 protected: //! @name low-level redrawing sub-routines
364 //! Prepare frame buffers for rendering.
365 Standard_EXPORT virtual bool prepareFrameBuffers (Graphic3d_Camera::Projection& theProj);
367 //! Redraws view for the given monographic camera projection, or left/right eye.
368 Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
369 OpenGl_FrameBuffer* theReadDrawFbo,
370 OpenGl_FrameBuffer* theOitAccumFbo);
372 //! Redraws view for the given monographic camera projection, or left/right eye.
374 //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer)
375 //! into presentation buffer (myMainSceneFbos -> offscreen FBO or
376 //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer),
377 //! and redraw immediate structures on top.
379 //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
380 //! the first step (blitting) will be skipped.
382 //! @return false if immediate structures has been rendered directly into FrontBuffer
383 //! and Buffer Swap should not be called.
384 Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
385 OpenGl_FrameBuffer* theReadFbo,
386 OpenGl_FrameBuffer* theDrawFbo,
387 OpenGl_FrameBuffer* theOitAccumFbo,
388 const Standard_Boolean theIsPartialUpdate = Standard_False);
390 //! Blit image from/to specified buffers.
391 Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo,
392 OpenGl_FrameBuffer* theDrawFbo,
393 const Standard_Boolean theToFlip = Standard_False);
395 //! Setup default FBO.
396 Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
398 protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
400 //! Renders the graphical contents of the view into the preprepared shadowmap framebuffer.
401 //! @param theShadowMap [in] the framebuffer for rendering shadowmap.
402 Standard_EXPORT virtual void renderShadowMap (const Handle(OpenGl_ShadowMap)& theShadowMap);
404 //! Renders the graphical contents of the view into the preprepared window or framebuffer.
405 //! @param theProjection [in] the projection that should be used for rendering.
406 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
407 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
408 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
409 Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
410 OpenGl_FrameBuffer* theReadDrawFbo,
411 OpenGl_FrameBuffer* theOitAccumFbo,
412 const Standard_Boolean theToDrawImmediate);
414 //! Renders the graphical scene.
415 //! @param theProjection [in] the projection that is used for rendering.
416 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
417 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
418 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
419 Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
420 OpenGl_FrameBuffer* theReadDrawFbo,
421 OpenGl_FrameBuffer* theOitAccumFbo,
422 const Standard_Boolean theToDrawImmediate);
424 //! Draw background (gradient / image)
425 Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
426 Graphic3d_Camera::Projection theProjection);
428 //! Render set of structures presented in the view.
429 //! @param theProjection [in] the projection that is used for rendering.
430 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
431 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
432 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
433 Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
434 OpenGl_FrameBuffer* theReadDrawFbo,
435 OpenGl_FrameBuffer* theOitAccumFbo,
436 const Standard_Boolean theToDrawImmediate);
438 //! Renders trihedron.
439 void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
441 //! Renders frame statistics.
442 void renderFrameStats();
446 //! Adds the structure to display lists of the view.
447 Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
448 const Standard_Integer thePriority) Standard_OVERRIDE;
450 //! Erases the structure from display lists of the view.
451 Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
453 //! Change Z layer of a structure already presented in view.
454 Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
455 const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
457 //! Changes the priority of a structure within its Z layer in the specified view.
458 Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
459 const Standard_Integer theNewPriority) Standard_OVERRIDE;
463 //! Release sRGB resources (frame-buffers, textures, etc.).
464 void releaseSrgbResources (const Handle(OpenGl_Context)& theCtx);
466 //! Copy content of Back buffer to the Front buffer.
467 bool copyBackToFront();
469 //! Initialize blit quad.
470 OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
472 //! Blend together views pair into stereo image.
473 void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
475 //! Check and update OIT compatibility with current OpenGL context's state.
476 bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
477 const Standard_Boolean theMSAA);
479 //! Chooses compatible internal color format for OIT frame buffer.
480 bool chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
481 const Standard_Integer theConfigIndex,
482 OpenGl_ColorFormats& theFormats);
486 OpenGl_GraphicDriver* myDriver;
487 Handle(OpenGl_Window) myWindow;
488 Handle(OpenGl_Workspace) myWorkspace;
489 Handle(OpenGl_Caps) myCaps;
490 Standard_Boolean myWasRedrawnGL;
492 Graphic3d_TypeOfBackfacingModel myBackfacing;
493 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
494 gp_XYZ myLocalOrigin;
495 Handle(OpenGl_FrameBuffer) myFBO;
496 Standard_Boolean myToShowGradTrihedron;
497 Handle(Graphic3d_TextureMap) myBackgroundImage;
498 Handle(Graphic3d_TextureEnv) myTextureEnvData;
499 Graphic3d_GraduatedTrihedron myGTrihedronData;
501 Handle(Graphic3d_LightSet) myNoShadingLight;
502 Handle(Graphic3d_LightSet) myLights;
503 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
505 Graphic3d_WorldViewProjState myWorldViewProjState; //!< camera modification state
506 OpenGl_StateCounter* myStateCounter;
507 Standard_Size myCurrLightSourceState;
508 Standard_Size myLightsRevision;
510 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
512 StateInfo myLastOrientationState;
513 StateInfo myLastViewMappingState;
514 StateInfo myLastLightSourceState;
516 //! Is needed for selection of overlapping objects and storage of the current view volume
517 Graphic3d_CullingTool myBVHSelector;
519 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
520 OpenGl_FrameStatsPrs myFrameStatsPrs;
522 Handle(OpenGl_TextureSet) myTextureEnv;
524 //! Framebuffers for OpenGL output.
525 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
526 Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
528 protected: //! @name Rendering properties
530 //! Two framebuffers (left and right views) store cached main presentation
531 //! of the view (without presentation of immediate layers).
532 Standard_Integer mySRgbState; //!< track sRGB state
533 GLint myFboColorFormat; //!< sized format for color attachments
534 GLint myFboDepthFormat; //!< sized format for depth-stencil attachments
535 OpenGl_ColorFormats myFboOitColorConfig; //!< selected color format configuration for OIT color attachments
536 Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
537 Handle(OpenGl_FrameBuffer) myMainSceneFbosOit[2]; //!< Additional buffers for transparent draw of main layer.
538 Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode.
539 Handle(OpenGl_FrameBuffer) myImmediateSceneFbosOit[2]; //!< Additional buffers for transparency draw of immediate layer.
540 Handle(OpenGl_FrameBuffer) myXrSceneFbo; //!< additional FBO (without MSAA) for submitting to XR
541 Handle(OpenGl_DepthPeeling) myDepthPeelingFbos; //!< additional buffers for depth peeling
542 Handle(OpenGl_ShadowMapArray) myShadowMaps; //!< additional FBOs for shadow map rendering
543 OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering.
544 OpenGl_VertexBuffer myFullScreenQuadFlip;
545 Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down
546 unsigned int myFrameCounter; //!< redraw counter, for debugging
547 Standard_Boolean myHasFboBlit; //!< disable FBOs on failure
548 Standard_Boolean myToDisableOIT; //!< disable OIT on failure
549 Standard_Boolean myToDisableOITMSAA; //!< disable OIT with MSAA on failure
550 Standard_Boolean myToDisableMSAA; //!< disable MSAA after failure
551 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
552 Standard_Boolean myBackBufferRestored;
553 Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data
555 protected: //! @name Background parameters
557 OpenGl_Aspects* myTextureParams; //!< Stores texture and its parameters for textured background
558 OpenGl_Aspects* myCubeMapParams; //!< Stores cubemap and its parameters for cubemap background
559 Handle(Graphic3d_CubeMap) myBackgroundCubeMap; //!< Cubemap has been set as background
560 Graphic3d_TypeOfBackground myBackgroundType; //!< Current type of background
561 OpenGl_BackgroundArray* myBackgrounds[Graphic3d_TypeOfBackground_NB]; //!< Array of primitive arrays of different background types
563 protected: //! @name methods related to PBR
565 //! Checks whether PBR is available.
566 Standard_EXPORT Standard_Boolean checkPBRAvailability() const;
568 //! Generates IBL maps used in PBR pipeline.
569 //! If background cubemap is not set clears all IBL maps.
570 Standard_EXPORT void bakePBREnvironment (const Handle(OpenGl_Context)& theCtx);
572 //! Fills all IBL maps with white color.
573 //! So that environment lighting is considered to be constant and is completely controls by ambient light sources.
574 Standard_EXPORT void clearPBREnvironment (const Handle(OpenGl_Context)& theCtx);
576 //! Process requests to generate or to clear PBR environment.
577 Standard_EXPORT void processPBREnvRequest (const Handle(OpenGl_Context)& theCtx);
579 protected: //! @name fields and types related to PBR
581 //! State of PBR environment.
582 enum PBREnvironmentState
584 OpenGl_PBREnvState_NONEXISTENT,
585 OpenGl_PBREnvState_UNAVAILABLE, // indicates failed try to create PBR environment
586 OpenGl_PBREnvState_CREATED
589 //! Type of action which can be done with PBR environment.
590 enum PBREnvironmentRequest
592 OpenGl_PBREnvRequest_NONE,
593 OpenGl_PBREnvRequest_BAKE,
594 OpenGl_PBREnvRequest_CLEAR
597 Handle(OpenGl_PBREnvironment) myPBREnvironment; //!< manager of IBL maps used in PBR pipeline
598 PBREnvironmentState myPBREnvState; //!< state of PBR environment
599 PBREnvironmentRequest myPBREnvRequest; //!< type of action is requested to be done with PBR environment
601 protected: //! @name data types related to ray-tracing
603 //! Result of OpenGL shaders initialization.
604 enum RaytraceInitStatus
611 //! Describes update mode (state).
612 enum RaytraceUpdateMode
614 OpenGl_GUM_CHECK, //!< check geometry state
615 OpenGl_GUM_PREPARE, //!< collect unchanged objects
616 OpenGl_GUM_REBUILD //!< rebuild changed and new objects
619 //! Defines frequently used shader variables.
620 enum ShaderVariableIndex
633 OpenGl_RT_uViewPrMat,
634 OpenGl_RT_uUnviewMat,
639 OpenGl_RT_uLightAmbnt,
640 OpenGl_RT_uLightCount,
643 OpenGl_RT_uBackColorTop,
644 OpenGl_RT_uBackColorBot,
646 // ray-tracing params
647 OpenGl_RT_uShadowsEnabled,
648 OpenGl_RT_uReflectEnabled,
649 OpenGl_RT_uEnvMapEnabled,
650 OpenGl_RT_uEnvMapForBack,
651 OpenGl_RT_uTexSamplersArray,
652 OpenGl_RT_uBlockedRngEnabled,
654 // size of render window
658 // sampled frame params
659 OpenGl_RT_uAccumSamples,
660 OpenGl_RT_uFrameRndSeed,
662 // adaptive FSAA params
663 OpenGl_RT_uFsaaOffset,
666 // images used by ISS mode
667 OpenGl_RT_uRenderImage,
668 OpenGl_RT_uTilesImage,
669 OpenGl_RT_uOffsetImage,
671 OpenGl_RT_uVarianceScaleFactor,
673 // maximum radiance value
674 OpenGl_RT_uMaxRadiance,
676 OpenGl_RT_NbVariables // special field
679 //! Defines OpenGL image samplers.
680 enum ShaderImageNames
682 OpenGl_RT_OutputImage = 0,
683 OpenGl_RT_VisualErrorImage = 1,
684 OpenGl_RT_TileOffsetsImage = 2,
685 OpenGl_RT_TileSamplesImage = 3
688 //! Tool class for management of shader sources.
693 //! Default shader prefix - empty string.
694 static const TCollection_AsciiString EMPTY_PREFIX;
696 //! Creates new uninitialized shader source.
704 //! Returns error description in case of load fail.
705 const TCollection_AsciiString& ErrorDescription() const
710 //! Returns prefix to insert before the source.
711 const TCollection_AsciiString& Prefix() const
716 //! Sets prefix to insert before the source.
717 void SetPrefix (const TCollection_AsciiString& thePrefix)
719 myPrefix = thePrefix;
722 //! Returns shader source combined with prefix.
723 TCollection_AsciiString Source (const Handle(OpenGl_Context)& theCtx,
724 const GLenum theType) const;
726 //! Loads shader source from specified files.
727 Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
729 //! Loads shader source from specified strings.
730 Standard_Boolean LoadFromStrings (const TCollection_AsciiString* theStrings, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
734 TCollection_AsciiString mySource; //!< Source string of the shader object
735 TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
736 TCollection_AsciiString myError; //!< error state
740 //! Default ray-tracing depth.
741 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
743 //! Default size of traversal stack.
744 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 10;
746 //! Compile-time ray-tracing parameters.
747 struct RaytracingParams
749 //! Actual size of traversal stack in shader program.
750 Standard_Integer StackSize;
752 //! Actual ray-tracing depth (number of ray bounces).
753 Standard_Integer NbBounces;
755 //! Enables/disables light propagation through transparent media.
756 Standard_Boolean TransparentShadows;
758 //! Enables/disables global illumination (GI) effects.
759 Standard_Boolean GlobalIllumination;
761 //! Enables/disables the use of OpenGL bindless textures.
762 Standard_Boolean UseBindlessTextures;
764 //! Enables/disables two-sided BSDF models instead of one-sided.
765 Standard_Boolean TwoSidedBsdfModels;
767 //! Enables/disables adaptive screen sampling for path tracing.
768 Standard_Boolean AdaptiveScreenSampling;
770 //! Enables/disables 1-pass atomic mode for AdaptiveScreenSampling.
771 Standard_Boolean AdaptiveScreenSamplingAtomic;
773 //! Enables/disables environment map for background.
774 Standard_Boolean UseEnvMapForBackground;
776 //! Enables/disables normal map ignoring during path tracing.
777 Standard_Boolean ToIgnoreNormalMap;
779 //! Maximum radiance value used for clamping radiance estimation.
780 Standard_ShortReal RadianceClampingValue;
782 //! Enables/disables depth-of-field effect (path tracing, perspective camera).
783 Standard_Boolean DepthOfField;
785 //! Enables/disables cubemap backgraund.
786 Standard_Boolean CubemapForBack;
788 //! Tone mapping method for path tracing.
789 Graphic3d_ToneMappingMethod ToneMappingMethod;
791 //! Creates default compile-time ray-tracing parameters.
793 : StackSize (THE_DEFAULT_STACK_SIZE),
794 NbBounces (THE_DEFAULT_NB_BOUNCES),
795 TransparentShadows (Standard_False),
796 GlobalIllumination (Standard_False),
797 UseBindlessTextures (Standard_False),
798 TwoSidedBsdfModels (Standard_False),
799 AdaptiveScreenSampling (Standard_False),
800 AdaptiveScreenSamplingAtomic (Standard_False),
801 UseEnvMapForBackground (Standard_False),
802 ToIgnoreNormalMap (Standard_False),
803 RadianceClampingValue (30.0),
804 DepthOfField (Standard_False),
805 CubemapForBack (Standard_False),
806 ToneMappingMethod (Graphic3d_ToneMappingMethod_Disabled) { }
809 //! Describes state of OpenGL structure.
812 Standard_Size StructureState;
813 Standard_Size InstancedState;
815 //! Creates new structure state.
816 StructState (const Standard_Size theStructureState = 0,
817 const Standard_Size theInstancedState = 0)
818 : StructureState (theStructureState),
819 InstancedState (theInstancedState)
824 //! Creates new structure state.
825 StructState (const OpenGl_Structure* theStructure)
827 StructureState = theStructure->ModificationState();
829 InstancedState = theStructure->InstancedStructure() != NULL ?
830 theStructure->InstancedStructure()->ModificationState() : 0;
834 protected: //! @name methods related to ray-tracing
836 //! Updates 3D scene geometry for ray-tracing.
837 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
838 const Standard_Integer theViewId,
839 const Handle(OpenGl_Context)& theGlContext);
841 //! Updates 3D scene light sources for ray-tracing.
842 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
844 //! Checks to see if the OpenGL structure is modified.
845 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
847 //! Adds OpenGL structure to ray-traced scene geometry.
848 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
849 const Handle(OpenGl_Context)& theGlContext);
851 //! Adds OpenGL groups to ray-traced scene geometry.
852 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
853 const OpenGl_RaytraceMaterial& theStructMat,
854 const Handle(TopLoc_Datum3D)& theTrsf,
855 const Handle(OpenGl_Context)& theGlContext);
857 //! Creates ray-tracing material properties.
858 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_Aspects* theAspect,
859 const Handle(OpenGl_Context)& theGlContext);
861 //! Adds OpenGL primitive array to ray-traced scene geometry.
862 Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
863 const Standard_Integer theMatID,
864 const OpenGl_Mat4* theTrans);
866 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
867 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
868 const Standard_Integer theMatID,
869 const Standard_Integer theCount,
870 const Standard_Integer theOffset,
871 const OpenGl_PrimitiveArray& theArray);
873 //! Adds OpenGL triangle array to ray-traced scene geometry.
874 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
875 const Standard_Integer theMatID,
876 const Standard_Integer theCount,
877 const Standard_Integer theOffset,
878 const Handle(Graphic3d_IndexBuffer)& theIndices);
880 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
881 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
882 const Standard_Integer theMatID,
883 const Standard_Integer theCount,
884 const Standard_Integer theOffset,
885 const Handle(Graphic3d_IndexBuffer)& theIndices);
887 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
888 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
889 const Standard_Integer theMatID,
890 const Standard_Integer theCount,
891 const Standard_Integer theOffset,
892 const Handle(Graphic3d_IndexBuffer)& theIndices);
894 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
895 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
896 const Standard_Integer theMatID,
897 const Standard_Integer theCount,
898 const Standard_Integer theOffset,
899 const Handle(Graphic3d_IndexBuffer)& theIndices);
901 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
902 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
903 const Standard_Integer theMatID,
904 const Standard_Integer theCount,
905 const Standard_Integer theOffset,
906 const Handle(Graphic3d_IndexBuffer)& theIndices);
908 //! Adds OpenGL polygon array to ray-traced scene geometry.
909 Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
910 const Standard_Integer theMatID,
911 const Standard_Integer theCount,
912 const Standard_Integer theOffset,
913 const Handle(Graphic3d_IndexBuffer)& theIndices);
915 //! Uploads ray-trace data to the GPU.
916 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
918 //! Generates shader prefix based on current ray-tracing options.
919 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
921 //! Performs safe exit when shaders initialization fails.
922 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
923 const Handle(OpenGl_Context)& theGlContext);
925 //! Loads and compiles shader object from specified source.
926 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
927 const ShaderSource& theSource,
928 const Handle(OpenGl_Context)& theGlContext);
930 //! Creates shader program from the given vertex and fragment shaders.
931 Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext,
932 const Handle(OpenGl_ShaderObject)& theVertShader,
933 const Handle(OpenGl_ShaderObject)& theFragShader,
934 const TCollection_AsciiString& theName);
936 //! Initializes OpenGL/GLSL shader programs.
937 Standard_Boolean initRaytraceResources (const Standard_Integer theSizeX,
938 const Standard_Integer theSizeY,
939 const Handle(OpenGl_Context)& theGlContext);
941 //! Releases OpenGL/GLSL shader programs.
942 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
943 const Standard_Boolean theToRebuild = Standard_False);
945 //! Updates auxiliary OpenGL frame buffers.
946 Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX,
947 const Standard_Integer theSizeY,
948 const Handle(OpenGl_Context)& theGlContext);
950 //! Generates viewing rays for corners of screen quad.
951 //! (ray tracing; path tracing for orthographic camera)
952 void updateCamera (const OpenGl_Mat4& theOrientation,
953 const OpenGl_Mat4& theViewMapping,
954 OpenGl_Vec3* theOrigins,
955 OpenGl_Vec3* theDirects,
956 OpenGl_Mat4& theView,
957 OpenGl_Mat4& theUnView);
959 //! Generate viewing rays (path tracing, perspective camera).
960 void updatePerspCameraPT(const OpenGl_Mat4& theOrientation,
961 const OpenGl_Mat4& theViewMapping,
962 Graphic3d_Camera::Projection theProjection,
963 OpenGl_Mat4& theViewPr,
964 OpenGl_Mat4& theUnview,
965 const int theWinSizeX,
966 const int theWinSizeY);
968 //! Binds ray-trace textures to corresponding texture units.
969 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext,
972 //! Unbinds ray-trace textures from corresponding texture unit.
973 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
975 //! Sets uniform state for the given ray-tracing shader program.
976 Standard_Boolean setUniformState (const Standard_Integer theProgramId,
977 const Standard_Integer theSizeX,
978 const Standard_Integer theSizeY,
979 Graphic3d_Camera::Projection theProjection,
980 const Handle(OpenGl_Context)& theGlContext);
982 //! Runs ray-tracing shader programs.
983 Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX,
984 const Standard_Integer theSizeY,
985 Graphic3d_Camera::Projection theProjection,
986 OpenGl_FrameBuffer* theReadDrawFbo,
987 const Handle(OpenGl_Context)& theGlContext);
989 //! Runs classical (Whitted-style) ray-tracing kernel.
990 Standard_Boolean runRaytrace (const Standard_Integer theSizeX,
991 const Standard_Integer theSizeY,
992 Graphic3d_Camera::Projection theProjection,
993 OpenGl_FrameBuffer* theReadDrawFbo,
994 const Handle(OpenGl_Context)& theGlContext);
996 //! Runs path tracing (global illumination) kernel.
997 Standard_Boolean runPathtrace (const Standard_Integer theSizeX,
998 const Standard_Integer theSizeY,
999 Graphic3d_Camera::Projection theProjection,
1000 const Handle(OpenGl_Context)& theGlContext);
1002 //! Runs path tracing (global illumination) kernel.
1003 Standard_Boolean runPathtraceOut (Graphic3d_Camera::Projection theProjection,
1004 OpenGl_FrameBuffer* theReadDrawFbo,
1005 const Handle(OpenGl_Context)& theGlContext);
1007 //! Redraws the window using OpenGL/GLSL ray-tracing or path tracing.
1008 Standard_Boolean raytrace (const Standard_Integer theSizeX,
1009 const Standard_Integer theSizeY,
1010 Graphic3d_Camera::Projection theProjection,
1011 OpenGl_FrameBuffer* theReadDrawFbo,
1012 const Handle(OpenGl_Context)& theGlContext);
1014 protected: //! @name fields related to ray-tracing
1016 //! Result of RT/PT shaders initialization.
1017 RaytraceInitStatus myRaytraceInitStatus;
1019 //! Is ray-tracing geometry data valid?
1020 Standard_Boolean myIsRaytraceDataValid;
1022 //! True if warning about missing extension GL_ARB_bindless_texture has been displayed.
1023 Standard_Boolean myIsRaytraceWarnTextures;
1025 //! 3D scene geometry data for ray-tracing.
1026 OpenGl_RaytraceGeometry myRaytraceGeometry;
1028 //! Builder for triangle set.
1029 opencascade::handle<BVH_Builder<Standard_ShortReal, 3> > myRaytraceBVHBuilder;
1031 //! Compile-time ray-tracing parameters.
1032 RaytracingParams myRaytraceParameters;
1034 //! Radius of bounding sphere of the scene.
1035 Standard_ShortReal myRaytraceSceneRadius;
1036 //! Scene epsilon to prevent self-intersections.
1037 Standard_ShortReal myRaytraceSceneEpsilon;
1039 //! OpenGL/GLSL source of ray-tracing fragment shader.
1040 ShaderSource myRaytraceShaderSource;
1041 //! OpenGL/GLSL source of adaptive-AA fragment shader.
1042 ShaderSource myPostFSAAShaderSource;
1043 //! OpenGL/GLSL source of RT/PT display fragment shader.
1044 ShaderSource myOutImageShaderSource;
1046 //! OpenGL/GLSL ray-tracing fragment shader.
1047 Handle(OpenGl_ShaderObject) myRaytraceShader;
1048 //! OpenGL/GLSL adaptive-AA fragment shader.
1049 Handle(OpenGl_ShaderObject) myPostFSAAShader;
1050 //! OpenGL/GLSL ray-tracing display fragment shader.
1051 Handle(OpenGl_ShaderObject) myOutImageShader;
1053 //! OpenGL/GLSL ray-tracing shader program.
1054 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
1055 //! OpenGL/GLSL adaptive-AA shader program.
1056 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
1057 //! OpenGL/GLSL program for displaying texture.
1058 Handle(OpenGl_ShaderProgram) myOutImageProgram;
1060 //! Texture buffer of data records of bottom-level BVH nodes.
1061 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
1062 //! Texture buffer of minimum points of bottom-level BVH nodes.
1063 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
1064 //! Texture buffer of maximum points of bottom-level BVH nodes.
1065 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
1066 //! Texture buffer of transformations of high-level BVH nodes.
1067 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
1069 //! Texture buffer of vertex coords.
1070 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
1071 //! Texture buffer of vertex normals.
1072 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
1073 //! Texture buffer of vertex UV coords.
1074 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
1075 //! Texture buffer of triangle indices.
1076 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
1078 //! Texture buffer of material properties.
1079 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
1080 //! Texture buffer of light source properties.
1081 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
1083 //! 1st framebuffer (FBO) to perform adaptive FSAA.
1084 //! Used in compatibility mode (no adaptive sampling).
1085 Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
1086 //! 2nd framebuffer (FBO) to perform adaptive FSAA.
1087 //! Used in compatibility mode (no adaptive sampling).
1088 Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
1090 //! Output textures (2 textures are used in stereo mode).
1091 //! Used if adaptive screen sampling is activated.
1092 Handle(OpenGl_Texture) myRaytraceOutputTexture[2];
1094 //! Texture containing per-tile visual error estimation (2 textures are used in stereo mode).
1095 //! Used if adaptive screen sampling is activated.
1096 Handle(OpenGl_Texture) myRaytraceVisualErrorTexture[2];
1097 //! Texture containing offsets of sampled screen tiles (2 textures are used in stereo mode).
1098 //! Used if adaptive screen sampling is activated.
1099 Handle(OpenGl_Texture) myRaytraceTileOffsetsTexture[2];
1100 //! Texture containing amount of extra per-tile samples (2 textures are used in stereo mode).
1101 //! Used if adaptive screen sampling is activated.
1102 Handle(OpenGl_Texture) myRaytraceTileSamplesTexture[2];
1104 //! Vertex buffer (VBO) for drawing dummy quad.
1105 OpenGl_VertexBuffer myRaytraceScreenQuad;
1107 //! Cached locations of frequently used uniform variables.
1108 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
1110 //! State of OpenGL structures reflected to ray-tracing.
1111 std::map<const OpenGl_Structure*, StructState> myStructureStates;
1113 //! PrimitiveArray to TriangleSet map for scene partial update.
1114 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
1116 //! Set of IDs of non-raytracable elements (to detect updates).
1117 std::set<Standard_Integer> myNonRaytraceStructureIDs;
1119 //! Marks if environment map should be updated.
1120 Standard_Boolean myToUpdateEnvironmentMap;
1122 //! State of OpenGL layer list.
1123 Standard_Size myRaytraceLayerListState;
1125 //! Number of accumulated frames (for progressive rendering).
1126 Standard_Integer myAccumFrames;
1128 //! Stored ray origins used for detection of camera movements.
1129 OpenGl_Vec3 myPreviousOrigins[3];
1131 //! Bullard RNG to produce random sequence.
1132 math_BullardGenerator myRNG;
1134 //! Tool object for sampling screen tiles in PT mode.
1135 OpenGl_TileSampler myTileSampler;
1137 //! Camera position used for projective mode
1138 OpenGl_Vec3 myEyeOrig;
1140 //! Camera view direction used for projective mode
1141 OpenGl_Vec3 myEyeView;
1143 //! Camera's screen vertical direction used for projective mode
1144 OpenGl_Vec3 myEyeVert;
1146 //! Camera's screen horizontal direction used for projective mode
1147 OpenGl_Vec3 myEyeSide;
1149 //! Camera's screen size used for projective mode
1150 OpenGl_Vec2 myEyeSize;
1152 //! Aperture radius of camera on previous frame used for depth-of-field (path tracing)
1153 float myPrevCameraApertureRadius;
1155 //! Focal distance of camera on previous frame used for depth-of-field (path tracing)
1156 float myPrevCameraFocalPlaneDist;
1160 DEFINE_STANDARD_ALLOC
1161 DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition
1163 friend class OpenGl_GraphicDriver;
1164 friend class OpenGl_Workspace;
1165 friend class OpenGl_LayerList;
1166 friend class OpenGl_FrameStats;
1169 #endif // _OpenGl_View_Header