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.
20 #ifndef _OpenGl_Workspace_Header
21 #define _OpenGl_Workspace_Header
23 #include <Handle_OpenGl_Workspace.hxx>
24 #include <OpenGl_Window.hxx>
26 #include <TColStd_Array2OfReal.hxx>
27 #include <Quantity_Color.hxx>
28 #include <Graphic3d_CView.hxx>
29 #include <Graphic3d_TypeOfComposition.hxx>
30 #include <Graphic3d_TypeOfTexture.hxx>
31 #include <Graphic3d_PtrFrameBuffer.hxx>
32 #include <Graphic3d_BufferType.hxx>
33 #include <Handle_Graphic3d_TextureParams.hxx>
35 #include <Aspect_CLayer2d.hxx>
36 #include <Aspect_Handle.hxx>
37 #include <Aspect_PrintAlgo.hxx>
39 #include <InterfaceGraphic_Graphic3d.hxx>
40 #include <InterfaceGraphic_Visual3d.hxx>
42 #include <OpenGl_tsm.hxx>
44 #include <OpenGl_AspectFace.hxx>
45 #include <OpenGl_Display.hxx>
46 #include <OpenGl_Matrix.hxx>
47 #include <OpenGl_NamedStatus.hxx>
48 #include <OpenGl_TextParam.hxx>
50 #include <Handle_OpenGl_View.hxx>
51 #include <Handle_OpenGl_Texture.hxx>
53 class OpenGl_AspectLine;
54 class OpenGl_AspectMarker;
55 class OpenGl_AspectText;
56 class OpenGl_FrameBuffer;
57 class OpenGl_Structure;
60 //! Reprepsents window with GL context.
61 //! Provides methods to render primitives and maintan GL state.
62 class OpenGl_Workspace : public OpenGl_Window
66 //! Main constructor - prepare GL context for specified window.
67 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
68 const CALL_DEF_WINDOW& theCWindow,
69 Aspect_RenderingContext theGContext,
70 const Handle(OpenGl_Context)& theShareCtx);
73 virtual ~OpenGl_Workspace();
75 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
76 const Handle(OpenGl_View)& ActiveView () const { return myView; }
78 //! Redraw the window.
79 void Redraw (const Graphic3d_CView& theCView,
80 const Aspect_CLayer2d& theCUnderLayer,
81 const Aspect_CLayer2d& theCOverLayer);
83 //! Deprecated. Simply calls Redraw().
84 void Update (const Graphic3d_CView& theCView,
85 const Aspect_CLayer2d& theCUnderLayer,
86 const Aspect_CLayer2d& theCOverLayer)
88 Redraw (theCView, theCUnderLayer, theCOverLayer);
91 //! Special method to perform printing.
92 //! System-specific and currently only Win platform implemented.
93 Standard_Boolean Print (const Graphic3d_CView& theCView,
94 const Aspect_CLayer2d& theCUnderLayer,
95 const Aspect_CLayer2d& theCOverLayer,
96 const Aspect_Handle theHPrintDC,
97 const Standard_Boolean theToShowBackground,
98 const Standard_CString theFileName,
99 const Aspect_PrintAlgo thePrintAlgorithm,
100 const Standard_Real theScaleFactor);
102 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
104 // szvgl: defined in OpenGl_Workspace_1.cxx
105 void BeginAnimation (const Standard_Boolean theUseDegeneration,
106 const Standard_Boolean theUpdateAM);
108 void EraseAnimation();
110 Standard_Boolean BeginAddMode();
112 void ClearImmediatMode (const Graphic3d_CView& theCView,
113 const Standard_Boolean theToFlush);
114 void RedrawImmediatMode();
115 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
116 const Standard_Boolean theUseDepthTest,
117 const Standard_Boolean theRetainMode);
118 void EndImmediatMode();
119 void Transform (const TColStd_Array2OfReal& theMatrix, const Graphic3d_TypeOfComposition theType);
120 void DrawStructure (const OpenGl_Structure* theStructure);
121 void BeginPolyline();
123 void Draw (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
124 void Move (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
125 void SetLineColor (const Standard_ShortReal theR, const Standard_ShortReal theG, const Standard_ShortReal theB);
126 void SetLineType (const Standard_Integer theType);
127 void SetLineWidth (const Standard_ShortReal theWidth);
128 void SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1,
129 const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2);
131 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
132 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
133 Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr,
134 Image_PixMap& theImage,
135 const Graphic3d_BufferType& theBufferType);
137 void UseTransparency (const Standard_Boolean theFlag);
138 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
139 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
140 Standard_Boolean& UseGLLight() { return myUseGLLight; }
142 //// RELATED TO STATUS ////
144 Standard_Integer NamedStatus;
146 Standard_Integer DegenerateModel;
147 Standard_ShortReal SkipRatio;
149 const TEL_COLOUR* HighlightColor;
151 const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
152 const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
154 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
155 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
156 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
157 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
159 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
161 //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
162 Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
163 Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
164 Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
165 Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
167 //! Clear the applied aspect state.
168 void ResetAppliedAspect();
170 Standard_EXPORT Handle(OpenGl_Texture) DisableTexture();
171 Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture,
172 const Handle(Graphic3d_TextureParams)& theParams = NULL);
174 //// RELATED TO FONTS ////
176 int FindFont (const char* theFontName,
177 const Font_FontAspect theFontAspect,
178 const int theBestSize = -1,
179 const float theXScale = 1.0f,
180 const float theYScale = 1.0f)
182 return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
185 void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
187 myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
190 void RenderText (const wchar_t* theText, const int theIs2d,
191 const float theX, const float theY, const float theZ)
193 const OpenGl_AspectText* anAspect = AspectText (Standard_True);
194 myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
199 void CopyBuffers (Tint vid, int FrontToBack,
200 Tfloat xm, Tfloat ym, Tfloat zm,
201 Tfloat XM, Tfloat YM, Tfloat ZM,
204 virtual Standard_Boolean Activate();
207 void Redraw1 (const Graphic3d_CView& theCView,
208 const Aspect_CLayer2d& theCUnderLayer,
209 const Aspect_CLayer2d& theCOverLayer,
210 const int theToSwap);
212 void UpdateMaterial (const int flag);
214 void setTextureParams (Handle(OpenGl_Texture)& theTexture,
215 const Handle(Graphic3d_TextureParams)& theParams);
217 protected: //! @name protected fields
219 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
220 Tint myTransientList; // WSTransient
221 Standard_Boolean myIsTransientOpen; // transientOpen
222 Tint myRetainMode; // WSRetainMode
224 Standard_Boolean myUseTransparency;
225 Standard_Boolean myUseZBuffer;
226 Standard_Boolean myUseDepthTest;
227 Standard_Boolean myUseGLLight;
228 Standard_Boolean myBackBufferRestored;
230 protected: //! @name fields related to status
232 Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture)
233 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
234 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
235 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
236 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
238 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
240 const OpenGl_Matrix* ViewMatrix_applied;
241 const OpenGl_Matrix* StructureMatrix_applied;
243 const TEL_POFFSET_PARAM* PolygonOffset_applied;
245 OpenGl_AspectFace myAspectFaceHl; // Hiddenline aspect
247 public: //! @name type definition
249 DEFINE_STANDARD_RTTI(OpenGl_Workspace)
250 DEFINE_STANDARD_ALLOC
254 #endif // _OpenGl_Workspace_Header