0024070: OpenGL capped object-level clipping planes
[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>
a174a3c5 50#include <OpenGl_PrinterContext.hxx>
2166f0fa 51#include <OpenGl_TextParam.hxx>
4269bd1b 52#include <OpenGl_RenderFilter.hxx>
2166f0fa
SK
53
54#include <Handle_OpenGl_View.hxx>
bf75be98 55#include <Handle_OpenGl_Texture.hxx>
2166f0fa
SK
56
57class OpenGl_AspectLine;
2166f0fa
SK
58class OpenGl_AspectMarker;
59class OpenGl_AspectText;
60class OpenGl_FrameBuffer;
61class OpenGl_Structure;
4269bd1b 62class OpenGl_Element;
692613e5 63class Image_PixMap;
2166f0fa
SK
64
65//! Reprepsents window with GL context.
66//! Provides methods to render primitives and maintan GL state.
67class OpenGl_Workspace : public OpenGl_Window
68{
69public:
70
71 //! Main constructor - prepare GL context for specified window.
72 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
73 const CALL_DEF_WINDOW& theCWindow,
5e27df78 74 Aspect_RenderingContext theGContext,
58655684 75 const Handle(OpenGl_Caps)& theCaps,
5e27df78 76 const Handle(OpenGl_Context)& theShareCtx);
2166f0fa
SK
77
78 //! Destructor
79 virtual ~OpenGl_Workspace();
80
81 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
82 const Handle(OpenGl_View)& ActiveView () const { return myView; }
83
84 //! Redraw the window.
85 void Redraw (const Graphic3d_CView& theCView,
86 const Aspect_CLayer2d& theCUnderLayer,
87 const Aspect_CLayer2d& theCOverLayer);
88
298f9ad7 89 //! Deprecated. Simply calls Redraw().
2166f0fa
SK
90 void Update (const Graphic3d_CView& theCView,
91 const Aspect_CLayer2d& theCUnderLayer,
92 const Aspect_CLayer2d& theCOverLayer)
93 {
298f9ad7 94 Redraw (theCView, theCUnderLayer, theCOverLayer);
2166f0fa
SK
95 }
96
97 //! Special method to perform printing.
98 //! System-specific and currently only Win platform implemented.
a174a3c5 99 Standard_Boolean Print (const Handle(OpenGl_PrinterContext)& thePrintContext,
100 const Graphic3d_CView& theCView,
bf75be98 101 const Aspect_CLayer2d& theCUnderLayer,
2166f0fa
SK
102 const Aspect_CLayer2d& theCOverLayer,
103 const Aspect_Handle theHPrintDC,
104 const Standard_Boolean theToShowBackground,
105 const Standard_CString theFileName,
106 const Aspect_PrintAlgo thePrintAlgorithm,
107 const Standard_Real theScaleFactor);
108
a174a3c5 109 const Handle(OpenGl_PrinterContext)& PrinterContext() const
110 {
111 return myPrintContext;
112 }
113
2166f0fa
SK
114 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
115
1981cb22 116 Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer);
2166f0fa
SK
117 Standard_Boolean BeginAddMode();
118 void EndAddMode();
119 void ClearImmediatMode (const Graphic3d_CView& theCView,
120 const Standard_Boolean theToFlush);
121 void RedrawImmediatMode();
122 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
123 const Standard_Boolean theUseDepthTest,
124 const Standard_Boolean theRetainMode);
125 void EndImmediatMode();
2166f0fa 126 void DrawStructure (const OpenGl_Structure* theStructure);
2166f0fa
SK
127
128 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
129 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
692613e5 130 Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr,
131 Image_PixMap& theImage,
132 const Graphic3d_BufferType& theBufferType);
2166f0fa 133
2166f0fa
SK
134 void UseTransparency (const Standard_Boolean theFlag);
135 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
136 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
137 Standard_Boolean& UseGLLight() { return myUseGLLight; }
138
139 //// RELATED TO STATUS ////
140
141 Standard_Integer NamedStatus;
142
2166f0fa
SK
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
3946774d 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);
a174a3c5 160 inline const OpenGl_TextParam* AspectTextParams() const
161 {
162 return TextParam_applied;
163 }
2166f0fa 164
34a44cbd 165 //! Clear the applied aspect state.
166 void ResetAppliedAspect();
167
bf75be98 168 Standard_EXPORT Handle(OpenGl_Texture) DisableTexture();
169 Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture,
170 const Handle(Graphic3d_TextureParams)& theParams = NULL);
171
4269bd1b 172 //! Set filter for restricting rendering of particular elements.
173 //! Filter can be applied for rendering passes used by recursive
174 //! rendering algorithms for rendering elements of groups.
175 //! @param theFilter [in] the filter instance.
176 inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
177 {
178 myRenderFilter = theFilter;
179 }
180
181 //! Get rendering filter.
182 //! @return filter instance.
183 inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const
184 {
185 return myRenderFilter;
186 }
187
188 //! @return applied view matrix.
189 inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
190
191 //! @return applied model structure matrix.
192 inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
193
2166f0fa
SK
194protected:
195
1981cb22 196 void CopyBuffers (const Standard_Boolean theFrontToBack);
2166f0fa
SK
197
198 virtual Standard_Boolean Activate();
199
200 // TEMPORARY!!!
bf75be98 201 void Redraw1 (const Graphic3d_CView& theCView,
202 const Aspect_CLayer2d& theCUnderLayer,
2166f0fa
SK
203 const Aspect_CLayer2d& theCOverLayer,
204 const int theToSwap);
205
bf75be98 206 void UpdateMaterial (const int flag);
2166f0fa 207
bf75be98 208 void setTextureParams (Handle(OpenGl_Texture)& theTexture,
209 const Handle(Graphic3d_TextureParams)& theParams);
2166f0fa 210
bf75be98 211protected: //! @name protected fields
2166f0fa 212
a174a3c5 213 Handle(OpenGl_PrinterContext) myPrintContext;
bf75be98 214 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
bf75be98 215 Standard_Boolean myIsTransientOpen; // transientOpen
1981cb22 216 Standard_Boolean myRetainMode;
217 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
218
219 NCollection_Sequence<const OpenGl_Structure*> myTransientList;
2166f0fa 220
bf75be98 221 Standard_Boolean myUseTransparency;
222 Standard_Boolean myUseZBuffer;
223 Standard_Boolean myUseDepthTest;
224 Standard_Boolean myUseGLLight;
225 Standard_Boolean myBackBufferRestored;
2166f0fa 226
bf75be98 227protected: //! @name fields related to status
228
4269bd1b 229 Handle(OpenGl_RenderFilter) myRenderFilter;
bf75be98 230 Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture)
2166f0fa
SK
231 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
232 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
233 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
234 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
235
236 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
237
238 const OpenGl_Matrix* ViewMatrix_applied;
239 const OpenGl_Matrix* StructureMatrix_applied;
240
241 const TEL_POFFSET_PARAM* PolygonOffset_applied;
242
bf75be98 243 OpenGl_AspectFace myAspectFaceHl; // Hiddenline aspect
244
245public: //! @name type definition
2166f0fa 246
bf75be98 247 DEFINE_STANDARD_RTTI(OpenGl_Workspace)
1c35b92f 248 DEFINE_STANDARD_ALLOC
2166f0fa
SK
249
250};
251
bf75be98 252#endif // _OpenGl_Workspace_Header