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

◆ ink_quads()

MAYAFLUX_API void MayaFlux::Portal::Text::ink_quads ( const std::shared_ptr< Buffers::TextBuffer > &  target,
std::span< const GlyphQuad >  quads,
glm::vec4  color,
GlyphAtlas *  atlas = nullptr 
)

Rasterize a mutated quad span into an existing TextBuffer.

Clears the buffer's pixel region to target->get_background(), rasterizes quads via rasterize_quads(), and marks the buffer dirty for GPU upload. The scratch pixel buffer is thread-local and reused across calls, so no heap allocation occurs after the first call at a given buffer size.

Typical usage:

auto layout = Portal::Text::create_layout(text, 0.F, 0.F, wrap_w);
// ... per-quad mutation ...
Portal::Text::ink_quads(text_buf, layout->quads, color);
glm::vec3 color
Definition Decoder.cpp:97
void ink_quads(const std::shared_ptr< Buffers::TextBuffer > &target, std::span< const GlyphQuad > quads, glm::vec4 color, GlyphAtlas *atlas_hint)
Rasterize a mutated quad span into an existing TextBuffer.
Definition InkPress.cpp:311
std::shared_ptr< LayoutResult > create_layout(std::string_view text, float pen_x, float pen_y, uint32_t wrap_w)
Lay out a UTF-8 string into screen-space glyph quads using the default atlas.
Definition Text.cpp:52

quads' UV coordinates are only meaningful against the atlas they were laid out from. atlas null (the default) resolves to whatever the TypeFaceFoundry default atlas is at this call, not at layout time: if something else has called set_default_font() since, or the atlas has grown, a held LayoutResult's quads will sample the wrong texture. Pass the same atlas the quads were laid out against explicitly whenever it might not still be the current default by the time this runs.

Parameters
targetTextBuffer to write into. Dimensions are read from the buffer.
quadsQuads produced by create_layout(), optionally mutated by the caller.
colorRGBA glyph color in [0, 1].
atlasAtlas the quads' UVs are relative to. Null selects the TypeFaceFoundry default at call time.

Definition at line 311 of file InkPress.cpp.

316{
317 if (!target) {
318 MF_ERROR(Journal::Component::Portal, Journal::Context::API,
319 "ink_quads: target buffer is null");
320 return;
321 }
322
323 GlyphAtlas* atlas = resolve_atlas(atlas_hint);
324 if (!atlas) {
325 return;
326 }
327
328 const uint32_t buf_w = target->get_budget_width();
329 const uint32_t buf_h = target->get_budget_height();
330 const size_t buf_bytes = static_cast<size_t>(buf_w) * buf_h * 4;
331
332 thread_local std::vector<uint8_t> pixels;
333 pixels.resize(buf_bytes);
334 fill_bytes(pixels.data(), buf_bytes, target->get_background());
335
336 rasterize_quads(quads, *atlas, color, pixels.data(), buf_w, buf_h);
337 target->set_pixel_data(pixels.data(), buf_bytes);
338}
#define MF_ERROR(comp, ctx,...)
std::vector< uint8_t > pixels
Definition InkPress.cpp:32

References MayaFlux::Journal::API, color, MF_ERROR, pixels, MayaFlux::Journal::Portal, and rasterize_quads().

+ Here is the call graph for this function: