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 <OpenGl_TextureSet.hxx>
21 #include <Graphic3d_AspectFillArea3d.hxx>
22 #include <Graphic3d_ShaderProgram.hxx>
23 #include <Graphic3d_TextureMap.hxx>
24 #include <Graphic3d_BSDF.hxx>
28 //! The element holding Graphic3d_AspectFillArea3d.
29 class OpenGl_AspectFace : public OpenGl_Element
34 //! Empty constructor.
35 Standard_EXPORT OpenGl_AspectFace();
37 //! Create and assign parameters.
38 Standard_EXPORT OpenGl_AspectFace (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
41 const Handle(Graphic3d_AspectFillArea3d)& Aspect() const { return myAspect; }
43 //! Assign parameters.
44 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
47 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; }
49 //! @return edge aspect.
50 const OpenGl_AspectLine* AspectEdge() const { return &myAspectEdge; }
52 //! Returns Shading Model.
53 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
55 //! Set if lighting should be disabled or not.
56 void SetNoLighting() { myShadingModel = Graphic3d_TOSM_UNLIT; }
58 //! Returns textures map.
59 const Handle(OpenGl_TextureSet)& TextureSet (const Handle(OpenGl_Context)& theCtx) const
61 if (!myResources.IsTextureReady())
63 myResources.BuildTextures (theCtx, myAspect->TextureSet());
64 myResources.SetTextureReady();
66 return myResources.TextureSet();
69 //! Init and return OpenGl shader program resource.
70 //! @return shader program resource.
71 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
73 if (!myResources.IsShaderReady())
75 myResources.BuildShader (theCtx, myAspect->ShaderProgram());
76 myResources.SetShaderReady();
79 return myResources.ShaderProgram;
82 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
83 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
88 mutable struct Resources
91 //! Empty constructor.
93 : myIsTextureReady (Standard_False),
94 myIsShaderReady (Standard_False) {}
96 //! Return TRUE if texture resource is up-to-date.
97 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
99 //! Return TRUE if shader resource is up-to-date.
100 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
102 //! Set texture resource up-to-date state.
103 void SetTextureReady() { myIsTextureReady = Standard_True; }
105 //! Set shader resource up-to-date state.
106 void SetShaderReady () { myIsShaderReady = Standard_True; }
108 //! Reset shader resource up-to-date state.
109 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
111 //! Return textures array.
112 const Handle(OpenGl_TextureSet)& TextureSet() const { return myTextures; }
114 //! Update texture resource up-to-date state.
115 Standard_EXPORT void UpdateTexturesRediness (const Handle(Graphic3d_TextureSet)& theTextures);
117 //! Build texture resource.
118 Standard_EXPORT void BuildTextures (const Handle(OpenGl_Context)& theCtx,
119 const Handle(Graphic3d_TextureSet)& theTextures);
121 //! Build shader resource.
122 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
123 const Handle(Graphic3d_ShaderProgram)& theShader);
125 //! Release texture resource.
126 Standard_EXPORT void ReleaseTextures (OpenGl_Context* theCtx);
128 Handle(OpenGl_ShaderProgram) ShaderProgram;
129 TCollection_AsciiString ShaderProgramId;
133 Handle(OpenGl_TextureSet) myTextures;
134 Standard_Boolean myIsTextureReady;
135 Standard_Boolean myIsShaderReady;
139 Handle(Graphic3d_AspectFillArea3d) myAspect;
140 OpenGl_AspectLine myAspectEdge;
141 Graphic3d_TypeOfShadingModel myShadingModel;
145 DEFINE_STANDARD_ALLOC
149 #endif //_OpenGl_AspectFace_Header