MayaFlux 0.4.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 = {} 
)

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.
Returns
GPU-resident VKImage, or nullptr on failure.

Definition at line 263 of file InkPress.cpp.

267{
268 GlyphAtlas* atlas = resolve_atlas(params.atlas);
269 if (!atlas)
270 return nullptr;
271
272 const uint32_t buf_w = render_bounds.x;
273
274 const uint32_t composite_h = std::max(render_bounds.y,
275 static_cast<uint32_t>(atlas->line_height()));
276
277 const auto result = composite(text, *atlas, params.color, buf_w, composite_h,
278 static_cast<float>(atlas->ascender()));
279
280 if (!result) {
281 MF_WARN(Journal::Component::Portal, Journal::Context::API,
282 "press(AsTexture): no glyphs produced for '{}'", std::string(text));
283 return nullptr;
284 }
285
286 const uint32_t budget_h = composite_h;
287
288 const size_t budget_bytes = static_cast<size_t>(buf_w) * budget_h * 4;
289 std::vector<uint8_t> pixels(budget_bytes, 0);
290
291 const auto copy_h = static_cast<uint32_t>(
292 result->pixels.size() / (static_cast<size_t>(buf_w) * 4));
293
294 for (uint32_t row = 0; row < copy_h; ++row) {
295 std::memcpy(
296 pixels.data() + static_cast<size_t>(row) * buf_w * 4,
297 result->pixels.data() + static_cast<size_t>(row) * buf_w * 4,
298 static_cast<size_t>(buf_w) * 4);
299 }
300
301 auto& loom = Portal::Graphics::get_texture_manager();
302 auto image = loom.create_2d(buf_w, budget_h, Portal::Graphics::ImageFormat::RGBA8,
303 pixels.data(), 1);
304
305 MF_DEBUG(Journal::Component::Portal, Journal::Context::API,
306 "press(AsTexture): {}x{} content in {}x{} texture",
307 buf_w, result->h, buf_w, budget_h);
308
309 return image;
310}
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:57
std::vector< uint8_t > pixels
Definition InkPress.cpp:31
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:50
glm::vec4 color
RGBA color applied to all glyphs.
Definition InkPress.hpp:53

References MayaFlux::Journal::API, MayaFlux::Portal::Text::GlyphAtlas::ascender(), MayaFlux::Portal::Text::PressParams::atlas, 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::Graphics::RGBA8.

+ Here is the call graph for this function: