MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ glyph_vertices()

MAYAFLUX_API std::vector< Kakshya::MeshVertex > MayaFlux::Portal::Text::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.

Positions come from map, UVs from the quads, and colour from the last entry of spans whose byte range holds the quad's byte_offset, else color. Vertex colour carries no alpha, so only rgb is used. Every vertex's weight is coverage_weight(slot).

Parameters
quadsQuads from lay_out().
colorColour of quads no span covers.
spansOptional per-byte-range colours, offsets into the laid out text.
mapLayout pixels to output space.
slotAtlas image slot, see coverage_weight().

Definition at line 14 of file GlyphMesh.cpp.

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}
glm::vec3 color
Definition Decoder.cpp:97
double weight
double q
std::vector< float > * out
constexpr T map(T x, T in_lo, T in_hi, T out_lo, T out_hi) noexcept
Map x from [in_lo, in_hi] to [out_lo, out_hi], unclamped.
Definition Scalar.hpp:18
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)

References color, coverage_weight(), out, q, and weight.

Referenced by MayaFlux::Portal::Text::TextRun::vertices().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: