1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_AspectText_Header
17 #define OpenGl_AspectText_Header
19 #include <Font_FontAspect.hxx>
20 #include <Graphic3d_AspectText3d.hxx>
22 #include <TCollection_AsciiString.hxx>
24 #include <OpenGl_Element.hxx>
26 class OpenGl_ShaderProgram;
28 //! Text representation parameters
29 class OpenGl_AspectText : public OpenGl_Element
34 //! Empty constructor.
35 Standard_EXPORT OpenGl_AspectText();
37 //! Create and assign parameters.
38 Standard_EXPORT OpenGl_AspectText (const Handle(Graphic3d_AspectText3d)& theAspect);
41 Standard_EXPORT virtual ~OpenGl_AspectText();
43 //! Return text aspect.
44 const Handle(Graphic3d_AspectText3d)& Aspect() const { return myAspect; }
46 //! Assign new parameters.
47 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectText3d)& theAspect);
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
53 if (!myResources.IsShaderReady())
55 myResources.BuildShader (theCtx, myAspect->ShaderProgram());
56 myResources.SetShaderReady();
59 return myResources.ShaderProgram;
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;
65 //! Update presentation aspects parameters after their modification.
66 virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); }
71 mutable struct Resources
74 Resources() : myIsShaderReady (Standard_False) {}
76 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
77 void SetShaderReady() { myIsShaderReady = Standard_True; }
78 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
80 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
81 const Handle(Graphic3d_ShaderProgram)& theShader);
83 Handle(OpenGl_ShaderProgram) ShaderProgram;
84 TCollection_AsciiString ShaderProgramId;
88 Standard_Boolean myIsShaderReady;
92 Handle(Graphic3d_AspectText3d) myAspect;
100 #endif // OpenGl_AspectText_Header