1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #ifndef _OpenGl_Workspace_Header
22 #define _OpenGl_Workspace_Header
24 #include <Handle_OpenGl_Workspace.hxx>
25 #include <OpenGl_Window.hxx>
27 #include <TColStd_Array2OfReal.hxx>
28 #include <Quantity_Color.hxx>
29 #include <Graphic3d_TypeOfComposition.hxx>
31 #include <Graphic3d_CView.hxx>
32 #include <Aspect_CLayer2d.hxx>
33 #include <Aspect_Handle.hxx>
34 #include <Aspect_PrintAlgo.hxx>
35 #include <Graphic3d_PtrFrameBuffer.hxx>
36 #include <Image_CRawBufferData.hxx>
38 #include <InterfaceGraphic_Graphic3d.hxx>
39 #include <InterfaceGraphic_Visual3d.hxx>
41 #include <OpenGl_tsm.hxx>
43 #include <OpenGl_Display.hxx>
44 #include <OpenGl_Matrix.hxx>
45 #include <OpenGl_NamedStatus.hxx>
46 #include <OpenGl_TextParam.hxx>
48 #include <Handle_OpenGl_View.hxx>
50 class OpenGl_AspectLine;
51 class OpenGl_AspectFace;
52 class OpenGl_AspectMarker;
53 class OpenGl_AspectText;
54 class OpenGl_FrameBuffer;
55 class OpenGl_Structure;
57 //! Reprepsents window with GL context.
58 //! Provides methods to render primitives and maintan GL state.
59 class OpenGl_Workspace : public OpenGl_Window
63 //! Main constructor - prepare GL context for specified window.
64 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
65 const CALL_DEF_WINDOW& theCWindow,
66 Aspect_RenderingContext theGContext);
69 virtual ~OpenGl_Workspace();
71 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
72 const Handle(OpenGl_View)& ActiveView () const { return myView; }
74 //! Redraw the window.
75 void Redraw (const Graphic3d_CView& theCView,
76 const Aspect_CLayer2d& theCUnderLayer,
77 const Aspect_CLayer2d& theCOverLayer);
79 //! Deprecated. Simply calls Redraw().
80 void Update (const Graphic3d_CView& theCView,
81 const Aspect_CLayer2d& theCUnderLayer,
82 const Aspect_CLayer2d& theCOverLayer)
84 Redraw (theCView, theCUnderLayer, theCOverLayer);
87 //! Special method to perform printing.
88 //! System-specific and currently only Win platform implemented.
89 Standard_Boolean Print (const Graphic3d_CView& theCView,
90 const Aspect_CLayer2d& theCUnderLayer,
91 const Aspect_CLayer2d& theCOverLayer,
92 const Aspect_Handle theHPrintDC,
93 const Standard_Boolean theToShowBackground,
94 const Standard_CString theFileName,
95 const Aspect_PrintAlgo thePrintAlgorithm,
96 const Standard_Real theScaleFactor);
98 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
100 // szvgl: defined in OpenGl_Workspace_1.cxx
101 void BeginAnimation (const Standard_Boolean theUseDegeneration,
102 const Standard_Boolean theUpdateAM);
104 void EraseAnimation();
106 Standard_Boolean BeginAddMode();
108 void ClearImmediatMode (const Graphic3d_CView& theCView,
109 const Standard_Boolean theToFlush);
110 void RedrawImmediatMode();
111 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
112 const Standard_Boolean theUseDepthTest,
113 const Standard_Boolean theRetainMode);
114 void EndImmediatMode();
115 void Transform (const TColStd_Array2OfReal& theMatrix, const Graphic3d_TypeOfComposition theType);
116 void DrawStructure (const OpenGl_Structure* theStructure);
117 void BeginPolyline();
119 void Draw (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
120 void Move (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
121 void SetLineColor (const Standard_ShortReal theR, const Standard_ShortReal theG, const Standard_ShortReal theB);
122 void SetLineType (const Standard_Integer theType);
123 void SetLineWidth (const Standard_ShortReal theWidth);
124 void SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1,
125 const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2);
127 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
128 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
129 Standard_Boolean BufferDump (OpenGl_FrameBuffer *theFBOPtr, Image_CRawBufferData& theBuffer);
131 void UseTransparency (const Standard_Boolean theFlag);
132 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
133 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
134 Standard_Boolean& UseGLLight() { return myUseGLLight; }
136 //// RELATED TO STATUS ////
138 Standard_Integer NamedStatus;
140 Standard_Integer DegenerateModel;
141 Standard_ShortReal SkipRatio;
143 const TEL_COLOUR* HighlightColor;
145 const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
146 const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
148 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
149 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
150 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
151 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
153 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
155 //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
156 Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
157 Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
158 Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
159 Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
161 //! Clear the applied aspect state.
162 void ResetAppliedAspect();
164 //// RELATED TO FONTS ////
166 int FindFont (const char* theFontName,
167 const OSD_FontAspect theFontAspect,
168 const int theBestSize = -1,
169 const float theXScale = 1.0f,
170 const float theYScale = 1.0f)
172 return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
175 void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
177 myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
180 void RenderText (const wchar_t* theText, const int theIs2d,
181 const float theX, const float theY, const float theZ)
183 const OpenGl_AspectText* anAspect = AspectText (Standard_True);
184 myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
189 void CopyBuffers (Tint vid, int FrontToBack,
190 Tfloat xm, Tfloat ym, Tfloat zm,
191 Tfloat XM, Tfloat YM, Tfloat ZM,
194 virtual Standard_Boolean Activate();
197 void Redraw1 (const Graphic3d_CView& theCView,
198 const Aspect_CLayer2d& theCUnderLayer,
199 const Aspect_CLayer2d& theCOverLayer,
200 const int theToSwap);
204 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
205 Tint myTransientList; // WSTransient
206 Standard_Boolean myIsTransientOpen; // transientOpen
207 Tint myRetainMode; // WSRetainMode
209 Standard_Boolean myUseTransparency;
210 Standard_Boolean myUseZBuffer;
211 Standard_Boolean myUseDepthTest;
212 Standard_Boolean myUseGLLight;
213 Standard_Boolean myBackBufferRestored;
215 //// RELATED TO STATUS ////
217 void UpdateMaterial (const int flag);
219 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
220 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
221 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
222 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
224 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
226 const OpenGl_Matrix* ViewMatrix_applied;
227 const OpenGl_Matrix* StructureMatrix_applied;
229 const TEL_POFFSET_PARAM* PolygonOffset_applied;
233 DEFINE_STANDARD_RTTI(OpenGl_Workspace) // Type definition
234 DEFINE_STANDARD_ALLOC
238 #endif //_OpenGl_Workspace_Header