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

◆ repress() [2/2]

MAYAFLUX_API bool MayaFlux::Portal::Text::repress ( std::shared_ptr< Core::VKImage > &  target,
std::string_view  text,
const PressParams &  params = {},
const std::shared_ptr< Buffers::VKBuffer > &  staging = nullptr 
)

Re-composite a UTF-8 string into an existing GPU texture.

Uploads in-place when content fits within the existing image dimensions. Reallocates and updates target when content height exceeds image height.

Parameters
targetVKImage to update. May be replaced on reallocation.
textUTF-8 string to composite.
paramsrender_bounds, atlas, color.
stagingPersistent host-visible staging buffer to upload through. Sized by the caller beforehand (e.g. via Buffers::ensure_image_staging_capacity()) and passed again on every call for the same target to avoid allocating a fresh one each time; nullptr falls back to an internal one-shot staging allocation (the prior behaviour).
Returns
True on success.

Definition at line 505 of file InkPress.cpp.

510{
511 if (!target) {
512 MF_ERROR(Journal::Component::Portal, Journal::Context::API,
513 "repress(VKImage): target is null");
514 return false;
515 }
516
517 GlyphAtlas* atlas = resolve_atlas(params.atlas);
518 if (!atlas)
519 return false;
520
521 const uint32_t buf_w = target->get_width();
522 const uint32_t buf_h = target->get_height();
523
524 const uint32_t composite_h = std::max(buf_h,
525 static_cast<uint32_t>(atlas->line_height()));
526
527 const auto result = composite(text, *atlas, params.color, buf_w, composite_h,
528 static_cast<float>(atlas->ascender()), params.spans, params.background);
529 if (!result) {
530 MF_WARN(Journal::Component::Portal, Journal::Context::API,
531 "repress(VKImage): no glyphs produced for '{}'", std::string(text));
532 return false;
533 }
534
535 auto& loom = Portal::Graphics::get_texture_manager();
536
537 const uint32_t new_h = composite_h;
538 const bool needs_realloc = composite_h != buf_h || buf_w != target->get_width();
539
540 const size_t buf_bytes = static_cast<size_t>(buf_w) * new_h * 4;
541 std::vector<uint8_t> pixels = make_filled(buf_bytes, params.background);
542
543 const uint32_t copy_h = std::min(result->h, new_h);
544 for (uint32_t row = 0; row < copy_h; ++row) {
545 std::memcpy(
546 pixels.data() + static_cast<size_t>(row) * buf_w * 4,
547 result->pixels.data() + static_cast<size_t>(row) * buf_w * 4,
548 static_cast<size_t>(buf_w) * 4);
549 }
550
551 if (needs_realloc) {
552 target = loom.create_2d_uninitialized(buf_w, new_h, Portal::Graphics::ImageFormat::RGBA8, 1);
553 if (!target)
554 return false;
555 if (staging) {
556 loom.upload_data(target, pixels.data(), buf_bytes, staging, true);
557 } else {
558 loom.upload_data(target, pixels.data(), buf_bytes);
559 }
560
561 MF_DEBUG(Journal::Component::Portal, Journal::Context::API,
562 "repress(VKImage): reallocated {}x{}", buf_w, new_h);
563 return true;
564 }
565
566 if (staging) {
567 loom.upload_data(target, pixels.data(), buf_bytes, staging, true);
568 } else {
569 loom.upload_data(target, pixels.data(), buf_bytes);
570 }
571
572 MF_DEBUG(Journal::Component::Portal, Journal::Context::API,
573 "repress(VKImage): updated {}x{} in-place", buf_w, buf_h);
574
575 return true;
576}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::vector< uint8_t > pixels
Definition InkPress.cpp:32
GlyphAtlas * atlas
Glyph atlas to use. Null selects the TypeFaceFoundry default at call time.
Definition InkPress.hpp:67
glm::vec4 color
RGBA color applied to all glyphs not covered by a span in spans.
Definition InkPress.hpp:70
std::vector< StyleSpan > spans
Optional per-byte-range color overrides. Empty applies color uniformly.
Definition InkPress.hpp:94
glm::vec4 background
RGBA fill composited beneath every glyph.
Definition InkPress.hpp:84

References MayaFlux::Journal::API, MayaFlux::Portal::Text::GlyphAtlas::ascender(), MayaFlux::Portal::Text::PressParams::atlas, MayaFlux::Portal::Text::PressParams::background, MayaFlux::Portal::Text::PressParams::color, MayaFlux::Portal::Graphics::get_texture_manager(), MayaFlux::Portal::Text::GlyphAtlas::line_height(), MF_DEBUG, MF_ERROR, MF_WARN, pixels, MayaFlux::Journal::Portal, and MayaFlux::Portal::Text::PressParams::spans.

+ Here is the call graph for this function: