0030470: Modeling Algorithms - Invalid result of offset operation in mode "Complete...
[occt.git] / src / OpenGl / OpenGl_AspectFace.hxx
1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _OpenGl_AspectFace_Header
17 #define _OpenGl_AspectFace_Header
18
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>
25
26 class OpenGl_Texture;
27
28 //! The element holding Graphic3d_AspectFillArea3d.
29 class OpenGl_AspectFace : public OpenGl_Element
30 {
31
32 public:
33
34   //! Empty constructor.
35   Standard_EXPORT OpenGl_AspectFace();
36
37   //! Create and assign parameters.
38   Standard_EXPORT OpenGl_AspectFace (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
39
40   //! Return aspect.
41   const Handle(Graphic3d_AspectFillArea3d)& Aspect() const { return myAspect; }
42
43   //! Assign parameters.
44   Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
45
46   //! Set edge aspect.
47   void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; }
48
49   //! @return edge aspect.
50   const OpenGl_AspectLine* AspectEdge() const  { return &myAspectEdge; }
51
52   //! Returns Shading Model.
53   Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
54
55   //! Set if lighting should be disabled or not.
56   void SetNoLighting() { myShadingModel = Graphic3d_TOSM_UNLIT; }
57
58   //! Returns textures map.
59   const Handle(OpenGl_TextureSet)& TextureSet (const Handle(OpenGl_Context)& theCtx) const
60   {
61     if (!myResources.IsTextureReady())
62     {
63       myResources.BuildTextures (theCtx, myAspect->TextureSet());
64       myResources.SetTextureReady();
65     }
66     return myResources.TextureSet();
67   }
68
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
72   {
73     if (!myResources.IsShaderReady())
74     {
75       myResources.BuildShader (theCtx, myAspect->ShaderProgram());
76       myResources.SetShaderReady();
77     }
78
79     return myResources.ShaderProgram;
80   }
81
82   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
83   Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
84
85   //! Update presentation aspects parameters after their modification.
86   virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); }
87
88 protected:
89
90   //! OpenGl resources
91   mutable struct Resources
92   {
93   public:
94     //! Empty constructor.
95     Resources()
96     : myIsTextureReady (Standard_False),
97       myIsShaderReady  (Standard_False) {}
98
99     //! Return TRUE if texture resource is up-to-date.
100     Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
101
102     //! Return TRUE if shader resource is up-to-date.
103     Standard_Boolean IsShaderReady () const { return myIsShaderReady;  }
104
105     //! Set texture resource up-to-date state.
106     void SetTextureReady() { myIsTextureReady = Standard_True; }
107
108     //! Set shader resource up-to-date state.
109     void SetShaderReady () { myIsShaderReady  = Standard_True; }
110
111     //! Reset shader resource up-to-date state.
112     void ResetShaderReadiness () { myIsShaderReady  = Standard_False; }
113
114     //! Return textures array.
115     const Handle(OpenGl_TextureSet)& TextureSet() const { return myTextures; }
116
117     //! Update texture resource up-to-date state.
118     Standard_EXPORT void UpdateTexturesRediness (const Handle(Graphic3d_TextureSet)& theTextures);
119
120     //! Build texture resource.
121     Standard_EXPORT void BuildTextures (const Handle(OpenGl_Context)& theCtx,
122                                         const Handle(Graphic3d_TextureSet)& theTextures);
123
124     //! Build shader resource.
125     Standard_EXPORT void BuildShader  (const Handle(OpenGl_Context)&          theCtx,
126                                        const Handle(Graphic3d_ShaderProgram)& theShader);
127
128     //! Release texture resource.
129     Standard_EXPORT void ReleaseTextures (OpenGl_Context* theCtx);
130
131     Handle(OpenGl_ShaderProgram) ShaderProgram;
132     TCollection_AsciiString      ShaderProgramId;
133
134   private:
135
136     Handle(OpenGl_TextureSet) myTextures;
137     Standard_Boolean myIsTextureReady;
138     Standard_Boolean myIsShaderReady;
139
140   } myResources;
141
142   Handle(Graphic3d_AspectFillArea3d) myAspect;
143   OpenGl_AspectLine                  myAspectEdge;
144   Graphic3d_TypeOfShadingModel       myShadingModel;
145
146 public:
147
148   DEFINE_STANDARD_ALLOC
149
150 };
151
152 #endif //_OpenGl_AspectFace_Header