0031505: Point Cloud Rendering - fix on-screen statistics about number of visible...
[occt.git] / src / OpenGl / OpenGl_Text.hxx
CommitLineData
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>
25#include <Graphic3d_Vertex.hxx>
26#include <Graphic3d_HorizontalTextAlignment.hxx>
4b1c8733 27#include <Graphic3d_RenderingParams.hxx>
8ed07085 28#include <Graphic3d_Text.hxx>
2166f0fa
SK
29#include <Graphic3d_VerticalTextAlignment.hxx>
30
ce01ec26 31#include <gp_Ax2.hxx>
32
a174a3c5 33//! Text rendering
2166f0fa
SK
34class OpenGl_Text : public OpenGl_Element
35{
5e27df78 36
37public:
2166f0fa 38
ce01ec26 39 //! Creates new text in 3D space.
8ed07085 40 Standard_EXPORT OpenGl_Text (const Handle(Graphic3d_Text)& theTextParams);
ce01ec26 41
5e30547b 42 //! Destructor
43 Standard_EXPORT virtual ~OpenGl_Text();
44
8ed07085 45 //! Release cached VBO resources and the previous font if height changed.
46 //! Cached structures will be refilled by the next render.
47 //! Call Reset after modifying text parameters.
48 Standard_EXPORT void Reset (const Handle(OpenGl_Context)& theCtx);
a174a3c5 49
8ed07085 50 //! Returns text parameters
51 //! @sa Reset()
52 const Handle(Graphic3d_Text)& Text() const { return myText; }
a174a3c5 53
8ed07085 54 //! Sets text parameters
55 //! @sa Reset()
56 void SetText (const Handle(Graphic3d_Text)& theText) { myText = theText; }
57
58 //! Return true if text is 2D
59 Standard_Boolean Is2D() const { return myIs2d; }
60
61 //! Set true if text is 2D
62 void Set2D (const Standard_Boolean theEnable) { myIs2d = theEnable; }
a174a3c5 63
64 //! Setup new font size
65 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
66 const Standard_Integer theFontSize);
67
bc73b006 68 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
69 Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
a174a3c5 70
3d60d73f 71 //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
72 Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
73
b9f43ad1 74 //! Increment draw calls statistics.
75 Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
76 bool theIsDetailed) const Standard_OVERRIDE;
77
a174a3c5 78public: //! @name methods for compatibility with layers
79
80 //! Empty constructor
6a240ff8 81 Standard_EXPORT OpenGl_Text();
a174a3c5 82
83 //! Create key for shared resource
bf5f0ca2 84 Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_Aspects& theAspect,
85 Standard_Integer theHeight,
86 unsigned int theResolution);
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,
93 const TCollection_AsciiString& theKey);
a174a3c5 94
95 //! Compute text width
6a240ff8 96 Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
97 const NCollection_String& theText,
bf5f0ca2 98 const OpenGl_Aspects& theTextAspect,
8ed07085 99 const Standard_ShortReal theHeight,
4b1c8733 100 const unsigned int theResolution,
6a240ff8 101 Standard_ShortReal& theWidth,
102 Standard_ShortReal& theAscent,
103 Standard_ShortReal& theDescent);
a174a3c5 104
a174a3c5 105 //! Perform rendering
60273f77 106 Standard_EXPORT void Render (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 107 const OpenGl_Aspects& theTextAspect,
108 unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
a174a3c5 109
bc73b006 110 //! Dumps the content of me into the stream
111 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
112
8ed07085 113//! @name obsolete methods
114public:
115
116 //! Setup new string and position
117 Standard_DEPRECATED("Deprecated method Init() with obsolete arguments, use Init() and Text() instead of it")
118 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
119 const Standard_Utf8Char* theText,
120 const OpenGl_Vec3& thePoint);
121
122 //! Setup new position
123 Standard_DEPRECATED("Deprecated method SetPosition(), use Graphic3d_Text for it")
124 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
125
a174a3c5 126protected:
127
a174a3c5 128 friend class OpenGl_Trihedron;
129 friend class OpenGl_GraduatedTrihedron;
130
a174a3c5 131 //! Release cached VBO resources
15669413 132 Standard_EXPORT void releaseVbos (OpenGl_Context* theCtx);
133
134private:
a174a3c5 135
136 //! Setup matrix.
60273f77 137 void setupMatrix (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 138 const OpenGl_Aspects& theTextAspect,
139 const OpenGl_Vec3& theDVec) const;
a174a3c5 140
141 //! Draw arrays of vertices.
60273f77 142 void drawText (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 143 const OpenGl_Aspects& theTextAspect) const;
a174a3c5 144
6fe58c66 145 //! Draw rectangle from bounding text box.
146 void drawRect (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 147 const OpenGl_Aspects& theTextAspect,
148 const OpenGl_Vec4& theColorSubs) const;
6fe58c66 149
a174a3c5 150 //! Main rendering code
60273f77 151 void render (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 152 const OpenGl_Aspects& theTextAspect,
153 const OpenGl_Vec4& theColorText,
154 const OpenGl_Vec4& theColorSubs,
155 unsigned int theResolution) const;
a174a3c5 156
157protected:
2166f0fa 158
8ed07085 159 Handle(Graphic3d_Text) myText; //!< text parameters
a174a3c5 160 mutable Handle(OpenGl_Font) myFont;
161 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
162 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
163 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
6fe58c66 164 mutable Handle(OpenGl_VertexBuffer) myBndVertsVbo;//!< VBOs of vertices for bounding box
d2eddacc 165 mutable Font_Rect myBndBox;
5e27df78 166
167protected:
168
c827ea3a 169 mutable OpenGl_Mat4d myProjMatrix;
170 mutable OpenGl_Mat4d myModelMatrix;
ce01ec26 171 mutable OpenGl_Mat4d myOrientationMatrix;
a3a3ff3d 172 mutable OpenGl_Vec3d myWinXYZ;
a174a3c5 173 mutable GLdouble myScaleHeight;
2166f0fa 174
5e27df78 175protected:
2166f0fa 176
8ed07085 177 Standard_Boolean myIs2d;
5e27df78 178public:
179
1c35b92f 180 DEFINE_STANDARD_ALLOC
5e27df78 181
2166f0fa
SK
182};
183
184#endif //OpenGl_Text_Header