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

◆ press() [2/2]

MAYAFLUX_API std::shared_ptr< Core::VKImage > MayaFlux::Portal::Text::press ( std::string_view  text,
glm::uvec2  render_bounds,
const PressParams &  params = {},
const std::shared_ptr< Buffers::VKBuffer > &  staging = nullptr 
)

Composite a UTF-8 string directly into a new GPU texture.

No TextBuffer, no quad geometry, no registration required. The returned VKImage is RGBA8, shader-read layout, ready for binding into a FormaBuffer or any other descriptor slot.

Parameters
textUTF-8 string to composite.
render_boundsTexture dimensions and wrap boundary in pixels.
paramsatlas, color, budget_h. render_bounds field ignored.
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 label/texture to avoid allocating a fresh one each time; nullptr falls back to an internal one-shot staging allocation (the prior behaviour).
Returns
GPU-resident VKImage, or nullptr on failure.

Definition at line 370 of file InkPress.cpp.

375{
376 GlyphAtlas* atlas = resolve_atlas(params.atlas);
377 if (!atlas)
378 return nullptr;
379
380 const uint32_t buf_w = render_bounds.x;
381
382 const uint32_t composite_h = std::max(render_bounds.y,
383 static_cast<uint32_t>(atlas->line_height()));
384
385 const auto result = composite(text, *atlas, params.color, buf_w, composite_h,
386 static_cast<float>(atlas->ascender()), params.spans, params.background);
387
388 if (!result) {
389 MF_WARN(Journal::Component::Portal, Journal::Context::API,
390 "press(AsTexture): no glyphs produced for '{}'", std::string(text));
391 return nullptr;
392 }
393
394 const uint32_t budget_h = composite_h;
395
396 const size_t budget_bytes = static_cast<size_t>(buf_w) * budget_h * 4;
397 std::vector<uint8_t> pixels = make_filled(budget_bytes, params.background);
398
399 const auto copy_h = static_cast<uint32_t>(
400 result->pixels.size() / (static_cast<size_t>(buf_w) * 4));
401
402 for (uint32_t row = 0; row < copy_h; ++row) {
403 std::memcpy(
404 pixels.data() + static_cast<size_t>(row) * buf_w * 4,
405 result->pixels.data() + static_cast<size_t>(row) * buf_w * 4,
406 static_cast<size_t>(buf_w) * 4);
407 }
408
409 auto& loom = Portal::Graphics::get_texture_manager();
410
411 std::shared_ptr<Core::VKImage> image;
412 if (staging) {
413 image = loom.create_2d_uninitialized(buf_w, budget_h, Portal::Graphics::ImageFormat::RGBA8, 1);
414 if (!image)
415 return nullptr;
416 loom.upload_data(image, pixels.data(), budget_bytes, staging, true);
417 } else {
418 image = loom.create_2d(buf_w, budget_h, Portal::Graphics::ImageFormat::RGBA8,
419 pixels.data(), 1);
420 }
421
422 MF_DEBUG(Journal::Component::Portal, Journal::Context::API,
423 "press(AsTexture): {}x{} content in {}x{} texture",
424 buf_w, result->h, buf_w, budget_h);
425
426 return image;
427}
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:47
std::vector< uint8_t > pixels
Definition InkPress.cpp:32
uint32_t line_height() const
Line advance in pixels for this atlas's pixel_size.
uint32_t ascender() const
Ascender in pixels for this atlas's pixel_size.
Rasterizes and packs glyphs from a FontFace into a TextureContainer.
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(), image, MayaFlux::Portal::Text::GlyphAtlas::line_height(), MF_DEBUG, MF_WARN, pixels, MayaFlux::Journal::Portal, and MayaFlux::Portal::Text::PressParams::spans.

+ Here is the call graph for this function: