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 <OpenGl_AspectLine.hxx>
20 #include <Graphic3d_AspectFillArea3d.hxx>
21 #include <Graphic3d_ShaderProgram.hxx>
22 #include <Graphic3d_TextureMap.hxx>
23 #include <Graphic3d_BSDF.hxx>
27 //! The element holding Graphic3d_AspectFillArea3d.
28 class OpenGl_AspectFace : public OpenGl_Element
33 //! Empty constructor.
34 Standard_EXPORT OpenGl_AspectFace();
36 //! Create and assign parameters.
37 Standard_EXPORT OpenGl_AspectFace (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
40 const Handle(Graphic3d_AspectFillArea3d)& Aspect() const { return myAspect; }
42 //! Assign parameters.
43 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
46 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; }
48 //! @return edge aspect.
49 const OpenGl_AspectLine* AspectEdge() const { return &myAspectEdge; }
51 //! Returns true if lighting should be disabled.
52 bool IsNoLighting() const { return myIsNoLighting; }
54 //! Set if lighting should be disabled or not.
55 void SetNoLighting (bool theValue) { myIsNoLighting = theValue; }
57 //! @return texture mapping parameters.
58 const Handle(Graphic3d_TextureParams)& TextureParams() const
60 return myAspect->TextureMap()->GetParams();
63 //! @return texture map.
64 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Context)& theCtx) const
66 if (!myResources.IsTextureReady())
68 myResources.BuildTexture (theCtx, myAspect->TextureMap());
69 myResources.SetTextureReady();
72 return myResources.Texture;
75 //! Init and return OpenGl shader program resource.
76 //! @return shader program resource.
77 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
79 if (!myResources.IsShaderReady())
81 myResources.BuildShader (theCtx, myAspect->ShaderProgram());
82 myResources.SetShaderReady();
85 return myResources.ShaderProgram;
88 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
89 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
94 mutable struct Resources
98 : myIsTextureReady (Standard_False),
99 myIsShaderReady (Standard_False) {}
101 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
102 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
103 void SetTextureReady() { myIsTextureReady = Standard_True; }
104 void SetShaderReady () { myIsShaderReady = Standard_True; }
105 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
106 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
108 Standard_EXPORT void BuildTexture (const Handle(OpenGl_Context)& theCtx,
109 const Handle(Graphic3d_TextureMap)& theTexture);
110 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
111 const Handle(Graphic3d_ShaderProgram)& theShader);
113 Handle(OpenGl_Texture) Texture;
114 TCollection_AsciiString TextureId;
115 Handle(OpenGl_ShaderProgram) ShaderProgram;
116 TCollection_AsciiString ShaderProgramId;
120 Standard_Boolean myIsTextureReady;
121 Standard_Boolean myIsShaderReady;
125 Handle(Graphic3d_AspectFillArea3d) myAspect;
126 OpenGl_AspectLine myAspectEdge;
131 DEFINE_STANDARD_ALLOC
135 #endif //_OpenGl_AspectFace_Header