0023525: Disappearing of highlight in screenshot
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
1981cb22 3// Copyright (c) 2011-2013 OPEN CASCADE SAS
b311480e 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#ifndef _OpenGl_Workspace_Header
21#define _OpenGl_Workspace_Header
22
23#include <Handle_OpenGl_Workspace.hxx>
24#include <OpenGl_Window.hxx>
25
26#include <TColStd_Array2OfReal.hxx>
27#include <Quantity_Color.hxx>
bf75be98 28#include <Graphic3d_CView.hxx>
2166f0fa 29#include <Graphic3d_TypeOfComposition.hxx>
bf75be98 30#include <Graphic3d_TypeOfTexture.hxx>
31#include <Graphic3d_PtrFrameBuffer.hxx>
32#include <Graphic3d_BufferType.hxx>
33#include <Handle_Graphic3d_TextureParams.hxx>
2166f0fa 34
2166f0fa
SK
35#include <Aspect_CLayer2d.hxx>
36#include <Aspect_Handle.hxx>
37#include <Aspect_PrintAlgo.hxx>
2166f0fa
SK
38
39#include <InterfaceGraphic_Graphic3d.hxx>
40#include <InterfaceGraphic_Visual3d.hxx>
41
1981cb22 42#include <NCollection_Sequence.hxx>
43
2166f0fa
SK
44#include <OpenGl_tsm.hxx>
45
bf75be98 46#include <OpenGl_AspectFace.hxx>
2166f0fa
SK
47#include <OpenGl_Display.hxx>
48#include <OpenGl_Matrix.hxx>
49#include <OpenGl_NamedStatus.hxx>
50#include <OpenGl_TextParam.hxx>
51
52#include <Handle_OpenGl_View.hxx>
bf75be98 53#include <Handle_OpenGl_Texture.hxx>
2166f0fa
SK
54
55class OpenGl_AspectLine;
2166f0fa
SK
56class OpenGl_AspectMarker;
57class OpenGl_AspectText;
58class OpenGl_FrameBuffer;
59class OpenGl_Structure;
692613e5 60class Image_PixMap;
2166f0fa
SK
61
62//! Reprepsents window with GL context.
63//! Provides methods to render primitives and maintan GL state.
64class OpenGl_Workspace : public OpenGl_Window
65{
66public:
67
68 //! Main constructor - prepare GL context for specified window.
69 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
70 const CALL_DEF_WINDOW& theCWindow,
5e27df78 71 Aspect_RenderingContext theGContext,
72 const Handle(OpenGl_Context)& theShareCtx);
2166f0fa
SK
73
74 //! Destructor
75 virtual ~OpenGl_Workspace();
76
77 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
78 const Handle(OpenGl_View)& ActiveView () const { return myView; }
79
80 //! Redraw the window.
81 void Redraw (const Graphic3d_CView& theCView,
82 const Aspect_CLayer2d& theCUnderLayer,
83 const Aspect_CLayer2d& theCOverLayer);
84
298f9ad7 85 //! Deprecated. Simply calls Redraw().
2166f0fa
SK
86 void Update (const Graphic3d_CView& theCView,
87 const Aspect_CLayer2d& theCUnderLayer,
88 const Aspect_CLayer2d& theCOverLayer)
89 {
298f9ad7 90 Redraw (theCView, theCUnderLayer, theCOverLayer);
2166f0fa
SK
91 }
92
93 //! Special method to perform printing.
94 //! System-specific and currently only Win platform implemented.
bf75be98 95 Standard_Boolean Print (const Graphic3d_CView& theCView,
96 const Aspect_CLayer2d& theCUnderLayer,
2166f0fa
SK
97 const Aspect_CLayer2d& theCOverLayer,
98 const Aspect_Handle theHPrintDC,
99 const Standard_Boolean theToShowBackground,
100 const Standard_CString theFileName,
101 const Aspect_PrintAlgo thePrintAlgorithm,
102 const Standard_Real theScaleFactor);
103
104 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
105
106 // szvgl: defined in OpenGl_Workspace_1.cxx
107 void BeginAnimation (const Standard_Boolean theUseDegeneration,
bf75be98 108 const Standard_Boolean theUpdateAM);
2166f0fa
SK
109 void EndAnimation();
110 void EraseAnimation();
111
1981cb22 112 Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer);
2166f0fa
SK
113 Standard_Boolean BeginAddMode();
114 void EndAddMode();
115 void ClearImmediatMode (const Graphic3d_CView& theCView,
116 const Standard_Boolean theToFlush);
117 void RedrawImmediatMode();
118 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
119 const Standard_Boolean theUseDepthTest,
120 const Standard_Boolean theRetainMode);
121 void EndImmediatMode();
2166f0fa 122 void DrawStructure (const OpenGl_Structure* theStructure);
2166f0fa
SK
123
124 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
125 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
692613e5 126 Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr,
127 Image_PixMap& theImage,
128 const Graphic3d_BufferType& theBufferType);
2166f0fa 129
2166f0fa
SK
130 void UseTransparency (const Standard_Boolean theFlag);
131 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
132 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
133 Standard_Boolean& UseGLLight() { return myUseGLLight; }
134
135 //// RELATED TO STATUS ////
136
137 Standard_Integer NamedStatus;
138
139 Standard_Integer DegenerateModel;
140 Standard_ShortReal SkipRatio;
141
142 const TEL_COLOUR* HighlightColor;
143
144 const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
145 const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
146
147 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
148 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
149 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
150 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
151
152 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
153
3946774d 154 //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
155 Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
156 Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
157 Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
158 Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
2166f0fa 159
34a44cbd 160 //! Clear the applied aspect state.
161 void ResetAppliedAspect();
162
bf75be98 163 Standard_EXPORT Handle(OpenGl_Texture) DisableTexture();
164 Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture,
165 const Handle(Graphic3d_TextureParams)& theParams = NULL);
166
2166f0fa
SK
167 //// RELATED TO FONTS ////
168
eeaaaefb 169 int FindFont (const char* theFontName,
170 const Font_FontAspect theFontAspect,
171 const int theBestSize = -1,
172 const float theXScale = 1.0f,
173 const float theYScale = 1.0f)
2166f0fa
SK
174 {
175 return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
176 }
177
178 void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
179 {
180 myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
181 }
182
183 void RenderText (const wchar_t* theText, const int theIs2d,
184 const float theX, const float theY, const float theZ)
185 {
186 const OpenGl_AspectText* anAspect = AspectText (Standard_True);
187 myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
188 }
189
190protected:
191
1981cb22 192 void CopyBuffers (const Standard_Boolean theFrontToBack);
2166f0fa
SK
193
194 virtual Standard_Boolean Activate();
195
196 // TEMPORARY!!!
bf75be98 197 void Redraw1 (const Graphic3d_CView& theCView,
198 const Aspect_CLayer2d& theCUnderLayer,
2166f0fa
SK
199 const Aspect_CLayer2d& theCOverLayer,
200 const int theToSwap);
201
bf75be98 202 void UpdateMaterial (const int flag);
2166f0fa 203
bf75be98 204 void setTextureParams (Handle(OpenGl_Texture)& theTexture,
205 const Handle(Graphic3d_TextureParams)& theParams);
2166f0fa 206
bf75be98 207protected: //! @name protected fields
2166f0fa 208
bf75be98 209 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
bf75be98 210 Standard_Boolean myIsTransientOpen; // transientOpen
1981cb22 211 Standard_Boolean myRetainMode;
212 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
213
214 NCollection_Sequence<const OpenGl_Structure*> myTransientList;
2166f0fa 215
bf75be98 216 Standard_Boolean myUseTransparency;
217 Standard_Boolean myUseZBuffer;
218 Standard_Boolean myUseDepthTest;
219 Standard_Boolean myUseGLLight;
220 Standard_Boolean myBackBufferRestored;
2166f0fa 221
bf75be98 222protected: //! @name fields related to status
223
224 Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture)
2166f0fa
SK
225 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
226 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
227 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
228 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
229
230 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
231
232 const OpenGl_Matrix* ViewMatrix_applied;
233 const OpenGl_Matrix* StructureMatrix_applied;
234
235 const TEL_POFFSET_PARAM* PolygonOffset_applied;
236
bf75be98 237 OpenGl_AspectFace myAspectFaceHl; // Hiddenline aspect
238
239public: //! @name type definition
2166f0fa 240
bf75be98 241 DEFINE_STANDARD_RTTI(OpenGl_Workspace)
1c35b92f 242 DEFINE_STANDARD_ALLOC
2166f0fa
SK
243
244};
245
bf75be98 246#endif // _OpenGl_Workspace_Header