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