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 SK |
25 | #include <OpenGl_Matrix.hxx> |
26 | #include <OpenGl_NamedStatus.hxx> | |
4269bd1b | 27 | #include <OpenGl_RenderFilter.hxx> |
fc73a202 | 28 | #include <OpenGl_ShaderObject.hxx> |
29 | #include <OpenGl_ShaderProgram.hxx> | |
c357e426 | 30 | #include <OpenGl_TextParam.hxx> |
fc73a202 | 31 | #include <OpenGl_TextureBufferArb.hxx> |
c357e426 | 32 | #include <OpenGl_Vec.hxx> |
33 | #include <OpenGl_Window.hxx> | |
fc73a202 | 34 | |
5b111128 | 35 | class OpenGl_View; |
692613e5 | 36 | class Image_PixMap; |
2166f0fa | 37 | |
c04c30b3 | 38 | class OpenGl_RaytraceFilter; |
a89742cf | 39 | DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter) |
40 | ||
25ef750e | 41 | //! Graphical ray-tracing filter. |
a89742cf | 42 | //! Filters out all raytracable structures. |
43 | class OpenGl_RaytraceFilter : public OpenGl_RenderFilter | |
44 | { | |
45 | public: | |
46 | ||
47 | //! Default constructor. | |
48 | OpenGl_RaytraceFilter() {} | |
49 | ||
91c60b57 | 50 | //! Returns the previously set filter. |
51 | const Handle(OpenGl_RenderFilter)& PrevRenderFilter() | |
52 | { | |
53 | return myPrevRenderFilter; | |
54 | } | |
55 | ||
a89742cf | 56 | //! Remembers the previously set filter. |
91c60b57 | 57 | void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) |
a89742cf | 58 | { |
59 | myPrevRenderFilter = theFilter; | |
60 | } | |
61 | ||
62 | //! Checks whether the element can be rendered or not. | |
63 | //! @param theElement [in] the element to check. | |
64 | //! @return True if element can be rendered. | |
79104795 | 65 | virtual Standard_Boolean CanRender (const OpenGl_Element* theElement) Standard_OVERRIDE; |
a89742cf | 66 | |
67 | private: | |
68 | ||
69 | Handle(OpenGl_RenderFilter) myPrevRenderFilter; | |
70 | ||
71 | public: | |
72 | ||
92efcf78 | 73 | DEFINE_STANDARD_RTTIEXT(OpenGl_RaytraceFilter,OpenGl_RenderFilter) |
a89742cf | 74 | }; |
75 | ||
c04c30b3 | 76 | class OpenGl_Workspace; |
c357e426 | 77 | DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient) |
c04c30b3 | 78 | |
c357e426 | 79 | //! Rendering workspace. |
e276548b | 80 | //! Provides methods to render primitives and maintain GL state. |
c357e426 | 81 | class OpenGl_Workspace : public Standard_Transient |
2166f0fa SK |
82 | { |
83 | public: | |
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 | ||
128 | Standard_Integer NamedStatus; | |
129 | ||
130 | //// RELATED TO STATUS //// | |
2166f0fa | 131 | |
b6472664 | 132 | //! Return true if active group might activate face culling (e.g. primitives are closed). |
133 | bool ToAllowFaceCulling() const { return myToAllowFaceCulling; } | |
134 | ||
135 | //! Allow or disallow face culling. | |
136 | //! This call does NOT affect current state of back face culling; | |
137 | //! ApplyAspectFace() should be called to update state. | |
138 | void SetAllowFaceCulling (bool theToAllow) { myToAllowFaceCulling = theToAllow; } | |
2166f0fa | 139 | |
f9ba5c4d | 140 | //! Return true if following structures should apply highlight color. |
f838dac4 | 141 | bool ToHighlight() const { return !myHighlightStyle.IsNull(); } |
142 | ||
143 | //! Return highlight style. | |
144 | const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; } | |
f9ba5c4d | 145 | |
f838dac4 | 146 | //! Set highlight style. |
147 | void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) { myHighlightStyle = theStyle; } | |
f9ba5c4d | 148 | |
149 | //! Return line color taking into account highlight flag. | |
b6472664 | 150 | const OpenGl_Vec4& LineColor() const |
f9ba5c4d | 151 | { |
f838dac4 | 152 | return !myHighlightStyle.IsNull() |
153 | ? myHighlightStyle->ColorRGBA() | |
154 | : myAspectLineSet->Aspect()->ColorRGBA(); | |
f9ba5c4d | 155 | } |
156 | ||
157 | //! Return edge color taking into account highlight flag. | |
b6472664 | 158 | const OpenGl_Vec4& EdgeColor() const |
f9ba5c4d | 159 | { |
f838dac4 | 160 | return !myHighlightStyle.IsNull() |
161 | ? myHighlightStyle->ColorRGBA() | |
162 | : myAspectFaceSet->AspectEdge()->Aspect()->ColorRGBA(); | |
f9ba5c4d | 163 | } |
164 | ||
165 | //! Return marker color taking into account highlight flag. | |
b6472664 | 166 | const OpenGl_Vec4& MarkerColor() const |
f9ba5c4d | 167 | { |
f838dac4 | 168 | return !myHighlightStyle.IsNull() |
169 | ? myHighlightStyle->ColorRGBA() | |
170 | : myAspectMarkerSet->Aspect()->ColorRGBA(); | |
f9ba5c4d | 171 | } |
172 | ||
173 | //! Return Interior color taking into account highlight flag. | |
b6472664 | 174 | const OpenGl_Vec4& InteriorColor() const |
f9ba5c4d | 175 | { |
f838dac4 | 176 | return !myHighlightStyle.IsNull() |
177 | ? myHighlightStyle->ColorRGBA() | |
178 | : myAspectFaceSet->Aspect()->InteriorColorRGBA(); | |
f9ba5c4d | 179 | } |
180 | ||
181 | //! Return text color taking into account highlight flag. | |
b6472664 | 182 | const OpenGl_Vec4& TextColor() const |
f9ba5c4d | 183 | { |
f838dac4 | 184 | return !myHighlightStyle.IsNull() |
185 | ? myHighlightStyle->ColorRGBA() | |
186 | : myAspectTextSet->Aspect()->ColorRGBA(); | |
f9ba5c4d | 187 | } |
188 | ||
189 | //! Return text Subtitle color taking into account highlight flag. | |
b6472664 | 190 | const OpenGl_Vec4& TextSubtitleColor() const |
f9ba5c4d | 191 | { |
f838dac4 | 192 | return !myHighlightStyle.IsNull() |
193 | ? myHighlightStyle->ColorRGBA() | |
194 | : myAspectTextSet->Aspect()->ColorSubTitleRGBA(); | |
f9ba5c4d | 195 | } |
196 | ||
197 | //! Currently set line aspect (can differ from applied). | |
198 | const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; } | |
199 | ||
200 | //! Currently set face aspect (can differ from applied). | |
201 | const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; } | |
202 | ||
203 | //! Currently set marker aspect (can differ from applied). | |
204 | const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; } | |
205 | ||
206 | //! Currently set text aspect (can differ from applied). | |
207 | const OpenGl_AspectText* AspectText() const { return myAspectTextSet; } | |
208 | ||
209 | //! Assign new line aspect (will be applied within ApplyAspectLine()). | |
71c6e1e5 | 210 | Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); |
f9ba5c4d | 211 | |
212 | //! Assign new face aspect (will be applied within ApplyAspectFace()). | |
71c6e1e5 | 213 | Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); |
f9ba5c4d | 214 | |
215 | //! Assign new marker aspect (will be applied within ApplyAspectMarker()). | |
71c6e1e5 | 216 | Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); |
f9ba5c4d | 217 | |
218 | //! Assign new text aspect (will be applied within ApplyAspectText()). | |
71c6e1e5 | 219 | Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); |
2166f0fa | 220 | |
f9ba5c4d | 221 | //! Apply line aspect. |
222 | //! @return aspect set by SetAspectLine() | |
223 | const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; } | |
224 | ||
225 | //! Apply face aspect. | |
226 | //! @return aspect set by SetAspectFace() | |
227 | Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace(); | |
228 | ||
229 | //! Apply marker aspect. | |
230 | //! @return aspect set by SetAspectMarker() | |
231 | Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker(); | |
232 | ||
233 | //! Apply text aspect. | |
234 | //! @return aspect set by SetAspectText() | |
235 | const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; } | |
2166f0fa | 236 | |
f9ba5c4d | 237 | //! Clear the applied aspect state to default values. |
34a44cbd | 238 | void ResetAppliedAspect(); |
239 | ||
bf75be98 | 240 | Standard_EXPORT Handle(OpenGl_Texture) DisableTexture(); |
241 | Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture, | |
242 | const Handle(Graphic3d_TextureParams)& theParams = NULL); | |
8625ef7e | 243 | const Handle(OpenGl_Texture)& ActiveTexture() const { return myTextureBound; } |
bf75be98 | 244 | |
4269bd1b | 245 | //! Set filter for restricting rendering of particular elements. |
246 | //! Filter can be applied for rendering passes used by recursive | |
247 | //! rendering algorithms for rendering elements of groups. | |
248 | //! @param theFilter [in] the filter instance. | |
249 | inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) | |
250 | { | |
5322131b | 251 | myRenderFilter = theFilter; |
4269bd1b | 252 | } |
253 | ||
254 | //! Get rendering filter. | |
255 | //! @return filter instance. | |
5322131b | 256 | inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const |
257 | { | |
258 | return myRenderFilter; | |
4269bd1b | 259 | } |
260 | ||
261 | //! @return applied view matrix. | |
262 | inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; } | |
263 | ||
264 | //! @return applied model structure matrix. | |
265 | inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } | |
266 | ||
550f3b8b | 267 | //! Sets and applies current polygon offset. |
b6472664 | 268 | void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams); |
550f3b8b | 269 | |
6d0e6be5 | 270 | //! Returns currently applied polygon offset parameters. |
b6472664 | 271 | const Graphic3d_PolygonOffset& AppliedPolygonOffset() { return myPolygonOffsetApplied; } |
550f3b8b | 272 | |
f8ae3605 | 273 | //! Returns capping algorithm rendering filter. |
274 | const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const | |
275 | { | |
276 | return myDefaultCappingAlgoFilter; | |
277 | } | |
278 | ||
279 | //! Returns face aspect for none culling mode. | |
280 | const OpenGl_AspectFace& NoneCulling() const | |
281 | { | |
282 | return myNoneCulling; | |
283 | } | |
284 | ||
285 | //! Returns face aspect for front face culling mode. | |
286 | const OpenGl_AspectFace& FrontCulling() const | |
287 | { | |
288 | return myFrontCulling; | |
289 | } | |
290 | ||
83da37b1 | 291 | //! Sets a new environment texture. |
292 | void SetEnvironmentTexture (const Handle(OpenGl_Texture)& theTexture) | |
293 | { | |
294 | myEnvironmentTexture = theTexture; | |
295 | } | |
296 | ||
297 | //! Returns environment texture. | |
298 | const Handle(OpenGl_Texture)& EnvironmentTexture() const | |
299 | { | |
300 | return myEnvironmentTexture; | |
301 | } | |
302 | ||
2166f0fa SK |
303 | protected: |
304 | ||
bf75be98 | 305 | void setTextureParams (Handle(OpenGl_Texture)& theTexture, |
306 | const Handle(Graphic3d_TextureParams)& theParams); | |
2166f0fa | 307 | |
91c60b57 | 308 | protected: //! @name protected fields |
265d4508 | 309 | |
c357e426 | 310 | OpenGl_View* myView; |
311 | Handle(OpenGl_Window) myWindow; | |
312 | Handle(OpenGl_Context) myGlContext; | |
c357e426 | 313 | Standard_Boolean myUseZBuffer; |
314 | Standard_Boolean myUseDepthWrite; | |
f8ae3605 | 315 | Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter; |
316 | OpenGl_AspectFace myNoneCulling; | |
317 | OpenGl_AspectFace myFrontCulling; | |
318 | ||
bf75be98 | 319 | protected: //! @name fields related to status |
320 | ||
4269bd1b | 321 | Handle(OpenGl_RenderFilter) myRenderFilter; |
bf75be98 | 322 | Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture) |
f9ba5c4d | 323 | const OpenGl_AspectLine* myAspectLineSet; |
324 | const OpenGl_AspectFace* myAspectFaceSet; | |
b6472664 | 325 | Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied; |
f9ba5c4d | 326 | const OpenGl_AspectMarker* myAspectMarkerSet; |
b6472664 | 327 | Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied; |
f9ba5c4d | 328 | const OpenGl_AspectText* myAspectTextSet; |
8613985b | 329 | Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL; |
2166f0fa | 330 | |
2166f0fa SK |
331 | const OpenGl_Matrix* ViewMatrix_applied; |
332 | const OpenGl_Matrix* StructureMatrix_applied; | |
333 | ||
b6472664 | 334 | bool myToAllowFaceCulling; //!< allow back face culling |
f838dac4 | 335 | Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style |
0adbd30f | 336 | |
550f3b8b | 337 | OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations |
0f8c0fb8 | 338 | |
b6472664 | 339 | Graphic3d_PolygonOffset myPolygonOffsetApplied; //!< currently applied polygon offset |
2166f0fa | 340 | |
550f3b8b | 341 | OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect |
bf75be98 | 342 | |
83da37b1 | 343 | Handle(OpenGl_Texture) myEnvironmentTexture; |
344 | ||
bf75be98 | 345 | public: //! @name type definition |
2166f0fa | 346 | |
92efcf78 | 347 | DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) |
1c35b92f | 348 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
349 | |
350 | }; | |
351 | ||
bf75be98 | 352 | #endif // _OpenGl_Workspace_Header |