Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 09:16:37

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