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