0025675: Visualization - Fix problems and inefficiencies with frustum culling
[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 <InterfaceGraphic_Graphic3d.hxx>
20 #include <Font_FontAspect.hxx>
21 #include <Aspect_TypeOfStyleText.hxx>
22 #include <Aspect_TypeOfDisplayText.hxx>
23 #include <Graphic3d_CAspectText.hxx>
24
25 #include <TCollection_AsciiString.hxx>
26
27 #include <OpenGl_Element.hxx>
28 #include <Handle_OpenGl_ShaderProgram.hxx>
29
30 //! Text representation parameters
31 class OpenGl_AspectText : public OpenGl_Element
32 {
33
34 public:
35
36   Standard_EXPORT OpenGl_AspectText();
37   Standard_EXPORT virtual ~OpenGl_AspectText();
38
39   //! Copy parameters
40   Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect);
41
42   //! @return font family name
43   const TCollection_AsciiString& FontName() const
44   {
45     return myFont;
46   }
47
48   //! @return font family name
49   TCollection_AsciiString& ChangeFontName()
50   {
51     return myFont;
52   }
53
54   //! @return is zoomable flag
55   bool IsZoomable() const
56   {
57     return myZoomable;
58   }
59
60   //! @return rotation angle
61   float Angle() const
62   {
63     return myAngle;
64   }
65
66   //! @return font aspect (regular/bold/italic)
67   Font_FontAspect FontAspect() const
68   {
69     return myFontAspect;
70   }
71
72   //! @param theValue font aspect (regular/bold/italic)
73   void SetFontAspect (const Font_FontAspect theValue)
74   {
75     myFontAspect = theValue;
76   }
77
78   //! @return text color
79   const TEL_COLOUR& Color() const
80   {
81     return myColor;
82   }
83
84   //! @return text color
85   TEL_COLOUR& ChangeColor()
86   {
87     return myColor;
88   }
89
90   //! @return annotation style
91   Aspect_TypeOfStyleText StyleType() const
92   {
93     return myStyleType;
94   }
95
96   //! @return subtitle style (none/blend/decale/subtitle)
97   Aspect_TypeOfDisplayText DisplayType() const
98   {
99     return myDisplayType;
100   }
101
102   void SetDisplayType (const Aspect_TypeOfDisplayText theType)
103   {
104     myDisplayType = theType;
105   }
106
107   //! @return subtitle color
108   const TEL_COLOUR& SubtitleColor() const
109   {
110     return mySubtitleColor;
111   }
112
113   //! @return subtitle color
114   TEL_COLOUR& ChangeSubtitleColor()
115   {
116     return mySubtitleColor;
117   }
118
119   //! Init and return OpenGl shader program resource.
120   //! @return shader program resource.
121   const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
122   {
123     if (!myResources.IsShaderReady())
124     {
125       myResources.BuildShader (theCtx, myShaderProgram);
126       myResources.SetShaderReady();
127     }
128
129     return myResources.ShaderProgram;
130   }
131
132   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
133   Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
134
135 protected:
136
137   TCollection_AsciiString         myFont;
138   TEL_COLOUR                      myColor;
139   TEL_COLOUR                      mySubtitleColor;
140   float                           myAngle;
141   Aspect_TypeOfStyleText          myStyleType;
142   Aspect_TypeOfDisplayText        myDisplayType;
143   Font_FontAspect                 myFontAspect;
144   bool                            myZoomable;
145   Handle(Graphic3d_ShaderProgram) myShaderProgram;
146
147 protected:
148
149   //! OpenGl resources
150   mutable struct Resources
151   {
152   public:
153     Resources() : myIsShaderReady (Standard_False) {}
154
155     Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
156     void SetShaderReady()       { myIsShaderReady = Standard_True; }
157     void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
158
159     Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)&          theCtx,
160                                       const Handle(Graphic3d_ShaderProgram)& theShader);
161
162     Handle(OpenGl_ShaderProgram) ShaderProgram;
163     TCollection_AsciiString      ShaderProgramId;
164
165   private:
166
167     Standard_Boolean myIsShaderReady;
168
169   } myResources;
170
171 public:
172
173   DEFINE_STANDARD_ALLOC
174
175 };
176
177 #endif // OpenGl_AspectText_Header