1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_Workspace_Header
17 #define _OpenGl_Workspace_Header
19 #include <Graphic3d_BufferType.hxx>
21 #include <OpenGl_AspectFace.hxx>
22 #include <OpenGl_CappingAlgo.hxx>
23 #include <OpenGl_FrameBuffer.hxx>
24 #include <OpenGl_Material.hxx>
25 #include <OpenGl_Matrix.hxx>
26 #include <OpenGl_RenderFilter.hxx>
27 #include <OpenGl_ShaderObject.hxx>
28 #include <OpenGl_ShaderProgram.hxx>
29 #include <OpenGl_TextParam.hxx>
30 #include <OpenGl_TextureBufferArb.hxx>
31 #include <OpenGl_Vec.hxx>
32 #include <OpenGl_Window.hxx>
37 class OpenGl_RaytraceFilter;
38 DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
40 //! Graphical ray-tracing filter.
41 //! Filters out all raytracable structures.
42 class OpenGl_RaytraceFilter : public OpenGl_RenderFilter
46 //! Default constructor.
47 OpenGl_RaytraceFilter() {}
49 //! Returns the previously set filter.
50 const Handle(OpenGl_RenderFilter)& PrevRenderFilter()
52 return myPrevRenderFilter;
55 //! Remembers the previously set filter.
56 void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
58 myPrevRenderFilter = theFilter;
61 //! Checks whether the element can be rendered or not.
62 //! @param theElement [in] the element to check.
63 //! @return True if element can be rendered.
64 virtual Standard_Boolean ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
65 const OpenGl_Element* theElement) Standard_OVERRIDE;
69 Handle(OpenGl_RenderFilter) myPrevRenderFilter;
73 DEFINE_STANDARD_RTTIEXT(OpenGl_RaytraceFilter,OpenGl_RenderFilter)
76 class OpenGl_Workspace;
77 DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient)
79 //! Rendering workspace.
80 //! Provides methods to render primitives and maintain GL state.
81 class OpenGl_Workspace : public Standard_Transient
85 //! Constructor of rendering workspace.
86 Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow);
89 virtual ~OpenGl_Workspace() {}
91 //! Activate rendering context.
92 Standard_EXPORT Standard_Boolean Activate();
94 OpenGl_View* View() const { return myView; }
96 const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; }
98 Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
100 Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo);
102 Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo,
103 Image_PixMap& theImage,
104 const Graphic3d_BufferType& theBufferType);
106 Standard_EXPORT Standard_Integer Width() const;
108 Standard_EXPORT Standard_Integer Height() const;
110 //! Setup Z-buffer usage flag (without affecting GL state!).
111 //! Returns previously set flag.
112 Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse)
114 const Standard_Boolean wasUsed = myUseZBuffer;
115 myUseZBuffer = theToUse;
119 //! @return true if usage of Z buffer is enabled.
120 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
122 //! @return true if depth writing is enabled.
123 Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
125 //! @return true if clipping algorithm enabled
126 Standard_EXPORT Standard_Boolean IsCullingEnabled() const;
128 //// RELATED TO STATUS ////
130 //! Return true if active group might activate face culling (e.g. primitives are closed).
131 bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
133 //! Allow or disallow face culling.
134 //! This call does NOT affect current state of back face culling;
135 //! ApplyAspectFace() should be called to update state.
136 void SetAllowFaceCulling (bool theToAllow) { myToAllowFaceCulling = theToAllow; }
138 //! Return true if following structures should apply highlight color.
139 bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
141 //! Return highlight style.
142 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
144 //! Set highlight style.
145 void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) { myHighlightStyle = theStyle; }
147 //! Return line color taking into account highlight flag.
148 const OpenGl_Vec4& LineColor() const
150 return !myHighlightStyle.IsNull()
151 ? myHighlightStyle->ColorRGBA()
152 : myAspectLineSet->Aspect()->ColorRGBA();
155 //! Return edge color taking into account highlight flag.
156 const OpenGl_Vec4& EdgeColor() const
158 return !myHighlightStyle.IsNull()
159 ? myHighlightStyle->ColorRGBA()
160 : myAspectFaceSet->AspectEdge()->Aspect()->ColorRGBA();
163 //! Return marker color taking into account highlight flag.
164 const OpenGl_Vec4& MarkerColor() const
166 return !myHighlightStyle.IsNull()
167 ? myHighlightStyle->ColorRGBA()
168 : myAspectMarkerSet->Aspect()->ColorRGBA();
171 //! Return Interior color taking into account highlight flag.
172 const OpenGl_Vec4& InteriorColor() const
174 return !myHighlightStyle.IsNull()
175 ? myHighlightStyle->ColorRGBA()
176 : myAspectFaceSet->Aspect()->InteriorColorRGBA();
179 //! Return text color taking into account highlight flag.
180 const OpenGl_Vec4& TextColor() const
182 return !myHighlightStyle.IsNull()
183 ? myHighlightStyle->ColorRGBA()
184 : myAspectTextSet->Aspect()->ColorRGBA();
187 //! Return text Subtitle color taking into account highlight flag.
188 const OpenGl_Vec4& TextSubtitleColor() const
190 return !myHighlightStyle.IsNull()
191 ? myHighlightStyle->ColorRGBA()
192 : myAspectTextSet->Aspect()->ColorSubTitleRGBA();
195 //! Currently set line aspect (can differ from applied).
196 const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; }
198 //! Currently set face aspect (can differ from applied).
199 const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; }
201 //! Currently set marker aspect (can differ from applied).
202 const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; }
204 //! Currently set text aspect (can differ from applied).
205 const OpenGl_AspectText* AspectText() const { return myAspectTextSet; }
207 //! Assign new line aspect (will be applied within ApplyAspectLine()).
208 Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
210 //! Assign new face aspect (will be applied within ApplyAspectFace()).
211 Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
213 //! Assign new marker aspect (will be applied within ApplyAspectMarker()).
214 Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
216 //! Assign new text aspect (will be applied within ApplyAspectText()).
217 Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
219 //! Apply line aspect.
220 //! @return aspect set by SetAspectLine()
221 const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; }
223 //! Apply face aspect.
224 //! @return aspect set by SetAspectFace()
225 Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace();
227 //! Apply marker aspect.
228 //! @return aspect set by SetAspectMarker()
229 Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker();
231 //! Apply text aspect.
232 //! @return aspect set by SetAspectText()
233 const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; }
235 //! Clear the applied aspect state to default values.
236 void ResetAppliedAspect();
238 //! Set filter for restricting rendering of particular elements.
239 //! Filter can be applied for rendering passes used by recursive
240 //! rendering algorithms for rendering elements of groups.
241 //! @param theFilter [in] the filter instance.
242 inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
244 myRenderFilter = theFilter;
247 //! Get rendering filter.
248 //! @return filter instance.
249 inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const
251 return myRenderFilter;
254 //! @return applied view matrix.
255 inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
257 //! @return applied model structure matrix.
258 inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
260 //! Returns face aspect for textured font rendering.
261 const OpenGl_AspectFace& FontFaceAspect() const { return myFontFaceAspect; }
263 //! Returns capping algorithm rendering filter.
264 const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const { return myDefaultCappingAlgoFilter; }
266 //! Returns face aspect for none culling mode.
267 const OpenGl_AspectFace& NoneCulling() const { return myNoneCulling; }
269 //! Returns face aspect for front face culling mode.
270 const OpenGl_AspectFace& FrontCulling() const { return myFrontCulling; }
272 //! Sets a new environment texture.
273 void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
275 //! Returns environment texture.
276 const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; }
278 protected: //! @name protected fields
281 Handle(OpenGl_Window) myWindow;
282 Handle(OpenGl_Context) myGlContext;
283 Standard_Boolean myUseZBuffer;
284 Standard_Boolean myUseDepthWrite;
285 Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter;
286 OpenGl_AspectFace myNoneCulling;
287 OpenGl_AspectFace myFrontCulling;
288 OpenGl_AspectFace myFontFaceAspect;
290 protected: //! @name fields related to status
292 Handle(OpenGl_RenderFilter) myRenderFilter;
293 const OpenGl_AspectLine* myAspectLineSet;
294 const OpenGl_AspectFace* myAspectFaceSet;
295 Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied;
296 const OpenGl_AspectMarker* myAspectMarkerSet;
297 Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied;
298 const OpenGl_AspectText* myAspectTextSet;
299 Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
301 const OpenGl_Matrix* ViewMatrix_applied;
302 const OpenGl_Matrix* StructureMatrix_applied;
304 bool myToAllowFaceCulling; //!< allow back face culling
305 Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
307 OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
309 OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
311 Handle(OpenGl_TextureSet) myEnvironmentTexture;
313 public: //! @name type definition
315 DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
316 DEFINE_STANDARD_ALLOC
320 #endif // _OpenGl_Workspace_Header