gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
Loading...
Searching...
No Matches
text_modeler.h
1// © Joseph Cameron - MIT License
2
3#ifndef GDK_GRAPHICS_EXT_TEXT_MODELER_H
4#define GDK_GRAPHICS_EXT_TEXT_MODELER_H
5
6#include <gdk/graphics/context.h>
7#include <gdk/graphics/ext/font.h>
8#include <gdk/graphics/ext/font_texture.h>
9#include <gdk/graphics/material.h>
10#include <gdk/graphics/model_data.h>
11#include <gdk/graphics/types.h>
12
13#include <cstddef>
14#include <memory>
15#include <string>
16#include <string_view>
17
18namespace gdk::graphics::ext {
20 class text_modeler final {
21 public:
23 [[nodiscard]] const_model_ptr_type model() const;
24
26 [[nodiscard]] const_material_ptr_type material() const;
27
35 void set_text(std::string_view aUTF8);
36
43 void upload();
44
46 [[nodiscard]] std::size_t uploaded_atlas_generation() const;
47
50 [[nodiscard]] std::size_t fallback_glyph_count() const;
51
53 [[nodiscard]] vector2_type size() const;
54
60 context_ptr_type aContext,
61 std::shared_ptr<font> aFont,
62 material_ptr_type aMaterial = {},
63 float aScale = 0.f
64 );
65
71 context_ptr_type aContext,
72 std::shared_ptr<font_texture> aFontTexture,
73 material_ptr_type aMaterial = {},
74 float aScale = 0.f
75 );
76
77 private:
78 void lay_out();
79
80 std::shared_ptr<font> m_pFont;
81
82 std::shared_ptr<font_texture> m_pFontTexture;
83
84 texture_ptr_type m_pBoundTexture;
85
86 material_ptr_type m_pMaterial;
87
88 model_ptr_type m_pModel;
89
90 std::string m_Text;
91
92 model_data m_Layout;
93
94 std::size_t m_LaidOutAtlasGeneration = 0;
95
96 bool m_LayoutSent = false;
97
98 std::size_t m_FallbackGlyphCount = 0;
99
100 float m_Scale = 0;
101
102 vector2_type m_Size = {0, 0};
103 };
104}
105
106#endif
void set_text(std::string_view aUTF8)
lay out new text, replacing whatever was there.
text_modeler(context_ptr_type aContext, std::shared_ptr< font_texture > aFontTexture, material_ptr_type aMaterial={}, float aScale=0.f)
builds a modeler that draws from a texture of the font's atlas it shares with others
vector2_type size() const
the size of the text laid out by the last set_text, in model units
std::size_t uploaded_atlas_generation() const
the font atlas generation of the texture this modeler draws from
void upload()
brings the model and the atlas texture up to date.
text_modeler(context_ptr_type aContext, std::shared_ptr< font > aFont, material_ptr_type aMaterial={}, float aScale=0.f)
builds a modeler
const_model_ptr_type model() const
get the model, contains the uploaded geometry for the text
const_material_ptr_type material() const
get the material, used to render the model
std::size_t fallback_glyph_count() const
how many glyphs in the last layout could not be rasterised, and were drawn as the font's fallback ins...
vertex data stored in system memory.
Definition model_data.h:25