0030153: Visualization, TKOpenGl - AIS_ColoredShape::SynchronizeAspects() doesn't...
[occt.git] / src / OpenGl / OpenGl_AspectText.hxx
1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 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_AspectText_Header
17 #define OpenGl_AspectText_Header
18
19 #include <Font_FontAspect.hxx>
20 #include <Graphic3d_AspectText3d.hxx>
21
22 #include <TCollection_AsciiString.hxx>
23
24 #include <OpenGl_Element.hxx>
25
26 class OpenGl_ShaderProgram;
27
28 //! Text representation parameters
29 class OpenGl_AspectText : public OpenGl_Element
30 {
31
32 public:
33
34   //! Empty constructor.
35   Standard_EXPORT OpenGl_AspectText();
36
37   //! Create and assign parameters.
38   Standard_EXPORT OpenGl_AspectText (const Handle(Graphic3d_AspectText3d)& theAspect);
39
40   //! Destructor.
41   Standard_EXPORT virtual ~OpenGl_AspectText();
42
43   //! Return text aspect.
44   const Handle(Graphic3d_AspectText3d)& Aspect() const { return myAspect; }
45
46   //! Assign new parameters.
47   Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectText3d)& theAspect);
48
49   //! Init and return OpenGl shader program resource.
50   //! @return shader program resource.
51   const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
52   {
53     if (!myResources.IsShaderReady())
54     {
55       myResources.BuildShader (theCtx, myAspect->ShaderProgram());
56       myResources.SetShaderReady();
57     }
58
59     return myResources.ShaderProgram;
60   }
61
62   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
63   Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
64
65   //! Update presentation aspects parameters after their modification.
66   virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); }
67
68 protected:
69
70   //! OpenGl resources
71   mutable struct Resources
72   {
73   public:
74     Resources() : myIsShaderReady (Standard_False) {}
75
76     Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
77     void SetShaderReady()       { myIsShaderReady = Standard_True; }
78     void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
79
80     Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)&          theCtx,
81                                       const Handle(Graphic3d_ShaderProgram)& theShader);
82
83     Handle(OpenGl_ShaderProgram) ShaderProgram;
84     TCollection_AsciiString      ShaderProgramId;
85
86   private:
87
88     Standard_Boolean myIsShaderReady;
89
90   } myResources;
91
92   Handle(Graphic3d_AspectText3d) myAspect;
93
94 public:
95
96   DEFINE_STANDARD_ALLOC
97
98 };
99
100 #endif // OpenGl_AspectText_Header