File indexing completed on 2025-01-18 10:04:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef OpenGl_Font_HeaderFile
0017 #define OpenGl_Font_HeaderFile
0018
0019 #include <OpenGl_Texture.hxx>
0020 #include <OpenGl_Vec.hxx>
0021
0022 #include <Font_Rect.hxx>
0023
0024 #include <NCollection_DataMap.hxx>
0025 #include <NCollection_Vector.hxx>
0026 #include <TCollection_AsciiString.hxx>
0027
0028 class Font_FTFont;
0029
0030
0031 class OpenGl_Font : public OpenGl_Resource
0032 {
0033
0034 public:
0035
0036
0037 struct Tile
0038 {
0039 Font_Rect uv;
0040 Font_Rect px;
0041 GLuint texture;
0042 };
0043
0044 struct RectI
0045 {
0046 Standard_Integer Left;
0047 Standard_Integer Right;
0048 Standard_Integer Top;
0049 Standard_Integer Bottom;
0050 };
0051
0052 public:
0053
0054
0055 Standard_EXPORT OpenGl_Font (const Handle(Font_FTFont)& theFont,
0056 const TCollection_AsciiString& theKey = "");
0057
0058
0059 Standard_EXPORT virtual ~OpenGl_Font();
0060
0061
0062 Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
0063
0064
0065 Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
0066
0067
0068 inline const TCollection_AsciiString& ResourceKey() const
0069 {
0070 return myKey;
0071 }
0072
0073
0074 inline const Handle(Font_FTFont)& FTFont() const
0075 {
0076 return myFont;
0077 }
0078
0079
0080 inline bool IsValid() const
0081 {
0082 return !myTextures.IsEmpty() && myTextures.First()->IsValid();
0083 }
0084
0085
0086
0087
0088 inline bool WasInitialized() const
0089 {
0090 return !myTextures.IsEmpty();
0091 }
0092
0093
0094
0095 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx);
0096
0097
0098 inline float Ascender() const
0099 {
0100 return myAscender;
0101 }
0102
0103
0104 inline float Descender() const
0105 {
0106 return myDescender;
0107 }
0108
0109
0110
0111
0112
0113 Standard_EXPORT bool RenderGlyph (const Handle(OpenGl_Context)& theCtx,
0114 const Standard_Utf32Char theUChar,
0115 Tile& theGlyph);
0116
0117
0118 const Handle(OpenGl_Texture)& Texture() const
0119 {
0120 return myTextures.First();
0121 }
0122
0123 protected:
0124
0125
0126 bool renderGlyph (const Handle(OpenGl_Context)& theCtx,
0127 const Standard_Utf32Char theChar);
0128
0129
0130 bool createTexture (const Handle(OpenGl_Context)& theCtx);
0131
0132 protected:
0133
0134 TCollection_AsciiString myKey;
0135 Handle(Font_FTFont) myFont;
0136 Standard_ShortReal myAscender;
0137 Standard_ShortReal myDescender;
0138 Standard_Integer myTileSizeY;
0139 Standard_Integer myLastTileId;
0140 RectI myLastTilePx;
0141 Standard_Integer myTextureFormat;
0142
0143 NCollection_Vector<Handle(OpenGl_Texture)> myTextures;
0144 NCollection_Vector<Tile> myTiles;
0145
0146 NCollection_DataMap<Standard_Utf32Char, Standard_Integer> myGlyphMap;
0147
0148 public:
0149
0150 DEFINE_STANDARD_RTTIEXT(OpenGl_Font,OpenGl_Resource)
0151
0152 };
0153
0154 DEFINE_STANDARD_HANDLE(OpenGl_Font, OpenGl_Resource)
0155
0156 #endif