0028466: Visualization, OpenGl_Context - read GPU memory using WGL_AMD_gpu_associatio...
[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;
63   Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
64
65 protected:
66
67   //! OpenGl resources
68   mutable struct Resources
69   {
70   public:
71     Resources() : myIsShaderReady (Standard_False) {}
72
73     Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
74     void SetShaderReady()       { myIsShaderReady = Standard_True; }
75     void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
76
77     Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)&          theCtx,
78                                       const Handle(Graphic3d_ShaderProgram)& theShader);
79
80     Handle(OpenGl_ShaderProgram) ShaderProgram;
81     TCollection_AsciiString      ShaderProgramId;
82
83   private:
84
85     Standard_Boolean myIsShaderReady;
86
87   } myResources;
88
89   Handle(Graphic3d_AspectText3d) myAspect;
90
91 public:
92
93   DEFINE_STANDARD_ALLOC
94
95 };
96
97 #endif // OpenGl_AspectText_Header