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 | |
2166f0fa | 21 | #include <InterfaceGraphic_Graphic3d.hxx> |
1981cb22 | 22 | |
bf75be98 | 23 | #include <OpenGl_AspectFace.hxx> |
c357e426 | 24 | #include <OpenGl_CappingAlgo.hxx> |
fc73a202 | 25 | #include <OpenGl_FrameBuffer.hxx> |
c357e426 | 26 | #include <OpenGl_LineAttributes.hxx> |
2166f0fa SK |
27 | #include <OpenGl_Matrix.hxx> |
28 | #include <OpenGl_NamedStatus.hxx> | |
a174a3c5 | 29 | #include <OpenGl_PrinterContext.hxx> |
4269bd1b | 30 | #include <OpenGl_RenderFilter.hxx> |
fc73a202 | 31 | #include <OpenGl_ShaderObject.hxx> |
32 | #include <OpenGl_ShaderProgram.hxx> | |
c357e426 | 33 | #include <OpenGl_TextParam.hxx> |
fc73a202 | 34 | #include <OpenGl_TextureBufferArb.hxx> |
c357e426 | 35 | #include <OpenGl_Vec.hxx> |
36 | #include <OpenGl_Window.hxx> | |
fc73a202 | 37 | |
2166f0fa | 38 | class OpenGl_AspectLine; |
2166f0fa SK |
39 | class OpenGl_AspectMarker; |
40 | class OpenGl_AspectText; | |
4269bd1b | 41 | class OpenGl_Element; |
5b111128 | 42 | class OpenGl_View; |
692613e5 | 43 | class Image_PixMap; |
2166f0fa | 44 | |
0adbd30f | 45 | //! OpenGL material definition |
46 | struct OpenGl_Material | |
47 | { | |
48 | ||
49 | OpenGl_Vec4 Ambient; //!< ambient reflection coefficient | |
50 | OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient | |
51 | OpenGl_Vec4 Specular; //!< glossy reflection coefficient | |
52 | OpenGl_Vec4 Emission; //!< material emission | |
53 | OpenGl_Vec4 Params; //!< extra packed parameters | |
54 | ||
55 | Standard_ShortReal Shine() const { return Params.x(); } | |
56 | Standard_ShortReal& ChangeShine() { return Params.x(); } | |
57 | ||
58 | Standard_ShortReal Transparency() const { return Params.y(); } | |
59 | Standard_ShortReal& ChangeTransparency() { return Params.y(); } | |
60 | ||
61 | //! Initialize material | |
62 | void Init (const OPENGL_SURF_PROP& theProps); | |
63 | ||
64 | //! Returns packed (serialized) representation of material properties | |
65 | const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); } | |
66 | static Standard_Integer NbOfVec4() { return 5; } | |
67 | ||
68 | }; | |
69 | ||
c04c30b3 | 70 | class OpenGl_RaytraceFilter; |
a89742cf | 71 | DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter) |
72 | ||
25ef750e | 73 | //! Graphical ray-tracing filter. |
a89742cf | 74 | //! Filters out all raytracable structures. |
75 | class OpenGl_RaytraceFilter : public OpenGl_RenderFilter | |
76 | { | |
77 | public: | |
78 | ||
79 | //! Default constructor. | |
80 | OpenGl_RaytraceFilter() {} | |
81 | ||
91c60b57 | 82 | //! Returns the previously set filter. |
83 | const Handle(OpenGl_RenderFilter)& PrevRenderFilter() | |
84 | { | |
85 | return myPrevRenderFilter; | |
86 | } | |
87 | ||
a89742cf | 88 | //! Remembers the previously set filter. |
91c60b57 | 89 | void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) |
a89742cf | 90 | { |
91 | myPrevRenderFilter = theFilter; | |
92 | } | |
93 | ||
94 | //! Checks whether the element can be rendered or not. | |
95 | //! @param theElement [in] the element to check. | |
96 | //! @return True if element can be rendered. | |
79104795 | 97 | virtual Standard_Boolean CanRender (const OpenGl_Element* theElement) Standard_OVERRIDE; |
a89742cf | 98 | |
99 | private: | |
100 | ||
101 | Handle(OpenGl_RenderFilter) myPrevRenderFilter; | |
102 | ||
103 | public: | |
104 | ||
92efcf78 | 105 | DEFINE_STANDARD_RTTIEXT(OpenGl_RaytraceFilter,OpenGl_RenderFilter) |
a89742cf | 106 | }; |
107 | ||
c04c30b3 | 108 | class OpenGl_Workspace; |
c357e426 | 109 | DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient) |
c04c30b3 | 110 | |
c357e426 | 111 | //! Rendering workspace. |
e276548b | 112 | //! Provides methods to render primitives and maintain GL state. |
c357e426 | 113 | class OpenGl_Workspace : public Standard_Transient |
2166f0fa SK |
114 | { |
115 | public: | |
116 | ||
c357e426 | 117 | //! Constructor of rendering workspace. |
118 | Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow); | |
2166f0fa SK |
119 | |
120 | //! Destructor | |
62e1beed | 121 | Standard_EXPORT virtual ~OpenGl_Workspace(); |
2166f0fa | 122 | |
c357e426 | 123 | //! Activate rendering context. |
124 | Standard_EXPORT Standard_Boolean Activate(); | |
a272ed94 | 125 | |
c357e426 | 126 | OpenGl_View* View() const { return myView; } |
2166f0fa | 127 | |
c357e426 | 128 | const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; } |
2166f0fa | 129 | |
b128c892 | 130 | Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight); |
679ecdee | 131 | |
b128c892 | 132 | Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo); |
a174a3c5 | 133 | |
b128c892 | 134 | Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo, |
135 | Image_PixMap& theImage, | |
136 | const Graphic3d_BufferType& theBufferType); | |
2166f0fa | 137 | |
c357e426 | 138 | Standard_EXPORT Standard_Integer Width() const; |
139 | ||
140 | Standard_EXPORT Standard_Integer Height() const; | |
141 | ||
eae454e3 | 142 | //! Setup Z-buffer usage flag (without affecting GL state!). |
143 | //! Returns previously set flag. | |
144 | Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse) | |
145 | { | |
146 | const Standard_Boolean wasUsed = myUseZBuffer; | |
147 | myUseZBuffer = theToUse; | |
148 | return wasUsed; | |
149 | } | |
150 | ||
c357e426 | 151 | Handle(OpenGl_PrinterContext)& PrinterContext() { return myPrintContext; } |
152 | ||
153 | //! @return true if usage of Z buffer is enabled. | |
154 | Standard_Boolean& UseZBuffer() { return myUseZBuffer; } | |
155 | ||
156 | //! @return true if depth writing is enabled. | |
eae454e3 | 157 | Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; } |
2166f0fa | 158 | |
c357e426 | 159 | //! @return true if usage of GL light is enabled. |
160 | Standard_EXPORT Standard_Boolean UseGLLight() const; | |
73192b37 | 161 | |
c357e426 | 162 | //! @return true if antialiasing is enabled. |
163 | Standard_EXPORT Standard_Integer AntiAliasingMode() const; | |
2166f0fa | 164 | |
c357e426 | 165 | //! @return true if clipping algorithm enabled |
166 | Standard_EXPORT Standard_Boolean IsCullingEnabled() const; | |
167 | ||
168 | Standard_Integer NamedStatus; | |
169 | ||
170 | //// RELATED TO STATUS //// | |
2166f0fa | 171 | |
2166f0fa SK |
172 | const TEL_COLOUR* HighlightColor; |
173 | ||
71c6e1e5 | 174 | Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); |
175 | Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); | |
176 | Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); | |
177 | Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); | |
2166f0fa | 178 | |
3946774d | 179 | //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW |
180 | Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply); | |
181 | Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply); | |
182 | Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply); | |
183 | Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply); | |
2166f0fa | 184 | |
34a44cbd | 185 | //! Clear the applied aspect state. |
186 | void ResetAppliedAspect(); | |
187 | ||
bf75be98 | 188 | Standard_EXPORT Handle(OpenGl_Texture) DisableTexture(); |
189 | Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture, | |
190 | const Handle(Graphic3d_TextureParams)& theParams = NULL); | |
8625ef7e | 191 | const Handle(OpenGl_Texture)& ActiveTexture() const { return myTextureBound; } |
bf75be98 | 192 | |
4269bd1b | 193 | //! Set filter for restricting rendering of particular elements. |
194 | //! Filter can be applied for rendering passes used by recursive | |
195 | //! rendering algorithms for rendering elements of groups. | |
196 | //! @param theFilter [in] the filter instance. | |
197 | inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) | |
198 | { | |
5322131b | 199 | myRenderFilter = theFilter; |
4269bd1b | 200 | } |
201 | ||
202 | //! Get rendering filter. | |
203 | //! @return filter instance. | |
5322131b | 204 | inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const |
205 | { | |
206 | return myRenderFilter; | |
4269bd1b | 207 | } |
208 | ||
209 | //! @return applied view matrix. | |
210 | inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; } | |
211 | ||
212 | //! @return applied model structure matrix. | |
213 | inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } | |
214 | ||
550f3b8b | 215 | //! Sets and applies current polygon offset. |
216 | void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits); | |
217 | ||
218 | //! Returns currently applied polygon offset params. | |
219 | const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; } | |
220 | ||
f8ae3605 | 221 | //! Returns capping algorithm rendering filter. |
222 | const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const | |
223 | { | |
224 | return myDefaultCappingAlgoFilter; | |
225 | } | |
226 | ||
227 | //! Returns face aspect for none culling mode. | |
228 | const OpenGl_AspectFace& NoneCulling() const | |
229 | { | |
230 | return myNoneCulling; | |
231 | } | |
232 | ||
233 | //! Returns face aspect for front face culling mode. | |
234 | const OpenGl_AspectFace& FrontCulling() const | |
235 | { | |
236 | return myFrontCulling; | |
237 | } | |
238 | ||
83da37b1 | 239 | //! Sets a new environment texture. |
240 | void SetEnvironmentTexture (const Handle(OpenGl_Texture)& theTexture) | |
241 | { | |
242 | myEnvironmentTexture = theTexture; | |
243 | } | |
244 | ||
245 | //! Returns environment texture. | |
246 | const Handle(OpenGl_Texture)& EnvironmentTexture() const | |
247 | { | |
248 | return myEnvironmentTexture; | |
249 | } | |
250 | ||
2166f0fa SK |
251 | protected: |
252 | ||
0adbd30f | 253 | void updateMaterial (const int theFlag); |
2166f0fa | 254 | |
bf75be98 | 255 | void setTextureParams (Handle(OpenGl_Texture)& theTexture, |
256 | const Handle(Graphic3d_TextureParams)& theParams); | |
2166f0fa | 257 | |
91c60b57 | 258 | protected: //! @name protected fields |
265d4508 | 259 | |
c357e426 | 260 | OpenGl_View* myView; |
261 | Handle(OpenGl_Window) myWindow; | |
262 | Handle(OpenGl_Context) myGlContext; | |
263 | Handle(OpenGl_PrinterContext) myPrintContext; | |
264 | Handle(OpenGl_LineAttributes) myLineAttribs; | |
265 | Standard_Integer myAntiAliasingMode; | |
266 | Standard_Boolean myUseZBuffer; | |
267 | Standard_Boolean myUseDepthWrite; | |
268 | Standard_Boolean myUseGLLight; | |
f8ae3605 | 269 | Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter; |
270 | OpenGl_AspectFace myNoneCulling; | |
271 | OpenGl_AspectFace myFrontCulling; | |
272 | ||
bf75be98 | 273 | protected: //! @name fields related to status |
274 | ||
4269bd1b | 275 | Handle(OpenGl_RenderFilter) myRenderFilter; |
bf75be98 | 276 | Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture) |
2166f0fa SK |
277 | const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied; |
278 | const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied; | |
279 | const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied; | |
280 | const OpenGl_AspectText *AspectText_set, *AspectText_applied; | |
281 | ||
2166f0fa SK |
282 | const OpenGl_Matrix* ViewMatrix_applied; |
283 | const OpenGl_Matrix* StructureMatrix_applied; | |
284 | ||
3b1817a9 | 285 | OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates) |
286 | OpenGl_Material myMatBack; //!< current back material state | |
287 | OpenGl_Material myMatTmp; //!< temporary variable | |
288 | TelCullMode myCullingMode; //!< back face culling mode, applied from face aspect | |
0adbd30f | 289 | |
550f3b8b | 290 | OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations |
0f8c0fb8 | 291 | |
550f3b8b | 292 | TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset. |
2166f0fa | 293 | |
550f3b8b | 294 | OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect |
bf75be98 | 295 | |
83da37b1 | 296 | Handle(OpenGl_Texture) myEnvironmentTexture; |
297 | ||
bf75be98 | 298 | public: //! @name type definition |
2166f0fa | 299 | |
92efcf78 | 300 | DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) |
1c35b92f | 301 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
302 | |
303 | }; | |
304 | ||
bf75be98 | 305 | #endif // _OpenGl_Workspace_Header |