1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_AspectFace_Header
17 #define _OpenGl_AspectFace_Header
19 #include <InterfaceGraphic_telem.hxx>
20 #include <Aspect_InteriorStyle.hxx>
21 #include <TCollection_AsciiString.hxx>
23 #include <Handle_Graphic3d_TextureParams.hxx>
24 #include <Handle_OpenGl_ShaderProgram.hxx>
25 #include <Handle_OpenGl_Texture.hxx>
26 #include <OpenGl_AspectLine.hxx>
27 #include <OpenGl_Element.hxx>
29 #include <Graphic3d_AspectFillArea3d.hxx>
30 #include <Graphic3d_ShaderProgram_Handle.hxx>
31 #include <Graphic3d_TextureMap.hxx>
33 #define OPENGL_AMBIENT_MASK (1<<0)
34 #define OPENGL_DIFFUSE_MASK (1<<1)
35 #define OPENGL_SPECULAR_MASK (1<<2)
36 #define OPENGL_EMISSIVE_MASK (1<<3)
38 class CALL_DEF_CONTEXTFILLAREA;
40 struct OPENGL_SURF_PROP
42 float amb, diff, spec, emsv;
46 unsigned int color_mask;
47 TEL_COLOUR speccol, difcol, ambcol, emscol, matcol;
51 class OpenGl_AspectFace : public OpenGl_Element
59 void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
60 void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
63 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
65 myAspectEdge = *theAspectEdge;
68 //! @return edge aspect.
69 const OpenGl_AspectLine* AspectEdge() const
74 //! @return interior style
75 const Aspect_InteriorStyle InteriorStyle() const
77 return myInteriorStyle;
80 Aspect_InteriorStyle& ChangeInteriorStyle()
82 return myInteriorStyle;
85 //! @return edge on flag.
91 //! @return edge on flag.
97 //! @return hatch type.
103 //! @return hatch type variable.
109 //! @return distinguishing mode.
110 int DistinguishingMode() const
112 return myDistinguishingMode;
115 //! @return distinguishing mode.
116 int& ChangeDistinguishingMode()
118 return myDistinguishingMode;
121 //! @return culling mode.
122 int CullingMode() const
124 return myCullingMode;
127 //! @return culling mode.
128 int& ChangeCullingMode()
130 return myCullingMode;
133 //! @return front material properties.
134 const OPENGL_SURF_PROP& IntFront() const
139 //! @return front material properties.
140 OPENGL_SURF_PROP& ChangeIntFront()
145 //! @return back material properties.
146 const OPENGL_SURF_PROP& IntBack() const
151 //! @return back material properties.
152 OPENGL_SURF_PROP& ChangeIntBack()
157 //! @return polygon offset parameters.
158 const TEL_POFFSET_PARAM& PolygonOffset() const
160 return myPolygonOffset;
163 //! @return polygon offset parameters.
164 TEL_POFFSET_PARAM& ChangePolygonOffset()
166 return myPolygonOffset;
169 //! @return texture mapping flag.
170 bool DoTextureMap() const
172 return myDoTextureMap;
175 //! @return texture mapping flag.
176 bool& ChangeDoTextureMap()
178 return myDoTextureMap;
181 //! @return texture mapping parameters.
182 const Handle(Graphic3d_TextureParams)& TextureParams() const
184 return myTexture->GetParams();
187 //! @return texture map.
188 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Workspace)& theWorkspace) const
190 if (!myResources.IsTextureReady())
192 myResources.BuildTexture (theWorkspace, myTexture);
193 myResources.SetTextureReady();
196 return myResources.Texture;
199 //! Init and return OpenGl shader program resource.
200 //! @return shader program resource.
201 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
203 if (!myResources.IsShaderReady())
205 myResources.BuildShader (theWorkspace, myShaderProgram);
206 myResources.SetShaderReady();
209 return myResources.ShaderProgram;
212 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
213 virtual void Release (const Handle(OpenGl_Context)& theContext);
217 void convertMaterial (const CALL_DEF_MATERIAL& theMat,
218 OPENGL_SURF_PROP& theSurf);
220 protected: //! @name ordinary aspect properties
222 Aspect_InteriorStyle myInteriorStyle;
225 int myDistinguishingMode;
227 OPENGL_SURF_PROP myIntFront;
228 OPENGL_SURF_PROP myIntBack;
229 TEL_POFFSET_PARAM myPolygonOffset;
231 Handle(Graphic3d_TextureMap) myTexture;
232 Handle(Graphic3d_ShaderProgram) myShaderProgram;
237 mutable struct Resources
241 : myIsTextureReady (Standard_False),
242 myIsShaderReady (Standard_False) {}
244 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
245 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
246 void SetTextureReady() { myIsTextureReady = Standard_True; }
247 void SetShaderReady () { myIsShaderReady = Standard_True; }
248 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
249 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
251 void BuildTexture (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_TextureMap)& theTexture);
252 void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
254 Handle(OpenGl_Texture) Texture;
255 TCollection_AsciiString TextureId;
256 Handle(OpenGl_ShaderProgram) ShaderProgram;
257 TCollection_AsciiString ShaderProgramId;
261 Standard_Boolean myIsTextureReady;
262 Standard_Boolean myIsShaderReady;
268 OpenGl_AspectLine myAspectEdge;
272 DEFINE_STANDARD_ALLOC
276 #endif //_OpenGl_AspectFace_Header