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_Text_HeaderFile
17 #define OpenGl_Text_HeaderFile
19 #include <OpenGl_Element.hxx>
21 #include <OpenGl_Aspects.hxx>
22 #include <OpenGl_TextBuilder.hxx>
24 #include <TCollection_ExtendedString.hxx>
25 #include <Graphic3d_HorizontalTextAlignment.hxx>
26 #include <Graphic3d_RenderingParams.hxx>
27 #include <Graphic3d_Text.hxx>
28 #include <Graphic3d_VerticalTextAlignment.hxx>
33 class OpenGl_Text : public OpenGl_Element
38 //! Creates new text in 3D space.
39 Standard_EXPORT OpenGl_Text (const Handle(Graphic3d_Text)& theTextParams);
42 Standard_EXPORT virtual ~OpenGl_Text();
44 //! Release cached VBO resources and the previous font if height changed.
45 //! Cached structures will be refilled by the next render.
46 //! Call Reset after modifying text parameters.
47 Standard_EXPORT void Reset (const Handle(OpenGl_Context)& theCtx);
49 //! Returns text parameters
51 const Handle(Graphic3d_Text)& Text() const { return myText; }
53 //! Sets text parameters
55 void SetText (const Handle(Graphic3d_Text)& theText) { myText = theText; }
57 //! Return true if text is 2D
58 Standard_Boolean Is2D() const { return myIs2d; }
60 //! Set true if text is 2D
61 void Set2D (const Standard_Boolean theEnable) { myIs2d = theEnable; }
63 //! Setup new font size
64 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
65 const Standard_Integer theFontSize);
67 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
68 Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
70 //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
71 Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
73 //! Increment draw calls statistics.
74 Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
75 bool theIsDetailed) const Standard_OVERRIDE;
77 public: //! @name methods for compatibility with layers
80 Standard_EXPORT OpenGl_Text();
82 //! Create key for shared resource
83 Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_Aspects& theAspect,
84 Standard_Integer theHeight,
85 unsigned int theResolution,
86 Font_Hinting theFontHinting);
88 //! Find shared resource for specified font or initialize new one
89 Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
90 const OpenGl_Aspects& theAspect,
91 Standard_Integer theHeight,
92 unsigned int theResolution,
93 Font_Hinting theFontHinting,
94 const TCollection_AsciiString& theKey);
96 //! Compute text width
97 Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
98 const NCollection_String& theText,
99 const OpenGl_Aspects& theTextAspect,
100 const Standard_ShortReal theHeight,
101 const unsigned int theResolution,
102 const Font_Hinting theFontHinting,
103 Standard_ShortReal& theWidth,
104 Standard_ShortReal& theAscent,
105 Standard_ShortReal& theDescent);
107 //! Perform rendering
108 Standard_EXPORT void Render (const Handle(OpenGl_Context)& theCtx,
109 const OpenGl_Aspects& theTextAspect,
110 unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION,
111 Font_Hinting theFontHinting = Font_Hinting_Off) const;
113 //! Dumps the content of me into the stream
114 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
116 //! @name obsolete methods
119 //! Setup new string and position
120 Standard_DEPRECATED("Deprecated method Init() with obsolete arguments, use Init() and Text() instead of it")
121 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
122 const Standard_Utf8Char* theText,
123 const OpenGl_Vec3& thePoint);
125 //! Setup new position
126 Standard_DEPRECATED("Deprecated method SetPosition(), use Graphic3d_Text for it")
127 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
131 friend class OpenGl_Trihedron;
132 friend class OpenGl_GraduatedTrihedron;
134 //! Release cached VBO resources
135 Standard_EXPORT void releaseVbos (OpenGl_Context* theCtx);
140 void setupMatrix (const Handle(OpenGl_Context)& theCtx,
141 const OpenGl_Aspects& theTextAspect,
142 const OpenGl_Vec3& theDVec) const;
144 //! Draw arrays of vertices.
145 void drawText (const Handle(OpenGl_Context)& theCtx,
146 const OpenGl_Aspects& theTextAspect) const;
148 //! Draw rectangle from bounding text box.
149 void drawRect (const Handle(OpenGl_Context)& theCtx,
150 const OpenGl_Aspects& theTextAspect,
151 const OpenGl_Vec4& theColorSubs) const;
153 //! Main rendering code
154 void render (const Handle(OpenGl_Context)& theCtx,
155 const OpenGl_Aspects& theTextAspect,
156 const OpenGl_Vec4& theColorText,
157 const OpenGl_Vec4& theColorSubs,
158 unsigned int theResolution,
159 Font_Hinting theFontHinting) const;
163 Handle(Graphic3d_Text) myText; //!< text parameters
164 mutable Handle(OpenGl_Font) myFont;
165 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
166 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
167 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
168 mutable Handle(OpenGl_VertexBuffer) myBndVertsVbo;//!< VBOs of vertices for bounding box
169 mutable Font_Rect myBndBox;
173 mutable OpenGl_Mat4d myProjMatrix;
174 mutable OpenGl_Mat4d myModelMatrix;
175 mutable OpenGl_Mat4d myOrientationMatrix;
176 mutable OpenGl_Vec3d myWinXYZ;
177 mutable GLdouble myScaleHeight;
181 Standard_Boolean myIs2d;
184 DEFINE_STANDARD_ALLOC
188 #endif //OpenGl_Text_Header