a711c7844522616e5ef99c9982945fcc16b13123
[occt.git] / src / OpenGl / OpenGl_Aspects.hxx
1 // Copyright (c) 2019 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _OpenGl_Aspects_Header
15 #define _OpenGl_Aspects_Header
16
17 #include <OpenGl_Element.hxx>
18 #include <OpenGl_AspectsProgram.hxx>
19 #include <OpenGl_AspectsTextureSet.hxx>
20 #include <OpenGl_AspectsSprite.hxx>
21 #include <Graphic3d_Aspects.hxx>
22 #include <Graphic3d_BSDF.hxx>
23
24 //! The element holding Graphic3d_Aspects.
25 class OpenGl_Aspects : public OpenGl_Element
26 {
27 public:
28
29   //! Empty constructor.
30   Standard_EXPORT OpenGl_Aspects();
31
32   //! Create and assign parameters.
33   Standard_EXPORT OpenGl_Aspects (const Handle(Graphic3d_Aspects)& theAspect);
34
35   //! Return aspect.
36   const Handle(Graphic3d_Aspects)& Aspect() const { return myAspect; }
37
38   //! Assign parameters.
39   Standard_EXPORT void SetAspect (const Handle(Graphic3d_Aspects)& theAspect);
40
41   //! Returns Shading Model.
42   Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
43
44   //! Set if lighting should be disabled or not.
45   void SetNoLighting() { myShadingModel = Graphic3d_TOSM_UNLIT; }
46
47   //! Returns textures map.
48   const Handle(OpenGl_TextureSet)& TextureSet (const Handle(OpenGl_Context)& theCtx) const
49   {
50     return myResTextureSet.TextureSet (theCtx, myAspect->TextureSet());
51   }
52
53   //! Init and return OpenGl shader program resource.
54   //! @return shader program resource.
55   const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
56   {
57     return myResProgram.ShaderProgram (theCtx, myAspect->ShaderProgram());
58   }
59
60   //! @return marker size
61   Standard_ShortReal MarkerSize() const { return myResSprite.MarkerSize(); }
62
63   //! Init and return OpenGl point sprite resource.
64   //! @return point sprite texture.
65   const Handle(OpenGl_TextureSet)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const
66   {
67     return myResSprite.Sprite (theCtx, myAspect);
68   }
69
70   //! Init and return OpenGl highlight point sprite resource.
71   //! @return point sprite texture for highlight.
72   const Handle(OpenGl_TextureSet)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const
73   {
74     return myResSprite.SpriteA (theCtx, myAspect);
75   }
76
77   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
78   Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
79
80   //! Update presentation aspects parameters after their modification.
81   virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); }
82
83 protected:
84
85   //! OpenGl resources
86   mutable OpenGl_AspectsProgram    myResProgram;
87   mutable OpenGl_AspectsTextureSet myResTextureSet;
88   mutable OpenGl_AspectsSprite     myResSprite;
89
90   Handle(Graphic3d_Aspects)    myAspect;
91   Graphic3d_TypeOfShadingModel myShadingModel;
92
93 public:
94
95   DEFINE_STANDARD_ALLOC
96
97 };
98
99 #endif // _OpenGl_Aspects_Header