0025442: Visualization, TKOpenGl - prevent inclusion of system header glxext.h
[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
30f0ad28 24#include <Handle_Graphic3d_TextureParams.hxx>
25#include <Handle_OpenGl_ShaderProgram.hxx>
26#include <Handle_OpenGl_Texture.hxx>
2166f0fa 27#include <OpenGl_AspectLine.hxx>
bf75be98 28#include <OpenGl_Element.hxx>
fd4a6963 29
4269bd1b 30#include <Graphic3d_AspectFillArea3d.hxx>
b64d84be 31#include <Graphic3d_CAspectFillArea.hxx>
30f0ad28 32#include <Graphic3d_ShaderProgram_Handle.hxx>
33#include <Graphic3d_TextureMap.hxx>
2166f0fa
SK
34
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{
44 float amb, diff, spec, emsv;
44c7c33e 45 float trans, shine, index;
2166f0fa
SK
46 float env_reflexion;
47 int isphysic;
48 unsigned int color_mask;
49 TEL_COLOUR speccol, difcol, ambcol, emscol, matcol;
1c35b92f 50 DEFINE_STANDARD_ALLOC
2166f0fa
SK
51};
52
2166f0fa
SK
53class OpenGl_AspectFace : public OpenGl_Element
54{
2166f0fa 55
bf75be98 56public:
2166f0fa 57
595a42a4 58 Standard_EXPORT OpenGl_AspectFace();
2166f0fa 59
fd4a6963 60 //! Copy parameters
595a42a4 61 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
62 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
fd4a6963 63
64 //! Set edge aspect.
65 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
66 {
67 myAspectEdge = *theAspectEdge;
68 }
69
70 //! @return edge aspect.
71 const OpenGl_AspectLine* AspectEdge() const
72 {
73 return &myAspectEdge;
74 }
75
76 //! @return interior style
77 const Aspect_InteriorStyle InteriorStyle() const
78 {
79 return myInteriorStyle;
80 }
81
82 Aspect_InteriorStyle& ChangeInteriorStyle()
83 {
84 return myInteriorStyle;
85 }
86
87 //! @return edge on flag.
88 int Edge() const
89 {
90 return myEdge;
91 }
92
93 //! @return edge on flag.
94 int& ChangeEdge()
95 {
96 return myEdge;
97 }
98
99 //! @return hatch type.
100 int Hatch() const
101 {
102 return myHatch;
103 }
104
105 //! @return hatch type variable.
106 int& ChangeHatch()
107 {
108 return myHatch;
109 }
110
111 //! @return distinguishing mode.
112 int DistinguishingMode() const
113 {
114 return myDistinguishingMode;
115 }
116
117 //! @return distinguishing mode.
118 int& ChangeDistinguishingMode()
119 {
120 return myDistinguishingMode;
121 }
122
123 //! @return culling mode.
124 int CullingMode() const
125 {
126 return myCullingMode;
127 }
128
129 //! @return culling mode.
130 int& ChangeCullingMode()
131 {
132 return myCullingMode;
133 }
134
135 //! @return front material properties.
136 const OPENGL_SURF_PROP& IntFront() const
137 {
138 return myIntFront;
139 }
140
141 //! @return front material properties.
142 OPENGL_SURF_PROP& ChangeIntFront()
143 {
144 return myIntFront;
145 }
146
147 //! @return back material properties.
148 const OPENGL_SURF_PROP& IntBack() const
149 {
150 return myIntBack;
151 }
152
153 //! @return back material properties.
154 OPENGL_SURF_PROP& ChangeIntBack()
155 {
156 return myIntBack;
157 }
158
159 //! @return polygon offset parameters.
160 const TEL_POFFSET_PARAM& PolygonOffset() const
161 {
162 return myPolygonOffset;
163 }
164
165 //! @return polygon offset parameters.
166 TEL_POFFSET_PARAM& ChangePolygonOffset()
167 {
168 return myPolygonOffset;
169 }
170
171 //! @return texture mapping flag.
172 bool DoTextureMap() const
173 {
174 return myDoTextureMap;
175 }
176
177 //! @return texture mapping flag.
178 bool& ChangeDoTextureMap()
179 {
180 return myDoTextureMap;
181 }
182
30f0ad28 183 //! @return texture mapping parameters.
184 const Handle(Graphic3d_TextureParams)& TextureParams() const
185 {
186 return myTexture->GetParams();
187 }
188
fd4a6963 189 //! @return texture map.
8625ef7e 190 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Context)& theCtx) const
fd4a6963 191 {
30f0ad28 192 if (!myResources.IsTextureReady())
fd4a6963 193 {
8625ef7e 194 myResources.BuildTexture (theCtx, myTexture);
30f0ad28 195 myResources.SetTextureReady();
fd4a6963 196 }
197
30f0ad28 198 return myResources.Texture;
fd4a6963 199 }
200
30f0ad28 201 //! Init and return OpenGl shader program resource.
202 //! @return shader program resource.
8625ef7e 203 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
fd4a6963 204 {
30f0ad28 205 if (!myResources.IsShaderReady())
206 {
8625ef7e 207 myResources.BuildShader (theCtx, myShaderProgram);
30f0ad28 208 myResources.SetShaderReady();
209 }
210
211 return myResources.ShaderProgram;
fd4a6963 212 }
2166f0fa 213
595a42a4 214 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
10b9c7df 215 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
2166f0fa 216
fd4a6963 217protected:
bf75be98 218
595a42a4 219 Standard_EXPORT void convertMaterial (const CALL_DEF_MATERIAL& theMat,
220 OPENGL_SURF_PROP& theSurf);
bf75be98 221
fd4a6963 222protected: //! @name ordinary aspect properties
223
224 Aspect_InteriorStyle myInteriorStyle;
225 int myEdge;
226 int myHatch;
227 int myDistinguishingMode;
228 int myCullingMode;
229 OPENGL_SURF_PROP myIntFront;
230 OPENGL_SURF_PROP myIntBack;
231 TEL_POFFSET_PARAM myPolygonOffset;
232 bool myDoTextureMap;
30f0ad28 233 Handle(Graphic3d_TextureMap) myTexture;
234 Handle(Graphic3d_ShaderProgram) myShaderProgram;
235
236protected:
237
238 //! OpenGl resources
239 mutable struct Resources
240 {
241 public:
242 Resources()
243 : myIsTextureReady (Standard_False),
244 myIsShaderReady (Standard_False) {}
245
246 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
247 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
248 void SetTextureReady() { myIsTextureReady = Standard_True; }
249 void SetShaderReady () { myIsShaderReady = Standard_True; }
f85399e5 250 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
251 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
30f0ad28 252
8625ef7e 253 Standard_EXPORT void BuildTexture (const Handle(OpenGl_Context)& theCtx,
595a42a4 254 const Handle(Graphic3d_TextureMap)& theTexture);
8625ef7e 255 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
595a42a4 256 const Handle(Graphic3d_ShaderProgram)& theShader);
30f0ad28 257
595a42a4 258 Handle(OpenGl_Texture) Texture;
259 TCollection_AsciiString TextureId;
30f0ad28 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