MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlyphMesh.cpp
Go to the documentation of this file.
1#include "GlyphMesh.hpp"
2
4
5GlyphMap GlyphMap::fit(Kinesis::AABB2D region, glm::vec2 source_px) noexcept
6{
7 const glm::vec2 source = glm::max(source_px, glm::vec2(1.F));
8 return {
9 .origin = { region.min.x, region.max.y },
10 .scale = { region.width() / source.x, -region.height() / source.y },
11 };
12}
13
14std::vector<Kakshya::MeshVertex> glyph_vertices(
15 std::span<const GlyphQuad> quads,
16 glm::vec4 color,
17 std::span<const StyleSpan> spans,
18 const GlyphMap& map,
19 uint32_t slot)
20{
21 using V = Kakshya::MeshVertex;
22
23 std::vector<V> out;
24 out.reserve(quads.size() * 6);
25
26 const float weight = coverage_weight(slot);
27
28 for (const auto& q : quads) {
29 glm::vec3 rgb { color };
30 for (auto it = spans.rbegin(); it != spans.rend(); ++it) {
31 const size_t lo = std::min(it->start, it->end);
32 const size_t hi = std::max(it->start, it->end);
33 if (q.byte_offset >= lo && q.byte_offset < hi) {
34 rgb = glm::vec3(it->color);
35 break;
36 }
37 }
38
39 const glm::vec2 top_left = map({ q.x0, q.y0 });
40 const glm::vec2 bottom_right = map({ q.x1, q.y1 });
41
42 const V bl { .position = { top_left.x, bottom_right.y, 0.F }, .color = rgb, .weight = weight, .uv = { q.uv_x0, q.uv_y1 } };
43 const V br { .position = { bottom_right.x, bottom_right.y, 0.F }, .color = rgb, .weight = weight, .uv = { q.uv_x1, q.uv_y1 } };
44 const V tl { .position = { top_left.x, top_left.y, 0.F }, .color = rgb, .weight = weight, .uv = { q.uv_x0, q.uv_y0 } };
45 const V tr { .position = { bottom_right.x, top_left.y, 0.F }, .color = rgb, .weight = weight, .uv = { q.uv_x1, q.uv_y0 } };
46
47 out.insert(out.end(), { bl, br, tl, br, tr, tl });
48 }
49
50 return out;
51}
52
53} // namespace MayaFlux::Portal::Text
glm::vec3 color
Definition Decoder.cpp:97
double weight
double q
std::vector< float > * out
std::vector< Kakshya::MeshVertex > glyph_vertices(std::span< const GlyphQuad > quads, glm::vec4 color, std::span< const StyleSpan > spans, const GlyphMap &map, uint32_t slot)
Triangle list vertices for glyph quads, six per quad.
Definition GlyphMesh.cpp:14
constexpr float coverage_weight(uint32_t slot) noexcept
MeshVertex::weight that makes a fragment shader read a texture slot as glyph coverage rather than as ...
Definition GlyphMesh.hpp:50
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
static GlyphMap fit(Kinesis::AABB2D region, glm::vec2 source_px) noexcept
Map layout pixels [0, source_px] onto region, y flipped.
Definition GlyphMesh.cpp:5
Linear map from layout pixels to whatever space the vertices are drawn in.
Definition GlyphMesh.hpp:21