Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:36

0001 // Created on: 2011-09-20
0002 // Created by: Sergey ZERCHANINOV
0003 // Copyright (c) 2011-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_View_HeaderFile
0017 #define OpenGl_View_HeaderFile
0018 
0019 #include <Graphic3d_CullingTool.hxx>
0020 #include <Graphic3d_WorldViewProjState.hxx>
0021 #include <math_BullardGenerator.hxx>
0022 
0023 #include <OpenGl_FrameBuffer.hxx>
0024 #include <OpenGl_FrameStatsPrs.hxx>
0025 #include <OpenGl_GraduatedTrihedron.hxx>
0026 #include <OpenGl_LayerList.hxx>
0027 #include <OpenGl_SceneGeometry.hxx>
0028 #include <OpenGl_Structure.hxx>
0029 #include <OpenGl_TileSampler.hxx>
0030 
0031 #include <map>
0032 #include <set>
0033 
0034 class OpenGl_BackgroundArray;
0035 class OpenGl_DepthPeeling;
0036 class OpenGl_PBREnvironment;
0037 struct OpenGl_RaytraceMaterial;
0038 class OpenGl_ShadowMap;
0039 class OpenGl_ShadowMapArray;
0040 class OpenGl_ShaderObject;
0041 class OpenGl_TextureBuffer;
0042 class OpenGl_Workspace;
0043 
0044 DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
0045 
0046 //! Implementation of OpenGl view.
0047 class OpenGl_View : public Graphic3d_CView
0048 {
0049 
0050 public:
0051 
0052   //! Constructor.
0053   Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
0054                                const Handle(OpenGl_GraphicDriver)& theDriver,
0055                                const Handle(OpenGl_Caps)& theCaps,
0056                                OpenGl_StateCounter* theCounter);
0057 
0058   //! Default destructor.
0059   Standard_EXPORT virtual ~OpenGl_View();
0060 
0061   //! Release OpenGL resources.
0062   Standard_EXPORT virtual void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
0063 
0064   //! Deletes and erases the view.
0065   Standard_EXPORT virtual void Remove() Standard_OVERRIDE;
0066 
0067   //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
0068   //! 1. TRUE.  Drawing immediate mode structures directly to the front buffer over the scene image.
0069   //! Fast, so preferred for interactive work (used by default).
0070   //! However these extra drawings will be missed in image dump since it is performed from back buffer.
0071   //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
0072   //! in run-time (in case of slow hardware) and/or tearing may appear.
0073   //! So this is strongly recommended to draw only simple (fast) structures.
0074   //! 2. FALSE. Drawing immediate mode structures to the back buffer.
0075   //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
0076   //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
0077   //! from the back buffer.
0078   //! @return previous mode.
0079   Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
0080 
0081   //! Creates and maps rendering window to the view.
0082   Standard_EXPORT virtual void SetWindow (const Handle(Graphic3d_CView)& theParentVIew,
0083                                           const Handle(Aspect_Window)& theWindow,
0084                                           const Aspect_RenderingContext theContext) Standard_OVERRIDE;
0085 
0086   //! Returns window associated with the view.
0087   Standard_EXPORT virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE;
0088 
0089   //! Returns True if the window associated to the view is defined.
0090   virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
0091   { return !myWindow.IsNull(); }
0092 
0093   //! Handle changing size of the rendering window.
0094   Standard_EXPORT virtual void Resized() Standard_OVERRIDE;
0095 
0096   //! Redraw content of the view.
0097   Standard_EXPORT virtual void Redraw() Standard_OVERRIDE;
0098 
0099   //! Redraw immediate content of the view.
0100   Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE;
0101 
0102   //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild.
0103   Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
0104 
0105   //! Return true if view content cache has been invalidated.
0106   virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
0107 
0108   //! Dump active rendering buffer into specified memory buffer.
0109   //! In Ray-Tracing allow to get a raw HDR buffer using Graphic3d_BT_RGB_RayTraceHdrLeft buffer type,
0110   //! only Left view will be dumped ignoring stereoscopic parameter.
0111   Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
0112                                                        const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
0113 
0114   //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
0115   Standard_EXPORT virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
0116 
0117   //! Add a layer to the view.
0118   //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
0119   //! @param theSettings   [in] new layer settings
0120   //! @param theLayerAfter [in] id of layer to append new layer before
0121   Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
0122                                                   const Graphic3d_ZLayerSettings& theSettings,
0123                                                   const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
0124 
0125   //! Add a layer to the view.
0126   //! @param theNewLayerId  [in] id of new layer, should be > 0 (negative values are reserved for default layers).
0127   //! @param theSettings    [in] new layer settings
0128   //! @param theLayerBefore [in] id of layer to append new layer after
0129   Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
0130                                                  const Graphic3d_ZLayerSettings& theSettings,
0131                                                  const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
0132 
0133   //! Remove a z layer with the given ID.
0134   Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
0135 
0136   //! Sets the settings for a single Z layer of specified view.
0137   Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
0138                                                   const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
0139 
0140   //! Returns the maximum Z layer ID.
0141   //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
0142   Standard_EXPORT virtual Standard_Integer ZLayerMax() const Standard_OVERRIDE;
0143 
0144   //! Returns the list of layers.
0145   Standard_EXPORT virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const Standard_OVERRIDE;
0146 
0147   //! Returns layer with given ID or NULL if undefined.
0148   Standard_EXPORT virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
0149 
0150   //! Returns the bounding box of all structures displayed in the view.
0151   //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
0152   //! of graphical elements forming parts of infinite and other auxiliary structures.
0153   //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
0154   //! @return computed bounding box
0155   Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const Standard_OVERRIDE;
0156 
0157   //! Returns pointer to an assigned framebuffer object.
0158   Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
0159 
0160   //! Sets framebuffer object for offscreen rendering.
0161   Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
0162 
0163   //! Generate offscreen FBO in the graphic library.
0164   //! If not supported on hardware returns NULL.
0165   Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
0166                                                                 const Standard_Integer theHeight) Standard_OVERRIDE;
0167 
0168   //! Remove offscreen FBO from the graphic library
0169   Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
0170 
0171   //! Read offscreen FBO configuration.
0172   Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
0173                                                  Standard_Integer& theWidth,
0174                                                  Standard_Integer& theHeight,
0175                                                  Standard_Integer& theWidthMax,
0176                                                  Standard_Integer& theHeightMax) Standard_OVERRIDE;
0177 
0178   //! Change offscreen FBO viewport.
0179   Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
0180                                                   const Standard_Integer theWidth,
0181                                                   const Standard_Integer theHeight) Standard_OVERRIDE;
0182 
0183   //! Returns additional buffers for depth peeling OIT.
0184   const Handle(OpenGl_DepthPeeling)& DepthPeelingFbos() const { return myDepthPeelingFbos; }
0185 
0186 public:
0187 
0188   //! Returns gradient background fill colors.
0189   Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
0190 
0191   //! Sets gradient background fill colors.
0192   Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
0193 
0194   //! Sets image texture or environment cubemap as background.
0195   //! @param theTextureMap [in] source to set a background;
0196   //!                           should be either Graphic3d_Texture2D or Graphic3d_CubeMap
0197   //! @param theToUpdatePBREnv [in] defines whether IBL maps will be generated or not
0198   //!                               (see GeneratePBREnvironment())
0199   Standard_EXPORT virtual void SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
0200                                                    Standard_Boolean theToUpdatePBREnv = Standard_True) Standard_OVERRIDE;
0201 
0202   //! Sets environment texture for the view.
0203   Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
0204 
0205   //! Returns background image fill style.
0206   Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
0207 
0208   //! Sets background image fill style.
0209   Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE;
0210 
0211   //! Enables or disables IBL (Image Based Lighting) from background cubemap.
0212   //! Has no effect if PBR is not used.
0213   //! @param[in] theToEnableIBL enable or disable IBL from background cubemap
0214   //! @param[in] theToUpdate redraw the view
0215   Standard_EXPORT virtual void SetImageBasedLighting (Standard_Boolean theToEnableIBL) Standard_OVERRIDE;
0216 
0217   //! Returns number of mipmap levels used in specular IBL map.
0218   //! 0 if PBR environment is not created.
0219   Standard_EXPORT unsigned int SpecIBLMapLevels() const;
0220 
0221   //! Returns local camera origin currently set for rendering, might be modified during rendering.
0222   const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
0223 
0224   //! Setup local camera origin currently set for rendering.
0225   Standard_EXPORT void SetLocalOrigin (const gp_XYZ& theOrigin);
0226 
0227   //! Returns list of lights of the view.
0228   virtual const Handle(Graphic3d_LightSet)& Lights() const Standard_OVERRIDE { return myLights; }
0229 
0230   //! Sets list of lights for the view.
0231   virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) Standard_OVERRIDE
0232   {
0233     myLights = theLights;
0234     myCurrLightSourceState = myStateCounter->Increment();
0235   }
0236 
0237   //! Returns list of clip planes set for the view.
0238   virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
0239 
0240   //! Sets list of clip planes for the view.
0241   virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
0242 
0243   //! Fill in the dictionary with diagnostic info.
0244   //! Should be called within rendering thread.
0245   //!
0246   //! This API should be used only for user output or for creating automated reports.
0247   //! The format of returned information (e.g. key-value layout)
0248   //! is NOT part of this API and can be changed at any time.
0249   //! Thus application should not parse returned information to weed out specific parameters.
0250   Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
0251                                                       Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE;
0252 
0253   //! Returns string with statistic performance info.
0254   Standard_EXPORT virtual TCollection_AsciiString StatisticInformation() const Standard_OVERRIDE;
0255 
0256   //! Fills in the dictionary with statistic performance info.
0257   Standard_EXPORT virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const Standard_OVERRIDE;
0258 
0259 public:
0260 
0261   //! Returns background color.
0262   const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
0263 
0264   //! Change graduated trihedron.
0265   OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
0266 
0267   void SetTextureEnv (const Handle(OpenGl_Context)&       theCtx,
0268                       const Handle(Graphic3d_TextureEnv)& theTexture);
0269 
0270   void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
0271 
0272   void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
0273 
0274   void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
0275 
0276   //! Returns list of OpenGL Z-layers.
0277   const OpenGl_LayerList& LayerList() const { return myZLayers; }
0278 
0279   //! Returns OpenGL window implementation.
0280   const Handle(OpenGl_Window)& GlWindow() const { return myWindow; }
0281 
0282   //! Returns OpenGL environment map.
0283   const Handle(OpenGl_TextureSet)& GlTextureEnv() const { return myTextureEnv; }
0284 
0285   //! Returns selector for BVH tree, providing a possibility to store information
0286   //! about current view volume and to detect which objects are overlapping it.
0287   const Graphic3d_CullingTool& BVHTreeSelector() const { return myBVHSelector; }
0288 
0289   //! Returns true if there are immediate structures to display
0290   bool HasImmediateStructures() const
0291   {
0292     return myZLayers.NbImmediateStructures() != 0;
0293   }
0294 
0295 public: //! @name obsolete Graduated Trihedron functionality
0296 
0297   //! Displays Graduated Trihedron.
0298   Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
0299 
0300   //! Erases Graduated Trihedron.
0301   Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
0302 
0303   //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
0304   //! @param theMin [in] the minimum point of scene.
0305   //! @param theMax [in] the maximum point of scene.
0306   Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
0307 
0308 protected: //! @name Internal methods for managing GL resources
0309 
0310   //! Initializes OpenGl resource for environment texture.
0311   void initTextureEnv (const Handle(OpenGl_Context)& theContext);
0312 
0313 protected: //! @name low-level redrawing sub-routines
0314 
0315   //! Prepare frame buffers for rendering.
0316   Standard_EXPORT virtual bool prepareFrameBuffers (Graphic3d_Camera::Projection& theProj);
0317 
0318   //! Redraws view for the given monographic camera projection, or left/right eye.
0319   Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
0320                                        OpenGl_FrameBuffer*                theReadDrawFbo,
0321                                        OpenGl_FrameBuffer*                theOitAccumFbo);
0322 
0323   //! Redraws view for the given monographic camera projection, or left/right eye.
0324   //!
0325   //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer)
0326   //! into presentation buffer (myMainSceneFbos -> offscreen FBO or
0327   //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer),
0328   //! and redraw immediate structures on top.
0329   //!
0330   //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
0331   //! the first step (blitting) will be skipped.
0332   //!
0333   //! @return false if immediate structures has been rendered directly into FrontBuffer
0334   //! and Buffer Swap should not be called.
0335   Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
0336                                                 OpenGl_FrameBuffer* theReadFbo,
0337                                                 OpenGl_FrameBuffer* theDrawFbo,
0338                                                 OpenGl_FrameBuffer* theOitAccumFbo,
0339                                                 const Standard_Boolean theIsPartialUpdate = Standard_False);
0340 
0341   //! Blit subviews into this view.
0342   Standard_EXPORT bool blitSubviews (const Graphic3d_Camera::Projection theProjection,
0343                                      OpenGl_FrameBuffer* theDrawFbo);
0344 
0345   //! Blit image from/to specified buffers.
0346   Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
0347                                     OpenGl_FrameBuffer*    theDrawFbo,
0348                                     const Standard_Boolean theToFlip = Standard_False);
0349 
0350   //! Setup default FBO.
0351   Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
0352 
0353 protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
0354 
0355   //! Renders the graphical contents of the view into the preprepared shadowmap framebuffer.
0356   //! @param theShadowMap [in] the framebuffer for rendering shadowmap.
0357   Standard_EXPORT virtual void renderShadowMap (const Handle(OpenGl_ShadowMap)& theShadowMap);
0358 
0359   //! Renders the graphical contents of the view into the preprepared window or framebuffer.
0360   //! @param theProjection [in] the projection that should be used for rendering.
0361   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
0362   //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
0363   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
0364   Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
0365                                        OpenGl_FrameBuffer*          theReadDrawFbo,
0366                                        OpenGl_FrameBuffer*          theOitAccumFbo,
0367                                        const Standard_Boolean       theToDrawImmediate);
0368 
0369   //! Renders the graphical scene.
0370   //! @param theProjection [in] the projection that is used for rendering.
0371   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
0372   //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
0373   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
0374   Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
0375                                             OpenGl_FrameBuffer*    theReadDrawFbo,
0376                                             OpenGl_FrameBuffer*    theOitAccumFbo,
0377                                             const Standard_Boolean theToDrawImmediate);
0378 
0379   //! Draw background (gradient / image / cubemap)
0380   Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
0381                                                Graphic3d_Camera::Projection theProjection);
0382 
0383   //! Render set of structures presented in the view.
0384   //! @param theProjection [in] the projection that is used for rendering.
0385   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
0386   //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
0387   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
0388   Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
0389                                               OpenGl_FrameBuffer*    theReadDrawFbo,
0390                                               OpenGl_FrameBuffer*    theOitAccumFbo,
0391                                               const Standard_Boolean theToDrawImmediate);
0392 
0393   //! Renders trihedron.
0394   void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
0395 
0396   //! Renders frame statistics.
0397   void renderFrameStats();
0398 
0399 private:
0400 
0401   //! Adds the structure to display lists of the view.
0402   Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
0403                                                  const Graphic3d_DisplayPriority thePriority) Standard_OVERRIDE;
0404 
0405   //! Erases the structure from display lists of the view.
0406   Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
0407 
0408   //! Change Z layer of a structure already presented in view.
0409   Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
0410                                              const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
0411 
0412   //! Changes the priority of a structure within its Z layer in the specified view.
0413   Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
0414                                                const Graphic3d_DisplayPriority theNewPriority) Standard_OVERRIDE;
0415 
0416 private:
0417 
0418   //! Release sRGB resources (frame-buffers, textures, etc.).
0419   void releaseSrgbResources (const Handle(OpenGl_Context)& theCtx);
0420 
0421   //! Copy content of Back buffer to the Front buffer.
0422   bool copyBackToFront();
0423 
0424   //! Initialize blit quad.
0425   OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
0426 
0427   //! Blend together views pair into stereo image.
0428   void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
0429 
0430   //! Check and update OIT compatibility with current OpenGL context's state.
0431   bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
0432                               const Standard_Boolean theMSAA);
0433 
0434 protected:
0435 
0436   OpenGl_GraphicDriver*    myDriver;
0437   Handle(OpenGl_Window)    myWindow;
0438   Handle(OpenGl_Workspace) myWorkspace;
0439   Handle(OpenGl_Caps)      myCaps;
0440   Standard_Boolean         myWasRedrawnGL;
0441 
0442   Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
0443   gp_XYZ                          myLocalOrigin;
0444   Handle(OpenGl_FrameBuffer)      myFBO;
0445   Standard_Boolean                myToShowGradTrihedron;
0446   Graphic3d_GraduatedTrihedron    myGTrihedronData;
0447 
0448   Handle(Graphic3d_LightSet)      myNoShadingLight;
0449   Handle(Graphic3d_LightSet)      myLights;
0450   OpenGl_LayerList                myZLayers; //!< main list of displayed structure, sorted by layers
0451 
0452   Graphic3d_WorldViewProjState    myWorldViewProjState; //!< camera modification state
0453   OpenGl_StateCounter*            myStateCounter;
0454   Standard_Size                   myCurrLightSourceState;
0455   Standard_Size                   myLightsRevision;
0456 
0457   typedef std::pair<Standard_Size, Standard_Size> StateInfo;
0458 
0459   StateInfo myLastOrientationState;
0460   StateInfo myLastViewMappingState;
0461   StateInfo myLastLightSourceState;
0462 
0463   //! Is needed for selection of overlapping objects and storage of the current view volume
0464   Graphic3d_CullingTool myBVHSelector;
0465 
0466   OpenGl_GraduatedTrihedron myGraduatedTrihedron;
0467   OpenGl_FrameStatsPrs      myFrameStatsPrs;
0468 
0469   //! Framebuffers for OpenGL output.
0470   Handle(OpenGl_FrameBuffer) myOpenGlFBO;
0471   Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
0472 
0473 protected: //! @name Rendering properties
0474 
0475   //! Two framebuffers (left and right views) store cached main presentation
0476   //! of the view (without presentation of immediate layers).
0477   Standard_Integer           mySRgbState;             //!< track sRGB state
0478   GLint                      myFboColorFormat;        //!< sized format for color attachments
0479   GLint                      myFboDepthFormat;        //!< sized format for depth-stencil attachments
0480   OpenGl_ColorFormats        myFboOitColorConfig;     //!< selected color format configuration for OIT color attachments
0481   Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
0482   Handle(OpenGl_FrameBuffer) myMainSceneFbosOit[2];      //!< Additional buffers for transparent draw of main layer.
0483   Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2];    //!< Additional buffers for immediate layer in stereo mode.
0484   Handle(OpenGl_FrameBuffer) myImmediateSceneFbosOit[2]; //!< Additional buffers for transparency draw of immediate layer.
0485   Handle(OpenGl_FrameBuffer) myXrSceneFbo;               //!< additional FBO (without MSAA) for submitting to XR
0486   Handle(OpenGl_DepthPeeling)   myDepthPeelingFbos;   //!< additional buffers for depth peeling
0487   Handle(OpenGl_ShadowMapArray) myShadowMaps;         //!< additional FBOs for shadow map rendering
0488   OpenGl_VertexBuffer        myFullScreenQuad;        //!< Vertices for full-screen quad rendering.
0489   OpenGl_VertexBuffer        myFullScreenQuadFlip;
0490   Standard_Boolean           myToFlipOutput;          //!< Flag to draw result image upside-down
0491   unsigned int               myFrameCounter;          //!< redraw counter, for debugging
0492   Standard_Boolean           myHasFboBlit;            //!< disable FBOs on failure
0493   Standard_Boolean           myToDisableOIT;          //!< disable OIT on failure
0494   Standard_Boolean           myToDisableOITMSAA;      //!< disable OIT with MSAA on failure
0495   Standard_Boolean           myToDisableMSAA;         //!< disable MSAA after failure
0496   Standard_Boolean           myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
0497   Standard_Boolean           myBackBufferRestored;
0498   Standard_Boolean           myIsImmediateDrawn;     //!< flag indicates that immediate mode buffer contains some data
0499 
0500 protected: //! @name Background parameters
0501 
0502   OpenGl_Aspects*            myTextureParams;                     //!< Stores texture and its parameters for textured background
0503   OpenGl_Aspects*            myCubeMapParams;                     //!< Stores cubemap and its parameters for cubemap background
0504   OpenGl_Aspects*            myColoredQuadParams;                 //!< Stores parameters for gradient (corner mode) background
0505   OpenGl_BackgroundArray*    myBackgrounds[Graphic3d_TypeOfBackground_NB]; //!< Array of primitive arrays of different background types
0506   Handle(OpenGl_TextureSet)  myTextureEnv;
0507   Handle(OpenGl_Texture)     mySkydomeTexture;
0508 
0509 protected: //! @name methods related to skydome background
0510 
0511   //! Generates skydome cubemap.
0512   Standard_EXPORT void updateSkydomeBg (const Handle(OpenGl_Context)& theCtx);
0513 
0514 protected: //! @name methods related to PBR
0515 
0516   //! Checks whether PBR is available.
0517   Standard_EXPORT Standard_Boolean checkPBRAvailability() const;
0518 
0519   //! Generates IBL maps used in PBR pipeline.
0520   //! If background cubemap is not set clears all IBL maps.
0521   Standard_EXPORT void updatePBREnvironment (const Handle(OpenGl_Context)& theCtx);
0522 
0523 protected: //! @name fields and types related to PBR
0524 
0525   //! State of PBR environment.
0526   enum PBREnvironmentState
0527   {
0528     OpenGl_PBREnvState_NONEXISTENT,
0529     OpenGl_PBREnvState_UNAVAILABLE, // indicates failed try to create PBR environment
0530     OpenGl_PBREnvState_CREATED
0531   };
0532 
0533   Handle(OpenGl_PBREnvironment) myPBREnvironment; //!< manager of IBL maps used in PBR pipeline
0534   PBREnvironmentState           myPBREnvState;    //!< state of PBR environment
0535   Standard_Boolean              myPBREnvRequest;  //!< update PBR environment
0536 
0537 protected: //! @name data types related to ray-tracing
0538 
0539   //! Result of OpenGL shaders initialization.
0540   enum RaytraceInitStatus
0541   {
0542     OpenGl_RT_NONE,
0543     OpenGl_RT_INIT,
0544     OpenGl_RT_FAIL
0545   };
0546 
0547   //! Describes update mode (state).
0548   enum RaytraceUpdateMode
0549   {
0550     OpenGl_GUM_CHECK,   //!< check geometry state
0551     OpenGl_GUM_PREPARE, //!< collect unchanged objects
0552     OpenGl_GUM_REBUILD  //!< rebuild changed and new objects
0553   };
0554 
0555   //! Defines frequently used shader variables.
0556   enum ShaderVariableIndex
0557   {
0558     OpenGl_RT_aPosition,
0559 
0560     // camera position
0561     OpenGl_RT_uOriginLT,
0562     OpenGl_RT_uOriginLB,
0563     OpenGl_RT_uOriginRT,
0564     OpenGl_RT_uOriginRB,
0565     OpenGl_RT_uDirectLT,
0566     OpenGl_RT_uDirectLB,
0567     OpenGl_RT_uDirectRT,
0568     OpenGl_RT_uDirectRB,
0569     OpenGl_RT_uViewPrMat,
0570     OpenGl_RT_uUnviewMat,
0571 
0572     // 3D scene params
0573     OpenGl_RT_uSceneRad,
0574     OpenGl_RT_uSceneEps,
0575     OpenGl_RT_uLightAmbnt,
0576     OpenGl_RT_uLightCount,
0577 
0578     // background params
0579     OpenGl_RT_uBackColorTop,
0580     OpenGl_RT_uBackColorBot,
0581 
0582     // ray-tracing params
0583     OpenGl_RT_uShadowsEnabled,
0584     OpenGl_RT_uReflectEnabled,
0585     OpenGl_RT_uEnvMapEnabled,
0586     OpenGl_RT_uEnvMapForBack,
0587     OpenGl_RT_uTexSamplersArray,
0588     OpenGl_RT_uBlockedRngEnabled,
0589 
0590     // size of render window
0591     OpenGl_RT_uWinSizeX,
0592     OpenGl_RT_uWinSizeY,
0593 
0594     // sampled frame params
0595     OpenGl_RT_uAccumSamples,
0596     OpenGl_RT_uFrameRndSeed,
0597 
0598     // adaptive FSAA params
0599     OpenGl_RT_uFsaaOffset,
0600     OpenGl_RT_uSamples,
0601 
0602     // images used by ISS mode
0603     OpenGl_RT_uRenderImage,
0604     OpenGl_RT_uTilesImage,
0605     OpenGl_RT_uOffsetImage,
0606     OpenGl_RT_uTileSize,
0607     OpenGl_RT_uVarianceScaleFactor,
0608 
0609     // maximum radiance value
0610     OpenGl_RT_uMaxRadiance,
0611 
0612     OpenGl_RT_NbVariables // special field
0613   };
0614 
0615   //! Defines OpenGL image samplers.
0616   enum ShaderImageNames
0617   {
0618     OpenGl_RT_OutputImage = 0,
0619     OpenGl_RT_VisualErrorImage = 1,
0620     OpenGl_RT_TileOffsetsImage = 2,
0621     OpenGl_RT_TileSamplesImage = 3
0622   };
0623 
0624   //! Tool class for management of shader sources.
0625   class ShaderSource
0626   {
0627   public:
0628 
0629     //! Default shader prefix - empty string.
0630     static const TCollection_AsciiString EMPTY_PREFIX;
0631 
0632     //! Creates new uninitialized shader source.
0633     ShaderSource()
0634     {
0635       //
0636     }
0637 
0638   public:
0639 
0640     //! Returns error description in case of load fail.
0641     const TCollection_AsciiString& ErrorDescription() const
0642     {
0643       return myError;
0644     }
0645 
0646     //! Returns prefix to insert before the source.
0647     const TCollection_AsciiString& Prefix() const
0648     {
0649       return myPrefix;
0650     }
0651 
0652     //! Sets prefix to insert before the source.
0653     void SetPrefix (const TCollection_AsciiString& thePrefix)
0654     {
0655       myPrefix = thePrefix;
0656     }
0657 
0658     //! Returns shader source combined with prefix.
0659     TCollection_AsciiString Source (const Handle(OpenGl_Context)& theCtx,
0660                                     const GLenum theType) const;
0661 
0662     //! Loads shader source from specified files.
0663     Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
0664 
0665     //! Loads shader source from specified strings.
0666     Standard_Boolean LoadFromStrings (const TCollection_AsciiString* theStrings, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
0667 
0668   private:
0669 
0670     TCollection_AsciiString mySource; //!< Source string of the shader object
0671     TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
0672     TCollection_AsciiString myError;  //!< error state
0673 
0674   };
0675 
0676   //! Default ray-tracing depth.
0677   static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
0678 
0679   //! Default size of traversal stack.
0680   static const Standard_Integer THE_DEFAULT_STACK_SIZE = 10;
0681 
0682   //! Compile-time ray-tracing parameters.
0683   struct RaytracingParams
0684   {
0685     //! Actual size of traversal stack in shader program.
0686     Standard_Integer StackSize;
0687 
0688     //! Actual ray-tracing depth (number of ray bounces).
0689     Standard_Integer NbBounces;
0690 
0691     //! Define depth computation
0692     Standard_Boolean IsZeroToOneDepth;
0693 
0694     //! Enables/disables light propagation through transparent media.
0695     Standard_Boolean TransparentShadows;
0696 
0697     //! Enables/disables global illumination (GI) effects.
0698     Standard_Boolean GlobalIllumination;
0699 
0700     //! Enables/disables the use of OpenGL bindless textures.
0701     Standard_Boolean UseBindlessTextures;
0702 
0703     //! Enables/disables two-sided BSDF models instead of one-sided.
0704     Standard_Boolean TwoSidedBsdfModels;
0705 
0706     //! Enables/disables adaptive screen sampling for path tracing.
0707     Standard_Boolean AdaptiveScreenSampling;
0708 
0709     //! Enables/disables 1-pass atomic mode for AdaptiveScreenSampling.
0710     Standard_Boolean AdaptiveScreenSamplingAtomic;
0711 
0712     //! Enables/disables environment map for background.
0713     Standard_Boolean UseEnvMapForBackground;
0714 
0715     //! Enables/disables normal map ignoring during path tracing.
0716     Standard_Boolean ToIgnoreNormalMap;
0717 
0718     //! Maximum radiance value used for clamping radiance estimation.
0719     Standard_ShortReal RadianceClampingValue;
0720     
0721     //! Enables/disables depth-of-field effect (path tracing, perspective camera).
0722     Standard_Boolean DepthOfField;
0723 
0724     //! Enables/disables cubemap background.
0725     Standard_Boolean CubemapForBack;
0726 
0727     //! Tone mapping method for path tracing.
0728     Graphic3d_ToneMappingMethod ToneMappingMethod;
0729 
0730     //! Creates default compile-time ray-tracing parameters.
0731     RaytracingParams()
0732     : StackSize              (THE_DEFAULT_STACK_SIZE),
0733       NbBounces              (THE_DEFAULT_NB_BOUNCES),
0734       IsZeroToOneDepth       (Standard_False),
0735       TransparentShadows     (Standard_False),
0736       GlobalIllumination     (Standard_False),
0737       UseBindlessTextures    (Standard_False),
0738       TwoSidedBsdfModels     (Standard_False),
0739       AdaptiveScreenSampling (Standard_False),
0740       AdaptiveScreenSamplingAtomic (Standard_False),
0741       UseEnvMapForBackground (Standard_False),
0742       ToIgnoreNormalMap      (Standard_False),
0743       RadianceClampingValue  (30.0),
0744       DepthOfField           (Standard_False),
0745       CubemapForBack         (Standard_False),
0746       ToneMappingMethod      (Graphic3d_ToneMappingMethod_Disabled) { }
0747   };
0748 
0749   //! Describes state of OpenGL structure.
0750   struct StructState
0751   {
0752     Standard_Size StructureState;
0753     Standard_Size InstancedState;
0754 
0755     //! Creates new structure state.
0756     StructState (const Standard_Size theStructureState = 0,
0757                  const Standard_Size theInstancedState = 0)
0758     : StructureState (theStructureState),
0759       InstancedState (theInstancedState)
0760     {
0761       //
0762     }
0763 
0764     //! Creates new structure state.
0765     StructState (const OpenGl_Structure* theStructure)
0766     {
0767       StructureState = theStructure->ModificationState();
0768 
0769       InstancedState = theStructure->InstancedStructure() != NULL ?
0770         theStructure->InstancedStructure()->ModificationState() : 0;
0771     }
0772   };
0773 
0774 protected: //! @name methods related to ray-tracing
0775 
0776   //! Updates 3D scene geometry for ray-tracing.
0777   Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode      theMode,
0778                                            const Standard_Integer        theViewId,
0779                                            const Handle(OpenGl_Context)& theGlContext);
0780 
0781   //! Updates 3D scene light sources for ray-tracing.
0782   Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
0783 
0784   //! Checks to see if the OpenGL structure is modified.
0785   Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
0786 
0787   //! Adds OpenGL structure to ray-traced scene geometry.
0788   Standard_Boolean addRaytraceStructure (const OpenGl_Structure*       theStructure,
0789                                          const Handle(OpenGl_Context)& theGlContext);
0790 
0791   //! Adds OpenGL groups to ray-traced scene geometry.
0792   Standard_Boolean addRaytraceGroups (const OpenGl_Structure*        theStructure,
0793                                       const OpenGl_RaytraceMaterial& theStructMat,
0794                                       const Handle(TopLoc_Datum3D)&  theTrsf,
0795                                       const Handle(OpenGl_Context)&  theGlContext);
0796 
0797   //! Creates ray-tracing material properties.
0798   OpenGl_RaytraceMaterial convertMaterial (const OpenGl_Aspects* theAspect,
0799                                            const Handle(OpenGl_Context)& theGlContext);
0800 
0801   //! Adds OpenGL primitive array to ray-traced scene geometry.
0802   Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
0803                                                         const Standard_Integer       theMatID,
0804                                                         const OpenGl_Mat4*           theTrans);
0805 
0806   //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
0807   Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet&                  theSet,
0808                                              const Standard_Integer               theMatID,
0809                                              const Standard_Integer               theCount,
0810                                              const Standard_Integer               theOffset,
0811                                              const OpenGl_PrimitiveArray&         theArray);
0812 
0813   //! Adds OpenGL triangle array to ray-traced scene geometry.
0814   Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet&                  theSet,
0815                                              const Standard_Integer               theMatID,
0816                                              const Standard_Integer               theCount,
0817                                              const Standard_Integer               theOffset,
0818                                              const Handle(Graphic3d_IndexBuffer)& theIndices);
0819 
0820   //! Adds OpenGL triangle fan array to ray-traced scene geometry.
0821   Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet&                  theSet,
0822                                                 const Standard_Integer               theMatID,
0823                                                 const Standard_Integer               theCount,
0824                                                 const Standard_Integer               theOffset,
0825                                                 const Handle(Graphic3d_IndexBuffer)& theIndices);
0826 
0827   //! Adds OpenGL triangle strip array to ray-traced scene geometry.
0828   Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet&                  theSet,
0829                                                   const Standard_Integer               theMatID,
0830                                                   const Standard_Integer               theCount,
0831                                                   const Standard_Integer               theOffset,
0832                                                   const Handle(Graphic3d_IndexBuffer)& theIndices);
0833 
0834   //! Adds OpenGL quadrangle array to ray-traced scene geometry.
0835   Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet&                  theSet,
0836                                                const Standard_Integer               theMatID,
0837                                                const Standard_Integer               theCount,
0838                                                const Standard_Integer               theOffset,
0839                                                const Handle(Graphic3d_IndexBuffer)& theIndices);
0840 
0841   //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
0842   Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet&                  theSet,
0843                                                     const Standard_Integer               theMatID,
0844                                                     const Standard_Integer               theCount,
0845                                                     const Standard_Integer               theOffset,
0846                                                     const Handle(Graphic3d_IndexBuffer)& theIndices);
0847 
0848   //! Adds OpenGL polygon array to ray-traced scene geometry.
0849   Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet&                  theSet,
0850                                             const Standard_Integer               theMatID,
0851                                             const Standard_Integer               theCount,
0852                                             const Standard_Integer               theOffset,
0853                                             const Handle(Graphic3d_IndexBuffer)& theIndices);
0854 
0855   //! Uploads ray-trace data to the GPU.
0856   Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
0857 
0858   //! Generates shader prefix based on current ray-tracing options.
0859   TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
0860 
0861   //! Performs safe exit when shaders initialization fails.
0862   Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
0863                                  const Handle(OpenGl_Context)&     theGlContext);
0864 
0865   //! Loads and compiles shader object from specified source.
0866   Handle(OpenGl_ShaderObject) initShader (const GLenum                  theType,
0867                                           const ShaderSource&           theSource,
0868                                           const Handle(OpenGl_Context)& theGlContext);
0869 
0870   //! Creates shader program from the given vertex and fragment shaders.
0871   Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)&      theGlContext,
0872                                             const Handle(OpenGl_ShaderObject)& theVertShader,
0873                                             const Handle(OpenGl_ShaderObject)& theFragShader,
0874                                             const TCollection_AsciiString& theName);
0875 
0876   //! Initializes OpenGL/GLSL shader programs.
0877   Standard_Boolean initRaytraceResources (const Standard_Integer theSizeX,
0878                                           const Standard_Integer theSizeY,
0879                                           const Handle(OpenGl_Context)& theGlContext);
0880 
0881   //! Releases OpenGL/GLSL shader programs.
0882   void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
0883                                  const Standard_Boolean        theToRebuild = Standard_False);
0884 
0885   //! Updates auxiliary OpenGL frame buffers.
0886   Standard_Boolean updateRaytraceBuffers (const Standard_Integer        theSizeX,
0887                                           const Standard_Integer        theSizeY,
0888                                           const Handle(OpenGl_Context)& theGlContext);
0889 
0890   //! Generates viewing rays for corners of screen quad.
0891   //! (ray tracing; path tracing for orthographic camera)
0892   void updateCamera (const OpenGl_Mat4& theOrientation,
0893                      const OpenGl_Mat4& theViewMapping,
0894                      OpenGl_Vec3*       theOrigins,
0895                      OpenGl_Vec3*       theDirects,
0896                      OpenGl_Mat4&       theView,
0897                      OpenGl_Mat4&       theUnView);
0898 
0899   //! Generate viewing rays (path tracing, perspective camera).
0900   void updatePerspCameraPT(const OpenGl_Mat4&           theOrientation,
0901                            const OpenGl_Mat4&           theViewMapping,
0902                            Graphic3d_Camera::Projection theProjection,
0903                            OpenGl_Mat4&                 theViewPr,
0904                            OpenGl_Mat4&                 theUnview,
0905                            const int                    theWinSizeX,
0906                            const int                    theWinSizeY);
0907 
0908   //! Binds ray-trace textures to corresponding texture units.
0909   void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext,
0910                              int theStereoView);
0911 
0912   //! Unbinds ray-trace textures from corresponding texture unit.
0913   void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
0914 
0915   //! Sets uniform state for the given ray-tracing shader program.
0916   Standard_Boolean setUniformState (const Standard_Integer        theProgramId,
0917                                     const Standard_Integer        theSizeX,
0918                                     const Standard_Integer        theSizeY,
0919                                     Graphic3d_Camera::Projection  theProjection,
0920                                     const Handle(OpenGl_Context)& theGlContext);
0921 
0922   //! Runs ray-tracing shader programs.
0923   Standard_Boolean runRaytraceShaders (const Standard_Integer        theSizeX,
0924                                        const Standard_Integer        theSizeY,
0925                                        Graphic3d_Camera::Projection  theProjection,
0926                                        OpenGl_FrameBuffer*           theReadDrawFbo,
0927                                        const Handle(OpenGl_Context)& theGlContext);
0928 
0929   //! Runs classical (Whitted-style) ray-tracing kernel.
0930   Standard_Boolean runRaytrace (const Standard_Integer        theSizeX,
0931                                 const Standard_Integer        theSizeY,
0932                                 Graphic3d_Camera::Projection  theProjection,
0933                                 OpenGl_FrameBuffer*           theReadDrawFbo,
0934                                 const Handle(OpenGl_Context)& theGlContext);
0935 
0936   //! Runs path tracing (global illumination) kernel.
0937   Standard_Boolean runPathtrace (const Standard_Integer        theSizeX,
0938                                  const Standard_Integer        theSizeY,
0939                                  Graphic3d_Camera::Projection  theProjection,
0940                                  const Handle(OpenGl_Context)& theGlContext);
0941 
0942   //! Runs path tracing (global illumination) kernel.
0943   Standard_Boolean runPathtraceOut (Graphic3d_Camera::Projection  theProjection,
0944                                     OpenGl_FrameBuffer*           theReadDrawFbo,
0945                                     const Handle(OpenGl_Context)& theGlContext);
0946 
0947   //! Redraws the window using OpenGL/GLSL ray-tracing or path tracing.
0948   Standard_Boolean raytrace (const Standard_Integer        theSizeX,
0949                              const Standard_Integer        theSizeY,
0950                              Graphic3d_Camera::Projection  theProjection,
0951                              OpenGl_FrameBuffer*           theReadDrawFbo,
0952                              const Handle(OpenGl_Context)& theGlContext);
0953 
0954 protected: //! @name fields related to ray-tracing
0955 
0956   //! Result of RT/PT shaders initialization.
0957   RaytraceInitStatus myRaytraceInitStatus;
0958 
0959   //! Is ray-tracing geometry data valid?
0960   Standard_Boolean myIsRaytraceDataValid;
0961 
0962   //! True if warning about missing extension GL_ARB_bindless_texture has been displayed.
0963   Standard_Boolean myIsRaytraceWarnTextures;
0964 
0965   //! 3D scene geometry data for ray-tracing.
0966   OpenGl_RaytraceGeometry myRaytraceGeometry;
0967 
0968   //! Builder for triangle set.
0969   opencascade::handle<BVH_Builder<Standard_ShortReal, 3> > myRaytraceBVHBuilder;
0970 
0971   //! Compile-time ray-tracing parameters.
0972   RaytracingParams myRaytraceParameters;
0973 
0974   //! Radius of bounding sphere of the scene.
0975   Standard_ShortReal myRaytraceSceneRadius;
0976   //! Scene epsilon to prevent self-intersections.
0977   Standard_ShortReal myRaytraceSceneEpsilon;
0978 
0979   //! OpenGL/GLSL source of ray-tracing fragment shader.
0980   ShaderSource myRaytraceShaderSource;
0981   //! OpenGL/GLSL source of adaptive-AA fragment shader.
0982   ShaderSource myPostFSAAShaderSource;
0983   //! OpenGL/GLSL source of RT/PT display fragment shader.
0984   ShaderSource myOutImageShaderSource;
0985 
0986   //! OpenGL/GLSL ray-tracing fragment shader.
0987   Handle(OpenGl_ShaderObject) myRaytraceShader;
0988   //! OpenGL/GLSL adaptive-AA fragment shader.
0989   Handle(OpenGl_ShaderObject) myPostFSAAShader;
0990   //! OpenGL/GLSL ray-tracing display fragment shader.
0991   Handle(OpenGl_ShaderObject) myOutImageShader;
0992 
0993   //! OpenGL/GLSL ray-tracing shader program.
0994   Handle(OpenGl_ShaderProgram) myRaytraceProgram;
0995   //! OpenGL/GLSL adaptive-AA shader program.
0996   Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
0997   //! OpenGL/GLSL program for displaying texture.
0998   Handle(OpenGl_ShaderProgram) myOutImageProgram;
0999 
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