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