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