c946267baf13307f029d7f8bc41b5377ff40d240
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21 #ifndef _OpenGl_Workspace_Header
22 #define _OpenGl_Workspace_Header
23
24 #include <Handle_OpenGl_Workspace.hxx>
25 #include <OpenGl_Window.hxx>
26
27 #include <TColStd_Array2OfReal.hxx>
28 #include <Quantity_Color.hxx>
29 #include <Graphic3d_TypeOfComposition.hxx>
30
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>
37
38 #include <InterfaceGraphic_Graphic3d.hxx>
39 #include <InterfaceGraphic_Visual3d.hxx>
40
41 #include <OpenGl_tsm.hxx>
42
43 #include <OpenGl_Display.hxx>
44 #include <OpenGl_Matrix.hxx>
45 #include <OpenGl_NamedStatus.hxx>
46 #include <OpenGl_TextParam.hxx>
47
48 #include <Handle_OpenGl_View.hxx>
49
50 class OpenGl_AspectLine;
51 class OpenGl_AspectFace;
52 class OpenGl_AspectMarker;
53 class OpenGl_AspectText;
54 class OpenGl_FrameBuffer;
55 class OpenGl_Structure;
56
57 //! Reprepsents window with GL context.
58 //! Provides methods to render primitives and maintan GL state.
59 class OpenGl_Workspace : public OpenGl_Window
60 {
61 public:
62
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);
67
68   //! Destructor
69   virtual ~OpenGl_Workspace();
70
71   void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
72   const Handle(OpenGl_View)& ActiveView () const { return myView; }
73
74   //! Redraw the window.
75   void Redraw (const Graphic3d_CView& theCView,
76                const Aspect_CLayer2d& theCUnderLayer,
77                const Aspect_CLayer2d& theCOverLayer);
78
79   //! Deprecated. Simply calls Redraw().
80   void Update (const Graphic3d_CView& theCView,
81                const Aspect_CLayer2d& theCUnderLayer,
82                const Aspect_CLayer2d& theCOverLayer)
83   {
84     Redraw (theCView, theCUnderLayer, theCOverLayer);
85   }
86
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);
97
98   void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
99
100   // szvgl: defined in OpenGl_Workspace_1.cxx
101   void BeginAnimation (const Standard_Boolean theUseDegeneration,
102                        const Standard_Boolean theUpdateAM); 
103   void EndAnimation();
104   void EraseAnimation();
105
106   Standard_Boolean BeginAddMode();
107   void EndAddMode();
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();
118   void EndPolyline();
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);
126
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);
130
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; }
135
136   //// RELATED TO STATUS ////
137
138   Standard_Integer   NamedStatus;
139
140   Standard_Integer   DegenerateModel;
141   Standard_ShortReal SkipRatio;
142
143   const TEL_COLOUR* HighlightColor;
144
145   const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
146   const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
147
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);
152
153   void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
154
155   const OpenGl_AspectLine*   AspectLine   (const Standard_Boolean theWithApply);
156   const OpenGl_AspectFace*   AspectFace   (const Standard_Boolean theWithApply);
157   const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
158   const OpenGl_AspectText*   AspectText   (const Standard_Boolean theWithApply);
159
160   //! Clear the applied aspect state.
161   void ResetAppliedAspect();
162
163   //// RELATED TO FONTS ////
164
165   int FindFont (const char*          theFontName,
166                 const OSD_FontAspect theFontAspect,
167                 const int            theBestSize = -1,
168                 const float          theXScale = 1.0f,
169                 const float          theYScale = 1.0f)
170   {
171     return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
172   }
173
174   void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
175   {
176     myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
177   }
178
179   void RenderText (const wchar_t* theText, const int theIs2d,
180                    const float theX, const float theY, const float theZ)
181   {
182     const OpenGl_AspectText* anAspect = AspectText (Standard_True);
183     myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
184   }
185
186 protected:
187
188   void CopyBuffers (Tint vid, int FrontToBack,
189                     Tfloat xm, Tfloat ym, Tfloat zm,
190                     Tfloat XM, Tfloat YM, Tfloat ZM,
191                     Tint flag);
192
193   virtual Standard_Boolean Activate();
194
195   // TEMPORARY!!!
196   void Redraw1 (const Graphic3d_CView& theCView, 
197                 const Aspect_CLayer2d& theCUnderLayer, 
198                 const Aspect_CLayer2d& theCOverLayer,
199                 const int theToSwap);
200
201 protected:
202
203   Handle(OpenGl_View) myView;            // WSViews - now just one view is supported
204   Tint                myTransientList;   // WSTransient
205   Standard_Boolean    myIsTransientOpen; // transientOpen
206   Tint                myRetainMode;      // WSRetainMode
207
208   Standard_Boolean    myUseTransparency;
209   Standard_Boolean    myUseZBuffer;
210   Standard_Boolean    myUseDepthTest;
211   Standard_Boolean    myUseGLLight;
212   Standard_Boolean    myBackBufferRestored;
213
214   //// RELATED TO STATUS ////
215
216   void UpdateMaterial (const int flag);
217
218   const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
219   const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
220   const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
221   const OpenGl_AspectText *AspectText_set, *AspectText_applied;
222
223   const OpenGl_TextParam *TextParam_set, *TextParam_applied;
224
225   const OpenGl_Matrix* ViewMatrix_applied;
226   const OpenGl_Matrix* StructureMatrix_applied;
227
228   const TEL_POFFSET_PARAM* PolygonOffset_applied;
229
230 public:
231
232   DEFINE_STANDARD_RTTI(OpenGl_Workspace) // Type definition
233   DEFINE_STANDARD_ALLOC
234
235 };
236
237 #endif //_OpenGl_Workspace_Header