1 // File: OpenGl_Workspace.hxx
2 // Created: 20 September 2011
3 // Author: Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
6 #ifndef _OpenGl_Workspace_Header
7 #define _OpenGl_Workspace_Header
9 #include <Handle_OpenGl_Workspace.hxx>
10 #include <OpenGl_Window.hxx>
12 #include <TColStd_Array2OfReal.hxx>
13 #include <Quantity_Color.hxx>
14 #include <Graphic3d_TypeOfComposition.hxx>
16 #include <Graphic3d_CView.hxx>
17 #include <Aspect_CLayer2d.hxx>
18 #include <Aspect_Handle.hxx>
19 #include <Aspect_PrintAlgo.hxx>
20 #include <Graphic3d_PtrFrameBuffer.hxx>
21 #include <Image_CRawBufferData.hxx>
23 #include <InterfaceGraphic_Graphic3d.hxx>
24 #include <InterfaceGraphic_Visual3d.hxx>
26 #include <OpenGl_tsm.hxx>
28 #include <OpenGl_Display.hxx>
29 #include <OpenGl_Matrix.hxx>
30 #include <OpenGl_NamedStatus.hxx>
31 #include <OpenGl_TextParam.hxx>
33 #include <Handle_OpenGl_View.hxx>
35 class OpenGl_AspectLine;
36 class OpenGl_AspectFace;
37 class OpenGl_AspectMarker;
38 class OpenGl_AspectText;
39 class OpenGl_FrameBuffer;
40 class OpenGl_Structure;
42 //! Reprepsents window with GL context.
43 //! Provides methods to render primitives and maintan GL state.
44 class OpenGl_Workspace : public OpenGl_Window
48 //! Main constructor - prepare GL context for specified window.
49 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
50 const CALL_DEF_WINDOW& theCWindow,
51 Aspect_RenderingContext theGContext);
54 virtual ~OpenGl_Workspace();
56 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
57 const Handle(OpenGl_View)& ActiveView () const { return myView; }
59 //! Redraw the window.
60 void Redraw (const Graphic3d_CView& theCView,
61 const Aspect_CLayer2d& theCUnderLayer,
62 const Aspect_CLayer2d& theCOverLayer);
64 //! Redraw window only if needed.
65 void Update (const Graphic3d_CView& theCView,
66 const Aspect_CLayer2d& theCUnderLayer,
67 const Aspect_CLayer2d& theCOverLayer)
70 Redraw (theCView, theCUnderLayer, theCOverLayer);
73 //! Special method to perform printing.
74 //! System-specific and currently only Win platform implemented.
75 Standard_Boolean Print (const Graphic3d_CView& theCView,
76 const Aspect_CLayer2d& theCUnderLayer,
77 const Aspect_CLayer2d& theCOverLayer,
78 const Aspect_Handle theHPrintDC,
79 const Standard_Boolean theToShowBackground,
80 const Standard_CString theFileName,
81 const Aspect_PrintAlgo thePrintAlgorithm,
82 const Standard_Real theScaleFactor);
84 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
86 // szvgl: defined in OpenGl_Workspace_1.cxx
87 void BeginAnimation (const Standard_Boolean theUseDegeneration,
88 const Standard_Boolean theUpdateAM);
90 void EraseAnimation();
92 Standard_Boolean BeginAddMode();
94 void ClearImmediatMode (const Graphic3d_CView& theCView,
95 const Standard_Boolean theToFlush);
96 void RedrawImmediatMode();
97 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
98 const Standard_Boolean theUseDepthTest,
99 const Standard_Boolean theRetainMode);
100 void EndImmediatMode();
101 void Transform (const TColStd_Array2OfReal& theMatrix, const Graphic3d_TypeOfComposition theType);
102 void DrawStructure (const OpenGl_Structure* theStructure);
103 void BeginPolyline();
105 void Draw (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
106 void Move (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
107 void SetLineColor (const Standard_ShortReal theR, const Standard_ShortReal theG, const Standard_ShortReal theB);
108 void SetLineType (const Standard_Integer theType);
109 void SetLineWidth (const Standard_ShortReal theWidth);
110 void SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1,
111 const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2);
113 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
114 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
115 Standard_Boolean BufferDump (OpenGl_FrameBuffer *theFBOPtr, Image_CRawBufferData& theBuffer);
117 //! Mark this window to be redrawn on next update.
118 void Invalidate() { myIsUpdated = Standard_False; }
120 void UseTransparency (const Standard_Boolean theFlag);
121 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
122 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
123 Standard_Boolean& UseGLLight() { return myUseGLLight; }
125 //// RELATED TO STATUS ////
127 Standard_Integer NamedStatus;
129 Standard_Integer DegenerateModel;
130 Standard_ShortReal SkipRatio;
132 const TEL_COLOUR* HighlightColor;
134 const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
135 const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
137 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
138 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
139 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
140 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
142 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
144 const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
145 const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
146 const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
147 const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
149 //// RELATED TO FONTS ////
151 int FindFont (const char* theFontName,
152 const OSD_FontAspect theFontAspect,
153 const int theBestSize = -1,
154 const float theXScale = 1.0f,
155 const float theYScale = 1.0f)
157 return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
160 void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
162 myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
165 void RenderText (const wchar_t* theText, const int theIs2d,
166 const float theX, const float theY, const float theZ)
168 const OpenGl_AspectText* anAspect = AspectText (Standard_True);
169 myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
174 void CopyBuffers (Tint vid, int FrontToBack,
175 Tfloat xm, Tfloat ym, Tfloat zm,
176 Tfloat XM, Tfloat YM, Tfloat ZM,
179 virtual Standard_Boolean Activate();
182 void Redraw1 (const Graphic3d_CView& theCView,
183 const Aspect_CLayer2d& theCUnderLayer,
184 const Aspect_CLayer2d& theCOverLayer,
185 const int theToSwap);
189 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
190 Standard_Boolean myIsUpdated; // WSUpdateState
191 Tint myTransientList; // WSTransient
192 Standard_Boolean myIsTransientOpen; // transientOpen
193 Tint myRetainMode; // WSRetainMode
195 Standard_Boolean myUseTransparency;
196 Standard_Boolean myUseZBuffer;
197 Standard_Boolean myUseDepthTest;
198 Standard_Boolean myUseGLLight;
199 Standard_Boolean myBackBufferRestored;
201 //// RELATED TO STATUS ////
203 void UpdateMaterial (const int flag);
205 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
206 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
207 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
208 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
210 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
212 const OpenGl_Matrix* ViewMatrix_applied;
213 const OpenGl_Matrix* StructureMatrix_applied;
215 const TEL_POFFSET_PARAM* PolygonOffset_applied;
219 DEFINE_STANDARD_RTTI(OpenGl_Workspace) // Type definition
220 DEFINE_STANDARD_ALLOC
224 #endif //_OpenGl_Workspace_Header