1 #ifndef COMPOSITOR_FONT_H 2 #define COMPOSITOR_FONT_H 3 4 #include <hb.h> 5 #include <hb-ft.h> 6 //#include <freetype/ftcache.h> 7 #include <vulkan/vulkan.h> 8 9 namespace Compositor{ 10 11 class Text : public Drawable{ 12 friend class TextEngine; 13 public: 14 Text(const char *[Pipeline::SHADER_MODULE_COUNT], class TextEngine *); 15 ~Text(); 16 void Set(const char *, const VkCommandBuffer *); //updates the vertex buffers 17 void Draw(const glm::uvec2 &, const glm::mat2x2 &, const VkCommandBuffer *); 18 void UpdateDescSets(); 19 float GetTextLength() const; 20 float GetBaseline() const; 21 protected: 22 hb_buffer_t *phbBuf; 23 uint glyphCount; 24 float textLength; 25 class TextEngine *ptextEngine; 26 class Buffer *pvertexBuffer; 27 class FontAtlas *pfontAtlas; 28 struct Vertex{ 29 glm::vec2 pos; 30 glm::uvec2 texc; 31 };// alignas(16); 32 static std::vector<std::pair<ShaderModule::INPUT, uint>> vertexBufferLayout; 33 }; 34 35 class TextEngine{ 36 friend class FontAtlas; 37 friend class Text; 38 friend class CompositorInterface; 39 public: 40 TextEngine(const char *, uint, class CompositorInterface *); 41 ~TextEngine(); 42 struct Glyph{ 43 uint codepoint; 44 uint w; 45 uint h; 46 uint pitch; 47 glm::vec2 offset; 48 unsigned char *pbuffer; 49 }; 50 FontAtlas * CreateAtlas(hb_glyph_info_t *, uint, const VkCommandBuffer *); 51 void ReleaseAtlas(FontAtlas *); 52 Buffer * CreateVertexBuffer(); 53 void ReleaseVertexBuffer(Buffer *); 54 void ReleaseCycle(); 55 Glyph * LoadGlyph(uint); 56 float GetFontSize() const; 57 private: 58 class CompositorInterface *pcomp; 59 Buffer *pindexBuffer; //shared index buffer between text objects 60 bool indexBufferMapped; 61 std::vector<Glyph> glyphMap; 62 std::vector<class FontAtlas *> fontAtlasMap; 63 struct VertexBufferCacheEntry{ 64 Buffer *pvertexBuffer; 65 uint64 releaseTag; 66 struct timespec releaseTime; 67 }; 68 std::vector<VertexBufferCacheEntry> vertexBufferCache; 69 FT_Library library; 70 FT_Face fontFace; 71 hb_font_t *phbFont; 72 }; 73 74 class FontAtlas{ 75 public: 76 FontAtlas(uint, class TextEngine *); 77 ~FontAtlas(); 78 void Update(hb_glyph_info_t *, uint, const VkCommandBuffer *); 79 TextEngine *ptextEngine; 80 TextureStaged *ptexture; 81 struct GlyphEntry{ 82 uint codepoint; 83 glm::uvec2 texc; 84 TextEngine::Glyph *pglyph; 85 }; 86 //std::vector<std::pair<uint, glm::uvec2>> glyphCollection; 87 std::vector<GlyphEntry> glyphCollection; 88 glm::uvec2 fontAtlasCursor; //this is useless since Map() for the full region erases everything 89 uint size; 90 uint refCount; 91 uint64 releaseTag; 92 }; 93 94 } 95 96 #endif 97 98