0024391: Erased AIS object can not be displayed in AIS_InteractiveContext after AIS_I...
[occt.git] / src / OpenGl / OpenGl_AspectFace.hxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
2166f0fa
SK
20#ifndef _OpenGl_AspectFace_Header
21#define _OpenGl_AspectFace_Header
22
23#include <InterfaceGraphic_telem.hxx>
24#include <Aspect_InteriorStyle.hxx>
bf75be98 25#include <TCollection_AsciiString.hxx>
fd4a6963 26
30f0ad28 27#include <Handle_Graphic3d_TextureParams.hxx>
28#include <Handle_OpenGl_ShaderProgram.hxx>
29#include <Handle_OpenGl_Texture.hxx>
2166f0fa 30#include <OpenGl_AspectLine.hxx>
bf75be98 31#include <OpenGl_Element.hxx>
fd4a6963 32
4269bd1b 33#include <Graphic3d_AspectFillArea3d.hxx>
30f0ad28 34#include <Graphic3d_ShaderProgram_Handle.hxx>
35#include <Graphic3d_TextureMap.hxx>
2166f0fa
SK
36
37#define OPENGL_AMBIENT_MASK (1<<0)
38#define OPENGL_DIFFUSE_MASK (1<<1)
39#define OPENGL_SPECULAR_MASK (1<<2)
40#define OPENGL_EMISSIVE_MASK (1<<3)
41
bf75be98 42class CALL_DEF_CONTEXTFILLAREA;
43
2166f0fa
SK
44struct OPENGL_SURF_PROP
45{
46 float amb, diff, spec, emsv;
47 float trans, shine;
48 float env_reflexion;
49 int isphysic;
50 unsigned int color_mask;
51 TEL_COLOUR speccol, difcol, ambcol, emscol, matcol;
1c35b92f 52 DEFINE_STANDARD_ALLOC
2166f0fa
SK
53};
54
2166f0fa
SK
55class OpenGl_AspectFace : public OpenGl_Element
56{
2166f0fa 57
bf75be98 58public:
2166f0fa 59
bf75be98 60 OpenGl_AspectFace();
2166f0fa 61
fd4a6963 62 //! Copy parameters
63 void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
64 void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
65
66 //! Set edge aspect.
67 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
68 {
69 myAspectEdge = *theAspectEdge;
70 }
71
72 //! @return edge aspect.
73 const OpenGl_AspectLine* AspectEdge() const
74 {
75 return &myAspectEdge;
76 }
77
78 //! @return interior style
79 const Aspect_InteriorStyle InteriorStyle() const
80 {
81 return myInteriorStyle;
82 }
83
84 Aspect_InteriorStyle& ChangeInteriorStyle()
85 {
86 return myInteriorStyle;
87 }
88
89 //! @return edge on flag.
90 int Edge() const
91 {
92 return myEdge;
93 }
94
95 //! @return edge on flag.
96 int& ChangeEdge()
97 {
98 return myEdge;
99 }
100
101 //! @return hatch type.
102 int Hatch() const
103 {
104 return myHatch;
105 }
106
107 //! @return hatch type variable.
108 int& ChangeHatch()
109 {
110 return myHatch;
111 }
112
113 //! @return distinguishing mode.
114 int DistinguishingMode() const
115 {
116 return myDistinguishingMode;
117 }
118
119 //! @return distinguishing mode.
120 int& ChangeDistinguishingMode()
121 {
122 return myDistinguishingMode;
123 }
124
125 //! @return culling mode.
126 int CullingMode() const
127 {
128 return myCullingMode;
129 }
130
131 //! @return culling mode.
132 int& ChangeCullingMode()
133 {
134 return myCullingMode;
135 }
136
137 //! @return front material properties.
138 const OPENGL_SURF_PROP& IntFront() const
139 {
140 return myIntFront;
141 }
142
143 //! @return front material properties.
144 OPENGL_SURF_PROP& ChangeIntFront()
145 {
146 return myIntFront;
147 }
148
149 //! @return back material properties.
150 const OPENGL_SURF_PROP& IntBack() const
151 {
152 return myIntBack;
153 }
154
155 //! @return back material properties.
156 OPENGL_SURF_PROP& ChangeIntBack()
157 {
158 return myIntBack;
159 }
160
161 //! @return polygon offset parameters.
162 const TEL_POFFSET_PARAM& PolygonOffset() const
163 {
164 return myPolygonOffset;
165 }
166
167 //! @return polygon offset parameters.
168 TEL_POFFSET_PARAM& ChangePolygonOffset()
169 {
170 return myPolygonOffset;
171 }
172
173 //! @return texture mapping flag.
174 bool DoTextureMap() const
175 {
176 return myDoTextureMap;
177 }
178
179 //! @return texture mapping flag.
180 bool& ChangeDoTextureMap()
181 {
182 return myDoTextureMap;
183 }
184
30f0ad28 185 //! @return texture mapping parameters.
186 const Handle(Graphic3d_TextureParams)& TextureParams() const
187 {
188 return myTexture->GetParams();
189 }
190
fd4a6963 191 //! @return texture map.
192 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Workspace)& theWorkspace) const
193 {
30f0ad28 194 if (!myResources.IsTextureReady())
fd4a6963 195 {
30f0ad28 196 myResources.BuildTexture (theWorkspace, myTexture);
197 myResources.SetTextureReady();
fd4a6963 198 }
199
30f0ad28 200 return myResources.Texture;
fd4a6963 201 }
202
30f0ad28 203 //! Init and return OpenGl shader program resource.
204 //! @return shader program resource.
205 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
fd4a6963 206 {
30f0ad28 207 if (!myResources.IsShaderReady())
208 {
209 myResources.BuildShader (theWorkspace, myShaderProgram);
210 myResources.SetShaderReady();
211 }
212
213 return myResources.ShaderProgram;
fd4a6963 214 }
2166f0fa 215
5e27df78 216 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
217 virtual void Release (const Handle(OpenGl_Context)& theContext);
2166f0fa 218
fd4a6963 219protected:
bf75be98 220
221 void convertMaterial (const CALL_DEF_MATERIAL& theMat,
222 OPENGL_SURF_PROP& theSurf);
223
fd4a6963 224protected: //! @name ordinary aspect properties
225
226 Aspect_InteriorStyle myInteriorStyle;
227 int myEdge;
228 int myHatch;
229 int myDistinguishingMode;
230 int myCullingMode;
231 OPENGL_SURF_PROP myIntFront;
232 OPENGL_SURF_PROP myIntBack;
233 TEL_POFFSET_PARAM myPolygonOffset;
234 bool myDoTextureMap;
30f0ad28 235 Handle(Graphic3d_TextureMap) myTexture;
236 Handle(Graphic3d_ShaderProgram) myShaderProgram;
237
238protected:
239
240 //! OpenGl resources
241 mutable struct Resources
242 {
243 public:
244 Resources()
245 : myIsTextureReady (Standard_False),
246 myIsShaderReady (Standard_False) {}
247
248 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
249 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
250 void SetTextureReady() { myIsTextureReady = Standard_True; }
251 void SetShaderReady () { myIsShaderReady = Standard_True; }
f85399e5 252 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
253 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
30f0ad28 254
255 void BuildTexture (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_TextureMap)& theTexture);
256 void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
257
258 Handle(OpenGl_Texture) Texture;
259 TCollection_AsciiString TextureId;
260 Handle(OpenGl_ShaderProgram) ShaderProgram;
261 TCollection_AsciiString ShaderProgramId;
262
263 private:
bf75be98 264
30f0ad28 265 Standard_Boolean myIsTextureReady;
266 Standard_Boolean myIsShaderReady;
2166f0fa 267
30f0ad28 268 } myResources;
bf75be98 269
270protected:
271
fd4a6963 272 OpenGl_AspectLine myAspectEdge;
bf75be98 273
274public:
2166f0fa 275
1c35b92f 276 DEFINE_STANDARD_ALLOC
bf75be98 277
2166f0fa
SK
278};
279
280#endif //_OpenGl_AspectFace_Header