Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
a174a3c5 | 3 | // Copyright (c) 2011-2013 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa SK |
16 | #ifndef OpenGl_Text_Header |
17 | #define OpenGl_Text_Header | |
18 | ||
19 | #include <OpenGl_Element.hxx> | |
20 | ||
bf5f0ca2 | 21 | #include <OpenGl_Aspects.hxx> |
317d68c9 | 22 | #include <OpenGl_TextBuilder.hxx> |
2166f0fa SK |
23 | |
24 | #include <TCollection_ExtendedString.hxx> | |
2166f0fa | 25 | #include <Graphic3d_HorizontalTextAlignment.hxx> |
4b1c8733 | 26 | #include <Graphic3d_RenderingParams.hxx> |
8ed07085 | 27 | #include <Graphic3d_Text.hxx> |
2166f0fa SK |
28 | #include <Graphic3d_VerticalTextAlignment.hxx> |
29 | ||
ce01ec26 | 30 | #include <gp_Ax2.hxx> |
31 | ||
a174a3c5 | 32 | //! Text rendering |
2166f0fa SK |
33 | class OpenGl_Text : public OpenGl_Element |
34 | { | |
5e27df78 | 35 | |
36 | public: | |
2166f0fa | 37 | |
ce01ec26 | 38 | //! Creates new text in 3D space. |
8ed07085 | 39 | Standard_EXPORT OpenGl_Text (const Handle(Graphic3d_Text)& theTextParams); |
ce01ec26 | 40 | |
5e30547b | 41 | //! Destructor |
42 | Standard_EXPORT virtual ~OpenGl_Text(); | |
43 | ||
8ed07085 | 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); | |
a174a3c5 | 48 | |
8ed07085 | 49 | //! Returns text parameters |
50 | //! @sa Reset() | |
51 | const Handle(Graphic3d_Text)& Text() const { return myText; } | |
a174a3c5 | 52 | |
8ed07085 | 53 | //! Sets text parameters |
54 | //! @sa Reset() | |
55 | void SetText (const Handle(Graphic3d_Text)& theText) { myText = theText; } | |
56 | ||
57 | //! Return true if text is 2D | |
58 | Standard_Boolean Is2D() const { return myIs2d; } | |
59 | ||
60 | //! Set true if text is 2D | |
61 | void Set2D (const Standard_Boolean theEnable) { myIs2d = theEnable; } | |
a174a3c5 | 62 | |
63 | //! Setup new font size | |
64 | Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext, | |
65 | const Standard_Integer theFontSize); | |
66 | ||
bc73b006 | 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; | |
a174a3c5 | 69 | |
3d60d73f | 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; | |
72 | ||
b9f43ad1 | 73 | //! Increment draw calls statistics. |
74 | Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, | |
75 | bool theIsDetailed) const Standard_OVERRIDE; | |
76 | ||
a174a3c5 | 77 | public: //! @name methods for compatibility with layers |
78 | ||
79 | //! Empty constructor | |
6a240ff8 | 80 | Standard_EXPORT OpenGl_Text(); |
a174a3c5 | 81 | |
82 | //! Create key for shared resource | |
bf5f0ca2 | 83 | Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_Aspects& theAspect, |
84 | Standard_Integer theHeight, | |
d37aef5c | 85 | unsigned int theResolution, |
86 | Font_Hinting theFontHinting); | |
a174a3c5 | 87 | |
88 | //! Find shared resource for specified font or initialize new one | |
6a240ff8 | 89 | Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx, |
bf5f0ca2 | 90 | const OpenGl_Aspects& theAspect, |
91 | Standard_Integer theHeight, | |
92 | unsigned int theResolution, | |
d37aef5c | 93 | Font_Hinting theFontHinting, |
bf5f0ca2 | 94 | const TCollection_AsciiString& theKey); |
a174a3c5 | 95 | |
96 | //! Compute text width | |
6a240ff8 | 97 | Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx, |
98 | const NCollection_String& theText, | |
bf5f0ca2 | 99 | const OpenGl_Aspects& theTextAspect, |
8ed07085 | 100 | const Standard_ShortReal theHeight, |
4b1c8733 | 101 | const unsigned int theResolution, |
d37aef5c | 102 | const Font_Hinting theFontHinting, |
6a240ff8 | 103 | Standard_ShortReal& theWidth, |
104 | Standard_ShortReal& theAscent, | |
105 | Standard_ShortReal& theDescent); | |
a174a3c5 | 106 | |
a174a3c5 | 107 | //! Perform rendering |
60273f77 | 108 | Standard_EXPORT void Render (const Handle(OpenGl_Context)& theCtx, |
bf5f0ca2 | 109 | const OpenGl_Aspects& theTextAspect, |
d37aef5c | 110 | unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION, |
111 | Font_Hinting theFontHinting = Font_Hinting_Off) const; | |
a174a3c5 | 112 | |
bc73b006 | 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; | |
115 | ||
8ed07085 | 116 | //! @name obsolete methods |
117 | public: | |
118 | ||
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); | |
124 | ||
125 | //! Setup new position | |
126 | Standard_DEPRECATED("Deprecated method SetPosition(), use Graphic3d_Text for it") | |
127 | Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint); | |
128 | ||
a174a3c5 | 129 | protected: |
130 | ||
a174a3c5 | 131 | friend class OpenGl_Trihedron; |
132 | friend class OpenGl_GraduatedTrihedron; | |
133 | ||
a174a3c5 | 134 | //! Release cached VBO resources |
15669413 | 135 | Standard_EXPORT void releaseVbos (OpenGl_Context* theCtx); |
136 | ||
137 | private: | |
a174a3c5 | 138 | |
139 | //! Setup matrix. | |
60273f77 | 140 | void setupMatrix (const Handle(OpenGl_Context)& theCtx, |
bf5f0ca2 | 141 | const OpenGl_Aspects& theTextAspect, |
142 | const OpenGl_Vec3& theDVec) const; | |
a174a3c5 | 143 | |
144 | //! Draw arrays of vertices. | |
60273f77 | 145 | void drawText (const Handle(OpenGl_Context)& theCtx, |
bf5f0ca2 | 146 | const OpenGl_Aspects& theTextAspect) const; |
a174a3c5 | 147 | |
6fe58c66 | 148 | //! Draw rectangle from bounding text box. |
149 | void drawRect (const Handle(OpenGl_Context)& theCtx, | |
bf5f0ca2 | 150 | const OpenGl_Aspects& theTextAspect, |
151 | const OpenGl_Vec4& theColorSubs) const; | |
6fe58c66 | 152 | |
a174a3c5 | 153 | //! Main rendering code |
60273f77 | 154 | void render (const Handle(OpenGl_Context)& theCtx, |
bf5f0ca2 | 155 | const OpenGl_Aspects& theTextAspect, |
156 | const OpenGl_Vec4& theColorText, | |
157 | const OpenGl_Vec4& theColorSubs, | |
d37aef5c | 158 | unsigned int theResolution, |
159 | Font_Hinting theFontHinting) const; | |
a174a3c5 | 160 | |
161 | protected: | |
2166f0fa | 162 | |
8ed07085 | 163 | Handle(Graphic3d_Text) myText; //!< text parameters |
a174a3c5 | 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 | |
6fe58c66 | 168 | mutable Handle(OpenGl_VertexBuffer) myBndVertsVbo;//!< VBOs of vertices for bounding box |
d2eddacc | 169 | mutable Font_Rect myBndBox; |
5e27df78 | 170 | |
171 | protected: | |
172 | ||
c827ea3a | 173 | mutable OpenGl_Mat4d myProjMatrix; |
174 | mutable OpenGl_Mat4d myModelMatrix; | |
ce01ec26 | 175 | mutable OpenGl_Mat4d myOrientationMatrix; |
a3a3ff3d | 176 | mutable OpenGl_Vec3d myWinXYZ; |
a174a3c5 | 177 | mutable GLdouble myScaleHeight; |
2166f0fa | 178 | |
5e27df78 | 179 | protected: |
2166f0fa | 180 | |
8ed07085 | 181 | Standard_Boolean myIs2d; |
5e27df78 | 182 | public: |
183 | ||
1c35b92f | 184 | DEFINE_STANDARD_ALLOC |
5e27df78 | 185 | |
2166f0fa SK |
186 | }; |
187 | ||
188 | #endif //OpenGl_Text_Header |