// Created on: 2011-09-20
// Created by: Sergey ZERCHANINOV
-// Copyright (c) 2011-2012 OPEN CASCADE SAS
+// Copyright (c) 2011-2013 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// 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.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#ifndef _OpenGl_Workspace_Header
#define _OpenGl_Workspace_Header
-#include <Handle_OpenGl_Workspace.hxx>
-#include <OpenGl_Window.hxx>
-
-#include <TColStd_Array2OfReal.hxx>
-#include <Quantity_Color.hxx>
-#include <Graphic3d_TypeOfComposition.hxx>
-
-#include <Graphic3d_CView.hxx>
-#include <Aspect_CLayer2d.hxx>
-#include <Aspect_Handle.hxx>
-#include <Aspect_PrintAlgo.hxx>
-#include <Graphic3d_PtrFrameBuffer.hxx>
-#include <Image_CRawBufferData.hxx>
-
-#include <InterfaceGraphic_Graphic3d.hxx>
-#include <InterfaceGraphic_Visual3d.hxx>
+#include <Graphic3d_BufferType.hxx>
-#include <OpenGl_tsm.hxx>
-
-#include <OpenGl_Display.hxx>
+#include <OpenGl_Aspects.hxx>
+#include <OpenGl_CappingAlgo.hxx>
+#include <OpenGl_FrameBuffer.hxx>
+#include <OpenGl_Material.hxx>
#include <OpenGl_Matrix.hxx>
-#include <OpenGl_NamedStatus.hxx>
+#include <OpenGl_ShaderObject.hxx>
+#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_TextParam.hxx>
+#include <OpenGl_TextureBufferArb.hxx>
+#include <OpenGl_RenderFilter.hxx>
+#include <OpenGl_Vec.hxx>
+#include <OpenGl_Window.hxx>
-#include <Handle_OpenGl_View.hxx>
+class OpenGl_View;
+class Image_PixMap;
-class OpenGl_AspectLine;
-class OpenGl_AspectFace;
-class OpenGl_AspectMarker;
-class OpenGl_AspectText;
-class OpenGl_FrameBuffer;
-class OpenGl_Structure;
+class OpenGl_Workspace;
+DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient)
-//! Reprepsents window with GL context.
-//! Provides methods to render primitives and maintan GL state.
-class OpenGl_Workspace : public OpenGl_Window
+//! Rendering workspace.
+//! Provides methods to render primitives and maintain GL state.
+class OpenGl_Workspace : public Standard_Transient
{
public:
- //! Main constructor - prepare GL context for specified window.
- OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
- const CALL_DEF_WINDOW& theCWindow,
- Aspect_RenderingContext theGContext);
+ //! Constructor of rendering workspace.
+ Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow);
//! Destructor
- virtual ~OpenGl_Workspace();
+ virtual ~OpenGl_Workspace() {}
+
+ //! Activate rendering context.
+ Standard_EXPORT Standard_Boolean Activate();
+
+ OpenGl_View* View() const { return myView; }
+
+ const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; }
- void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
- const Handle(OpenGl_View)& ActiveView () const { return myView; }
+ Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
- //! Redraw the window.
- void Redraw (const Graphic3d_CView& theCView,
- const Aspect_CLayer2d& theCUnderLayer,
- const Aspect_CLayer2d& theCOverLayer);
+ Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo);
- //! Redraw window only if needed.
- void Update (const Graphic3d_CView& theCView,
- const Aspect_CLayer2d& theCUnderLayer,
- const Aspect_CLayer2d& theCOverLayer)
+ Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo,
+ Image_PixMap& theImage,
+ const Graphic3d_BufferType& theBufferType);
+
+ Standard_EXPORT Standard_Integer Width() const;
+
+ Standard_EXPORT Standard_Integer Height() const;
+
+ //! Setup Z-buffer usage flag (without affecting GL state!).
+ //! Returns previously set flag.
+ Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse)
{
- if (!myIsUpdated)
- Redraw (theCView, theCUnderLayer, theCOverLayer);
+ const Standard_Boolean wasUsed = myUseZBuffer;
+ myUseZBuffer = theToUse;
+ return wasUsed;
}
- //! Special method to perform printing.
- //! System-specific and currently only Win platform implemented.
- Standard_Boolean Print (const Graphic3d_CView& theCView,
- const Aspect_CLayer2d& theCUnderLayer,
- const Aspect_CLayer2d& theCOverLayer,
- const Aspect_Handle theHPrintDC,
- const Standard_Boolean theToShowBackground,
- const Standard_CString theFileName,
- const Aspect_PrintAlgo thePrintAlgorithm,
- const Standard_Real theScaleFactor);
-
- void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
-
- // szvgl: defined in OpenGl_Workspace_1.cxx
- void BeginAnimation (const Standard_Boolean theUseDegeneration,
- const Standard_Boolean theUpdateAM);
- void EndAnimation();
- void EraseAnimation();
-
- Standard_Boolean BeginAddMode();
- void EndAddMode();
- void ClearImmediatMode (const Graphic3d_CView& theCView,
- const Standard_Boolean theToFlush);
- void RedrawImmediatMode();
- Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
- const Standard_Boolean theUseDepthTest,
- const Standard_Boolean theRetainMode);
- void EndImmediatMode();
- void Transform (const TColStd_Array2OfReal& theMatrix, const Graphic3d_TypeOfComposition theType);
- void DrawStructure (const OpenGl_Structure* theStructure);
- void BeginPolyline();
- void EndPolyline();
- void Draw (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
- void Move (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
- void SetLineColor (const Standard_ShortReal theR, const Standard_ShortReal theG, const Standard_ShortReal theB);
- void SetLineType (const Standard_Integer theType);
- void SetLineWidth (const Standard_ShortReal theWidth);
- void SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1,
- const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2);
-
- Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
- void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
- Standard_Boolean BufferDump (OpenGl_FrameBuffer *theFBOPtr, Image_CRawBufferData& theBuffer);
-
- //! Mark this window to be redrawn on next update.
- void Invalidate() { myIsUpdated = Standard_False; }
-
- void UseTransparency (const Standard_Boolean theFlag);
- Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
- Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
- Standard_Boolean& UseGLLight() { return myUseGLLight; }
-
- //// RELATED TO STATUS ////
+ //! @return true if usage of Z buffer is enabled.
+ Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
- Standard_Integer NamedStatus;
+ //! @return true if depth writing is enabled.
+ Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
- Standard_Integer DegenerateModel;
- Standard_ShortReal SkipRatio;
+ //! Configure default polygon offset parameters.
+ //! Return previous settings.
+ Standard_EXPORT Graphic3d_PolygonOffset SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
- const TEL_COLOUR* HighlightColor;
+ //// RELATED TO STATUS ////
- const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
- const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
+ //! Return true if active group might activate face culling (e.g. primitives are closed).
+ bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
- const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
- const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
- const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
- const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
+ //! Allow or disallow face culling.
+ //! This call does NOT affect current state of back face culling;
+ //! ApplyAspectFace() should be called to update state.
+ bool SetAllowFaceCulling (bool theToAllow)
+ {
+ const bool wasAllowed = myToAllowFaceCulling;
+ myToAllowFaceCulling = theToAllow;
+ return wasAllowed;
+ }
- void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
+ //! Return true if following structures should apply highlight color.
+ bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
- const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
- const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
- const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
- const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
+ //! Return highlight style.
+ const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
- //! Clear the applied aspect state.
- void ResetAppliedAspect();
+ //! Set highlight style.
+ void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) { myHighlightStyle = theStyle; }
- //// RELATED TO FONTS ////
+ //! Return edge color taking into account highlight flag.
+ const OpenGl_Vec4& EdgeColor() const
+ {
+ return !myHighlightStyle.IsNull()
+ ? myHighlightStyle->ColorRGBA()
+ : myAspectsSet->Aspect()->EdgeColorRGBA();
+ }
- int FindFont (const char* theFontName,
- const OSD_FontAspect theFontAspect,
- const int theBestSize = -1,
- const float theXScale = 1.0f,
- const float theYScale = 1.0f)
+ //! Return Interior color taking into account highlight flag.
+ const OpenGl_Vec4& InteriorColor() const
{
- return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
+ return !myHighlightStyle.IsNull()
+ ? myHighlightStyle->ColorRGBA()
+ : myAspectsSet->Aspect()->InteriorColorRGBA();
}
- void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
+ //! Return text color taking into account highlight flag.
+ const OpenGl_Vec4& TextColor() const
{
- myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
+ return !myHighlightStyle.IsNull()
+ ? myHighlightStyle->ColorRGBA()
+ : myAspectsSet->Aspect()->ColorRGBA();
}
- void RenderText (const wchar_t* theText, const int theIs2d,
- const float theX, const float theY, const float theZ)
+ //! Return text Subtitle color taking into account highlight flag.
+ const OpenGl_Vec4& TextSubtitleColor() const
{
- const OpenGl_AspectText* anAspect = AspectText (Standard_True);
- myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
+ return !myHighlightStyle.IsNull()
+ ? myHighlightStyle->ColorRGBA()
+ : myAspectsSet->Aspect()->ColorSubTitleRGBA();
}
-protected:
+ //! Currently set aspects (can differ from applied).
+ const OpenGl_Aspects* Aspects() const { return myAspectsSet; }
- void CopyBuffers (Tint vid, int FrontToBack,
- Tfloat xm, Tfloat ym, Tfloat zm,
- Tfloat XM, Tfloat YM, Tfloat ZM,
- Tint flag);
+ //! Assign new aspects (will be applied within ApplyAspects()).
+ Standard_EXPORT const OpenGl_Aspects* SetAspects (const OpenGl_Aspects* theAspect);
- virtual Standard_Boolean Activate();
+ //! Apply aspects.
+ //! @return aspect set by SetAspects()
+ Standard_EXPORT const OpenGl_Aspects* ApplyAspects();
- // TEMPORARY!!!
- void Redraw1 (const Graphic3d_CView& theCView,
- const Aspect_CLayer2d& theCUnderLayer,
- const Aspect_CLayer2d& theCOverLayer,
- const int theToSwap);
+ //! Clear the applied aspect state to default values.
+ void ResetAppliedAspect();
-protected:
+ //! Get rendering filter.
+ //! @sa ShouldRender()
+ Standard_Integer RenderFilter() const { return myRenderFilter; }
- Handle(OpenGl_View) myView; // WSViews - now just one view is supported
- Standard_Boolean myIsUpdated; // WSUpdateState
- Tint myTransientList; // WSTransient
- Standard_Boolean myIsTransientOpen; // transientOpen
- Tint myRetainMode; // WSRetainMode
+ //! Set filter for restricting rendering of particular elements.
+ //! @sa ShouldRender()
+ void SetRenderFilter (Standard_Integer theFilter) { myRenderFilter = theFilter; }
- Standard_Boolean myUseTransparency;
- Standard_Boolean myUseZBuffer;
- Standard_Boolean myUseDepthTest;
- Standard_Boolean myUseGLLight;
- Standard_Boolean myBackBufferRestored;
+ //! Checks whether the element can be rendered or not.
+ //! @param theElement [in] the element to check
+ //! @return True if element can be rendered
+ bool ShouldRender (const OpenGl_Element* theElement);
- //// RELATED TO STATUS ////
+ //! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter.
+ //! @sa OpenGl_LayerList::Render()
+ Standard_Integer NbSkippedTransparentElements() { return myNbSkippedTranspElems; }
+
+ //! Reset skipped transparent elements counter.
+ //! @sa OpenGl_LayerList::Render()
+ void ResetSkippedCounter() { myNbSkippedTranspElems = 0; }
+
+ //! @return applied view matrix.
+ inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
+
+ //! @return applied model structure matrix.
+ inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
+
+ //! Returns face aspect for none culling mode.
+ const OpenGl_Aspects& NoneCulling() const { return myNoneCulling; }
+
+ //! Returns face aspect for front face culling mode.
+ const OpenGl_Aspects& FrontCulling() const { return myFrontCulling; }
- void UpdateMaterial (const int flag);
+ //! Sets a new environment texture.
+ void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
- const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
- const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
- const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
- const OpenGl_AspectText *AspectText_set, *AspectText_applied;
+ //! Returns environment texture.
+ const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; }
- const OpenGl_TextParam *TextParam_set, *TextParam_applied;
+protected: //! @name protected fields
+
+ OpenGl_View* myView;
+ Handle(OpenGl_Window) myWindow;
+ Handle(OpenGl_Context) myGlContext;
+ Standard_Boolean myUseZBuffer;
+ Standard_Boolean myUseDepthWrite;
+ OpenGl_Aspects myNoneCulling;
+ OpenGl_Aspects myFrontCulling;
+
+protected: //! @name fields related to status
+
+ Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method
+ Standard_Integer myRenderFilter; //!< active filter for skipping rendering of elements by some criteria (multiple render passes)
+
+ OpenGl_Aspects myDefaultAspects;
+ const OpenGl_Aspects* myAspectsSet;
+ Handle(Graphic3d_Aspects) myAspectsApplied;
+
+ Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
const OpenGl_Matrix* ViewMatrix_applied;
const OpenGl_Matrix* StructureMatrix_applied;
- const TEL_POFFSET_PARAM* PolygonOffset_applied;
+ bool myToAllowFaceCulling; //!< allow back face culling
+ Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
-public:
+ OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
+
+ OpenGl_Aspects myAspectFaceHl; //!< Hiddenline aspect
+
+ Handle(OpenGl_TextureSet) myEnvironmentTexture;
+
+public: //! @name type definition
- DEFINE_STANDARD_RTTI(OpenGl_Workspace) // Type definition
+ DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
DEFINE_STANDARD_ALLOC
};
-#endif //_OpenGl_Workspace_Header
+#endif // _OpenGl_Workspace_Header