File indexing completed on 2026-09-22 08:58:50
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_DynamicArray.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 struct Tile
0037 {
0038 Font_Rect uv;
0039 Font_Rect px;
0040 GLuint texture;
0041 };
0042
0043 struct RectI
0044 {
0045 int Left;
0046 int Right;
0047 int Top;
0048 int Bottom;
0049 };
0050
0051 public:
0052
0053 Standard_EXPORT OpenGl_Font(const occ::handle<Font_FTFont>& theFont,
0054 const TCollection_AsciiString& theKey = "");
0055
0056
0057 Standard_EXPORT ~OpenGl_Font() override;
0058
0059
0060 Standard_EXPORT void Release(OpenGl_Context* theCtx) override;
0061
0062
0063 Standard_EXPORT size_t EstimatedDataSize() const override;
0064
0065
0066 inline const TCollection_AsciiString& ResourceKey() const { return myKey; }
0067
0068
0069 inline const occ::handle<Font_FTFont>& FTFont() const { return myFont; }
0070
0071
0072 inline bool IsValid() const { return !myTextures.IsEmpty() && myTextures.First()->IsValid(); }
0073
0074
0075
0076
0077 inline bool WasInitialized() const { return !myTextures.IsEmpty(); }
0078
0079
0080
0081 Standard_EXPORT bool Init(const occ::handle<OpenGl_Context>& theCtx);
0082
0083
0084 inline float Ascender() const { return myAscender; }
0085
0086
0087 inline float Descender() const { return myDescender; }
0088
0089
0090
0091
0092
0093 Standard_EXPORT bool RenderGlyph(const occ::handle<OpenGl_Context>& theCtx,
0094 const char32_t theUChar,
0095 Tile& theGlyph);
0096
0097
0098 const occ::handle<OpenGl_Texture>& Texture() const { return myTextures.First(); }
0099
0100 protected:
0101
0102 bool renderGlyph(const occ::handle<OpenGl_Context>& theCtx, const char32_t theChar);
0103
0104
0105 bool createTexture(const occ::handle<OpenGl_Context>& theCtx);
0106
0107 protected:
0108 TCollection_AsciiString myKey;
0109 occ::handle<Font_FTFont> myFont;
0110 float myAscender;
0111 float myDescender;
0112 int myTileSizeY;
0113 int myLastTileId;
0114 RectI myLastTilePx;
0115 int myTextureFormat;
0116
0117 NCollection_DynamicArray<occ::handle<OpenGl_Texture>> myTextures;
0118 NCollection_DynamicArray<Tile> myTiles;
0119
0120 NCollection_DataMap<char32_t, int> myGlyphMap;
0121
0122 public:
0123 DEFINE_STANDARD_RTTIEXT(OpenGl_Font, OpenGl_Resource)
0124 };
0125
0126 #endif