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 under
8 // the terms of the GNU Lesser General Public License 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 <Aspect_PolygonOffsetMode.hxx>
22 #include <TCollection_AsciiString.hxx>
24 #include <Handle_Graphic3d_TextureParams.hxx>
25 #include <Handle_OpenGl_ShaderProgram.hxx>
26 #include <Handle_OpenGl_Texture.hxx>
27 #include <OpenGl_AspectLine.hxx>
28 #include <OpenGl_Element.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <Graphic3d_CAspectFillArea.hxx>
32 #include <Graphic3d_ShaderProgram_Handle.hxx>
33 #include <Graphic3d_TextureMap.hxx>
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)
40 static const TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F };
42 struct OPENGL_SURF_PROP
44 float amb, diff, spec, emsv;
45 float trans, shine, index;
48 unsigned int color_mask;
49 TEL_COLOUR speccol, difcol, ambcol, emscol, matcol;
53 class OpenGl_AspectFace : public OpenGl_Element
58 Standard_EXPORT OpenGl_AspectFace();
61 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
62 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
65 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
67 myAspectEdge = *theAspectEdge;
70 //! @return edge aspect.
71 const OpenGl_AspectLine* AspectEdge() const
76 //! @return interior style
77 const Aspect_InteriorStyle InteriorStyle() const
79 return myInteriorStyle;
82 Aspect_InteriorStyle& ChangeInteriorStyle()
84 return myInteriorStyle;
87 //! @return edge on flag.
93 //! @return edge on flag.
99 //! @return hatch type.
105 //! @return hatch type variable.
111 //! @return distinguishing mode.
112 int DistinguishingMode() const
114 return myDistinguishingMode;
117 //! @return distinguishing mode.
118 int& ChangeDistinguishingMode()
120 return myDistinguishingMode;
123 //! @return culling mode.
124 int CullingMode() const
126 return myCullingMode;
129 //! @return culling mode.
130 int& ChangeCullingMode()
132 return myCullingMode;
135 //! @return front material properties.
136 const OPENGL_SURF_PROP& IntFront() const
141 //! @return front material properties.
142 OPENGL_SURF_PROP& ChangeIntFront()
147 //! @return back material properties.
148 const OPENGL_SURF_PROP& IntBack() const
153 //! @return back material properties.
154 OPENGL_SURF_PROP& ChangeIntBack()
159 //! @return polygon offset parameters.
160 const TEL_POFFSET_PARAM& PolygonOffset() const
162 return myPolygonOffset;
165 //! @return polygon offset parameters.
166 TEL_POFFSET_PARAM& ChangePolygonOffset()
168 return myPolygonOffset;
171 //! @return texture mapping flag.
172 bool DoTextureMap() const
174 return myDoTextureMap;
177 //! @return texture mapping flag.
178 bool& ChangeDoTextureMap()
180 return myDoTextureMap;
183 //! @return texture mapping parameters.
184 const Handle(Graphic3d_TextureParams)& TextureParams() const
186 return myTexture->GetParams();
189 //! @return texture map.
190 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Workspace)& theWorkspace) const
192 if (!myResources.IsTextureReady())
194 myResources.BuildTexture (theWorkspace, myTexture);
195 myResources.SetTextureReady();
198 return myResources.Texture;
201 //! Init and return OpenGl shader program resource.
202 //! @return shader program resource.
203 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
205 if (!myResources.IsShaderReady())
207 myResources.BuildShader (theWorkspace, myShaderProgram);
208 myResources.SetShaderReady();
211 return myResources.ShaderProgram;
214 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
215 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
219 Standard_EXPORT void convertMaterial (const CALL_DEF_MATERIAL& theMat,
220 OPENGL_SURF_PROP& theSurf);
222 protected: //! @name ordinary aspect properties
224 Aspect_InteriorStyle myInteriorStyle;
227 int myDistinguishingMode;
229 OPENGL_SURF_PROP myIntFront;
230 OPENGL_SURF_PROP myIntBack;
231 TEL_POFFSET_PARAM myPolygonOffset;
233 Handle(Graphic3d_TextureMap) myTexture;
234 Handle(Graphic3d_ShaderProgram) myShaderProgram;
239 mutable struct Resources
243 : myIsTextureReady (Standard_False),
244 myIsShaderReady (Standard_False) {}
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; }
250 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
251 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
253 Standard_EXPORT void BuildTexture (const Handle(OpenGl_Workspace)& theWS,
254 const Handle(Graphic3d_TextureMap)& theTexture);
255 Standard_EXPORT void BuildShader (const Handle(OpenGl_Workspace)& theWS,
256 const Handle(Graphic3d_ShaderProgram)& theShader);
258 Handle(OpenGl_Texture) Texture;
259 TCollection_AsciiString TextureId;
260 Handle(OpenGl_ShaderProgram) ShaderProgram;
261 TCollection_AsciiString ShaderProgramId;
265 Standard_Boolean myIsTextureReady;
266 Standard_Boolean myIsShaderReady;
272 OpenGl_AspectLine myAspectEdge;
276 DEFINE_STANDARD_ALLOC
280 #endif //_OpenGl_AspectFace_Header