0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[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
a174a3c5 21#include <OpenGl_AspectText.hxx>
2166f0fa 22#include <OpenGl_TextParam.hxx>
a174a3c5 23#include <OpenGl_TextFormatter.hxx>
2166f0fa
SK
24
25#include <TCollection_ExtendedString.hxx>
26#include <Graphic3d_Vertex.hxx>
27#include <Graphic3d_HorizontalTextAlignment.hxx>
28#include <Graphic3d_VerticalTextAlignment.hxx>
29
a174a3c5 30class Handle(OpenGl_PrinterContext);
31
32//! Text rendering
2166f0fa
SK
33class OpenGl_Text : public OpenGl_Element
34{
5e27df78 35
36public:
2166f0fa 37
a174a3c5 38 //! Main constructor
b64d84be 39 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
40 const OpenGl_Vec3& thePoint,
41 const OpenGl_TextParam& theParams);
a174a3c5 42
43 //! Setup new string and position
44 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
45 const Standard_Utf8Char* theText,
46 const OpenGl_Vec3& thePoint);
47
48 //! Setup new string and parameters
49 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
50 const Standard_Utf8Char* theText,
51 const OpenGl_Vec3& thePoint,
52 const OpenGl_TextParam& theParams);
53
54 //! Setup new position
55 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
56
57 //! Setup new font size
58 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
59 const Standard_Integer theFontSize);
60
61 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
62 Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theContext);
63
64public: //! @name methods for compatibility with layers
65
66 //! Empty constructor
6a240ff8 67 Standard_EXPORT OpenGl_Text();
a174a3c5 68
69 //! Create key for shared resource
6a240ff8 70 Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
71 const Standard_Integer theHeight);
a174a3c5 72
73 //! Find shared resource for specified font or initialize new one
6a240ff8 74 Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
75 const OpenGl_AspectText& theAspect,
76 const Standard_Integer theHeight,
77 const TCollection_AsciiString theKey);
a174a3c5 78
79 //! Compute text width
6a240ff8 80 Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
81 const NCollection_String& theText,
82 const OpenGl_AspectText& theTextAspect,
83 const OpenGl_TextParam& theParams,
84 Standard_ShortReal& theWidth,
85 Standard_ShortReal& theAscent,
86 Standard_ShortReal& theDescent);
a174a3c5 87
88 //! Setup new string and parameters
6a240ff8 89 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
90 const TCollection_ExtendedString& theText,
91 const OpenGl_Vec2& thePoint,
92 const OpenGl_TextParam& theParams);
a174a3c5 93
94 //! Perform rendering
6a240ff8 95 Standard_EXPORT void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
96 const Handle(OpenGl_Context)& theCtx,
97 const OpenGl_AspectText& theTextAspect) const;
a174a3c5 98
99protected:
100
101 //! Destructor
102 Standard_EXPORT virtual ~OpenGl_Text();
103
104 friend class OpenGl_Trihedron;
105 friend class OpenGl_GraduatedTrihedron;
106
107private:
108
109 //! Release cached VBO resources
110 void releaseVbos (const Handle(OpenGl_Context)& theCtx);
111
112 //! Setup matrix.
113 void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
114 const Handle(OpenGl_Context)& theCtx,
115 const OpenGl_AspectText& theTextAspect,
116 const OpenGl_Vec3 theDVec) const;
117
118 //! Draw arrays of vertices.
119 void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
120 const Handle(OpenGl_Context)& theCtx,
121 const OpenGl_AspectText& theTextAspect) const;
122
123 //! Main rendering code
124 void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
125 const Handle(OpenGl_Context)& theCtx,
126 const OpenGl_AspectText& theTextAspect,
127 const TEL_COLOUR& theColorText,
128 const TEL_COLOUR& theColorSubs) const;
129
130protected:
2166f0fa 131
a174a3c5 132 mutable Handle(OpenGl_Font) myFont;
133 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
134 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
135 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
136 mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myVertsArray; //!< arrays of vertices (for compatibility mode)
137 mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myTCrdsArray; //!< arrays of vertices (for compatibility mode)
138 mutable Font_FTFont::Rect myBndBox;
5e27df78 139
140protected:
141
a174a3c5 142 mutable GLdouble myProjMatrix[16];
143 mutable GLdouble myModelMatrix[16];
144 mutable GLint myViewport[4];
145 mutable GLdouble myWinX;
146 mutable GLdouble myWinY;
147 mutable GLdouble myWinZ;
148 mutable GLdouble myScaleHeight;
149 mutable GLdouble myExportHeight;
2166f0fa 150
5e27df78 151protected:
2166f0fa 152
a174a3c5 153 OpenGl_TextParam myParams;
154 NCollection_String myString;
155 OpenGl_Vec3 myPoint;
156 bool myIs2d;
2166f0fa 157
5e27df78 158public:
159
1c35b92f 160 DEFINE_STANDARD_ALLOC
5e27df78 161
2166f0fa
SK
162};
163
164#endif //OpenGl_Text_Header