#define _OpenGl_View_Header
#include <MMgt_TShared.hxx>
-#include <Standard_DefineHandle.hxx>
+#include <Standard_Type.hxx>
#include <TColStd_Array2OfReal.hxx>
#include <NCollection_List.hxx>
#include <Aspect_FillMethod.hxx>
#include <Aspect_GradientFillMethod.hxx>
#include <Aspect_TypeOfTriedronPosition.hxx>
-#include <Aspect_CLayer2d.hxx>
-
-#include <InterfaceGraphic_Graphic3d.hxx>
-#include <InterfaceGraphic_Visual3d.hxx>
#include <Graphic3d_CView.hxx>
#include <Graphic3d_GraduatedTrihedron.hxx>
#include <Graphic3d_SequenceOfHClipPlane.hxx>
+#include <Graphic3d_TypeOfShadingModel.hxx>
+#include <Graphic3d_WorldViewProjState.hxx>
#include <Graphic3d_ZLayerSettings.hxx>
-#include <Visual3d_TypeOfSurfaceDetail.hxx>
-#include <Visual3d_TypeOfModel.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_BackgroundArray.hxx>
#include <OpenGl_BVHTreeSelector.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_FrameBuffer.hxx>
+#include <OpenGl_GraduatedTrihedron.hxx>
#include <OpenGl_LayerList.hxx>
#include <OpenGl_Light.hxx>
#include <OpenGl_LineAttributes.hxx>
+#include <OpenGl_SceneGeometry.hxx>
+#include <OpenGl_Structure.hxx>
#include <OpenGl_Trihedron.hxx>
-#include <OpenGl_GraduatedTrihedron.hxx>
+#include <OpenGl_Window.hxx>
+#include <OpenGl_Workspace.hxx>
+#include <OpenGl_TileSampler.hxx>
-#include <Handle_OpenGl_Context.hxx>
-#include <Handle_OpenGl_GraphicDriver.hxx>
-#include <Handle_OpenGl_Workspace.hxx>
-#include <Handle_OpenGl_View.hxx>
-#include <Handle_OpenGl_Texture.hxx>
-
-struct OPENGL_ZCLIP
-{
- struct {
- Standard_Boolean IsOn;
- Standard_ShortReal Limit; /* in the range [0., 1.] */
- } Back;
- struct {
- Standard_Boolean IsOn;
- Standard_ShortReal Limit; /* in the range [0., 1.] */
- } Front;
-};
-
-struct OPENGL_FOG
-{
- Standard_Boolean IsOn;
- Standard_ShortReal Front; /* in the range [0., 1.] */
- Standard_ShortReal Back; /* in the range [0., 1.] */
- TEL_COLOUR Color;
-};
+#include <map>
+#include <set>
struct OpenGl_Matrix;
-class OpenGl_Structure;
-class Handle(OpenGl_PrinterContext);
-class OpenGl_StateCounter;
-class OpenGl_View : public MMgt_TShared
+class Graphic3d_StructureManager;
+class OpenGl_GraphicDriver;
+class OpenGl_StateCounter;
+class OpenGl_RaytraceMaterial;
+class OpenGl_TriangleSet;
+class OpenGl_Workspace;
+class OpenGl_View;
+DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
+
+//! Implementation of OpenGl view.
+class OpenGl_View : public Graphic3d_CView
{
- public:
- OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
- virtual ~OpenGl_View ();
- void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
-
- void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
- const Handle(Graphic3d_TextureEnv)& theTexture);
- void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
- void SetBackfacing (const Standard_Integer AMode);
- void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
- void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
- void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
- void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
-
- const Handle(Graphic3d_Camera)& Camera() { return myCamera; }
- void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
-
- void SetClipLimit (const Graphic3d_CView& theCView);
-
- void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
+public:
- OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; }
- void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
- const Quantity_NameOfColor theColor,
- const Standard_Real theScale,
- const Standard_Boolean theAsWireframe);
- void TriedronErase (const Handle(OpenGl_Context)& theCtx);
+ //! Constructor.
+ Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
+ const Handle(OpenGl_GraphicDriver)& theDriver,
+ const Handle(OpenGl_Caps)& theCaps,
+ Standard_Boolean& theDeviceLostFlag,
+ OpenGl_StateCounter* theCounter);
+
+ //! Default destructor.
+ Standard_EXPORT virtual ~OpenGl_View();
+
+ Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
+
+ //! Deletes and erases the view.
+ Standard_EXPORT virtual void Remove() Standard_OVERRIDE;
+
+ //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
+ //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
+ //! Fast, so preferred for interactive work (used by default).
+ //! However these extra drawings will be missed in image dump since it is performed from back buffer.
+ //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
+ //! in run-time (in case of slow hardware) and/or tearing may appear.
+ //! So this is strongly recommended to draw only simple (fast) structures.
+ //! 2. FALSE. Drawing immediate mode structures to the back buffer.
+ //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
+ //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
+ //! from the back buffer.
+ //! @return previous mode.
+ Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
+
+ //! Creates and maps rendering window to the view.
+ //! @param theWindow [in] the window.
+ //! @param theContext [in] the rendering context. If NULL the context will be created internally.
+ Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
+ const Aspect_RenderingContext theContext) Standard_OVERRIDE;
+
+ //! Returns window associated with the view.
+ virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE
+ { return myWindow->PlatformWindow(); }
+
+ //! Returns True if the window associated to the view is defined.
+ virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
+ { return !myWindow.IsNull(); }
+
+ //! Handle changing size of the rendering window.
+ Standard_EXPORT virtual void Resized() Standard_OVERRIDE;
+
+ //! Redraw content of the view.
+ Standard_EXPORT virtual void Redraw() Standard_OVERRIDE;
+
+ //! Redraw immediate content of the view.
+ Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE;
+
+ //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild.
+ Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
+
+ //! Return true if view content cache has been invalidated.
+ virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
+
+ //! Displays z-buffer trihedron.
+ Standard_EXPORT virtual void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER,
+ const Quantity_NameOfColor theColor = Quantity_NOC_WHITE,
+ const Standard_Real theScale = 0.02,
+ const Standard_Boolean theAsWireframe = Standard_True) Standard_OVERRIDE;
+
+ //! Erases z-buffer trihedron.
+ Standard_EXPORT virtual void TriedronErase() Standard_OVERRIDE;
+
+ //! Setup parameters of z-buffer trihedron.
+ Standard_EXPORT virtual void ZBufferTriedronSetup (const Quantity_NameOfColor theXColor = Quantity_NOC_RED,
+ const Quantity_NameOfColor theYColor = Quantity_NOC_GREEN,
+ const Quantity_NameOfColor theZColor = Quantity_NOC_BLUE1,
+ const Standard_Real theSizeRatio = 0.8,
+ const Standard_Real theAxisDiametr = 0.05,
+ const Standard_Integer theNbFacettes = 12) Standard_OVERRIDE;
+
+ //! Displays trihedron echo.
+ Standard_EXPORT virtual void TriedronEcho (const Aspect_TypeOfTriedronEcho theType = Aspect_TOTE_NONE) Standard_OVERRIDE;
+
+ //! Returns data of a graduated trihedron
+ const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() Standard_OVERRIDE
+ { return myGTrihedronData; }
+
+ //! Displays Graduated Trihedron.
+ Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
+
+ //! Erases Graduated Trihedron.
+ Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
+
+ //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
+ //! @param theMin [in] the minimum point of scene.
+ //! @param theMax [in] the maximum point of scene.
+ Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
+
+ //! Dump active rendering buffer into specified memory buffer.
+ Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
+ const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
+
+ //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
+ //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits
+ //! on printing to laser printer). Notice however that results may differ a lot and
+ //! do not contain some elements.
+ Standard_EXPORT virtual Standard_Boolean Export (const Standard_CString theFileName,
+ const Graphic3d_ExportFormat theFormat,
+ const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree) Standard_OVERRIDE;
+
+ //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
+ Standard_EXPORT virtual void InvalidateBVHData (const Standard_Integer theLayerId) Standard_OVERRIDE;
+
+ //! Insert a new top-level z layer with the given ID.
+ Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
+
+ //! Remove a z layer with the given ID.
+ Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
- OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
- void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
- const Graphic3d_GraduatedTrihedron& theCubic);
- void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
-
- Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
- Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
+ //! Sets the settings for a single Z layer of specified view.
+ Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
+ const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
+
+ //! Returns the maximum Z layer ID.
+ //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
+ Standard_EXPORT virtual Standard_Integer ZLayerMax() const Standard_OVERRIDE;
+
+ //! Returns the bounding box of all structures displayed in the Z layer.
+ //! Never fails. If Z layer does not exist nothing happens.
+ Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
+
+ //! Returns the bounding box of all structures displayed in the Z layer.
+ //! If Z layer does not exist the empty box is returned.
+ //! @param theLayerId layer identifier
+ //! @param theCamera camera definition
+ //! @param theWindowWidth viewport width (for applying transformation-persistence)
+ //! @param theWindowHeight viewport height (for applying transformation-persistence)
+ //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
+ //! @return computed bounding box
+ Standard_EXPORT virtual Graphic3d_BndBox4f ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
+ const Handle(Graphic3d_Camera)& theCamera,
+ const Standard_Integer theWindowWidth,
+ const Standard_Integer theWindowHeight,
+ const Standard_Boolean theToIncludeAuxiliary) const Standard_OVERRIDE;
+
+ //! Returns pointer to an assigned framebuffer object.
+ Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
+
+ //! Sets framebuffer object for offscreen rendering.
+ Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
+
+ //! Generate offscreen FBO in the graphic library.
+ //! If not supported on hardware returns NULL.
+ Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
+ const Standard_Integer theHeight) Standard_OVERRIDE;
+
+ //! Remove offscreen FBO from the graphic library
+ Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
+
+ //! Read offscreen FBO configuration.
+ Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
+ Standard_Integer& theWidth,
+ Standard_Integer& theHeight,
+ Standard_Integer& theWidthMax,
+ Standard_Integer& theHeightMax) Standard_OVERRIDE;
+
+ //! Change offscreen FBO viewport.
+ Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight) Standard_OVERRIDE;
- Standard_Integer Backfacing () const { return myBackfacing; }
+public:
- const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
- const TEL_TRANSFORM_PERSISTENCE *theTransPers,
- Standard_Integer theWidth,
- Standard_Integer theHeight);
- void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
+ //! Returns background fill color.
+ Standard_EXPORT virtual Aspect_Background Background() const Standard_OVERRIDE;
- //! Add structure to display list with specified priority.
- //! The structure will be added to associated with it z layer.
- //! If the z layer is not presented in the view, the structure will
- //! be displayed in default bottom-level z layer.
- void DisplayStructure (const Handle(Graphic3d_Structure)& theStructure,
- const Standard_Integer thePriority);
+ //! Sets background fill color.
+ Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground) Standard_OVERRIDE;
- //! Erase structure from display list.
- void EraseStructure (const Handle(Graphic3d_Structure)& theStructure);
+ //! Returns gradient background fill colors.
+ Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
- //! Add structure to the list of immediate structures.
- void DisplayImmediateStructure (const Handle(Graphic3d_Structure)& theStructure);
+ //! Sets gradient background fill colors.
+ Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
- //! Erase structure from display list.
- void EraseImmediateStructure (const OpenGl_Structure* theStructure);
+ //! Returns background image texture file path.
+ Standard_EXPORT virtual TCollection_AsciiString BackgroundImage() Standard_OVERRIDE { return myBackgroundImagePath; }
- //! Insert a new top-level z layer with ID <theLayerId>
- void AddZLayer (const Graphic3d_ZLayerId theLayerId);
+ //! Sets background image texture file path.
+ Standard_EXPORT virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) Standard_OVERRIDE;
- //! Remove a z layer with ID <theLayerId>
- void RemoveZLayer (const Graphic3d_ZLayerId theLayerId);
+ //! Returns background image fill style.
+ Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
- //! Display structure in z layer with ID <theNewLayerId>
- //! If the layer with ID <theNewLayerId> is not presented in the view,
- //! the structure will be displayed in default bottom-level layer.
- void ChangeZLayer (const OpenGl_Structure* theStructure,
- const Graphic3d_ZLayerId theNewLayerId);
+ //! Sets background image fill style.
+ Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE;
- //! Sets the settings for a single Z layer of specified view.
- void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
- const Graphic3d_ZLayerSettings& theSettings);
+ //! Returns environment texture set for the view.
+ Standard_EXPORT virtual Handle(Graphic3d_TextureEnv) TextureEnv() const Standard_OVERRIDE { return myTextureEnvData; }
- //! Changes the priority of a structure within its ZLayer
- void ChangePriority (const OpenGl_Structure* theStructure,
- const Standard_Integer theNewPriority);
+ //! Sets environment texture for the view.
+ Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
- void CreateBackgroundTexture (const Standard_CString AFileName,
- const Aspect_FillMethod AFillStyle);
+ //! Returns the state of frustum culling optimization.
+ virtual Standard_Boolean IsCullingEnabled() const Standard_OVERRIDE { return myCulling; }
- void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
- void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
- void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
+ //! Enables or disables frustum culling optimization.
+ virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myCulling = theIsEnabled; }
- void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
- const Handle(OpenGl_Workspace)& theWorkspace,
- OpenGl_FrameBuffer* theReadDrawFbo,
- Graphic3d_Camera::Projection theProjection,
- const Graphic3d_CView& theCView,
- const Aspect_CLayer2d& theCUnderLayer,
- const Aspect_CLayer2d& theCOverLayer,
- const Standard_Boolean theToDrawImmediate);
+ //! Returns shading model of the view.
+ virtual Graphic3d_TypeOfShadingModel ShadingModel() const Standard_OVERRIDE { return myShadingModel; }
+ //! Sets shading model of the view.
+ virtual void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) Standard_OVERRIDE { myShadingModel = theModel; }
- void DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
+ //! Return backfacing model used for the view.
+ virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; }
- //! Returns list of OpenGL Z-layers.
- const OpenGl_LayerList& LayerList() const { return myZLayers; }
+ //! Sets backfacing model for the view.
+ virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; }
- //! Returns list of openGL light sources.
- const OpenGl_ListOfLight& LightList() const { return myLights; }
+ //! Returns camera object of the view.
+ virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; }
- //! Returns OpenGL environment map.
- const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
+ //! Sets camera used by the view.
+ virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE { myCamera = theCamera; }
- //! Returns visualization mode for objects in the view.
- Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
+ //! Returns true if GL lighting is enabled.
+ virtual Standard_Boolean IsGLLightEnabled() const Standard_OVERRIDE { return myUseGLLight; }
- //! Returns selector for BVH tree, providing a possibility to store information
- //! about current view volume and to detect which objects are overlapping it.
- OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
+ //! Sets GL lighting enabled or disable state.
+ virtual void SetGLLightEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myUseGLLight = theIsEnabled; }
- //! Marks BVH tree for given priority list as dirty and
- //! marks primitive set for rebuild.
- void InvalidateBVHData (const Standard_Integer theLayerId);
+ //! Returns list of lights of the view.
+ virtual const Graphic3d_ListOfCLight& Lights() const Standard_OVERRIDE { return myLights; }
- //! Returns list of immediate structures rendered on top of main presentation
- const OpenGl_IndexedMapOfStructure& ImmediateStructures() const
+ //! Sets list of lights for the view.
+ virtual void SetLights (const Graphic3d_ListOfCLight& theLights) Standard_OVERRIDE
{
- return myImmediateList;
+ myLights = theLights;
+ myCurrLightSourceState = myStateCounter->Increment();
}
- //! Returns true if there are immediate structures to display
- bool HasImmediateStructures() const
- {
- return !myImmediateList.IsEmpty()
- || myZLayers.NbImmediateStructures() != 0;
- }
+ //! Returns list of clip planes set for the view.
+ virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
-protected:
+ //! Sets list of clip planes for the view.
+ virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
+
+ //! Fill in the dictionary with diagnostic info.
+ //! Should be called within rendering thread.
+ //!
+ //! This API should be used only for user output or for creating automated reports.
+ //! The format of returned information (e.g. key-value layout)
+ //! is NOT part of this API and can be changed at any time.
+ //! Thus application should not parse returned information to weed out specific parameters.
+ Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
+ Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE;
+
+public:
- void RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
- OpenGl_FrameBuffer* theReadDrawFbo,
- const Graphic3d_CView& theCView,
- const Standard_Boolean theToDrawImmediate);
+ //! Returns background color.
+ const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
- void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
- const Handle(OpenGl_Workspace)& theWorkspace,
- const Graphic3d_CView& theCView,
- const Aspect_CLayer2d& theCLayer);
+ //! Change trihedron.
+ OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; }
- void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
+ //! Change graduated trihedron.
+ OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
- //! Redraw contents of model scene: clipping planes,
- //! lights, structures. The peculiar properties of "scene" is that
- //! it requires empty Z-Buffer and uses projection and orientation
- //! matrices supplied by 3d view.
- void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
- const Handle(OpenGl_Workspace)& theWorkspace,
- OpenGl_FrameBuffer* theReadDrawFbo,
- const Graphic3d_CView& theCView,
- const Standard_Boolean theToDrawImmediate);
+ void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
+ const Handle(Graphic3d_TextureEnv)& theTexture);
- Handle(OpenGl_LineAttributes) myLineAttribs;
- Handle(OpenGl_Texture) myTextureEnv;
- Visual3d_TypeOfSurfaceDetail mySurfaceDetail;
- Standard_Integer myBackfacing;
+ void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
- OPENGL_ZCLIP myZClip;
+ void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
- Graphic3d_SequenceOfHClipPlane myClipPlanes;
-
- Handle(Graphic3d_Camera) myCamera;
+ void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
- OPENGL_FOG myFog;
- OpenGl_Trihedron myTrihedron;
- OpenGl_GraduatedTrihedron myGraduatedTrihedron;
- bool myToShowTrihedron;
- bool myToShowGradTrihedron;
+ //! Returns list of OpenGL Z-layers.
+ const OpenGl_LayerList& LayerList() const { return myZLayers; }
- //View_LABViewContext
- int myVisualization;
- Visual3d_TypeOfModel myShadingModel; //!< lighting shading model
+ //! Returns list of openGL light sources.
+ const OpenGl_ListOfLight& LightList() const { return myLights; }
- //View_LABLight
- OpenGl_ListOfLight myLights;
+ //! Returns OpenGL window implementation.
+ const Handle(OpenGl_Window) GlWindow() const { return myWindow; }
- //View_LABPlane
- //View_LABAliasing
- Standard_Boolean myAntiAliasing;
+ //! Returns OpenGL environment map.
+ const Handle(OpenGl_Texture)& GlTextureEnv() const { return myTextureEnv; }
- //View_LABDepthCueing - fixed index used
+ //! Returns selector for BVH tree, providing a possibility to store information
+ //! about current view volume and to detect which objects are overlapping it.
+ OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
- OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
- OpenGl_IndexedMapOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
+ //! Returns true if there are immediate structures to display
+ bool HasImmediateStructures() const
+ {
+ return myZLayers.NbImmediateStructures() != 0;
+ }
- const TEL_TRANSFORM_PERSISTENCE *myTransPers;
- Standard_Boolean myIsTransPers;
+protected: //! @name Internal methods for managing GL resources
+
+ //! Initializes OpenGl resource for environment texture.
+ void initTextureEnv (const Handle(OpenGl_Context)& theContext);
+
+protected: //! @name low-level redrawing sub-routines
+
+ //! Redraws view for the given monographic camera projection, or left/right eye.
+ Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadDrawFbo);
+
+ //! Redraws view for the given monographic camera projection, or left/right eye.
+ //!
+ //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer)
+ //! into presentation buffer (myMainSceneFbos -> offscreen FBO or
+ //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer),
+ //! and redraw immediate structures on top.
+ //!
+ //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
+ //! the first step (blitting) will be skipped.
+ //!
+ //! @return false if immediate structures has been rendered directly into FrontBuffer
+ //! and Buffer Swap should not be called.
+ Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadFbo,
+ OpenGl_FrameBuffer* theDrawFbo,
+ const Standard_Boolean theIsPartialUpdate = Standard_False);
+
+ //! Blit image from/to specified buffers.
+ Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo,
+ OpenGl_FrameBuffer* theDrawFbo,
+ const Standard_Boolean theToFlip = Standard_False);
+
+ //! Setup default FBO.
+ Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
+
+protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
+
+ //! Renders the graphical contents of the view into the preprepared window or framebuffer.
+ //! @param theProjection [in] the projection that should be used for rendering.
+ //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
+ //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
+ Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadDrawFbo,
+ const Standard_Boolean theToDrawImmediate);
+
+ //! Renders the graphical scene.
+ //! @param theProjection [in] the projection that is used for rendering.
+ //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
+ //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
+ Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadDrawFbo,
+ const Standard_Boolean theToDrawImmediate);
+
+ //! Draw background (gradient / image)
+ Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
+
+ //! Render set of structures presented in the view.
+ //! @param theProjection [in] the projection that is used for rendering.
+ //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
+ //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
+ Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadDrawFbo,
+ const Standard_Boolean theToDrawImmediate);
+
+ //! Renders trihedron.
+ void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
+
+private:
+
+ //! Adds the structure to display lists of the view.
+ Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
+ const Standard_Integer thePriority) Standard_OVERRIDE;
+
+ //! Erases the structure from display lists of the view.
+ Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
+
+ //! Change Z layer of a structure already presented in view.
+ Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
+ const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
+
+ //! Changes the priority of a structure within its Z layer in the specified view.
+ Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
+ const Standard_Integer theNewPriority) Standard_OVERRIDE;
+
+ //! Returns zoom-scale factor.
+ Standard_EXPORT virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
+ const Handle(Graphic3d_Camera)& theCamera,
+ const Standard_Integer theWindowWidth,
+ const Standard_Integer theWindowHeight) const Standard_OVERRIDE;
+
+private:
+
+ //! Copy content of Back buffer to the Front buffer.
+ void copyBackToFront();
+
+ //! Initialize blit quad.
+ OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
+
+ //! Blend together views pair into stereo image.
+ void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
- //! Modification state
- Standard_Size myProjectionState;
- Standard_Size myModelViewState;
- OpenGl_StateCounter* myStateCounter;
+protected:
- Standard_Size myCurrLightSourceState;
+ OpenGl_GraphicDriver* myDriver;
+ Handle(OpenGl_Window) myWindow;
+ Handle(OpenGl_Workspace) myWorkspace;
+ Handle(OpenGl_Caps) myCaps;
+ Standard_Boolean& myDeviceLostFlag;
+ Standard_Boolean myWasRedrawnGL;
+
+ Standard_Boolean myCulling;
+ Graphic3d_TypeOfShadingModel myShadingModel;
+ Graphic3d_TypeOfBackfacingModel myBackfacing;
+ Quantity_ColorRGBA myBgColor;
+ Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
+ Handle(Graphic3d_Camera) myCamera;
+ Handle(OpenGl_FrameBuffer) myFBO;
+ Standard_Boolean myUseGLLight;
+ Standard_Boolean myToShowTrihedron;
+ Standard_Boolean myToShowGradTrihedron;
+ TCollection_AsciiString myBackgroundImagePath;
+ Handle(Graphic3d_TextureEnv) myTextureEnvData;
+ Graphic3d_GraduatedTrihedron myGTrihedronData;
+
+ OpenGl_ListOfLight myNoShadingLight;
+ OpenGl_ListOfLight myLights;
+ OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
+
+ Graphic3d_WorldViewProjState myWorldViewProjState; //!< camera modification state
+ OpenGl_StateCounter* myStateCounter;
+ Standard_Size myCurrLightSourceState;
typedef std::pair<Standard_Size, Standard_Size> StateInfo;
//! Is needed for selection of overlapping objects and storage of the current view volume
OpenGl_BVHTreeSelector myBVHSelector;
+ OpenGl_Trihedron myTrihedron;
+ OpenGl_GraduatedTrihedron myGraduatedTrihedron;
+
+ Handle(OpenGl_Texture) myTextureEnv;
+
+ //! Framebuffers for OpenGL output.
+ Handle(OpenGl_FrameBuffer) myOpenGlFBO;
+ Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
+
+protected: //! @name Rendering properties
+
+ //! Two framebuffers (left and right views) store cached main presentation
+ //! of the view (without presentation of immediate layers).
+ GLint myFboColorFormat; //!< sized format for color attachments
+ GLint myFboDepthFormat; //!< sized format for depth-stencil attachments
+ Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
+ Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode.
+ OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering.
+ OpenGl_VertexBuffer myFullScreenQuadFlip;
+ Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down
+ unsigned int myFrameCounter; //!< redraw counter, for debugging
+ Standard_Boolean myHasFboBlit; //!< disable FBOs on failure
+ Standard_Boolean myToDisableMSAA; //!< disable MSAA after failure
+ 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
+
protected: //! @name Background parameters
OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
OpenGl_RT_uDirectLB,
OpenGl_RT_uDirectRT,
OpenGl_RT_uDirectRB,
+ OpenGl_RT_uViewPrMat,
OpenGl_RT_uUnviewMat,
// 3D scene params
OpenGl_RT_uSphereMapEnabled,
OpenGl_RT_uSphereMapForBack,
OpenGl_RT_uTexSamplersArray,
+ OpenGl_RT_uBlockedRngEnabled,
+
+ // size of render window
+ OpenGl_RT_uWinSizeX,
+ OpenGl_RT_uWinSizeY,
// sampled frame params
OpenGl_RT_uSampleWeight,
OpenGl_RT_uOffsetY,
OpenGl_RT_uSamples,
+ // adaptive path tracing images
+ OpenGl_RT_uRenderImage,
+ OpenGl_RT_uOffsetImage,
+
OpenGl_RT_NbVariables // special field
};
- //! Defines texture samplers.
+ //! Defines OpenGL texture samplers.
enum ShaderSamplerNames
{
OpenGl_RT_SceneNodeInfoTexture = 0,
OpenGl_RT_FsaaInputTexture = 11,
OpenGl_RT_PrevAccumTexture = 12,
- OpenGl_RT_OpenGlColorTexture = 13,
- OpenGl_RT_OpenGlDepthTexture = 14
+ OpenGl_RT_RaytraceDepthTexture = 13
+ };
+
+ //! Defines OpenGL image samplers.
+ enum ShaderImageNames
+ {
+ OpenGl_RT_OutputImageLft = 0,
+ OpenGl_RT_OutputImageRgh = 1,
+ OpenGl_RT_VisualErrorImage = 2,
+ OpenGl_RT_TileOffsetsImage = 3
};
//! Tool class for management of shader sources.
//
}
- //! Creates new shader source from specified file.
- ShaderSource (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX)
- {
- TCollection_AsciiString aFileNames[] = { theFileName, "" };
+ public:
- Load (aFileNames, thePrefix);
+ //! Returns error description in case of load fail.
+ const TCollection_AsciiString& ErrorDescription() const
+ {
+ return myError;
}
- public:
-
//! Returns prefix to insert before the source.
const TCollection_AsciiString& Prefix() const
{
TCollection_AsciiString Source() const;
//! Loads shader source from specified files.
- void Load (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
+ Standard_Boolean Load (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
private:
TCollection_AsciiString mySource; //!< Source string of the shader object
TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
+ TCollection_AsciiString myError; //!< error state
};
static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
//! Default size of traversal stack.
- static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
+ static const Standard_Integer THE_DEFAULT_STACK_SIZE = 10;
//! Compile-time ray-tracing parameters.
struct RaytracingParams
//! Enables/disables the use of OpenGL bindless textures.
Standard_Boolean UseBindlessTextures;
+ //! Enables/disables adaptive screen sampling for path tracing.
+ Standard_Boolean AdaptiveScreenSampling;
+
//! Creates default compile-time ray-tracing parameters.
RaytracingParams()
: StackSize (THE_DEFAULT_STACK_SIZE),
NbBounces (THE_DEFAULT_NB_BOUNCES),
TransparentShadows (Standard_False),
GlobalIllumination (Standard_False),
- UseBindlessTextures (Standard_False)
+ UseBindlessTextures (Standard_False),
+ AdaptiveScreenSampling (Standard_False)
{
//
}
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);
+ Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
+ const OpenGl_RaytraceMaterial& theStructMat,
+ const Handle(Geom_Transformation)& theTrsf,
+ const Handle(OpenGl_Context)& theGlContext);
//! Creates ray-tracing material properties.
OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
const Handle(OpenGl_ShaderObject)& theFragShader);
//! Initializes OpenGL/GLSL shader programs.
- Standard_Boolean initRaytraceResources (const Graphic3d_CView& theCView,
- const Handle(OpenGl_Context)& theGlContext);
+ Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
//! Releases OpenGL/GLSL shader programs.
- void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
+ void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
+ const Standard_Boolean theToRebuild = Standard_False);
- //! Resizes OpenGL frame buffers.
- Standard_Boolean resizeRaytraceBuffers (const Standard_Integer theSizeX,
+ //! Updates auxiliary OpenGL frame buffers.
+ Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Handle(OpenGl_Context)& theGlContext);
const OpenGl_Mat4& theViewMapping,
OpenGl_Vec3* theOrigins,
OpenGl_Vec3* theDirects,
+ OpenGl_Mat4& theView,
OpenGl_Mat4& theUnView);
//! Binds ray-trace textures to corresponding texture units.
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,
+ Standard_Boolean setUniformState (const Standard_Integer theProgramId,
+ const Standard_Integer theSizeX,
+ const Standard_Integer theSizeY,
const Handle(OpenGl_Context)& theGlContext);
//! Runs ray-tracing shader programs.
- Standard_Boolean runRaytraceShaders (const Graphic3d_CView& theCView,
- const Standard_Integer theSizeX,
+ Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
- const OpenGl_Vec3* theOrigins,
- const OpenGl_Vec3* theDirects,
- const OpenGl_Mat4& theUnviewMat,
+ Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext);
- //! Redraws the window using OpenGL/GLSL ray-tracing.
- Standard_Boolean raytrace (const Graphic3d_CView& theCView,
- const Standard_Integer theSizeX,
+ //! Runs classical (Whitted-style) ray-tracing kernel.
+ Standard_Boolean runRaytrace (const Standard_Integer theSizeX,
+ const Standard_Integer theSizeY,
+ Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadDrawFbo,
+ const Handle(OpenGl_Context)& theGlContext);
+
+ //! Runs path tracing (global illumination) kernel.
+ Standard_Boolean runPathtrace (const Graphic3d_Camera::Projection theProjection,
+ OpenGl_FrameBuffer* theReadDrawFbo,
+ const Handle(OpenGl_Context)& theGlContext);
+
+ //! Redraws the window using OpenGL/GLSL ray-tracing or path tracing.
+ Standard_Boolean raytrace (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
+ Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext);
protected: //! @name fields related to ray-tracing
- //! Result of shaders initialization.
+ //! Result of RT/PT shaders initialization.
RaytraceInitStatus myRaytraceInitStatus;
- //! Is geometry data valid?
+ //! Is ray-tracing geometry data valid?
Standard_Boolean myIsRaytraceDataValid;
- //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
+ //! True if warning about missing extension GL_ARB_bindless_texture has been displayed.
Standard_Boolean myIsRaytraceWarnTextures;
//! 3D scene geometry data for ray-tracing.
ShaderSource myRaytraceShaderSource;
//! OpenGL/GLSL source of adaptive-AA fragment shader.
ShaderSource myPostFSAAShaderSource;
+ //! OpenGL/GLSL source of RT/PT display fragment shader.
+ ShaderSource myOutImageShaderSource;
//! OpenGL/GLSL ray-tracing fragment shader.
Handle(OpenGl_ShaderObject) myRaytraceShader;
//! OpenGL/GLSL adaptive-AA fragment shader.
Handle(OpenGl_ShaderObject) myPostFSAAShader;
+ //! OpenGL/GLSL ray-tracing display fragment shader.
+ Handle(OpenGl_ShaderObject) myOutImageShader;
//! OpenGL/GLSL ray-tracing shader program.
Handle(OpenGl_ShaderProgram) myRaytraceProgram;
Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
//! 1st framebuffer (FBO) to perform adaptive FSAA.
- Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
+ //! Used in compatibility mode (no adaptive sampling).
+ Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
//! 2nd framebuffer (FBO) to perform adaptive FSAA.
- Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
- //! Framebuffer (FBO) for preliminary OpenGL output.
- Handle(OpenGl_FrameBuffer) myOpenGlFBO;
+ //! Used in compatibility mode (no adaptive sampling).
+ Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
+
+ //! Output textures (2 textures are used in stereo mode).
+ //! Used if adaptive screen sampling is activated.
+ Handle(OpenGl_Texture) myRaytraceOutputTexture[2];
+
+ //! Texture containing per-tile visual error estimation.
+ //! Used if adaptive screen sampling is activated.
+ Handle(OpenGl_Texture) myRaytraceVisualErrorTexture;
+ //! Texture containing offsets of sampled screen tiles.
+ //! Used if adaptive screen sampling is activated.
+ Handle(OpenGl_Texture) myRaytraceTileOffsetsTexture;
//! Vertex buffer (VBO) for drawing dummy quad.
OpenGl_VertexBuffer myRaytraceScreenQuad;
//! Bullard RNG to produce random sequence.
math_BullardGenerator myRNG;
+ //! Tool object for sampling screen tiles in PT mode.
+ OpenGl_TileSampler myTileSampler;
+
public:
DEFINE_STANDARD_ALLOC
- DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
+ DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition
+ friend class OpenGl_GraphicDriver;
friend class OpenGl_Workspace;
-
};
#endif // _OpenGl_View_Header