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 <OpenGl_AspectLine.hxx>
25 #include <OpenGl_Element.hxx>
27 #include <Graphic3d_AspectFillArea3d.hxx>
28 #include <Graphic3d_CAspectFillArea.hxx>
29 #include <Graphic3d_ShaderProgram.hxx>
30 #include <Graphic3d_TextureMap.hxx>
31 #include <Graphic3d_BSDF.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 static const TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F };
40 struct OPENGL_SURF_PROP
42 Standard_ShortReal amb;
43 Standard_ShortReal diff;
44 Standard_ShortReal spec;
45 Standard_ShortReal emsv;
47 Standard_ShortReal trans;
48 Standard_ShortReal shine;
49 Standard_ShortReal index;
51 Standard_ShortReal env_reflexion;
52 Standard_Integer isphysic;
54 unsigned int color_mask;
67 class OpenGl_AspectFace : public OpenGl_Element
72 Standard_EXPORT OpenGl_AspectFace();
75 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
76 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
79 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
81 myAspectEdge = *theAspectEdge;
84 //! @return edge aspect.
85 const OpenGl_AspectLine* AspectEdge() const
90 //! @return interior style
91 const Aspect_InteriorStyle InteriorStyle() const
93 return myInteriorStyle;
96 Aspect_InteriorStyle& ChangeInteriorStyle()
98 return myInteriorStyle;
101 //! @return edge on flag.
107 //! @return edge on flag.
113 //! @return hatch type.
119 //! @return hatch type variable.
125 //! @return distinguishing mode.
126 int DistinguishingMode() const
128 return myDistinguishingMode;
131 //! @return distinguishing mode.
132 int& ChangeDistinguishingMode()
134 return myDistinguishingMode;
137 //! @return culling mode.
138 int CullingMode() const
140 return myCullingMode;
143 //! @return culling mode.
144 int& ChangeCullingMode()
146 return myCullingMode;
149 //! @return front material properties.
150 const OPENGL_SURF_PROP& IntFront() const
155 //! @return front material properties.
156 OPENGL_SURF_PROP& ChangeIntFront()
161 //! @return back material properties.
162 const OPENGL_SURF_PROP& IntBack() const
167 //! @return back material properties.
168 OPENGL_SURF_PROP& ChangeIntBack()
173 //! @return polygon offset parameters.
174 const TEL_POFFSET_PARAM& PolygonOffset() const
176 return myPolygonOffset;
179 //! @return polygon offset parameters.
180 TEL_POFFSET_PARAM& ChangePolygonOffset()
182 return myPolygonOffset;
185 //! @return texture mapping flag.
186 bool DoTextureMap() const
188 return myDoTextureMap;
191 //! @return texture mapping flag.
192 bool& ChangeDoTextureMap()
194 return myDoTextureMap;
197 //! @return texture mapping parameters.
198 const Handle(Graphic3d_TextureParams)& TextureParams() const
200 return myTexture->GetParams();
203 //! @return texture map.
204 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Context)& theCtx) const
206 if (!myResources.IsTextureReady())
208 myResources.BuildTexture (theCtx, myTexture);
209 myResources.SetTextureReady();
212 return myResources.Texture;
215 //! Init and return OpenGl shader program resource.
216 //! @return shader program resource.
217 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
219 if (!myResources.IsShaderReady())
221 myResources.BuildShader (theCtx, myShaderProgram);
222 myResources.SetShaderReady();
225 return myResources.ShaderProgram;
228 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
229 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
233 Standard_EXPORT void convertMaterial (const CALL_DEF_MATERIAL& theMat,
234 OPENGL_SURF_PROP& theSurf);
236 protected: //! @name ordinary aspect properties
238 Aspect_InteriorStyle myInteriorStyle;
241 int myDistinguishingMode;
243 OPENGL_SURF_PROP myIntFront;
244 OPENGL_SURF_PROP myIntBack;
245 TEL_POFFSET_PARAM myPolygonOffset;
247 Handle(Graphic3d_TextureMap) myTexture;
248 Handle(Graphic3d_ShaderProgram) myShaderProgram;
253 mutable struct Resources
257 : myIsTextureReady (Standard_False),
258 myIsShaderReady (Standard_False) {}
260 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
261 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
262 void SetTextureReady() { myIsTextureReady = Standard_True; }
263 void SetShaderReady () { myIsShaderReady = Standard_True; }
264 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
265 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
267 Standard_EXPORT void BuildTexture (const Handle(OpenGl_Context)& theCtx,
268 const Handle(Graphic3d_TextureMap)& theTexture);
269 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
270 const Handle(Graphic3d_ShaderProgram)& theShader);
272 Handle(OpenGl_Texture) Texture;
273 TCollection_AsciiString TextureId;
274 Handle(OpenGl_ShaderProgram) ShaderProgram;
275 TCollection_AsciiString ShaderProgramId;
279 Standard_Boolean myIsTextureReady;
280 Standard_Boolean myIsShaderReady;
286 OpenGl_AspectLine myAspectEdge;
290 DEFINE_STANDARD_ALLOC
294 #endif //_OpenGl_AspectFace_Header