Commit | Line | Data |
---|---|---|
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> |
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 | 34 | class OpenGl_View; |
692613e5 | 35 | class Image_PixMap; |
2166f0fa | 36 | |
c04c30b3 | 37 | class OpenGl_Workspace; |
c357e426 | 38 | DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient) |
c04c30b3 | 39 | |
c357e426 | 40 | //! Rendering workspace. |
e276548b | 41 | //! Provides methods to render primitives and maintain GL state. |
c357e426 | 42 | class OpenGl_Workspace : public Standard_Transient |
2166f0fa SK |
43 | { |
44 | public: | |
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 | |
114 | //! Return line color taking into account highlight flag. | |
b6472664 | 115 | const OpenGl_Vec4& LineColor() const |
f9ba5c4d | 116 | { |
f838dac4 | 117 | return !myHighlightStyle.IsNull() |
118 | ? myHighlightStyle->ColorRGBA() | |
119 | : myAspectLineSet->Aspect()->ColorRGBA(); | |
f9ba5c4d | 120 | } |
121 | ||
122 | //! Return edge color taking into account highlight flag. | |
b6472664 | 123 | const OpenGl_Vec4& EdgeColor() const |
f9ba5c4d | 124 | { |
f838dac4 | 125 | return !myHighlightStyle.IsNull() |
126 | ? myHighlightStyle->ColorRGBA() | |
127 | : myAspectFaceSet->AspectEdge()->Aspect()->ColorRGBA(); | |
f9ba5c4d | 128 | } |
129 | ||
130 | //! Return marker color taking into account highlight flag. | |
b6472664 | 131 | const OpenGl_Vec4& MarkerColor() const |
f9ba5c4d | 132 | { |
f838dac4 | 133 | return !myHighlightStyle.IsNull() |
134 | ? myHighlightStyle->ColorRGBA() | |
135 | : myAspectMarkerSet->Aspect()->ColorRGBA(); | |
f9ba5c4d | 136 | } |
137 | ||
138 | //! Return Interior color taking into account highlight flag. | |
b6472664 | 139 | const OpenGl_Vec4& InteriorColor() const |
f9ba5c4d | 140 | { |
f838dac4 | 141 | return !myHighlightStyle.IsNull() |
142 | ? myHighlightStyle->ColorRGBA() | |
143 | : myAspectFaceSet->Aspect()->InteriorColorRGBA(); | |
f9ba5c4d | 144 | } |
145 | ||
146 | //! Return text color taking into account highlight flag. | |
b6472664 | 147 | const OpenGl_Vec4& TextColor() const |
f9ba5c4d | 148 | { |
f838dac4 | 149 | return !myHighlightStyle.IsNull() |
150 | ? myHighlightStyle->ColorRGBA() | |
151 | : myAspectTextSet->Aspect()->ColorRGBA(); | |
f9ba5c4d | 152 | } |
153 | ||
154 | //! Return text Subtitle color taking into account highlight flag. | |
b6472664 | 155 | const OpenGl_Vec4& TextSubtitleColor() const |
f9ba5c4d | 156 | { |
f838dac4 | 157 | return !myHighlightStyle.IsNull() |
158 | ? myHighlightStyle->ColorRGBA() | |
159 | : myAspectTextSet->Aspect()->ColorSubTitleRGBA(); | |
f9ba5c4d | 160 | } |
161 | ||
162 | //! Currently set line aspect (can differ from applied). | |
163 | const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; } | |
164 | ||
165 | //! Currently set face aspect (can differ from applied). | |
166 | const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; } | |
167 | ||
168 | //! Currently set marker aspect (can differ from applied). | |
169 | const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; } | |
170 | ||
171 | //! Currently set text aspect (can differ from applied). | |
172 | const OpenGl_AspectText* AspectText() const { return myAspectTextSet; } | |
173 | ||
174 | //! Assign new line aspect (will be applied within ApplyAspectLine()). | |
71c6e1e5 | 175 | Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); |
f9ba5c4d | 176 | |
177 | //! Assign new face aspect (will be applied within ApplyAspectFace()). | |
71c6e1e5 | 178 | Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); |
f9ba5c4d | 179 | |
180 | //! Assign new marker aspect (will be applied within ApplyAspectMarker()). | |
71c6e1e5 | 181 | Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); |
f9ba5c4d | 182 | |
183 | //! Assign new text aspect (will be applied within ApplyAspectText()). | |
71c6e1e5 | 184 | Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); |
2166f0fa | 185 | |
f9ba5c4d | 186 | //! Apply line aspect. |
187 | //! @return aspect set by SetAspectLine() | |
188 | const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; } | |
189 | ||
190 | //! Apply face aspect. | |
191 | //! @return aspect set by SetAspectFace() | |
192 | Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace(); | |
193 | ||
194 | //! Apply marker aspect. | |
195 | //! @return aspect set by SetAspectMarker() | |
196 | Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker(); | |
197 | ||
198 | //! Apply text aspect. | |
199 | //! @return aspect set by SetAspectText() | |
200 | const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; } | |
2166f0fa | 201 | |
f9ba5c4d | 202 | //! Clear the applied aspect state to default values. |
34a44cbd | 203 | void ResetAppliedAspect(); |
204 | ||
1b661a81 | 205 | //! Get rendering filter. |
206 | //! @sa ShouldRender() | |
207 | Standard_Integer RenderFilter() const { return myRenderFilter; } | |
208 | ||
4269bd1b | 209 | //! Set filter for restricting rendering of particular elements. |
1b661a81 | 210 | //! @sa ShouldRender() |
211 | void SetRenderFilter (Standard_Integer theFilter) { myRenderFilter = theFilter; } | |
4269bd1b | 212 | |
1b661a81 | 213 | //! Checks whether the element can be rendered or not. |
214 | //! @param theElement [in] the element to check | |
215 | //! @return True if element can be rendered | |
216 | bool ShouldRender (const OpenGl_Element* theElement); | |
217 | ||
218 | //! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter. | |
219 | //! @sa OpenGl_LayerList::Render() | |
220 | Standard_Integer NbSkippedTransparentElements() { return myNbSkippedTranspElems; } | |
221 | ||
222 | //! Reset skipped transparent elements counter. | |
223 | //! @sa OpenGl_LayerList::Render() | |
224 | void ResetSkippedCounter() { myNbSkippedTranspElems = 0; } | |
4269bd1b | 225 | |
226 | //! @return applied view matrix. | |
227 | inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; } | |
228 | ||
229 | //! @return applied model structure matrix. | |
230 | inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } | |
231 | ||
c40eb6b9 | 232 | //! Returns face aspect for textured font rendering. |
233 | const OpenGl_AspectFace& FontFaceAspect() const { return myFontFaceAspect; } | |
234 | ||
f8ae3605 | 235 | //! Returns face aspect for none culling mode. |
c40eb6b9 | 236 | const OpenGl_AspectFace& NoneCulling() const { return myNoneCulling; } |
f8ae3605 | 237 | |
238 | //! Returns face aspect for front face culling mode. | |
c40eb6b9 | 239 | const OpenGl_AspectFace& FrontCulling() const { return myFrontCulling; } |
f8ae3605 | 240 | |
83da37b1 | 241 | //! Sets a new environment texture. |
cc8cbabe | 242 | void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; } |
83da37b1 | 243 | |
244 | //! Returns environment texture. | |
cc8cbabe | 245 | const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; } |
2166f0fa | 246 | |
91c60b57 | 247 | protected: //! @name protected fields |
265d4508 | 248 | |
c357e426 | 249 | OpenGl_View* myView; |
250 | Handle(OpenGl_Window) myWindow; | |
251 | Handle(OpenGl_Context) myGlContext; | |
c357e426 | 252 | Standard_Boolean myUseZBuffer; |
253 | Standard_Boolean myUseDepthWrite; | |
f8ae3605 | 254 | OpenGl_AspectFace myNoneCulling; |
255 | OpenGl_AspectFace myFrontCulling; | |
c40eb6b9 | 256 | OpenGl_AspectFace myFontFaceAspect; |
f8ae3605 | 257 | |
bf75be98 | 258 | protected: //! @name fields related to status |
259 | ||
1b661a81 | 260 | Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method |
261 | Standard_Integer myRenderFilter; //!< active filter for skipping rendering of elements by some criteria (multiple render passes) | |
262 | ||
a6df1715 | 263 | OpenGl_AspectLine myDefaultAspectLine; |
264 | OpenGl_AspectFace myDefaultAspectFace; | |
265 | OpenGl_AspectMarker myDefaultAspectMarker; | |
266 | OpenGl_AspectText myDefaultAspectText; | |
267 | ||
f9ba5c4d | 268 | const OpenGl_AspectLine* myAspectLineSet; |
269 | const OpenGl_AspectFace* myAspectFaceSet; | |
b6472664 | 270 | Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied; |
f9ba5c4d | 271 | const OpenGl_AspectMarker* myAspectMarkerSet; |
b6472664 | 272 | Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied; |
f9ba5c4d | 273 | const OpenGl_AspectText* myAspectTextSet; |
8613985b | 274 | Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL; |
2166f0fa | 275 | |
2166f0fa SK |
276 | const OpenGl_Matrix* ViewMatrix_applied; |
277 | const OpenGl_Matrix* StructureMatrix_applied; | |
278 | ||
b6472664 | 279 | bool myToAllowFaceCulling; //!< allow back face culling |
f838dac4 | 280 | Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style |
0adbd30f | 281 | |
550f3b8b | 282 | OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations |
0f8c0fb8 | 283 | |
550f3b8b | 284 | OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect |
bf75be98 | 285 | |
cc8cbabe | 286 | Handle(OpenGl_TextureSet) myEnvironmentTexture; |
83da37b1 | 287 | |
bf75be98 | 288 | public: //! @name type definition |
2166f0fa | 289 | |
92efcf78 | 290 | DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) |
1c35b92f | 291 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
292 | |
293 | }; | |
294 | ||
bf75be98 | 295 | #endif // _OpenGl_Workspace_Header |