#include <Aspect_CLayer2d.hxx>
#include <Aspect_Handle.hxx>
#include <Aspect_PrintAlgo.hxx>
+#include <Aspect_PolygonOffsetMode.hxx>
#include <InterfaceGraphic_Graphic3d.hxx>
#include <InterfaceGraphic_Visual3d.hxx>
#include <NCollection_Sequence.hxx>
#include <OpenGl_AspectFace.hxx>
-#include <OpenGl_Display.hxx>
#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_Matrix.hxx>
#include <OpenGl_NamedStatus.hxx>
#include <OpenGl_TextParam.hxx>
#include <OpenGl_RenderFilter.hxx>
#include <OpenGl_Vec.hxx>
+#include <OpenGl_LineAttributes.hxx>
#include <Handle_OpenGl_View.hxx>
#include <Handle_OpenGl_Texture.hxx>
class OpenGl_AspectText;
class OpenGl_FrameBuffer;
class OpenGl_Structure;
+class OpenGl_TriangleSet;
class OpenGl_Element;
class Image_PixMap;
};
+DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
+
+//! Graphical raytracing filter.
+//! Filters out all raytracable structures.
+class OpenGl_RaytraceFilter : public OpenGl_RenderFilter
+{
+public:
+
+ //! Default constructor.
+ OpenGl_RaytraceFilter() {}
+
+ //! Remembers the previously set filter.
+ inline void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
+ {
+ myPrevRenderFilter = theFilter;
+ }
+
+ //! Checks whether the element can be rendered or not.
+ //! @param theElement [in] the element to check.
+ //! @return True if element can be rendered.
+ virtual Standard_Boolean CanRender (const OpenGl_Element* theElement);
+
+private:
+
+ Handle(OpenGl_RenderFilter) myPrevRenderFilter;
+
+public:
+
+ DEFINE_STANDARD_RTTI(OpenGl_RaytraceFilter)
+};
+
//! Represents window with GL context.
//! Provides methods to render primitives and maintain GL state.
class OpenGl_Workspace : public OpenGl_Window
public:
//! Main constructor - prepare GL context for specified window.
- OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
+ OpenGl_Workspace (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
const CALL_DEF_WINDOW& theCWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
Standard_Boolean& UseGLLight() { return myUseGLLight; }
+ Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; }
+
//// RELATED TO STATUS ////
Standard_Integer NamedStatus;
//! @return applied model structure matrix.
inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
+ //! Sets and applies current polygon offset.
+ void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits);
+
+ //! Returns currently applied polygon offset params.
+ const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; }
+
+ //! @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; }
+
protected:
//! Copy content of Back buffer to the Front buffer
OpenGl_RT_uDirectLB,
OpenGl_RT_uDirectRT,
OpenGl_RT_uDirectRB,
+ OpenGl_RT_uInvModelProj,
OpenGl_RT_uSceneRad,
OpenGl_RT_uSceneEps,
OpenGl_RT_FSAAInputTexture = 12,
- OpenGl_RT_SceneTransformTexture = 13
+ OpenGl_RT_SceneTransformTexture = 13,
+
+ OpenGl_RT_OpenGlColorTexture = 14,
+ OpenGl_RT_OpenGlDepthTexture = 15
};
//! Tool class for management of shader sources.
};
+ //! Default ray-tracing depth.
+ static const Standard_Integer THE_DEFAULT_RAY_DEPTH = 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 TraceDepth;
+
+ //! Sets light propagation through transparent media.
+ Standard_Boolean TransparentShadows;
+
+ //! Creates default compile-time ray-tracing parameters.
+ RaytracingParams()
+ : StackSize (THE_DEFAULT_STACK_SIZE),
+ TraceDepth (THE_DEFAULT_RAY_DEPTH),
+ TransparentShadows (Standard_False)
+ {
+ //
+ }
+ };
+
protected: //! @name methods related to ray-tracing
//! Updates 3D scene geometry for ray-tracing.
Standard_Boolean UpdateRaytraceEnvironmentMap();
//! Adds OpenGL structure to ray-traced scene geometry.
- Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure,
- const Standard_ShortReal* theTransform, std::set<const OpenGl_Structure*>& theElements);
+ 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 Standard_ShortReal* theTrans);
//! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
- Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet* theSet,
- const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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 CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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 CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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 CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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 CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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 CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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 CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
+ 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);
Standard_Boolean SafeFailBack (const TCollection_ExtendedString& theMessage);
//! Initializes OpenGL/GLSL shader programs.
- Standard_Boolean InitRaytraceResources();
+ Standard_Boolean InitRaytraceResources (const Graphic3d_CView& theCView);
//! Releases OpenGL/GLSL shader programs.
void ReleaseRaytraceResources();
void UpdateCamera (const NCollection_Mat4<GLdouble>& theOrientation,
const NCollection_Mat4<GLdouble>& theViewMapping,
OpenGl_Vec3 theOrigins[4],
- OpenGl_Vec3 theDirects[4]);
+ OpenGl_Vec3 theDirects[4],
+ NCollection_Mat4<GLdouble>& theInvModelProj);
//! Runs ray-tracing shader programs.
Standard_Boolean RunRaytraceShaders (const Graphic3d_CView& theCView,
const Standard_Integer theSizeY,
const OpenGl_Vec3 theOrigins[4],
const OpenGl_Vec3 theDirects[4],
+ const OpenGl_Matrix& theInvModelProj,
OpenGl_FrameBuffer* theFrameBuffer);
//! Redraws the window using OpenGL/GLSL ray-tracing.
const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Standard_Boolean theToSwap,
+ const Aspect_CLayer2d& theCOverLayer,
+ const Aspect_CLayer2d& theCUnderLayer,
OpenGl_FrameBuffer* theFrameBuffer);
protected: //! @name fields related to ray-tracing
//! Scene epsilon to prevent self-intersections.
Standard_ShortReal myRaytraceSceneEpsilon;
- //! Actual size of traversal stack in shader program.
- Standard_Integer myTraversalStackSize;
+ //! Compile-time ray-tracing parameters.
+ RaytracingParams myRaytraceParameters;
//! OpenGL/GLSL source of ray-tracing fragment shader.
ShaderSource myRaytraceShaderSource;
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;
//! State of OpenGL view.
Standard_Size myViewModificationStatus;
std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
//! PrimitiveArray to TriangleSet map for scene partial update.
- std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*> myArrayToTrianglesMap;
+ std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
//! Cached locations of frequently used uniform variables.
Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
+ //! Graphical raytracing filter to filter out all raytracable structures.
+ Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
+
+ //! Redraw the scene using OpenGL rasterization or raytracing?
+ Standard_Boolean myToRedrawGL;
+
protected: //! @name protected fields
Handle(OpenGl_PrinterContext) myPrintContext;
- Handle(OpenGl_View) myView; // WSViews - now just one view is supported
+ Handle(OpenGl_View) myView;
+ Handle(OpenGl_LineAttributes) myLineAttribs;
+ Standard_Integer myAntiAliasingMode;
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 myUseZBuffer;
Standard_Boolean myUseDepthTest;
Standard_Boolean myUseGLLight;
+ Standard_Boolean myIsCullingEnabled; //!< frustum culling flag
+
+ unsigned int myFrameCounter; //!< redraw counter, for debugging
protected: //! @name fields related to status
OpenGl_Material myMatTmp; //!< temporary variable
TelCullMode myCullingMode; //!< back face culling mode, applied from face aspect
- //! Model matrix with applied structure transformations
- OpenGl_Matrix myModelViewMatrix;
+ OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
- const TEL_POFFSET_PARAM* PolygonOffset_applied;
+ TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset.
- OpenGl_AspectFace myAspectFaceHl; // Hiddenline aspect
+ OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
public: //! @name type definition