0025703: Visualization - Decrease number of samplers used in ray-tracing mode
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
index c43f1de..5450975 100644 (file)
@@ -95,7 +95,7 @@ struct OpenGl_Material
 
 DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
 
-//! Graphical raytracing filter.
+//! Graphical ray-tracing filter.
 //! Filters out all raytracable structures.
 class OpenGl_RaytraceFilter : public OpenGl_RenderFilter
 {
@@ -184,7 +184,6 @@ public:
                                Image_PixMap&               theImage,
                                const Graphic3d_BufferType& theBufferType);
 
-  void UseTransparency (const Standard_Boolean theFlag);
   Standard_Boolean& UseZBuffer()   { return myUseZBuffer; }
   Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
   Standard_Boolean& UseGLLight()   { return myUseGLLight; }
@@ -197,13 +196,6 @@ public:
 
   const TEL_COLOUR* HighlightColor;
 
-  const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
-  const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix*, bool aRevert = false);
-
-  //! Updates current model-view matrix
-  //! replacing it with StructureMatrixT*ViewMatrix from the workspace.
-  const void UpdateModelViewMatrix();
-
   const OpenGl_AspectLine*   SetAspectLine   (const OpenGl_AspectLine*   theAspect);
   const OpenGl_AspectFace*   SetAspectFace   (const OpenGl_AspectFace*   theAspect);
   const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
@@ -307,29 +299,28 @@ protected:
     OpenGl_RT_uOriginLB,
     OpenGl_RT_uOriginRT,
     OpenGl_RT_uOriginRB,
-
     OpenGl_RT_uDirectLT,
     OpenGl_RT_uDirectLB,
     OpenGl_RT_uDirectRT,
     OpenGl_RT_uDirectRB,
-    OpenGl_RT_uInvModelProj,
-    
+    OpenGl_RT_uUnviewMat,
+
     OpenGl_RT_uSceneRad,
     OpenGl_RT_uSceneEps,
-
     OpenGl_RT_uLightAmbnt,
     OpenGl_RT_uLightCount,
 
     OpenGl_RT_uShadEnabled,
     OpenGl_RT_uReflEnabled,
-    
-    OpenGl_RT_uInputTexture,
+    OpenGl_RT_uEnvMapEnable,
 
     OpenGl_RT_uOffsetX,
     OpenGl_RT_uOffsetY,
     OpenGl_RT_uSamples,
+    OpenGl_RT_uWinSizeX,
+    OpenGl_RT_uWinSizeY,
 
-    OpenGl_RT_uEnvironmentEnable,
+    OpenGl_RT_uTextures,
 
     OpenGl_RT_NbVariables // special field
   };
@@ -337,29 +328,25 @@ protected:
   //! Defines texture samplers.
   enum ShaderSamplerNames
   {
-    OpenGl_RT_SceneNodeInfoTexture = 0,
-    OpenGl_RT_SceneMinPointTexture = 1,
-    OpenGl_RT_SceneMaxPointTexture = 2,
+    OpenGl_RT_SceneNodeInfoTexture  = 0,
+    OpenGl_RT_SceneMinPointTexture  = 1,
+    OpenGl_RT_SceneMaxPointTexture  = 2,
+    OpenGl_RT_SceneTransformTexture = 3,
 
-    OpenGl_RT_ObjectNodeInfoTexture = 3,
-    OpenGl_RT_ObjectMinPointTexture = 4,
-    OpenGl_RT_ObjectMaxPointTexture = 5,
+    OpenGl_RT_GeometryVertexTexture = 4,
+    OpenGl_RT_GeometryNormalTexture = 5,
+    OpenGl_RT_GeometryTexCrdTexture = 6,
+    OpenGl_RT_GeometryTriangTexture = 7,
 
-    OpenGl_RT_GeometryVertexTexture = 6,
-    OpenGl_RT_GeometryNormalTexture = 7,
-    OpenGl_RT_GeometryTriangTexture = 8,
+    OpenGl_RT_EnvironmentMapTexture = 8,
 
-    OpenGl_RT_EnvironmentMapTexture = 9,
+    OpenGl_RT_RaytraceMaterialTexture = 9,
+    OpenGl_RT_RaytraceLightSrcTexture = 10,
 
-    OpenGl_RT_RaytraceMaterialTexture = 10,
-    OpenGl_RT_RaytraceLightSrcTexture = 11,
+    OpenGl_RT_FSAAInputTexture = 11,
 
-    OpenGl_RT_FSAAInputTexture = 12,
-
-    OpenGl_RT_SceneTransformTexture = 13,
-
-    OpenGl_RT_OpenGlColorTexture = 14,
-    OpenGl_RT_OpenGlDepthTexture = 15
+    OpenGl_RT_OpenGlColorTexture = 12,
+    OpenGl_RT_OpenGlDepthTexture = 13
   };
 
   //! Tool class for management of shader sources.
@@ -407,7 +394,7 @@ protected:
   };
 
   //! Default ray-tracing depth.
-  static const Standard_Integer THE_DEFAULT_RAY_DEPTH = 3;
+  static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
 
   //! Default size of traversal stack.
   static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
@@ -419,7 +406,7 @@ protected:
     Standard_Integer StackSize;
 
     //! Actual ray-tracing depth (number of ray bounces).
-    Standard_Integer TraceDepth;
+    Standard_Integer NbBounces;
 
     //! Sets light propagation through transparent media.
     Standard_Boolean TransparentShadows;
@@ -427,7 +414,7 @@ protected:
     //! Creates default compile-time ray-tracing parameters.
     RaytracingParams()
     : StackSize (THE_DEFAULT_STACK_SIZE),
-      TraceDepth (THE_DEFAULT_RAY_DEPTH),
+      NbBounces (THE_DEFAULT_NB_BOUNCES),
       TransparentShadows (Standard_False)
     {
       //
@@ -442,8 +429,11 @@ protected: //! @name methods related to ray-tracing
   //! Checks to see if the structure is modified.
   Standard_Boolean CheckRaytraceStructure (const OpenGl_Structure* theStructure);
 
+  //! Creates ray-tracing material properties.
+  Standard_Boolean CreateMaterial (const OpenGl_AspectFace* theAspect, OpenGl_RaytraceMaterial& theMaterial);
+
   //! Updates 3D scene light sources for ray-tracing.
-  Standard_Boolean UpdateRaytraceLightSources (const GLdouble theInvModelView[16]);
+  Standard_Boolean UpdateRaytraceLightSources (const OpenGl_Mat4& theInvModelView);
 
   //! Updates environment map for ray-tracing.
   Standard_Boolean UpdateRaytraceEnvironmentMap();
@@ -458,7 +448,7 @@ protected: //! @name methods related to ray-tracing
 
   //! Adds OpenGL primitive array to ray-traced scene geometry.
   OpenGl_TriangleSet* AddRaytracePrimitiveArray (
-    const OpenGl_PrimitiveArray* theArray, int theMatID, const Standard_ShortReal* theTrans);
+    const OpenGl_PrimitiveArray* theArray, int theMatID, const OpenGl_Mat4* theTrans);
 
   //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
   Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet&          theSet,
@@ -515,6 +505,9 @@ protected: //! @name methods related to ray-tracing
   //! Performs safe exit when shaders initialization fails.
   Standard_Boolean SafeFailBack (const TCollection_ExtendedString& theMessage);
 
+  //! Generates shader prefix based on current ray-tracing options.
+  TCollection_AsciiString GenerateShaderPrefix();
+
   //! Initializes OpenGL/GLSL shader programs.
   Standard_Boolean InitRaytraceResources (const Graphic3d_CView& theCView);
 
@@ -529,11 +522,21 @@ protected: //! @name methods related to ray-tracing
                                           const Standard_Integer theSizeY);
 
   //! Generates viewing rays for corners of screen quad.
-  void UpdateCamera (const NCollection_Mat4<GLdouble>& theOrientation,
-                     const NCollection_Mat4<GLdouble>& theViewMapping,
-                     OpenGl_Vec3                       theOrigins[4],
-                     OpenGl_Vec3                       theDirects[4],
-                     NCollection_Mat4<GLdouble>&       theInvModelProj);
+  void UpdateCamera (const OpenGl_Mat4& theOrientation,
+                     const OpenGl_Mat4& theViewMapping,
+                     OpenGl_Vec3        theOrigins[4],
+                     OpenGl_Vec3        theDirects[4],
+                     OpenGl_Mat4&       theInvModelProj);
+
+  //! Sets uniform state for the given ray-tracing shader program.
+  Standard_Boolean SetUniformState (const Graphic3d_CView&        theCView,
+                                    const Standard_Integer        theSizeX,
+                                    const Standard_Integer        theSizeY,
+                                    const OpenGl_Vec3*            theOrigins,
+                                    const OpenGl_Vec3*            theDirects,
+                                    const OpenGl_Mat4&            theUnviewMat,
+                                    const Standard_Integer        theProgramIndex,
+                                    Handle(OpenGl_ShaderProgram)& theRaytraceProgram);
 
   //! Runs ray-tracing shader programs.
   Standard_Boolean RunRaytraceShaders (const Graphic3d_CView& theCView,
@@ -541,7 +544,7 @@ protected: //! @name methods related to ray-tracing
                                        const Standard_Integer theSizeY,
                                        const OpenGl_Vec3      theOrigins[4],
                                        const OpenGl_Vec3      theDirects[4],
-                                       const OpenGl_Matrix&   theInvModelProj,
+                                       const OpenGl_Mat4&     theUnviewMat,
                                        OpenGl_FrameBuffer*    theFrameBuffer);
 
   //! Redraws the window using OpenGL/GLSL ray-tracing.
@@ -561,6 +564,9 @@ protected: //! @name fields related to ray-tracing
   //! Is geometry data valid?
   Standard_Boolean myIsRaytraceDataValid;
 
+  //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
+  Standard_Boolean myIsRaytraceWarnTextures;
+
   //! 3D scene geometry data for ray-tracing.
   OpenGl_RaytraceGeometry myRaytraceGeometry;
 
@@ -587,29 +593,24 @@ protected: //! @name fields related to ray-tracing
   //! OpenGL/GLSL adaptive-AA shader program.
   Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
 
-  //! Texture buffer of data records of high-level BVH nodes.
+  //! Texture buffer of data records of bottom-level BVH nodes.
   Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
-  //! Texture buffer of minimum points of high-level BVH nodes.
+  //! Texture buffer of minimum points of bottom-level BVH nodes.
   Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
-  //! Texture buffer of maximum points of high-level BVH nodes.
+  //! Texture buffer of maximum points of bottom-level BVH nodes.
   Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
   //! Texture buffer of transformations of high-level BVH nodes.
   Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
 
-  //! Texture buffer of data records of bottom-level BVH nodes.
-  Handle(OpenGl_TextureBufferArb) myObjectNodeInfoTexture;
-  //! Texture buffer of minimum points of bottom-level BVH nodes.
-  Handle(OpenGl_TextureBufferArb) myObjectMinPointTexture;
-  //! Texture buffer of maximum points of bottom-level BVH nodes.
-  Handle(OpenGl_TextureBufferArb) myObjectMaxPointTexture;
-
   //! Texture buffer of vertex coords.
   Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
   //! Texture buffer of vertex normals.
   Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
+  //! Texture buffer of vertex UV coords.
+  Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
   //! Texture buffer of triangle indices.
   Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
-  
+
   //! Texture buffer of material properties.
   Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
   //! Texture buffer of light source properties.
@@ -639,10 +640,10 @@ protected: //! @name fields related to ray-tracing
   //! Cached locations of frequently used uniform variables.
   Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
 
-  //! Graphical raytracing filter to filter out all raytracable structures.
+  //! Graphical ray-tracing filter to filter out all raytracable structures.
   Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
 
-  //! Redraw the scene using OpenGL rasterization or raytracing?
+  //! Redraw the scene using OpenGL rasterization or ray-tracing?
   Standard_Boolean myToRedrawGL;
 
 protected: //! @name protected fields
@@ -654,7 +655,6 @@ protected: //! @name protected fields
   Standard_Boolean       myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
   Standard_Boolean       myBackBufferRestored;
   Standard_Boolean       myIsImmediateDrawn;     //!< flag indicates that immediate mode buffer contains some data
-  Standard_Boolean       myUseTransparency;
   Standard_Boolean       myUseZBuffer;
   Standard_Boolean       myUseDepthTest;
   Standard_Boolean       myUseGLLight;