1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #ifndef _OpenGl_AspectFace_Header
21 #define _OpenGl_AspectFace_Header
23 #include <InterfaceGraphic_telem.hxx>
24 #include <Aspect_InteriorStyle.hxx>
25 #include <TCollection_AsciiString.hxx>
27 #include <Handle_Graphic3d_TextureParams.hxx>
28 #include <Handle_OpenGl_ShaderProgram.hxx>
29 #include <Handle_OpenGl_Texture.hxx>
30 #include <OpenGl_AspectLine.hxx>
31 #include <OpenGl_Element.hxx>
33 #include <Graphic3d_AspectFillArea3d.hxx>
34 #include <Graphic3d_ShaderProgram_Handle.hxx>
35 #include <Graphic3d_TextureMap.hxx>
37 #define OPENGL_AMBIENT_MASK (1<<0)
38 #define OPENGL_DIFFUSE_MASK (1<<1)
39 #define OPENGL_SPECULAR_MASK (1<<2)
40 #define OPENGL_EMISSIVE_MASK (1<<3)
42 class CALL_DEF_CONTEXTFILLAREA;
44 struct OPENGL_SURF_PROP
46 float amb, diff, spec, emsv;
50 unsigned int color_mask;
51 TEL_COLOUR speccol, difcol, ambcol, emscol, matcol;
55 class OpenGl_AspectFace : public OpenGl_Element
63 void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect);
64 void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
67 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge)
69 myAspectEdge = *theAspectEdge;
72 //! @return edge aspect.
73 const OpenGl_AspectLine* AspectEdge() const
78 //! @return interior style
79 const Aspect_InteriorStyle InteriorStyle() const
81 return myInteriorStyle;
84 Aspect_InteriorStyle& ChangeInteriorStyle()
86 return myInteriorStyle;
89 //! @return edge on flag.
95 //! @return edge on flag.
101 //! @return hatch type.
107 //! @return hatch type variable.
113 //! @return distinguishing mode.
114 int DistinguishingMode() const
116 return myDistinguishingMode;
119 //! @return distinguishing mode.
120 int& ChangeDistinguishingMode()
122 return myDistinguishingMode;
125 //! @return culling mode.
126 int CullingMode() const
128 return myCullingMode;
131 //! @return culling mode.
132 int& ChangeCullingMode()
134 return myCullingMode;
137 //! @return front material properties.
138 const OPENGL_SURF_PROP& IntFront() const
143 //! @return front material properties.
144 OPENGL_SURF_PROP& ChangeIntFront()
149 //! @return back material properties.
150 const OPENGL_SURF_PROP& IntBack() const
155 //! @return back material properties.
156 OPENGL_SURF_PROP& ChangeIntBack()
161 //! @return polygon offset parameters.
162 const TEL_POFFSET_PARAM& PolygonOffset() const
164 return myPolygonOffset;
167 //! @return polygon offset parameters.
168 TEL_POFFSET_PARAM& ChangePolygonOffset()
170 return myPolygonOffset;
173 //! @return texture mapping flag.
174 bool DoTextureMap() const
176 return myDoTextureMap;
179 //! @return texture mapping flag.
180 bool& ChangeDoTextureMap()
182 return myDoTextureMap;
185 //! @return texture mapping parameters.
186 const Handle(Graphic3d_TextureParams)& TextureParams() const
188 return myTexture->GetParams();
191 //! @return texture map.
192 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Workspace)& theWorkspace) const
194 if (!myResources.IsTextureReady())
196 myResources.BuildTexture (theWorkspace, myTexture);
197 myResources.SetTextureReady();
200 return myResources.Texture;
203 //! Init and return OpenGl shader program resource.
204 //! @return shader program resource.
205 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
207 if (!myResources.IsShaderReady())
209 myResources.BuildShader (theWorkspace, myShaderProgram);
210 myResources.SetShaderReady();
213 return myResources.ShaderProgram;
216 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
217 virtual void Release (const Handle(OpenGl_Context)& theContext);
221 void convertMaterial (const CALL_DEF_MATERIAL& theMat,
222 OPENGL_SURF_PROP& theSurf);
224 protected: //! @name ordinary aspect properties
226 Aspect_InteriorStyle myInteriorStyle;
229 int myDistinguishingMode;
231 OPENGL_SURF_PROP myIntFront;
232 OPENGL_SURF_PROP myIntBack;
233 TEL_POFFSET_PARAM myPolygonOffset;
235 Handle(Graphic3d_TextureMap) myTexture;
236 Handle(Graphic3d_ShaderProgram) myShaderProgram;
241 mutable struct Resources
245 : myIsTextureReady (Standard_False),
246 myIsShaderReady (Standard_False) {}
248 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
249 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
250 void SetTextureReady() { myIsTextureReady = Standard_True; }
251 void SetShaderReady () { myIsShaderReady = Standard_True; }
252 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
253 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
255 void BuildTexture (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_TextureMap)& theTexture);
256 void BuildShader (const Handle(OpenGl_Workspace)& theWS, 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