0028912: Visualization, TKOpenGl - multi-texture support
[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//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef _OpenGl_Workspace_Header
17#define _OpenGl_Workspace_Header
18
bf75be98 19#include <Graphic3d_BufferType.hxx>
2166f0fa 20
bf75be98 21#include <OpenGl_AspectFace.hxx>
c357e426 22#include <OpenGl_CappingAlgo.hxx>
fc73a202 23#include <OpenGl_FrameBuffer.hxx>
8613985b 24#include <OpenGl_Material.hxx>
2166f0fa 25#include <OpenGl_Matrix.hxx>
4269bd1b 26#include <OpenGl_RenderFilter.hxx>
fc73a202 27#include <OpenGl_ShaderObject.hxx>
28#include <OpenGl_ShaderProgram.hxx>
c357e426 29#include <OpenGl_TextParam.hxx>
fc73a202 30#include <OpenGl_TextureBufferArb.hxx>
c357e426 31#include <OpenGl_Vec.hxx>
32#include <OpenGl_Window.hxx>
fc73a202 33
5b111128 34class OpenGl_View;
692613e5 35class Image_PixMap;
2166f0fa 36
c04c30b3 37class OpenGl_RaytraceFilter;
a89742cf 38DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
39
25ef750e 40//! Graphical ray-tracing filter.
a89742cf 41//! Filters out all raytracable structures.
42class OpenGl_RaytraceFilter : public OpenGl_RenderFilter
43{
44public:
45
46 //! Default constructor.
47 OpenGl_RaytraceFilter() {}
48
91c60b57 49 //! Returns the previously set filter.
50 const Handle(OpenGl_RenderFilter)& PrevRenderFilter()
51 {
52 return myPrevRenderFilter;
53 }
54
a89742cf 55 //! Remembers the previously set filter.
91c60b57 56 void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
a89742cf 57 {
58 myPrevRenderFilter = theFilter;
59 }
60
61 //! Checks whether the element can be rendered or not.
62 //! @param theElement [in] the element to check.
63 //! @return True if element can be rendered.
a1073ae2 64 virtual Standard_Boolean ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
65 const OpenGl_Element* theElement) Standard_OVERRIDE;
a89742cf 66
67private:
68
69 Handle(OpenGl_RenderFilter) myPrevRenderFilter;
70
71public:
72
92efcf78 73 DEFINE_STANDARD_RTTIEXT(OpenGl_RaytraceFilter,OpenGl_RenderFilter)
a89742cf 74};
75
c04c30b3 76class OpenGl_Workspace;
c357e426 77DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient)
c04c30b3 78
c357e426 79//! Rendering workspace.
e276548b 80//! Provides methods to render primitives and maintain GL state.
c357e426 81class OpenGl_Workspace : public Standard_Transient
2166f0fa
SK
82{
83public:
84
c357e426 85 //! Constructor of rendering workspace.
86 Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow);
2166f0fa
SK
87
88 //! Destructor
6d0e6be5 89 virtual ~OpenGl_Workspace() {}
2166f0fa 90
c357e426 91 //! Activate rendering context.
92 Standard_EXPORT Standard_Boolean Activate();
a272ed94 93
c357e426 94 OpenGl_View* View() const { return myView; }
2166f0fa 95
c357e426 96 const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; }
2166f0fa 97
b128c892 98 Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
679ecdee 99
b128c892 100 Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo);
a174a3c5 101
b128c892 102 Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo,
103 Image_PixMap& theImage,
104 const Graphic3d_BufferType& theBufferType);
2166f0fa 105
c357e426 106 Standard_EXPORT Standard_Integer Width() const;
107
108 Standard_EXPORT Standard_Integer Height() const;
109
eae454e3 110 //! Setup Z-buffer usage flag (without affecting GL state!).
111 //! Returns previously set flag.
112 Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse)
113 {
114 const Standard_Boolean wasUsed = myUseZBuffer;
115 myUseZBuffer = theToUse;
116 return wasUsed;
117 }
118
c357e426 119 //! @return true if usage of Z buffer is enabled.
120 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
121
122 //! @return true if depth writing is enabled.
eae454e3 123 Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
2166f0fa 124
c357e426 125 //! @return true if clipping algorithm enabled
126 Standard_EXPORT Standard_Boolean IsCullingEnabled() const;
127
c357e426 128 //// RELATED TO STATUS ////
2166f0fa 129
b6472664 130 //! Return true if active group might activate face culling (e.g. primitives are closed).
131 bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
132
133 //! Allow or disallow face culling.
134 //! This call does NOT affect current state of back face culling;
135 //! ApplyAspectFace() should be called to update state.
136 void SetAllowFaceCulling (bool theToAllow) { myToAllowFaceCulling = theToAllow; }
2166f0fa 137
f9ba5c4d 138 //! Return true if following structures should apply highlight color.
f838dac4 139 bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
140
141 //! Return highlight style.
142 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
f9ba5c4d 143
f838dac4 144 //! Set highlight style.
145 void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) { myHighlightStyle = theStyle; }
f9ba5c4d 146
147 //! Return line color taking into account highlight flag.
b6472664 148 const OpenGl_Vec4& LineColor() const
f9ba5c4d 149 {
f838dac4 150 return !myHighlightStyle.IsNull()
151 ? myHighlightStyle->ColorRGBA()
152 : myAspectLineSet->Aspect()->ColorRGBA();
f9ba5c4d 153 }
154
155 //! Return edge color taking into account highlight flag.
b6472664 156 const OpenGl_Vec4& EdgeColor() const
f9ba5c4d 157 {
f838dac4 158 return !myHighlightStyle.IsNull()
159 ? myHighlightStyle->ColorRGBA()
160 : myAspectFaceSet->AspectEdge()->Aspect()->ColorRGBA();
f9ba5c4d 161 }
162
163 //! Return marker color taking into account highlight flag.
b6472664 164 const OpenGl_Vec4& MarkerColor() const
f9ba5c4d 165 {
f838dac4 166 return !myHighlightStyle.IsNull()
167 ? myHighlightStyle->ColorRGBA()
168 : myAspectMarkerSet->Aspect()->ColorRGBA();
f9ba5c4d 169 }
170
171 //! Return Interior color taking into account highlight flag.
b6472664 172 const OpenGl_Vec4& InteriorColor() const
f9ba5c4d 173 {
f838dac4 174 return !myHighlightStyle.IsNull()
175 ? myHighlightStyle->ColorRGBA()
176 : myAspectFaceSet->Aspect()->InteriorColorRGBA();
f9ba5c4d 177 }
178
179 //! Return text color taking into account highlight flag.
b6472664 180 const OpenGl_Vec4& TextColor() const
f9ba5c4d 181 {
f838dac4 182 return !myHighlightStyle.IsNull()
183 ? myHighlightStyle->ColorRGBA()
184 : myAspectTextSet->Aspect()->ColorRGBA();
f9ba5c4d 185 }
186
187 //! Return text Subtitle color taking into account highlight flag.
b6472664 188 const OpenGl_Vec4& TextSubtitleColor() const
f9ba5c4d 189 {
f838dac4 190 return !myHighlightStyle.IsNull()
191 ? myHighlightStyle->ColorRGBA()
192 : myAspectTextSet->Aspect()->ColorSubTitleRGBA();
f9ba5c4d 193 }
194
195 //! Currently set line aspect (can differ from applied).
196 const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; }
197
198 //! Currently set face aspect (can differ from applied).
199 const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; }
200
201 //! Currently set marker aspect (can differ from applied).
202 const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; }
203
204 //! Currently set text aspect (can differ from applied).
205 const OpenGl_AspectText* AspectText() const { return myAspectTextSet; }
206
207 //! Assign new line aspect (will be applied within ApplyAspectLine()).
71c6e1e5 208 Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
f9ba5c4d 209
210 //! Assign new face aspect (will be applied within ApplyAspectFace()).
71c6e1e5 211 Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
f9ba5c4d 212
213 //! Assign new marker aspect (will be applied within ApplyAspectMarker()).
71c6e1e5 214 Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
f9ba5c4d 215
216 //! Assign new text aspect (will be applied within ApplyAspectText()).
71c6e1e5 217 Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
2166f0fa 218
f9ba5c4d 219 //! Apply line aspect.
220 //! @return aspect set by SetAspectLine()
221 const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; }
222
223 //! Apply face aspect.
224 //! @return aspect set by SetAspectFace()
225 Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace();
226
227 //! Apply marker aspect.
228 //! @return aspect set by SetAspectMarker()
229 Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker();
230
231 //! Apply text aspect.
232 //! @return aspect set by SetAspectText()
233 const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; }
2166f0fa 234
f9ba5c4d 235 //! Clear the applied aspect state to default values.
34a44cbd 236 void ResetAppliedAspect();
237
4269bd1b 238 //! Set filter for restricting rendering of particular elements.
239 //! Filter can be applied for rendering passes used by recursive
240 //! rendering algorithms for rendering elements of groups.
241 //! @param theFilter [in] the filter instance.
242 inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
243 {
5322131b 244 myRenderFilter = theFilter;
4269bd1b 245 }
246
247 //! Get rendering filter.
248 //! @return filter instance.
5322131b 249 inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const
250 {
251 return myRenderFilter;
4269bd1b 252 }
253
254 //! @return applied view matrix.
255 inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
256
257 //! @return applied model structure matrix.
258 inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
259
550f3b8b 260 //! Sets and applies current polygon offset.
b6472664 261 void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams);
550f3b8b 262
6d0e6be5 263 //! Returns currently applied polygon offset parameters.
b6472664 264 const Graphic3d_PolygonOffset& AppliedPolygonOffset() { return myPolygonOffsetApplied; }
550f3b8b 265
f8ae3605 266 //! Returns capping algorithm rendering filter.
267 const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const
268 {
269 return myDefaultCappingAlgoFilter;
270 }
271
272 //! Returns face aspect for none culling mode.
273 const OpenGl_AspectFace& NoneCulling() const
274 {
275 return myNoneCulling;
276 }
277
278 //! Returns face aspect for front face culling mode.
279 const OpenGl_AspectFace& FrontCulling() const
280 {
281 return myFrontCulling;
282 }
283
83da37b1 284 //! Sets a new environment texture.
cc8cbabe 285 void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
83da37b1 286
287 //! Returns environment texture.
cc8cbabe 288 const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; }
2166f0fa 289
91c60b57 290protected: //! @name protected fields
265d4508 291
c357e426 292 OpenGl_View* myView;
293 Handle(OpenGl_Window) myWindow;
294 Handle(OpenGl_Context) myGlContext;
c357e426 295 Standard_Boolean myUseZBuffer;
296 Standard_Boolean myUseDepthWrite;
f8ae3605 297 Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter;
298 OpenGl_AspectFace myNoneCulling;
299 OpenGl_AspectFace myFrontCulling;
300
bf75be98 301protected: //! @name fields related to status
302
4269bd1b 303 Handle(OpenGl_RenderFilter) myRenderFilter;
f9ba5c4d 304 const OpenGl_AspectLine* myAspectLineSet;
305 const OpenGl_AspectFace* myAspectFaceSet;
b6472664 306 Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied;
f9ba5c4d 307 const OpenGl_AspectMarker* myAspectMarkerSet;
b6472664 308 Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied;
f9ba5c4d 309 const OpenGl_AspectText* myAspectTextSet;
8613985b 310 Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
2166f0fa 311
2166f0fa
SK
312 const OpenGl_Matrix* ViewMatrix_applied;
313 const OpenGl_Matrix* StructureMatrix_applied;
314
b6472664 315 bool myToAllowFaceCulling; //!< allow back face culling
f838dac4 316 Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
0adbd30f 317
550f3b8b 318 OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
0f8c0fb8 319
b6472664 320 Graphic3d_PolygonOffset myPolygonOffsetApplied; //!< currently applied polygon offset
2166f0fa 321
550f3b8b 322 OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
bf75be98 323
cc8cbabe 324 Handle(OpenGl_TextureSet) myEnvironmentTexture;
83da37b1 325
bf75be98 326public: //! @name type definition
2166f0fa 327
92efcf78 328 DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
1c35b92f 329 DEFINE_STANDARD_ALLOC
2166f0fa
SK
330
331};
332
bf75be98 333#endif // _OpenGl_Workspace_Header