MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlyphMesh.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "InkPress.hpp"
4#include "TypeSetter.hpp"
5
8
10
11/**
12 * @struct GlyphMap
13 * @brief Linear map from layout pixels to whatever space the vertices are drawn in.
14 *
15 * lay_out() places glyphs in pixels with y growing downward. A map takes such
16 * a point to output space as origin + pixel * scale, so one set of quads can
17 * be drawn in NDC, a world plane or any other space by choosing the map.
18 * Glyphs land on whole output pixels when scale is one pixel of that space
19 * and origin lies on a pixel boundary.
20 */
21struct GlyphMap {
22 glm::vec2 origin { 0.F };
23 glm::vec2 scale { 1.F };
24
25 /**
26 * @brief Map layout pixels [0, source_px] onto @p region, y flipped.
27 *
28 * Pixel (0, 0) lands on the region's top left and @p source_px on its
29 * bottom right, the same placement a texture of that size gets on a quad.
30 *
31 * @param region Destination bounds, y up.
32 * @param source_px Layout size in pixels. Components below one count as one.
33 */
34 [[nodiscard]] static GlyphMap fit(Kinesis::AABB2D region, glm::vec2 source_px) noexcept;
35
36 [[nodiscard]] glm::vec2 operator()(glm::vec2 px) const noexcept { return origin + px * scale; }
37};
38
39/**
40 * @brief MeshVertex::weight that makes a fragment shader read a texture slot
41 * as glyph coverage rather than as an image.
42 *
43 * Positive weights select a slot as an image, zero is a flat colour, and a
44 * negative weight selects slot -weight - 1 as coverage: the shader outputs the
45 * vertex colour with the slot's red channel as alpha (see
46 * data/shaders/include/glyph_coverage.glsl).
47 *
48 * @param slot Zero based index of the atlas image in the shader's texture array.
49 */
50[[nodiscard]] constexpr float coverage_weight(uint32_t slot) noexcept
51{
52 return -static_cast<float>(slot + 1);
53}
54
55/**
56 * @brief Triangle list vertices for glyph quads, six per quad.
57 *
58 * Positions come from @p map, UVs from the quads, and colour from the last
59 * entry of @p spans whose byte range holds the quad's byte_offset, else
60 * @p color. Vertex colour carries no alpha, so only rgb is used. Every
61 * vertex's weight is coverage_weight(@p slot).
62 *
63 * @param quads Quads from lay_out().
64 * @param color Colour of quads no span covers.
65 * @param spans Optional per-byte-range colours, offsets into the laid out text.
66 * @param map Layout pixels to output space.
67 * @param slot Atlas image slot, see coverage_weight().
68 */
69[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::MeshVertex> glyph_vertices(
70 std::span<const GlyphQuad> quads,
71 glm::vec4 color,
72 std::span<const StyleSpan> spans,
73 const GlyphMap& map,
74 uint32_t slot);
75
76} // namespace MayaFlux::Portal::Text
glm::vec3 color
Definition Decoder.cpp:97
uint32_t px
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
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
glm::vec2 operator()(glm::vec2 px) const noexcept
Definition GlyphMesh.hpp:36
Linear map from layout pixels to whatever space the vertices are drawn in.
Definition GlyphMesh.hpp:21