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 | |
5b111128 | 38 | class OpenGl_View; |
692613e5 | 39 | class Image_PixMap; |
2166f0fa | 40 | |
0adbd30f | 41 | //! OpenGL material definition |
42 | struct OpenGl_Material | |
43 | { | |
44 | ||
45 | OpenGl_Vec4 Ambient; //!< ambient reflection coefficient | |
46 | OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient | |
47 | OpenGl_Vec4 Specular; //!< glossy reflection coefficient | |
48 | OpenGl_Vec4 Emission; //!< material emission | |
49 | OpenGl_Vec4 Params; //!< extra packed parameters | |
50 | ||
51 | Standard_ShortReal Shine() const { return Params.x(); } | |
52 | Standard_ShortReal& ChangeShine() { return Params.x(); } | |
53 | ||
54 | Standard_ShortReal Transparency() const { return Params.y(); } | |
55 | Standard_ShortReal& ChangeTransparency() { return Params.y(); } | |
56 | ||
f9ba5c4d | 57 | //! Set material color. |
58 | void SetColor (const OpenGl_Vec4& theColor) | |
59 | { | |
60 | // apply the same formula as in Graphic3d_MaterialAspect::SetColor() | |
61 | Ambient.xyz() = theColor.rgb() * 0.25f; | |
62 | Diffuse.xyz() = theColor.rgb(); | |
63 | } | |
64 | ||
0adbd30f | 65 | //! Initialize material |
66 | void Init (const OPENGL_SURF_PROP& theProps); | |
67 | ||
68 | //! Returns packed (serialized) representation of material properties | |
69 | const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); } | |
70 | static Standard_Integer NbOfVec4() { return 5; } | |
71 | ||
72 | }; | |
73 | ||
c04c30b3 | 74 | class OpenGl_RaytraceFilter; |
a89742cf | 75 | DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter) |
76 | ||
25ef750e | 77 | //! Graphical ray-tracing filter. |
a89742cf | 78 | //! Filters out all raytracable structures. |
79 | class OpenGl_RaytraceFilter : public OpenGl_RenderFilter | |
80 | { | |
81 | public: | |
82 | ||
83 | //! Default constructor. | |
84 | OpenGl_RaytraceFilter() {} | |
85 | ||
91c60b57 | 86 | //! Returns the previously set filter. |
87 | const Handle(OpenGl_RenderFilter)& PrevRenderFilter() | |
88 | { | |
89 | return myPrevRenderFilter; | |
90 | } | |
91 | ||
a89742cf | 92 | //! Remembers the previously set filter. |
91c60b57 | 93 | void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) |
a89742cf | 94 | { |
95 | myPrevRenderFilter = theFilter; | |
96 | } | |
97 | ||
98 | //! Checks whether the element can be rendered or not. | |
99 | //! @param theElement [in] the element to check. | |
100 | //! @return True if element can be rendered. | |
79104795 | 101 | virtual Standard_Boolean CanRender (const OpenGl_Element* theElement) Standard_OVERRIDE; |
a89742cf | 102 | |
103 | private: | |
104 | ||
105 | Handle(OpenGl_RenderFilter) myPrevRenderFilter; | |
106 | ||
107 | public: | |
108 | ||
92efcf78 | 109 | DEFINE_STANDARD_RTTIEXT(OpenGl_RaytraceFilter,OpenGl_RenderFilter) |
a89742cf | 110 | }; |
111 | ||
c04c30b3 | 112 | class OpenGl_Workspace; |
c357e426 | 113 | DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient) |
c04c30b3 | 114 | |
c357e426 | 115 | //! Rendering workspace. |
e276548b | 116 | //! Provides methods to render primitives and maintain GL state. |
c357e426 | 117 | class OpenGl_Workspace : public Standard_Transient |
2166f0fa SK |
118 | { |
119 | public: | |
120 | ||
c357e426 | 121 | //! Constructor of rendering workspace. |
122 | Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow); | |
2166f0fa SK |
123 | |
124 | //! Destructor | |
62e1beed | 125 | Standard_EXPORT virtual ~OpenGl_Workspace(); |
2166f0fa | 126 | |
c357e426 | 127 | //! Activate rendering context. |
128 | Standard_EXPORT Standard_Boolean Activate(); | |
a272ed94 | 129 | |
c357e426 | 130 | OpenGl_View* View() const { return myView; } |
2166f0fa | 131 | |
c357e426 | 132 | const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; } |
2166f0fa | 133 | |
b128c892 | 134 | Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight); |
679ecdee | 135 | |
b128c892 | 136 | Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo); |
a174a3c5 | 137 | |
b128c892 | 138 | Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo, |
139 | Image_PixMap& theImage, | |
140 | const Graphic3d_BufferType& theBufferType); | |
2166f0fa | 141 | |
c357e426 | 142 | Standard_EXPORT Standard_Integer Width() const; |
143 | ||
144 | Standard_EXPORT Standard_Integer Height() const; | |
145 | ||
eae454e3 | 146 | //! Setup Z-buffer usage flag (without affecting GL state!). |
147 | //! Returns previously set flag. | |
148 | Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse) | |
149 | { | |
150 | const Standard_Boolean wasUsed = myUseZBuffer; | |
151 | myUseZBuffer = theToUse; | |
152 | return wasUsed; | |
153 | } | |
154 | ||
c357e426 | 155 | Handle(OpenGl_PrinterContext)& PrinterContext() { return myPrintContext; } |
156 | ||
157 | //! @return true if usage of Z buffer is enabled. | |
158 | Standard_Boolean& UseZBuffer() { return myUseZBuffer; } | |
159 | ||
160 | //! @return true if depth writing is enabled. | |
eae454e3 | 161 | Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; } |
2166f0fa | 162 | |
c357e426 | 163 | //! @return true if usage of GL light is enabled. |
164 | Standard_EXPORT Standard_Boolean UseGLLight() const; | |
73192b37 | 165 | |
c357e426 | 166 | //! @return true if antialiasing is enabled. |
167 | Standard_EXPORT Standard_Integer AntiAliasingMode() const; | |
2166f0fa | 168 | |
c357e426 | 169 | //! @return true if clipping algorithm enabled |
170 | Standard_EXPORT Standard_Boolean IsCullingEnabled() const; | |
171 | ||
172 | Standard_Integer NamedStatus; | |
173 | ||
174 | //// RELATED TO STATUS //// | |
2166f0fa | 175 | |
2166f0fa SK |
176 | const TEL_COLOUR* HighlightColor; |
177 | ||
f9ba5c4d | 178 | //! Return true if following structures should apply highlight color. |
179 | bool ToHighlight() const { return myToHighlight; } | |
180 | ||
181 | //! Set highlight. | |
182 | void SetHighlight (bool theToHighlight) { myToHighlight = theToHighlight; } | |
183 | ||
184 | //! Return line color taking into account highlight flag. | |
185 | const TEL_COLOUR& LineColor() const | |
186 | { | |
187 | return myToHighlight | |
188 | ? *HighlightColor | |
189 | : myAspectLineSet->Color(); | |
190 | } | |
191 | ||
192 | //! Return edge color taking into account highlight flag. | |
193 | const TEL_COLOUR& EdgeColor() const | |
194 | { | |
195 | return myToHighlight | |
196 | ? *HighlightColor | |
197 | : myAspectFaceSet->AspectEdge()->Color(); | |
198 | } | |
199 | ||
200 | //! Return marker color taking into account highlight flag. | |
201 | const TEL_COLOUR& MarkerColor() const | |
202 | { | |
203 | return myToHighlight | |
204 | ? *HighlightColor | |
205 | : myAspectMarkerSet->Color(); | |
206 | } | |
207 | ||
208 | //! Return Interior color taking into account highlight flag. | |
209 | const TEL_COLOUR& InteriorColor() const | |
210 | { | |
211 | return myToHighlight | |
212 | ? *HighlightColor | |
213 | : myAspectFaceSet->IntFront().matcol; | |
214 | } | |
215 | ||
216 | //! Return text color taking into account highlight flag. | |
217 | const TEL_COLOUR& TextColor() const | |
218 | { | |
219 | return myToHighlight | |
220 | ? *HighlightColor | |
221 | : myAspectTextSet->Color(); | |
222 | } | |
223 | ||
224 | //! Return text Subtitle color taking into account highlight flag. | |
225 | const TEL_COLOUR& TextSubtitleColor() const | |
226 | { | |
227 | return myToHighlight | |
228 | ? *HighlightColor | |
229 | : myAspectTextSet->SubtitleColor(); | |
230 | } | |
231 | ||
232 | //! Currently set line aspect (can differ from applied). | |
233 | const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; } | |
234 | ||
235 | //! Currently set face aspect (can differ from applied). | |
236 | const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; } | |
237 | ||
238 | //! Currently set marker aspect (can differ from applied). | |
239 | const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; } | |
240 | ||
241 | //! Currently set text aspect (can differ from applied). | |
242 | const OpenGl_AspectText* AspectText() const { return myAspectTextSet; } | |
243 | ||
244 | //! Assign new line aspect (will be applied within ApplyAspectLine()). | |
71c6e1e5 | 245 | Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); |
f9ba5c4d | 246 | |
247 | //! Assign new face aspect (will be applied within ApplyAspectFace()). | |
71c6e1e5 | 248 | Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); |
f9ba5c4d | 249 | |
250 | //! Assign new marker aspect (will be applied within ApplyAspectMarker()). | |
71c6e1e5 | 251 | Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); |
f9ba5c4d | 252 | |
253 | //! Assign new text aspect (will be applied within ApplyAspectText()). | |
71c6e1e5 | 254 | Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); |
2166f0fa | 255 | |
f9ba5c4d | 256 | //! Apply line aspect. |
257 | //! @return aspect set by SetAspectLine() | |
258 | const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; } | |
259 | ||
260 | //! Apply face aspect. | |
261 | //! @return aspect set by SetAspectFace() | |
262 | Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace(); | |
263 | ||
264 | //! Apply marker aspect. | |
265 | //! @return aspect set by SetAspectMarker() | |
266 | Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker(); | |
267 | ||
268 | //! Apply text aspect. | |
269 | //! @return aspect set by SetAspectText() | |
270 | const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; } | |
2166f0fa | 271 | |
f9ba5c4d | 272 | //! Clear the applied aspect state to default values. |
34a44cbd | 273 | void ResetAppliedAspect(); |
274 | ||
bf75be98 | 275 | Standard_EXPORT Handle(OpenGl_Texture) DisableTexture(); |
276 | Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture, | |
277 | const Handle(Graphic3d_TextureParams)& theParams = NULL); | |
8625ef7e | 278 | const Handle(OpenGl_Texture)& ActiveTexture() const { return myTextureBound; } |
bf75be98 | 279 | |
4269bd1b | 280 | //! Set filter for restricting rendering of particular elements. |
281 | //! Filter can be applied for rendering passes used by recursive | |
282 | //! rendering algorithms for rendering elements of groups. | |
283 | //! @param theFilter [in] the filter instance. | |
284 | inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) | |
285 | { | |
5322131b | 286 | myRenderFilter = theFilter; |
4269bd1b | 287 | } |
288 | ||
289 | //! Get rendering filter. | |
290 | //! @return filter instance. | |
5322131b | 291 | inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const |
292 | { | |
293 | return myRenderFilter; | |
4269bd1b | 294 | } |
295 | ||
296 | //! @return applied view matrix. | |
297 | inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; } | |
298 | ||
299 | //! @return applied model structure matrix. | |
300 | inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } | |
301 | ||
550f3b8b | 302 | //! Sets and applies current polygon offset. |
303 | void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits); | |
304 | ||
305 | //! Returns currently applied polygon offset params. | |
306 | const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; } | |
307 | ||
f8ae3605 | 308 | //! Returns capping algorithm rendering filter. |
309 | const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const | |
310 | { | |
311 | return myDefaultCappingAlgoFilter; | |
312 | } | |
313 | ||
314 | //! Returns face aspect for none culling mode. | |
315 | const OpenGl_AspectFace& NoneCulling() const | |
316 | { | |
317 | return myNoneCulling; | |
318 | } | |
319 | ||
320 | //! Returns face aspect for front face culling mode. | |
321 | const OpenGl_AspectFace& FrontCulling() const | |
322 | { | |
323 | return myFrontCulling; | |
324 | } | |
325 | ||
83da37b1 | 326 | //! Sets a new environment texture. |
327 | void SetEnvironmentTexture (const Handle(OpenGl_Texture)& theTexture) | |
328 | { | |
329 | myEnvironmentTexture = theTexture; | |
330 | } | |
331 | ||
332 | //! Returns environment texture. | |
333 | const Handle(OpenGl_Texture)& EnvironmentTexture() const | |
334 | { | |
335 | return myEnvironmentTexture; | |
336 | } | |
337 | ||
2166f0fa SK |
338 | protected: |
339 | ||
0adbd30f | 340 | void updateMaterial (const int theFlag); |
2166f0fa | 341 | |
bf75be98 | 342 | void setTextureParams (Handle(OpenGl_Texture)& theTexture, |
343 | const Handle(Graphic3d_TextureParams)& theParams); | |
2166f0fa | 344 | |
91c60b57 | 345 | protected: //! @name protected fields |
265d4508 | 346 | |
c357e426 | 347 | OpenGl_View* myView; |
348 | Handle(OpenGl_Window) myWindow; | |
349 | Handle(OpenGl_Context) myGlContext; | |
350 | Handle(OpenGl_PrinterContext) myPrintContext; | |
351 | Handle(OpenGl_LineAttributes) myLineAttribs; | |
352 | Standard_Integer myAntiAliasingMode; | |
353 | Standard_Boolean myUseZBuffer; | |
354 | Standard_Boolean myUseDepthWrite; | |
355 | Standard_Boolean myUseGLLight; | |
f8ae3605 | 356 | Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter; |
357 | OpenGl_AspectFace myNoneCulling; | |
358 | OpenGl_AspectFace myFrontCulling; | |
359 | ||
bf75be98 | 360 | protected: //! @name fields related to status |
361 | ||
4269bd1b | 362 | Handle(OpenGl_RenderFilter) myRenderFilter; |
bf75be98 | 363 | Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture) |
f9ba5c4d | 364 | const OpenGl_AspectLine* myAspectLineSet; |
365 | const OpenGl_AspectFace* myAspectFaceSet; | |
366 | const OpenGl_AspectFace* myAspectFaceApplied; | |
367 | const OpenGl_AspectMarker* myAspectMarkerSet; | |
368 | const OpenGl_AspectMarker* myAspectMarkerApplied; | |
369 | const OpenGl_AspectText* myAspectTextSet; | |
370 | bool myAspectFaceAppliedWithHL; | |
2166f0fa | 371 | |
2166f0fa SK |
372 | const OpenGl_Matrix* ViewMatrix_applied; |
373 | const OpenGl_Matrix* StructureMatrix_applied; | |
374 | ||
3b1817a9 | 375 | OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates) |
376 | OpenGl_Material myMatBack; //!< current back material state | |
377 | OpenGl_Material myMatTmp; //!< temporary variable | |
378 | TelCullMode myCullingMode; //!< back face culling mode, applied from face aspect | |
f9ba5c4d | 379 | bool myToHighlight; //!< flag indicating highlighting mode |
0adbd30f | 380 | |
550f3b8b | 381 | OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations |
0f8c0fb8 | 382 | |
550f3b8b | 383 | TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset. |
2166f0fa | 384 | |
550f3b8b | 385 | OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect |
bf75be98 | 386 | |
83da37b1 | 387 | Handle(OpenGl_Texture) myEnvironmentTexture; |
388 | ||
bf75be98 | 389 | public: //! @name type definition |
2166f0fa | 390 | |
92efcf78 | 391 | DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) |
1c35b92f | 392 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
393 | |
394 | }; | |
395 | ||
bf75be98 | 396 | #endif // _OpenGl_Workspace_Header |