0026361: Visualization - move OpenGl_TextFormatter to Font_TextFormatter
[occt.git] / src / OpenGl / OpenGl_AspectFace.hxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 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_AspectFace_Header
17#define _OpenGl_AspectFace_Header
18
19#include <InterfaceGraphic_telem.hxx>
20#include <Aspect_InteriorStyle.hxx>
550f3b8b 21#include <Aspect_PolygonOffsetMode.hxx>
bf75be98 22#include <TCollection_AsciiString.hxx>
fd4a6963 23
2166f0fa 24#include <OpenGl_AspectLine.hxx>
bf75be98 25#include <OpenGl_Element.hxx>
fd4a6963 26
4269bd1b 27#include <Graphic3d_AspectFillArea3d.hxx>
b64d84be 28#include <Graphic3d_CAspectFillArea.hxx>
494782f6 29#include <Graphic3d_ShaderProgram.hxx>
30f0ad28 30#include <Graphic3d_TextureMap.hxx>
189f85a3 31#include <Graphic3d_BSDF.hxx>
2166f0fa 32
c04c30b3 33class OpenGl_Texture;
34
2166f0fa
SK
35#define OPENGL_AMBIENT_MASK (1<<0)
36#define OPENGL_DIFFUSE_MASK (1<<1)
37#define OPENGL_SPECULAR_MASK (1<<2)
38#define OPENGL_EMISSIVE_MASK (1<<3)
39
550f3b8b 40static const TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F };
41
2166f0fa
SK
42struct OPENGL_SURF_PROP
43{
189f85a3 44 Standard_ShortReal amb;
45 Standard_ShortReal diff;
46 Standard_ShortReal spec;
47 Standard_ShortReal emsv;
48
49 Standard_ShortReal trans;
50 Standard_ShortReal shine;
51 Standard_ShortReal index;
52
53 Standard_ShortReal env_reflexion;
54 Standard_Integer isphysic;
55
2166f0fa 56 unsigned int color_mask;
189f85a3 57
58 TEL_COLOUR speccol;
59 TEL_COLOUR difcol;
60 TEL_COLOUR ambcol;
61 TEL_COLOUR emscol;
62 TEL_COLOUR matcol;
63
64 Graphic3d_BSDF BSDF;
65
1c35b92f 66 DEFINE_STANDARD_ALLOC
2166f0fa
SK
67};
68
2166f0fa
SK
69class OpenGl_AspectFace : public OpenGl_Element
70{
2166f0fa 71
bf75be98 72public:
2166f0fa 73
595a42a4 74 Standard_EXPORT OpenGl_AspectFace();
2166f0fa 75
fd4a6963 76 //! Copy parameters
595a42a4 77 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
78 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
fd4a6963 79
80 //! Set edge aspect.
81 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
82 {
83 myAspectEdge = *theAspectEdge;
84 }
85
86 //! @return edge aspect.
87 const OpenGl_AspectLine* AspectEdge() const
88 {
89 return &myAspectEdge;
90 }
91
92 //! @return interior style
93 const Aspect_InteriorStyle InteriorStyle() const
94 {
95 return myInteriorStyle;
96 }
97
98 Aspect_InteriorStyle& ChangeInteriorStyle()
99 {
100 return myInteriorStyle;
101 }
102
103 //! @return edge on flag.
104 int Edge() const
105 {
106 return myEdge;
107 }
108
109 //! @return edge on flag.
110 int& ChangeEdge()
111 {
112 return myEdge;
113 }
114
115 //! @return hatch type.
116 int Hatch() const
117 {
118 return myHatch;
119 }
120
121 //! @return hatch type variable.
122 int& ChangeHatch()
123 {
124 return myHatch;
125 }
126
127 //! @return distinguishing mode.
128 int DistinguishingMode() const
129 {
130 return myDistinguishingMode;
131 }
132
133 //! @return distinguishing mode.
134 int& ChangeDistinguishingMode()
135 {
136 return myDistinguishingMode;
137 }
138
139 //! @return culling mode.
140 int CullingMode() const
141 {
142 return myCullingMode;
143 }
144
145 //! @return culling mode.
146 int& ChangeCullingMode()
147 {
148 return myCullingMode;
149 }
150
151 //! @return front material properties.
152 const OPENGL_SURF_PROP& IntFront() const
153 {
154 return myIntFront;
155 }
156
157 //! @return front material properties.
158 OPENGL_SURF_PROP& ChangeIntFront()
159 {
160 return myIntFront;
161 }
162
163 //! @return back material properties.
164 const OPENGL_SURF_PROP& IntBack() const
165 {
166 return myIntBack;
167 }
168
169 //! @return back material properties.
170 OPENGL_SURF_PROP& ChangeIntBack()
171 {
172 return myIntBack;
173 }
174
175 //! @return polygon offset parameters.
176 const TEL_POFFSET_PARAM& PolygonOffset() const
177 {
178 return myPolygonOffset;
179 }
180
181 //! @return polygon offset parameters.
182 TEL_POFFSET_PARAM& ChangePolygonOffset()
183 {
184 return myPolygonOffset;
185 }
186
187 //! @return texture mapping flag.
188 bool DoTextureMap() const
189 {
190 return myDoTextureMap;
191 }
192
193 //! @return texture mapping flag.
194 bool& ChangeDoTextureMap()
195 {
196 return myDoTextureMap;
197 }
198
30f0ad28 199 //! @return texture mapping parameters.
200 const Handle(Graphic3d_TextureParams)& TextureParams() const
201 {
202 return myTexture->GetParams();
203 }
204
fd4a6963 205 //! @return texture map.
8625ef7e 206 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Context)& theCtx) const
fd4a6963 207 {
30f0ad28 208 if (!myResources.IsTextureReady())
fd4a6963 209 {
8625ef7e 210 myResources.BuildTexture (theCtx, myTexture);
30f0ad28 211 myResources.SetTextureReady();
fd4a6963 212 }
213
30f0ad28 214 return myResources.Texture;
fd4a6963 215 }
216
30f0ad28 217 //! Init and return OpenGl shader program resource.
218 //! @return shader program resource.
8625ef7e 219 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
fd4a6963 220 {
30f0ad28 221 if (!myResources.IsShaderReady())
222 {
8625ef7e 223 myResources.BuildShader (theCtx, myShaderProgram);
30f0ad28 224 myResources.SetShaderReady();
225 }
226
227 return myResources.ShaderProgram;
fd4a6963 228 }
2166f0fa 229
595a42a4 230 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
10b9c7df 231 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
2166f0fa 232
fd4a6963 233protected:
bf75be98 234
595a42a4 235 Standard_EXPORT void convertMaterial (const CALL_DEF_MATERIAL& theMat,
236 OPENGL_SURF_PROP& theSurf);
bf75be98 237
fd4a6963 238protected: //! @name ordinary aspect properties
239
240 Aspect_InteriorStyle myInteriorStyle;
241 int myEdge;
242 int myHatch;
243 int myDistinguishingMode;
244 int myCullingMode;
245 OPENGL_SURF_PROP myIntFront;
246 OPENGL_SURF_PROP myIntBack;
247 TEL_POFFSET_PARAM myPolygonOffset;
248 bool myDoTextureMap;
30f0ad28 249 Handle(Graphic3d_TextureMap) myTexture;
250 Handle(Graphic3d_ShaderProgram) myShaderProgram;
251
252protected:
253
254 //! OpenGl resources
255 mutable struct Resources
256 {
257 public:
258 Resources()
259 : myIsTextureReady (Standard_False),
260 myIsShaderReady (Standard_False) {}
261
262 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
263 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
264 void SetTextureReady() { myIsTextureReady = Standard_True; }
265 void SetShaderReady () { myIsShaderReady = Standard_True; }
f85399e5 266 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
267 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
30f0ad28 268
8625ef7e 269 Standard_EXPORT void BuildTexture (const Handle(OpenGl_Context)& theCtx,
595a42a4 270 const Handle(Graphic3d_TextureMap)& theTexture);
8625ef7e 271 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
595a42a4 272 const Handle(Graphic3d_ShaderProgram)& theShader);
30f0ad28 273
595a42a4 274 Handle(OpenGl_Texture) Texture;
275 TCollection_AsciiString TextureId;
30f0ad28 276 Handle(OpenGl_ShaderProgram) ShaderProgram;
277 TCollection_AsciiString ShaderProgramId;
278
279 private:
bf75be98 280
30f0ad28 281 Standard_Boolean myIsTextureReady;
282 Standard_Boolean myIsShaderReady;
2166f0fa 283
30f0ad28 284 } myResources;
bf75be98 285
286protected:
287
fd4a6963 288 OpenGl_AspectLine myAspectEdge;
bf75be98 289
290public:
2166f0fa 291
1c35b92f 292 DEFINE_STANDARD_ALLOC
bf75be98 293
2166f0fa
SK
294};
295
296#endif //_OpenGl_AspectFace_Header