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