0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[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
bf5f0ca2 21#include <OpenGl_Aspects.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>
fc73a202 26#include <OpenGl_ShaderObject.hxx>
27#include <OpenGl_ShaderProgram.hxx>
c357e426 28#include <OpenGl_TextParam.hxx>
fc73a202 29#include <OpenGl_TextureBufferArb.hxx>
1b661a81 30#include <OpenGl_RenderFilter.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_Workspace;
c357e426 38DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient)
c04c30b3 39
c357e426 40//! Rendering workspace.
e276548b 41//! Provides methods to render primitives and maintain GL state.
c357e426 42class OpenGl_Workspace : public Standard_Transient
2166f0fa
SK
43{
44public:
45
c357e426 46 //! Constructor of rendering workspace.
47 Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow);
2166f0fa
SK
48
49 //! Destructor
6d0e6be5 50 virtual ~OpenGl_Workspace() {}
2166f0fa 51
c357e426 52 //! Activate rendering context.
53 Standard_EXPORT Standard_Boolean Activate();
a272ed94 54
c357e426 55 OpenGl_View* View() const { return myView; }
2166f0fa 56
c357e426 57 const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; }
2166f0fa 58
b128c892 59 Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
679ecdee 60
b128c892 61 Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo);
a174a3c5 62
b128c892 63 Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo,
64 Image_PixMap& theImage,
65 const Graphic3d_BufferType& theBufferType);
2166f0fa 66
c357e426 67 Standard_EXPORT Standard_Integer Width() const;
68
69 Standard_EXPORT Standard_Integer Height() const;
70
eae454e3 71 //! Setup Z-buffer usage flag (without affecting GL state!).
72 //! Returns previously set flag.
73 Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse)
74 {
75 const Standard_Boolean wasUsed = myUseZBuffer;
76 myUseZBuffer = theToUse;
77 return wasUsed;
78 }
79
c357e426 80 //! @return true if usage of Z buffer is enabled.
81 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
82
83 //! @return true if depth writing is enabled.
eae454e3 84 Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
2166f0fa 85
a6df1715 86 //! Configure default polygon offset parameters.
87 //! Return previous settings.
88 Standard_EXPORT Graphic3d_PolygonOffset SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
89
c357e426 90 //// RELATED TO STATUS ////
2166f0fa 91
b6472664 92 //! Return true if active group might activate face culling (e.g. primitives are closed).
93 bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
94
95 //! Allow or disallow face culling.
96 //! This call does NOT affect current state of back face culling;
97 //! ApplyAspectFace() should be called to update state.
25c35042 98 bool SetAllowFaceCulling (bool theToAllow)
99 {
100 const bool wasAllowed = myToAllowFaceCulling;
101 myToAllowFaceCulling = theToAllow;
102 return wasAllowed;
103 }
2166f0fa 104
f9ba5c4d 105 //! Return true if following structures should apply highlight color.
f838dac4 106 bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
107
108 //! Return highlight style.
109 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
f9ba5c4d 110
f838dac4 111 //! Set highlight style.
112 void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) { myHighlightStyle = theStyle; }
f9ba5c4d 113
f9ba5c4d 114 //! Return edge color taking into account highlight flag.
b6472664 115 const OpenGl_Vec4& EdgeColor() const
f9ba5c4d 116 {
f838dac4 117 return !myHighlightStyle.IsNull()
118 ? myHighlightStyle->ColorRGBA()
bf5f0ca2 119 : myAspectsSet->Aspect()->EdgeColorRGBA();
f9ba5c4d 120 }
121
122 //! Return Interior color taking into account highlight flag.
b6472664 123 const OpenGl_Vec4& InteriorColor() const
f9ba5c4d 124 {
f838dac4 125 return !myHighlightStyle.IsNull()
126 ? myHighlightStyle->ColorRGBA()
bf5f0ca2 127 : myAspectsSet->Aspect()->InteriorColorRGBA();
f9ba5c4d 128 }
129
130 //! Return text color taking into account highlight flag.
b6472664 131 const OpenGl_Vec4& TextColor() const
f9ba5c4d 132 {
f838dac4 133 return !myHighlightStyle.IsNull()
134 ? myHighlightStyle->ColorRGBA()
bf5f0ca2 135 : myAspectsSet->Aspect()->ColorRGBA();
f9ba5c4d 136 }
137
138 //! Return text Subtitle color taking into account highlight flag.
b6472664 139 const OpenGl_Vec4& TextSubtitleColor() const
f9ba5c4d 140 {
f838dac4 141 return !myHighlightStyle.IsNull()
142 ? myHighlightStyle->ColorRGBA()
bf5f0ca2 143 : myAspectsSet->Aspect()->ColorSubTitleRGBA();
f9ba5c4d 144 }
145
bf5f0ca2 146 //! Currently set aspects (can differ from applied).
147 const OpenGl_Aspects* Aspects() const { return myAspectsSet; }
f9ba5c4d 148
bf5f0ca2 149 //! Assign new aspects (will be applied within ApplyAspects()).
150 Standard_EXPORT const OpenGl_Aspects* SetAspects (const OpenGl_Aspects* theAspect);
f9ba5c4d 151
bf5f0ca2 152 //! Apply aspects.
153 //! @return aspect set by SetAspects()
154 Standard_EXPORT const OpenGl_Aspects* ApplyAspects();
2166f0fa 155
f9ba5c4d 156 //! Clear the applied aspect state to default values.
34a44cbd 157 void ResetAppliedAspect();
158
1b661a81 159 //! Get rendering filter.
160 //! @sa ShouldRender()
161 Standard_Integer RenderFilter() const { return myRenderFilter; }
162
4269bd1b 163 //! Set filter for restricting rendering of particular elements.
1b661a81 164 //! @sa ShouldRender()
165 void SetRenderFilter (Standard_Integer theFilter) { myRenderFilter = theFilter; }
4269bd1b 166
1b661a81 167 //! Checks whether the element can be rendered or not.
168 //! @param theElement [in] the element to check
169 //! @return True if element can be rendered
170 bool ShouldRender (const OpenGl_Element* theElement);
171
172 //! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter.
173 //! @sa OpenGl_LayerList::Render()
174 Standard_Integer NbSkippedTransparentElements() { return myNbSkippedTranspElems; }
175
176 //! Reset skipped transparent elements counter.
177 //! @sa OpenGl_LayerList::Render()
178 void ResetSkippedCounter() { myNbSkippedTranspElems = 0; }
4269bd1b 179
180 //! @return applied view matrix.
181 inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
182
183 //! @return applied model structure matrix.
184 inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
185
f8ae3605 186 //! Returns face aspect for none culling mode.
bf5f0ca2 187 const OpenGl_Aspects& NoneCulling() const { return myNoneCulling; }
f8ae3605 188
189 //! Returns face aspect for front face culling mode.
bf5f0ca2 190 const OpenGl_Aspects& FrontCulling() const { return myFrontCulling; }
f8ae3605 191
83da37b1 192 //! Sets a new environment texture.
cc8cbabe 193 void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
83da37b1 194
195 //! Returns environment texture.
cc8cbabe 196 const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; }
2166f0fa 197
91c60b57 198protected: //! @name protected fields
265d4508 199
bf5f0ca2 200 OpenGl_View* myView;
201 Handle(OpenGl_Window) myWindow;
202 Handle(OpenGl_Context) myGlContext;
203 Standard_Boolean myUseZBuffer;
204 Standard_Boolean myUseDepthWrite;
205 OpenGl_Aspects myNoneCulling;
206 OpenGl_Aspects myFrontCulling;
f8ae3605 207
bf75be98 208protected: //! @name fields related to status
209
1b661a81 210 Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method
211 Standard_Integer myRenderFilter; //!< active filter for skipping rendering of elements by some criteria (multiple render passes)
212
bf5f0ca2 213 OpenGl_Aspects myDefaultAspects;
214 const OpenGl_Aspects* myAspectsSet;
215 Handle(Graphic3d_Aspects) myAspectsApplied;
216
8613985b 217 Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
2166f0fa 218
2166f0fa
SK
219 const OpenGl_Matrix* ViewMatrix_applied;
220 const OpenGl_Matrix* StructureMatrix_applied;
221
b6472664 222 bool myToAllowFaceCulling; //!< allow back face culling
f838dac4 223 Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
0adbd30f 224
550f3b8b 225 OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
0f8c0fb8 226
bf5f0ca2 227 OpenGl_Aspects myAspectFaceHl; //!< Hiddenline aspect
bf75be98 228
cc8cbabe 229 Handle(OpenGl_TextureSet) myEnvironmentTexture;
83da37b1 230
bf75be98 231public: //! @name type definition
2166f0fa 232
92efcf78 233 DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
1c35b92f 234 DEFINE_STANDARD_ALLOC
2166f0fa
SK
235
236};
237
bf75be98 238#endif // _OpenGl_Workspace_Header