MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AtlasImage.cpp
Go to the documentation of this file.
1#include "AtlasImage.hpp"
2
6
8
9std::shared_ptr<Core::VKImage> AtlasImage::sync(GlyphAtlas& atlas)
10{
12 if (!loom.is_initialized()) {
13 return nullptr;
14 }
15
16 const std::span<const uint8_t> pixels = atlas.texture().pixel_bytes(0);
17 const uint32_t size = atlas.atlas_size();
18
19 if (!m_image || !m_image->is_initialized() || m_atlas != &atlas || m_size != size) {
20 m_image = loom.create_2d(size, size, Portal::Graphics::ImageFormat::R8, pixels.data(), 1);
21 if (!m_image) {
23 "AtlasImage: could not create a {}x{} atlas image", size, size);
24 m_atlas = nullptr;
25 m_size = 0;
26 return nullptr;
27 }
28 m_atlas = &atlas;
29 m_size = size;
31 atlas.clear_dirty();
32 return m_image;
33 }
34
35 if (atlas.is_dirty()) {
36 loom.upload_data(m_image, pixels.data(), pixels.size());
37 atlas.clear_dirty();
38 }
39
40 return m_image;
41}
42
43} // namespace MayaFlux::Portal::Text
#define MF_ERROR(comp, ctx,...)
const std::vector< float > * pixels
Definition Decoder.cpp:48
bool size
std::span< const uint8_t > pixel_bytes(uint32_t layer=0) const
Read-only byte-level view over the pixel buffer.
std::shared_ptr< Core::VKImage > sync(GlyphAtlas &atlas)
Bring the image up to date with atlas.
Definition AtlasImage.cpp:9
std::shared_ptr< Core::VKImage > m_image
bool is_dirty() const
Returns true if at least one glyph was rasterized since the last call to clear_dirty().
void clear_dirty()
Clear the dirty flag after re-uploading the atlas to GPU.
uint32_t atlas_size() const
Atlas texture dimension (width == height == atlas_size).
const Kakshya::TextureContainer & texture() const
The atlas texture as a TextureContainer (R8, atlas_size x atlas_size).
Rasterizes and packs glyphs from a FontFace into a TextureContainer.
@ API
API calls from external code.
@ Portal
High-level user-facing API layer.
MAYAFLUX_API TextureLoom & get_texture_manager()
Get the global texture manager instance.