Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
TextPlugin.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
5#include "BatchPlugin.hpp"
7
8#include <string>
9#include <unordered_map>
10#include <vector>
11
12namespace esengine {
13namespace text { class BitmapFont; }
14namespace ecs { struct BitmapText; }
15
16class TextPlugin : public BatchPlugin {
17public:
18 void collect(RenderCollectContext& ctx) override;
19 const char* collectScope() const override { return "render.collect.text"; }
20
21private:
22 static constexpr u32 GLYPHS_PER_BLOCK = 64;
23 struct GlyphBlock { glm::vec3 min, max; };
24 // Local glyph quads and ink bounds are cached per content signature.
25 // World transforms, parallax and tint apply at collect; the whole text
26 // remains one command rather than one per glyph.
27 struct TextLayoutCache {
28 std::vector<BatchVertex> vertices;
29 std::vector<u32> indices;
30 std::vector<GlyphBlock> blocks;
31 glm::vec3 min{0.0f};
32 glm::vec3 max{0.0f};
33 std::string text;
34 u32 font_id = 0;
35 f32 font_size = 0.0f;
36 f32 spacing = 0.0f;
37 u8 align = 0;
38 };
39
40 void rebuildLayout(const text::BitmapFont& font, const ecs::BitmapText& bt,
41 f32 texW, f32 texH, TextLayoutCache& cache);
42
43 std::unordered_map<Entity, TextLayoutCache> layout_cache_;
44 std::vector<BatchVertex> scratch_;
45 std::vector<u32> index_scratch_;
46};
47
48} // namespace esengine
Base class for render-type plugins that emit textured quads into the Batch stream.
const char * collectScope() const override
What this plugin's collect is called in a frame profile.
void collect(RenderCollectContext &ctx) override
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::uint8_t u8
Unsigned 8-bit integer.
Definition Types.hpp:41
static EstellaContext & ctx()
float f32
32-bit floating point
Definition Types.hpp:59