1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0025885: Visualization, ray tracing - Improve layer processing

Move Ray-tracing core from OpenGl_Workspace to OpenGl_View.
This patch also contains a number of useful architectural changes.
This commit is contained in:
dbp 2015-04-09 08:58:10 +03:00 committed by bugmaster
parent 5b055f07b3
commit 91c60b5790
14 changed files with 1568 additions and 1427 deletions

View File

@ -175,6 +175,25 @@ public:
v[1] > theVec.v[1] ? v[1] : theVec.v[1]);
}
//! Compute component-wise modulus of the vector.
NCollection_Vec2 cwiseAbs() const
{
return NCollection_Vec2 (std::abs (v[0]),
std::abs (v[1]));
}
//! Compute maximum component of the vector.
Element_t maxComp() const
{
return v[0] > v[1] ? v[0] : v[1];
}
//! Compute minimum component of the vector.
Element_t minComp() const
{
return v[0] < v[1] ? v[0] : v[1];
}
//! Compute per-component multiplication by scale factor.
NCollection_Vec2& operator*= (const Element_t theFactor)
{

View File

@ -250,6 +250,28 @@ public:
v[2] > theVec.v[2] ? v[2] : theVec.v[2]);
}
//! Compute component-wise modulus of the vector.
NCollection_Vec3 cwiseAbs() const
{
return NCollection_Vec3 (std::abs (v[0]),
std::abs (v[1]),
std::abs (v[2]));
}
//! Compute maximum component of the vector.
Element_t maxComp() const
{
return v[0] > v[1] ? (v[0] > v[2] ? v[0] : v[2])
: (v[1] > v[2] ? v[1] : v[2]);
}
//! Compute minimum component of the vector.
Element_t minComp() const
{
return v[0] < v[1] ? (v[0] < v[2] ? v[0] : v[2])
: (v[1] < v[2] ? v[1] : v[2]);
}
//! Compute per-component division by scale factor.
NCollection_Vec3& operator/= (const Element_t theInvFactor)
{

View File

@ -302,6 +302,33 @@ public:
v[3] > theVec.v[3] ? v[3] : theVec.v[3]);
}
//! Compute component-wise modulus of the vector.
NCollection_Vec4 cwiseAbs() const
{
return NCollection_Vec4 (std::abs (v[0]),
std::abs (v[1]),
std::abs (v[2]),
std::abs (v[3]));
}
//! Compute maximum component of the vector.
Element_t maxComp() const
{
const Element_t aMax1 = v[0] > v[1] ? v[0] : v[1];
const Element_t aMax2 = v[2] > v[3] ? v[2] : v[3];
return aMax1 > aMax2 ? aMax1 : aMax2;
}
//! Compute minimum component of the vector.
Element_t minComp() const
{
const Element_t aMin1 = v[0] < v[1] ? v[0] : v[1];
const Element_t aMin2 = v[2] < v[3] ? v[2] : v[3];
return aMin1 < aMin2 ? aMin1 : aMin2;
}
//! Compute per-component division by scale factor.
NCollection_Vec4& operator/= (const Element_t theInvFactor)
{

View File

@ -108,6 +108,7 @@ OpenGl_GlCore43.hxx
OpenGl_GlCore44.hxx
OpenGl_LayerList.cxx
OpenGl_LayerList.hxx
OpenGl_LayerFilter.hxx
OpenGl_IndexBuffer.hxx
OpenGl_IndexBuffer.cxx
OpenGl_Layer.cxx
@ -146,7 +147,7 @@ Handle_OpenGl_ShaderProgram.hxx
Handle_OpenGl_ShaderManager.hxx
OpenGl_SceneGeometry.hxx
OpenGl_SceneGeometry.cxx
OpenGl_Workspace_Raytrace.cxx
OpenGl_View_Raytrace.cxx
OpenGl_Flipper.hxx
OpenGl_Flipper.cxx
OpenGl_BVHTreeSelector.hxx

View File

@ -0,0 +1,28 @@
// Created on: 2015-03-20
// Created by: Denis BOGOLEPOV
// Copyright (c) 2012-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _OpenGl_LayerFilter_H__
#define _OpenGl_LayerFilter_H__
//! Tool object to specify processed OpenGL layers.
enum OpenGl_LayerFilter
{
OpenGl_LF_All, //!< process all layers
OpenGl_LF_Upper, //!< process only top layers
OpenGl_LF_Bottom, //!< process only bottom layer
OpenGl_LF_Default //!< process only default layer
};
#endif //_OpenGl_LayerFilter_H__

View File

@ -357,7 +357,8 @@ void OpenGl_LayerList::SetLayerSettings (const Graphic3d_ZLayerId theLaye
//purpose :
//=======================================================================
void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
const Standard_Boolean theToDrawImmediate) const
const Standard_Boolean theToDrawImmediate,
const OpenGl_LayerFilter theLayersToProcess) const
{
OpenGl_GlobalLayerSettings aDefaultSettings;
@ -365,9 +366,22 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
aCtx->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDefaultSettings.DepthFunc);
aCtx->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &aDefaultSettings.DepthMask);
Standard_Integer aSeqId = myLayers.Lower();
Standard_Integer aSeqId = myLayers.Lower(), aMainId = myLayerIds.Find (Graphic3d_ZLayerId_Default);
for (OpenGl_SequenceOfLayers::Iterator anIts (myLayers); anIts.More(); anIts.Next(), ++aSeqId)
{
if (theLayersToProcess == OpenGl_LF_Bottom)
{
if (aSeqId >= aMainId) continue;
}
else if (theLayersToProcess == OpenGl_LF_Upper)
{
if (aSeqId <= aMainId) continue;
}
else if (theLayersToProcess == OpenGl_LF_Default)
{
if (aSeqId != aMainId) continue;
}
const OpenGl_Layer& aLayer = anIts.Value();
if (aLayer.NbStructures() < 1)
{

View File

@ -17,6 +17,7 @@
#define _OpenGl_LayerList_Header
#include <OpenGl_Layer.hxx>
#include <OpenGl_LayerFilter.hxx>
#include <InterfaceGraphic_telem.hxx>
@ -89,7 +90,8 @@ public:
//! Render this element
void Render (const Handle(OpenGl_Workspace)& theWorkspace,
const Standard_Boolean theToDrawImmediate) const;
const Standard_Boolean theToDrawImmediate,
const OpenGl_LayerFilter theLayersToProcess) const;
//! Returns the set of OpenGL Z-layers.
const OpenGl_SequenceOfLayers& Layers() const { return myLayers; }

View File

@ -132,7 +132,7 @@ const int MaxStateTypes = 6;
//! Wrapper for OpenGL program object.
class OpenGl_ShaderProgram : public OpenGl_Resource
{
friend class OpenGl_Workspace;
friend class OpenGl_View;
public:

View File

@ -73,10 +73,15 @@ OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
myModelViewState (0),
myStateCounter (theCounter),
myLastLightSourceState (0, 0),
myModificationState (1), // initial state
myTextureParams (new OpenGl_AspectFace()),
myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE))
myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
// ray-tracing fields initialization
myRaytraceInitStatus (OpenGl_RT_NONE),
myIsRaytraceDataValid (Standard_False),
myIsRaytraceWarnTextures (Standard_False),
myToUpdateEnvironmentMap (Standard_False),
myLayersModificationStatus (0)
{
myCurrLightSourceState = myStateCounter->Increment();
}
@ -114,6 +119,8 @@ void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
{
myBgTextureArray->Release (theCtx.operator->());
}
releaseRaytraceResources (theCtx);
}
void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
@ -135,14 +142,14 @@ void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
if (!anImage.IsNull())
myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
myModificationState++;
myToUpdateEnvironmentMap = Standard_True;
}
void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode)
{
mySurfaceDetail = theMode;
myModificationState++;
myToUpdateEnvironmentMap = Standard_True;
}
// =======================================================================

View File

@ -213,17 +213,17 @@ class OpenGl_View : public MMgt_TShared
|| myZLayers.NbImmediateStructures() != 0;
}
//! Returns modification state for ray-tracing.
Standard_Size ModificationState() const { return myModificationState; }
protected:
void RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
const Graphic3d_CView& theCView,
const Standard_Boolean theToDrawImmediate);
void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
const Handle(OpenGl_Workspace) &theWorkspace,
const Handle(OpenGl_Workspace)& theWorkspace,
const Graphic3d_CView& theCView,
const Aspect_CLayer2d& theCLayer);
void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
//! Redraw contents of model scene: clipping planes,
@ -232,6 +232,7 @@ protected:
//! matrices supplied by 3d view.
void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
const Handle(OpenGl_Workspace)& theWorkspace,
const Graphic3d_CView& theCView,
const Standard_Boolean theToDrawImmediate);
Handle(OpenGl_LineAttributes) myLineAttribs;
@ -286,14 +287,398 @@ protected:
//! Is needed for selection of overlapping objects and storage of the current view volume
OpenGl_BVHTreeSelector myBVHSelector;
Standard_Size myModificationState;
protected: //! @name Background parameters
OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
protected: //! @name data types related to ray-tracing
//! Result of OpenGL shaders initialization.
enum RaytraceInitStatus
{
OpenGl_RT_NONE,
OpenGl_RT_INIT,
OpenGl_RT_FAIL
};
//! Describes update mode (state).
enum RaytraceUpdateMode
{
OpenGl_GUM_CHECK, //!< check geometry state
OpenGl_GUM_PREPARE, //!< collect unchanged objects
OpenGl_GUM_REBUILD //!< rebuild changed and new objects
};
//! Defines frequently used shader variables.
enum ShaderVariableIndex
{
OpenGl_RT_aPosition,
OpenGl_RT_uOriginLT,
OpenGl_RT_uOriginLB,
OpenGl_RT_uOriginRT,
OpenGl_RT_uOriginRB,
OpenGl_RT_uDirectLT,
OpenGl_RT_uDirectLB,
OpenGl_RT_uDirectRT,
OpenGl_RT_uDirectRB,
OpenGl_RT_uUnviewMat,
OpenGl_RT_uSceneRad,
OpenGl_RT_uSceneEps,
OpenGl_RT_uLightAmbnt,
OpenGl_RT_uLightCount,
OpenGl_RT_uShadEnabled,
OpenGl_RT_uReflEnabled,
OpenGl_RT_uEnvMapEnable,
OpenGl_RT_uOffsetX,
OpenGl_RT_uOffsetY,
OpenGl_RT_uSamples,
OpenGl_RT_uWinSizeX,
OpenGl_RT_uWinSizeY,
OpenGl_RT_uTextures,
OpenGl_RT_NbVariables // special field
};
//! Defines texture samplers.
enum ShaderSamplerNames
{
OpenGl_RT_SceneNodeInfoTexture = 0,
OpenGl_RT_SceneMinPointTexture = 1,
OpenGl_RT_SceneMaxPointTexture = 2,
OpenGl_RT_SceneTransformTexture = 3,
OpenGl_RT_GeometryVertexTexture = 4,
OpenGl_RT_GeometryNormalTexture = 5,
OpenGl_RT_GeometryTexCrdTexture = 6,
OpenGl_RT_GeometryTriangTexture = 7,
OpenGl_RT_EnvironmentMapTexture = 8,
OpenGl_RT_RaytraceMaterialTexture = 9,
OpenGl_RT_RaytraceLightSrcTexture = 10,
OpenGl_RT_FSAAInputTexture = 11,
OpenGl_RT_OpenGlColorTexture = 12,
OpenGl_RT_OpenGlDepthTexture = 13
};
//! Tool class for management of shader sources.
class ShaderSource
{
public:
//! Creates new uninitialized shader source.
ShaderSource()
{
//
}
//! Creates new shader source from specified file.
ShaderSource (const TCollection_AsciiString& theFileName)
{
Load (&theFileName, 1);
}
public:
//! Returns prefix to insert before the source.
const TCollection_AsciiString& Prefix() const
{
return myPrefix;
}
//! Sets prefix to insert before the source.
void SetPrefix (const TCollection_AsciiString& thePrefix)
{
myPrefix = thePrefix;
}
//! Returns shader source combined with prefix.
TCollection_AsciiString Source() const;
//! Loads shader source from specified files.
void Load (const TCollection_AsciiString* theFileNames, const Standard_Integer theCount);
private:
TCollection_AsciiString mySource; //!< Source string of the shader object
TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
};
//! Default ray-tracing depth.
static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
//! Default size of traversal stack.
static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
//! Compile-time ray-tracing parameters.
struct RaytracingParams
{
//! Actual size of traversal stack in shader program.
Standard_Integer StackSize;
//! Actual ray-tracing depth (number of ray bounces).
Standard_Integer NbBounces;
//! Sets light propagation through transparent media.
Standard_Boolean TransparentShadows;
//! Creates default compile-time ray-tracing parameters.
RaytracingParams()
: StackSize (THE_DEFAULT_STACK_SIZE),
NbBounces (THE_DEFAULT_NB_BOUNCES),
TransparentShadows (Standard_False)
{
//
}
};
protected: //! @name methods related to ray-tracing
//! Updates 3D scene geometry for ray-tracing.
Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
const Standard_Integer theViewId,
const Handle(OpenGl_Context)& theGlContext);
//! Updates 3D scene light sources for ray-tracing.
Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
//! Updates environment map for ray-tracing.
Standard_Boolean updateRaytraceEnvironmentMap (const Handle(OpenGl_Context)& theGlContext);
//! Checks to see if the OpenGL structure is modified.
Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
//! Adds OpenGL structure to ray-traced scene geometry.
Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
const Handle(OpenGl_Context)& theGlContext);
//! Adds OpenGL groups to ray-traced scene geometry.
Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
const Standard_Integer theStructMat,
const Standard_ShortReal* theTransform,
const Handle(OpenGl_Context)& theGlContext);
//! Creates ray-tracing material properties.
OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
const Handle(OpenGl_Context)& theGlContext);
//! Adds OpenGL primitive array to ray-traced scene geometry.
OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
const Standard_Integer theMatID,
const OpenGl_Mat4* theTrans);
//! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const OpenGl_PrimitiveArray& theArray);
//! Adds OpenGL triangle array to ray-traced scene geometry.
Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(Graphic3d_IndexBuffer)& theIndices);
//! Adds OpenGL triangle fan array to ray-traced scene geometry.
Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(Graphic3d_IndexBuffer)& theIndices);
//! Adds OpenGL triangle strip array to ray-traced scene geometry.
Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(Graphic3d_IndexBuffer)& theIndices);
//! Adds OpenGL quadrangle array to ray-traced scene geometry.
Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(Graphic3d_IndexBuffer)& theIndices);
//! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(Graphic3d_IndexBuffer)& theIndices);
//! Adds OpenGL polygon array to ray-traced scene geometry.
Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(Graphic3d_IndexBuffer)& theIndices);
//! Uploads ray-trace data to the GPU.
Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
//! Generates shader prefix based on current ray-tracing options.
TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
//! Performs safe exit when shaders initialization fails.
Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
const Handle(OpenGl_Context)& theGlContext);
//! Loads and compiles shader object from specified source.
Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
const ShaderSource& theSource,
const Handle(OpenGl_Context)& theGlContext);
//! Initializes OpenGL/GLSL shader programs.
Standard_Boolean initRaytraceResources (const Graphic3d_CView& theCView,
const Handle(OpenGl_Context)& theGlContext);
//! Releases OpenGL/GLSL shader programs.
void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
//! Resizes OpenGL frame buffers.
Standard_Boolean resizeRaytraceBuffers (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Handle(OpenGl_Context)& theGlContext);
//! Generates viewing rays for corners of screen quad.
void updateCamera (const OpenGl_Mat4& theOrientation,
const OpenGl_Mat4& theViewMapping,
OpenGl_Vec3* theOrigins,
OpenGl_Vec3* theDirects,
OpenGl_Mat4& theUnView);
//! Binds ray-trace textures to corresponding texture units.
void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
//! Unbinds ray-trace textures from corresponding texture unit.
void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
//! Sets uniform state for the given ray-tracing shader program.
Standard_Boolean setUniformState (const Graphic3d_CView& theCView,
const OpenGl_Vec3* theOrigins,
const OpenGl_Vec3* theDirects,
const OpenGl_Mat4& theUnviewMat,
const Standard_Integer theProgramId,
const Handle(OpenGl_Context)& theGlContext);
//! Runs ray-tracing shader programs.
Standard_Boolean runRaytraceShaders (const Graphic3d_CView& theCView,
const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const OpenGl_Vec3* theOrigins,
const OpenGl_Vec3* theDirects,
const OpenGl_Mat4& theUnviewMat,
OpenGl_FrameBuffer* theOutputFBO,
const Handle(OpenGl_Context)& theGlContext);
//! Redraws the window using OpenGL/GLSL ray-tracing.
Standard_Boolean raytrace (const Graphic3d_CView& theCView,
const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
OpenGl_FrameBuffer* theOutputFBO,
const Handle(OpenGl_Context)& theGlContext);
protected: //! @name fields related to ray-tracing
//! Result of shaders initialization.
RaytraceInitStatus myRaytraceInitStatus;
//! 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;
//! Compile-time ray-tracing parameters.
RaytracingParams myRaytraceParameters;
//! Radius of bounding sphere of the scene.
Standard_ShortReal myRaytraceSceneRadius;
//! Scene epsilon to prevent self-intersections.
Standard_ShortReal myRaytraceSceneEpsilon;
//! OpenGL/GLSL source of ray-tracing fragment shader.
ShaderSource myRaytraceShaderSource;
//! OpenGL/GLSL source of adaptive-AA fragment shader.
ShaderSource myPostFSAAShaderSource;
//! OpenGL/GLSL ray-tracing fragment shader.
Handle(OpenGl_ShaderObject) myRaytraceShader;
//! OpenGL/GLSL adaptive-AA fragment shader.
Handle(OpenGl_ShaderObject) myPostFSAAShader;
//! OpenGL/GLSL ray-tracing shader program.
Handle(OpenGl_ShaderProgram) myRaytraceProgram;
//! OpenGL/GLSL adaptive-AA shader program.
Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
//! Texture buffer of data records of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
//! Texture buffer of minimum points of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
//! 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 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.
Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
//! 1st framebuffer (FBO) to perform adaptive FSAA.
Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
//! 2nd framebuffer (FBO) to perform adaptive FSAA.
Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
//! Framebuffer (FBO) for preliminary OpenGL output.
Handle(OpenGl_FrameBuffer) myOpenGlFBO;
//! Vertex buffer (VBO) for drawing dummy quad.
OpenGl_VertexBuffer myRaytraceScreenQuad;
//! Cached locations of frequently used uniform variables.
Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
//! State of OpenGL structures reflected to ray-tracing.
std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
//! PrimitiveArray to TriangleSet map for scene partial update.
std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
//! Graphical ray-tracing filter to filter out all raytracable structures.
Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
//! Marks if environment map should be updated.
Standard_Boolean myToUpdateEnvironmentMap;
//! State of OpenGL layer list.
Standard_Size myLayersModificationStatus;
public:
DEFINE_STANDARD_ALLOC

View File

@ -38,6 +38,7 @@
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_ArbFBO.hxx>
#define EPSI 0.0001
@ -241,7 +242,7 @@ void OpenGl_View::DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
aCtx->ProjectionState.Pop();
aCtx->ApplyProjectionMatrix();
if (theWorkspace->UseZBuffer() && theWorkspace->ToRedrawGL())
if (theWorkspace->UseZBuffer())
{
aCtx->core11fwd->glEnable (GL_DEPTH_TEST);
}
@ -340,8 +341,7 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
// ====================================
// Render background
if (theWorkspace->ToRedrawGL()
&& !theToDrawImmediate)
if (!theToDrawImmediate)
{
DrawBackground (theWorkspace);
}
@ -456,7 +456,7 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
{
// single-pass monographic rendering
// redraw scene with normal orientation and projection
RedrawScene (thePrintContext, theWorkspace, theToDrawImmediate);
RedrawScene (thePrintContext, theWorkspace, theCView, theToDrawImmediate);
}
else
{
@ -469,7 +469,7 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
aContext->ApplyProjectionMatrix();
// redraw left Eye
RedrawScene (thePrintContext, theWorkspace, theToDrawImmediate);
RedrawScene (thePrintContext, theWorkspace, theCView, theToDrawImmediate);
// reset depth buffer of first rendering pass
if (theWorkspace->UseDepthTest())
@ -483,7 +483,7 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
aContext->ApplyProjectionMatrix();
// redraw right Eye
RedrawScene (thePrintContext, theWorkspace, theToDrawImmediate);
RedrawScene (thePrintContext, theWorkspace, theCView, theToDrawImmediate);
// switch back to monographic rendering
aContext->SetDrawBufferMono();
@ -513,8 +513,7 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
}
// Render trihedron
if (theWorkspace->ToRedrawGL()
&& !theToDrawImmediate)
if (!theToDrawImmediate)
{
RedrawTrihedron (theWorkspace);
@ -587,6 +586,7 @@ void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
//ExecuteViewDisplay
void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
const Graphic3d_CView& theCView,
const Standard_Boolean theToDrawImmediate)
{
if ( myZLayers.NbStructures() <= 0 )
@ -628,7 +628,109 @@ void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
}
}
myZLayers.Render (theWorkspace, theToDrawImmediate);
Standard_Boolean toRenderGL = theToDrawImmediate ||
theCView.RenderParams.Method != Graphic3d_RM_RAYTRACING || myRaytraceInitStatus == OpenGl_RT_FAIL;
if (!toRenderGL)
{
toRenderGL = !initRaytraceResources (theCView, aCtx) ||
!updateRaytraceGeometry (OpenGl_GUM_CHECK, theWorkspace->ActiveViewId(), aCtx);
OpenGl_FrameBuffer* anOutputFBO = NULL;
if (theWorkspace->ResultFBO()->IsValid())
{
anOutputFBO = theWorkspace->ResultFBO().operator->();
}
else if (theCView.ptrFBO != NULL)
{
anOutputFBO = (OpenGl_FrameBuffer* )theCView.ptrFBO;
}
else
{
//toRenderGL = Standard_True; // failed to get valid FBO
}
if (!toRenderGL && myIsRaytraceDataValid)
{
const Standard_Integer aSizeX = anOutputFBO != NULL ?
anOutputFBO->GetVPSizeX() : theWorkspace->Width();
const Standard_Integer aSizeY = anOutputFBO != NULL ?
anOutputFBO->GetVPSizeY() : theWorkspace->Height();
if (myOpenGlFBO.IsNull())
myOpenGlFBO = new OpenGl_FrameBuffer;
if (myOpenGlFBO->GetVPSizeX() != aSizeX
|| myOpenGlFBO->GetVPSizeY() != aSizeY)
{
myOpenGlFBO->Init (aCtx, aSizeX, aSizeY);
}
if (myRaytraceFilter.IsNull())
myRaytraceFilter = new OpenGl_RaytraceFilter;
myRaytraceFilter->SetPrevRenderFilter (theWorkspace->GetRenderFilter());
if (anOutputFBO != NULL)
anOutputFBO->UnbindBuffer (aCtx);
// Prepare preliminary OpenGL output
if (aCtx->arbFBOBlit != NULL)
{
// Render bottom OSD layer
myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_Bottom);
theWorkspace->SetRenderFilter (myRaytraceFilter);
{
if (anOutputFBO != NULL)
{
anOutputFBO->BindReadBuffer (aCtx);
}
else
{
aCtx->arbFBO->glBindFramebuffer (GL_READ_FRAMEBUFFER, 0);
}
myOpenGlFBO->BindDrawBuffer (aCtx);
aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aSizeX, aSizeY,
0, 0, aSizeX, aSizeY,
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
GL_NEAREST);
// Render non-polygonal elements in default layer
myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_Default);
}
theWorkspace->SetRenderFilter (myRaytraceFilter->PrevRenderFilter());
}
if (anOutputFBO != NULL)
{
anOutputFBO->BindBuffer (aCtx);
}
else
{
aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, 0);
}
// Ray-tracing polygonal primitive arrays
raytrace (theCView, aSizeX, aSizeY, anOutputFBO, aCtx);
// Render upper (top and topmost) OpenGL layers
myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_Upper);
}
}
// Redraw 3D scene using OpenGL in standard
// mode or in case of ray-tracing failure
if (toRenderGL)
{
myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_All);
// Set flag that scene was redrawn by standard pipeline
theCView.WasRedrawnGL = Standard_True;
}
}
/*----------------------------------------------------------------------*/
@ -971,6 +1073,7 @@ void OpenGl_View::ChangePriority (const OpenGl_Structure *theStructure,
void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
const Handle(OpenGl_Workspace)& theWorkspace,
const Graphic3d_CView& theCView,
const Standard_Boolean theToDrawImmediate)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
@ -1103,14 +1206,14 @@ void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintCont
theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
theWorkspace->DisableTexture();
// Render the view
RenderStructs (theWorkspace, theToDrawImmediate);
RenderStructs (theWorkspace, theCView, theToDrawImmediate);
break;
case Visual3d_TOD_ENVIRONMENT:
theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
theWorkspace->EnableTexture (myTextureEnv);
// Render the view
RenderStructs (theWorkspace, theToDrawImmediate);
RenderStructs (theWorkspace, theCView, theToDrawImmediate);
theWorkspace->DisableTexture();
break;
@ -1118,7 +1221,7 @@ void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintCont
// First pass
theWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
// Render the view
RenderStructs (theWorkspace, theToDrawImmediate);
RenderStructs (theWorkspace, theCView, theToDrawImmediate);
theWorkspace->DisableTexture();
// Second pass
@ -1151,7 +1254,7 @@ void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintCont
theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
// Render the view
RenderStructs (theWorkspace, theToDrawImmediate);
RenderStructs (theWorkspace, theCView, theToDrawImmediate);
theWorkspace->DisableTexture();
// Restore properties back

View File

@ -146,15 +146,8 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDrive
NamedStatus (0),
HighlightColor (&THE_WHITE_COLOR),
//
myComputeInitStatus (OpenGl_RT_NONE),
myIsRaytraceDataValid (Standard_False),
myIsRaytraceWarnTextures (Standard_False),
myHasFboBlit (Standard_True),
myViewModificationStatus (0),
myLayersModificationStatus (0),
//
myRaytraceFilter (new OpenGl_RaytraceFilter()),
myToRedrawGL (Standard_True),
myViewId (-1),
myAntiAliasingMode (3),
myTransientDrawToFront (Standard_True),
@ -252,8 +245,6 @@ OpenGl_Workspace::~OpenGl_Workspace()
{
myFullScreenQuad.Release (myGlContext.operator->());
}
ReleaseRaytraceResources();
}
// =======================================================================
@ -727,77 +718,25 @@ void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
else
{
myResultFBO->Release (myGlContext.operator->());
myResultFBO->ChangeViewport (0, 0);
}
myToRedrawGL = Standard_True;
if (theCView.RenderParams.Method == Graphic3d_RM_RAYTRACING
&& myComputeInitStatus != OpenGl_RT_FAIL)
// draw entire frame using normal OpenGL pipeline
if (myResultFBO->IsValid())
{
if (InitRaytraceResources (theCView) && UpdateRaytraceGeometry (OpenGl_GUM_CHECK) && myIsRaytraceDataValid)
{
myToRedrawGL = Standard_False;
// Only non-raytracable structures should be rendered in OpenGL mode.
Handle(OpenGl_RenderFilter) aRenderFilter = GetRenderFilter();
myRaytraceFilter->SetPrevRenderFilter (aRenderFilter);
SetRenderFilter (myRaytraceFilter);
if (myOpenGlFBO.IsNull())
{
myOpenGlFBO = new OpenGl_FrameBuffer();
}
if (myOpenGlFBO->GetVPSizeX() != aSizeX
|| myOpenGlFBO->GetVPSizeY() != aSizeY)
{
myOpenGlFBO->Init (myGlContext, aSizeX, aSizeY);
}
// OverLayer and UnderLayer shouldn't be drawn by OpenGL.
// They will be drawn during ray-tracing.
Aspect_CLayer2d anEmptyCLayer;
anEmptyCLayer.ptrLayer = NULL;
myOpenGlFBO->BindBuffer (myGlContext);
redraw1 (theCView, anEmptyCLayer, anEmptyCLayer);
myOpenGlFBO->UnbindBuffer (myGlContext);
Raytrace (theCView, aSizeX, aSizeY,
theCOverLayer, theCUnderLayer,
myResultFBO->IsValid() ? myResultFBO.operator->() : aFrameBuffer);
myBackBufferRestored = Standard_True;
myIsImmediateDrawn = Standard_False;
if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
{
toSwap = false;
}
SetRenderFilter (aRenderFilter);
theCView.WasRedrawnGL = Standard_False;
}
myResultFBO->BindBuffer (myGlContext);
}
else if (aFrameBuffer != NULL)
{
aFrameBuffer->BindBuffer (myGlContext);
}
if (myToRedrawGL)
redraw1 (theCView, theCUnderLayer, theCOverLayer);
myBackBufferRestored = Standard_True;
myIsImmediateDrawn = Standard_False;
if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
{
// draw entire frame using normal OpenGL pipeline
if (myResultFBO->IsValid())
{
myResultFBO->BindBuffer (myGlContext);
}
else if (aFrameBuffer != NULL)
{
aFrameBuffer->BindBuffer (myGlContext);
}
redraw1 (theCView, theCUnderLayer, theCOverLayer);
myBackBufferRestored = Standard_True;
myIsImmediateDrawn = Standard_False;
if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
{
toSwap = false;
}
theCView.WasRedrawnGL = Standard_True;
toSwap = false;
}
if (aFrameBuffer != NULL)
@ -885,25 +824,17 @@ void OpenGl_Workspace::redraw1 (const Graphic3d_CView& theCView,
glDisable (GL_DEPTH_TEST);
}
if (!ToRedrawGL())
if (NamedStatus & OPENGL_NS_WHITEBACK)
{
// set background to black
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
toClear |= GL_DEPTH_BUFFER_BIT; //
// set background to white
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
toClear |= GL_DEPTH_BUFFER_BIT;
}
else
{
if (NamedStatus & OPENGL_NS_WHITEBACK)
{
// set background to white
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
toClear |= GL_DEPTH_BUFFER_BIT;
}
else
{
glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
}
glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
}
glClear (toClear);
Handle(OpenGl_Workspace) aWS (this);
@ -1211,3 +1142,21 @@ bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView,
}
return true;
}
IMPLEMENT_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_RaytraceFilter, OpenGl_RenderFilter)
// =======================================================================
// function : CanRender
// purpose :
// =======================================================================
Standard_Boolean OpenGl_RaytraceFilter::CanRender (const OpenGl_Element* theElement)
{
Standard_Boolean aPrevFilterResult = Standard_True;
if (!myPrevRenderFilter.IsNull())
{
aPrevFilterResult = myPrevRenderFilter->CanRender (theElement);
}
return aPrevFilterResult &&
!OpenGl_Raytrace::IsRaytracedElement (theElement);
}

View File

@ -104,8 +104,14 @@ public:
//! Default constructor.
OpenGl_RaytraceFilter() {}
//! Returns the previously set filter.
const Handle(OpenGl_RenderFilter)& PrevRenderFilter()
{
return myPrevRenderFilter;
}
//! Remembers the previously set filter.
inline void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
{
myPrevRenderFilter = theFilter;
}
@ -259,8 +265,8 @@ public:
//! @return true if clipping algorithm enabled
inline Standard_Boolean IsCullingEnabled() const { return myIsCullingEnabled; }
//! Returns a flag whether to redraw the scene using OpenGL rasterization
Standard_Boolean ToRedrawGL() const { return myToRedrawGL; }
//! Returns framebuffer storing cached main presentation of the view.
const Handle(OpenGl_FrameBuffer)& ResultFBO() const { return myResultFBO; }
protected:
@ -292,358 +298,7 @@ protected:
void setTextureParams (Handle(OpenGl_Texture)& theTexture,
const Handle(Graphic3d_TextureParams)& theParams);
protected:
//! Result of OpenGL shaders initialization.
enum RaytraceInitStatus
{
OpenGl_RT_NONE,
OpenGl_RT_INIT,
OpenGl_RT_FAIL
};
//! Describes update mode (state).
enum GeomUpdateMode
{
OpenGl_GUM_CHECK, //!< check if geometry update is necessary
OpenGl_GUM_PREPARE, //!< collect unchanged objects
OpenGl_GUM_UPDATE //!< update raytracing data, rebuild changed objects
};
//! Defines frequently used shader variables.
enum ShaderVariableIndex
{
OpenGl_RT_aPosition,
OpenGl_RT_uOriginLT,
OpenGl_RT_uOriginLB,
OpenGl_RT_uOriginRT,
OpenGl_RT_uOriginRB,
OpenGl_RT_uDirectLT,
OpenGl_RT_uDirectLB,
OpenGl_RT_uDirectRT,
OpenGl_RT_uDirectRB,
OpenGl_RT_uUnviewMat,
OpenGl_RT_uSceneRad,
OpenGl_RT_uSceneEps,
OpenGl_RT_uLightAmbnt,
OpenGl_RT_uLightCount,
OpenGl_RT_uShadEnabled,
OpenGl_RT_uReflEnabled,
OpenGl_RT_uEnvMapEnable,
OpenGl_RT_uOffsetX,
OpenGl_RT_uOffsetY,
OpenGl_RT_uSamples,
OpenGl_RT_uWinSizeX,
OpenGl_RT_uWinSizeY,
OpenGl_RT_uTextures,
OpenGl_RT_NbVariables // special field
};
//! Defines texture samplers.
enum ShaderSamplerNames
{
OpenGl_RT_SceneNodeInfoTexture = 0,
OpenGl_RT_SceneMinPointTexture = 1,
OpenGl_RT_SceneMaxPointTexture = 2,
OpenGl_RT_SceneTransformTexture = 3,
OpenGl_RT_GeometryVertexTexture = 4,
OpenGl_RT_GeometryNormalTexture = 5,
OpenGl_RT_GeometryTexCrdTexture = 6,
OpenGl_RT_GeometryTriangTexture = 7,
OpenGl_RT_EnvironmentMapTexture = 8,
OpenGl_RT_RaytraceMaterialTexture = 9,
OpenGl_RT_RaytraceLightSrcTexture = 10,
OpenGl_RT_FSAAInputTexture = 11,
OpenGl_RT_OpenGlColorTexture = 12,
OpenGl_RT_OpenGlDepthTexture = 13
};
//! Tool class for management of shader sources.
class ShaderSource
{
public:
//! Creates new uninitialized shader source.
ShaderSource()
{
//
}
//! Creates new shader source from specified file.
ShaderSource (const TCollection_AsciiString& theFileName)
{
Load (&theFileName, 1);
}
public:
//! Returns prefix to insert before the source.
const TCollection_AsciiString& Prefix() const
{
return myPrefix;
}
//! Sets prefix to insert before the source.
void SetPrefix (const TCollection_AsciiString& thePrefix)
{
myPrefix = thePrefix;
}
//! Returns shader source combined with prefix.
TCollection_AsciiString Source() const;
//! Loads shader source from specified files.
void Load (const TCollection_AsciiString* theFileNames, const Standard_Integer theCount);
private:
TCollection_AsciiString mySource; //!< Source string of the shader object
TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
};
//! Default ray-tracing depth.
static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
//! Default size of traversal stack.
static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
//! Compile-time ray-tracing parameters.
struct RaytracingParams
{
//! Actual size of traversal stack in shader program.
Standard_Integer StackSize;
//! Actual ray-tracing depth (number of ray bounces).
Standard_Integer NbBounces;
//! Sets light propagation through transparent media.
Standard_Boolean TransparentShadows;
//! Creates default compile-time ray-tracing parameters.
RaytracingParams()
: StackSize (THE_DEFAULT_STACK_SIZE),
NbBounces (THE_DEFAULT_NB_BOUNCES),
TransparentShadows (Standard_False)
{
//
}
};
protected: //! @name methods related to ray-tracing
//! Updates 3D scene geometry for ray-tracing.
Standard_Boolean UpdateRaytraceGeometry (GeomUpdateMode theMode);
//! 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 OpenGl_Mat4& theInvModelView);
//! Updates environment map for ray-tracing.
Standard_Boolean UpdateRaytraceEnvironmentMap();
//! Adds OpenGL structure to ray-traced scene geometry.
Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure, std::set<const OpenGl_Structure*>& theElements);
//! Adds OpenGL groups to ray-traced scene geometry.
Standard_Boolean AddRaytraceGroups (const OpenGl_Structure* theStructure,
const Standard_Integer theStructMatId,
const Standard_ShortReal* theTransform);
//! Adds OpenGL primitive array to ray-traced scene geometry.
OpenGl_TriangleSet* AddRaytracePrimitiveArray (
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,
const OpenGl_PrimitiveArray& theArray,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Adds OpenGL triangle array to ray-traced scene geometry.
Standard_Boolean AddRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
const Handle(Graphic3d_IndexBuffer)& theIndices,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Adds OpenGL triangle fan array to ray-traced scene geometry.
Standard_Boolean AddRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
const Handle(Graphic3d_IndexBuffer)& theIndices,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Adds OpenGL triangle strip array to ray-traced scene geometry.
Standard_Boolean AddRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
const Handle(Graphic3d_IndexBuffer)& theIndices,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Adds OpenGL quadrangle array to ray-traced scene geometry.
Standard_Boolean AddRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
const Handle(Graphic3d_IndexBuffer)& theIndices,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
Standard_Boolean AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
const Handle(Graphic3d_IndexBuffer)& theIndices,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Adds OpenGL polygon array to ray-traced scene geometry.
Standard_Boolean AddRaytracePolygonArray (OpenGl_TriangleSet& theSet,
const Handle(Graphic3d_IndexBuffer)& theIndices,
Standard_Integer theOffset,
Standard_Integer theCount,
Standard_Integer theMatID);
//! Loads and compiles shader object from specified source.
Handle(OpenGl_ShaderObject) LoadShader (const ShaderSource& theSource, GLenum theType);
//! 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);
//! Releases OpenGL/GLSL shader programs.
void ReleaseRaytraceResources();
//! Uploads ray-trace data to the GPU.
Standard_Boolean UploadRaytraceData();
//! Resizes OpenGL frame buffers.
Standard_Boolean ResizeRaytraceBuffers (const Standard_Integer theSizeX,
const Standard_Integer theSizeY);
//! Generates viewing rays for corners of screen quad.
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,
const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const OpenGl_Vec3 theOrigins[4],
const OpenGl_Vec3 theDirects[4],
const OpenGl_Mat4& theUnviewMat,
OpenGl_FrameBuffer* theFrameBuffer);
//! Redraws the window using OpenGL/GLSL ray-tracing.
Standard_Boolean Raytrace (const Graphic3d_CView& theCView,
const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Aspect_CLayer2d& theCOverLayer,
const Aspect_CLayer2d& theCUnderLayer,
OpenGl_FrameBuffer* theFrameBuffer);
protected: //! @name fields related to ray-tracing
//! Result of shaders initialization.
RaytraceInitStatus myComputeInitStatus;
//! 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;
//! Radius of bounding sphere of the scene.
Standard_ShortReal myRaytraceSceneRadius;
//! Scene epsilon to prevent self-intersections.
Standard_ShortReal myRaytraceSceneEpsilon;
//! Compile-time ray-tracing parameters.
RaytracingParams myRaytraceParameters;
//! OpenGL/GLSL source of ray-tracing fragment shader.
ShaderSource myRaytraceShaderSource;
//! OpenGL/GLSL source of adaptive-AA fragment shader.
ShaderSource myPostFSAAShaderSource;
//! OpenGL/GLSL ray-tracing fragment shader.
Handle(OpenGl_ShaderObject) myRaytraceShader;
//! OpenGL/GLSL adaptive-AA fragment shader.
Handle(OpenGl_ShaderObject) myPostFSAAShader;
//! OpenGL/GLSL ray-tracing shader program.
Handle(OpenGl_ShaderProgram) myRaytraceProgram;
//! OpenGL/GLSL adaptive-AA shader program.
Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
//! Texture buffer of data records of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
//! Texture buffer of minimum points of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
//! 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 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.
Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
//! Vertex buffer (VBO) for drawing dummy quad.
OpenGl_VertexBuffer myRaytraceScreenQuad;
//! Framebuffer (FBO) to perform adaptive FSAA.
Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
//! Framebuffer (FBO) to perform adaptive FSAA.
Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
//! Framebuffer (FBO) for pre-raytrace rendering by OpenGL.
Handle(OpenGl_FrameBuffer) myOpenGlFBO;
protected: //! @name protected fields
//! Framebuffer stores cached main presentation of the view (without presentation of immediate layers).
Handle(OpenGl_FrameBuffer) myResultFBO;
@ -653,28 +308,6 @@ protected: //! @name fields related to ray-tracing
//! Vertices for full-screen quad rendering.
OpenGl_VertexBuffer myFullScreenQuad;
//! State of OpenGL view.
Standard_Size myViewModificationStatus;
//! State of OpenGL layer list.
Standard_Size myLayersModificationStatus;
//! State of OpenGL structures reflected to ray-tracing.
std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
//! PrimitiveArray to TriangleSet map for scene partial update.
std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
//! Cached locations of frequently used uniform variables.
Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
//! Graphical ray-tracing filter to filter out all raytracable structures.
Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
//! Redraw the scene using OpenGL rasterization or ray-tracing?
Standard_Boolean myToRedrawGL;
protected: //! @name protected fields
Handle(OpenGl_PrinterContext) myPrintContext;
Handle(OpenGl_View) myView;
Handle(OpenGl_LineAttributes) myLineAttribs;