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