0023428: Extend OpenGl_Context to use Geometry Shaders extension
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
CommitLineData
b311480e 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
2166f0fa
SK
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>
692613e5 36#include <Graphic3d_BufferType.hxx>
2166f0fa
SK
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
50class OpenGl_AspectLine;
51class OpenGl_AspectFace;
52class OpenGl_AspectMarker;
53class OpenGl_AspectText;
54class OpenGl_FrameBuffer;
55class OpenGl_Structure;
692613e5 56class Image_PixMap;
2166f0fa
SK
57
58//! Reprepsents window with GL context.
59//! Provides methods to render primitives and maintan GL state.
60class OpenGl_Workspace : public OpenGl_Window
61{
62public:
63
64 //! Main constructor - prepare GL context for specified window.
65 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
66 const CALL_DEF_WINDOW& theCWindow,
5e27df78 67 Aspect_RenderingContext theGContext,
68 const Handle(OpenGl_Context)& theShareCtx);
2166f0fa
SK
69
70 //! Destructor
71 virtual ~OpenGl_Workspace();
72
73 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
74 const Handle(OpenGl_View)& ActiveView () const { return myView; }
75
76 //! Redraw the window.
77 void Redraw (const Graphic3d_CView& theCView,
78 const Aspect_CLayer2d& theCUnderLayer,
79 const Aspect_CLayer2d& theCOverLayer);
80
298f9ad7 81 //! Deprecated. Simply calls Redraw().
2166f0fa
SK
82 void Update (const Graphic3d_CView& theCView,
83 const Aspect_CLayer2d& theCUnderLayer,
84 const Aspect_CLayer2d& theCOverLayer)
85 {
298f9ad7 86 Redraw (theCView, theCUnderLayer, theCOverLayer);
2166f0fa
SK
87 }
88
89 //! Special method to perform printing.
90 //! System-specific and currently only Win platform implemented.
91 Standard_Boolean Print (const Graphic3d_CView& theCView,
92 const Aspect_CLayer2d& theCUnderLayer,
93 const Aspect_CLayer2d& theCOverLayer,
94 const Aspect_Handle theHPrintDC,
95 const Standard_Boolean theToShowBackground,
96 const Standard_CString theFileName,
97 const Aspect_PrintAlgo thePrintAlgorithm,
98 const Standard_Real theScaleFactor);
99
100 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
101
102 // szvgl: defined in OpenGl_Workspace_1.cxx
103 void BeginAnimation (const Standard_Boolean theUseDegeneration,
104 const Standard_Boolean theUpdateAM);
105 void EndAnimation();
106 void EraseAnimation();
107
108 Standard_Boolean BeginAddMode();
109 void EndAddMode();
110 void ClearImmediatMode (const Graphic3d_CView& theCView,
111 const Standard_Boolean theToFlush);
112 void RedrawImmediatMode();
113 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
114 const Standard_Boolean theUseDepthTest,
115 const Standard_Boolean theRetainMode);
116 void EndImmediatMode();
117 void Transform (const TColStd_Array2OfReal& theMatrix, const Graphic3d_TypeOfComposition theType);
118 void DrawStructure (const OpenGl_Structure* theStructure);
119 void BeginPolyline();
120 void EndPolyline();
121 void Draw (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
122 void Move (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
123 void SetLineColor (const Standard_ShortReal theR, const Standard_ShortReal theG, const Standard_ShortReal theB);
124 void SetLineType (const Standard_Integer theType);
125 void SetLineWidth (const Standard_ShortReal theWidth);
126 void SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1,
127 const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2);
128
129 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
130 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
692613e5 131 Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr,
132 Image_PixMap& theImage,
133 const Graphic3d_BufferType& theBufferType);
2166f0fa 134
2166f0fa
SK
135 void UseTransparency (const Standard_Boolean theFlag);
136 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
137 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
138 Standard_Boolean& UseGLLight() { return myUseGLLight; }
139
140 //// RELATED TO STATUS ////
141
142 Standard_Integer NamedStatus;
143
144 Standard_Integer DegenerateModel;
145 Standard_ShortReal SkipRatio;
146
147 const TEL_COLOUR* HighlightColor;
148
149 const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
150 const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
151
152 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
153 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
154 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
155 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
156
157 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
158
3946774d 159 //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
160 Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
161 Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
162 Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
163 Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
2166f0fa 164
34a44cbd 165 //! Clear the applied aspect state.
166 void ResetAppliedAspect();
167
2166f0fa
SK
168 //// RELATED TO FONTS ////
169
170 int FindFont (const char* theFontName,
171 const OSD_FontAspect theFontAspect,
172 const int theBestSize = -1,
173 const float theXScale = 1.0f,
174 const float theYScale = 1.0f)
175 {
176 return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
177 }
178
179 void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
180 {
181 myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
182 }
183
184 void RenderText (const wchar_t* theText, const int theIs2d,
185 const float theX, const float theY, const float theZ)
186 {
187 const OpenGl_AspectText* anAspect = AspectText (Standard_True);
188 myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
189 }
190
191protected:
192
193 void CopyBuffers (Tint vid, int FrontToBack,
194 Tfloat xm, Tfloat ym, Tfloat zm,
195 Tfloat XM, Tfloat YM, Tfloat ZM,
196 Tint flag);
197
198 virtual Standard_Boolean Activate();
199
200 // TEMPORARY!!!
201 void Redraw1 (const Graphic3d_CView& theCView,
202 const Aspect_CLayer2d& theCUnderLayer,
203 const Aspect_CLayer2d& theCOverLayer,
204 const int theToSwap);
205
206protected:
207
208 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
2166f0fa
SK
209 Tint myTransientList; // WSTransient
210 Standard_Boolean myIsTransientOpen; // transientOpen
211 Tint myRetainMode; // WSRetainMode
212
213 Standard_Boolean myUseTransparency;
214 Standard_Boolean myUseZBuffer;
215 Standard_Boolean myUseDepthTest;
216 Standard_Boolean myUseGLLight;
217 Standard_Boolean myBackBufferRestored;
218
219 //// RELATED TO STATUS ////
220
221 void UpdateMaterial (const int flag);
222
223 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
224 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
225 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
226 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
227
228 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
229
230 const OpenGl_Matrix* ViewMatrix_applied;
231 const OpenGl_Matrix* StructureMatrix_applied;
232
233 const TEL_POFFSET_PARAM* PolygonOffset_applied;
234
235public:
236
237 DEFINE_STANDARD_RTTI(OpenGl_Workspace) // Type definition
1c35b92f 238 DEFINE_STANDARD_ALLOC
2166f0fa
SK
239
240};
241
242#endif //_OpenGl_Workspace_Header