10using Portal::Graphics::TextureLoom;
18 vk::Rect2D fitted(uint32_t
src_w, uint32_t
src_h, uint32_t dst_w, uint32_t dst_h)
20 const double scale = std::min(
21 static_cast<double>(dst_w) /
static_cast<double>(
src_w),
22 static_cast<double>(dst_h) /
static_cast<double>(
src_h));
24 const auto w = std::clamp(
static_cast<uint32_t
>(std::lround(
src_w * scale)), 1U, dst_w);
25 const auto h = std::clamp(
static_cast<uint32_t
>(std::lround(
src_h * scale)), 1U, dst_h);
28 vk::Offset2D {
static_cast<int32_t
>((dst_w - w) / 2),
static_cast<int32_t
>((dst_h -
h) / 2) },
53 "TextureCollection::append called with an uninitialised image");
67 const auto slot = reuse
89 const std::shared_ptr<Core::VKImage>&
image,
90 const std::shared_ptr<Core::VKImage>& target)
95 const std::vector<uint8_t> zeros(
byte_size(), 0);
102 const auto filter = same_extent || !loom.can_blit(
image, target, FilterMode::LINEAR)
103 ? FilterMode::NEAREST
104 : FilterMode::LINEAR;
106 if (!loom.can_blit(
image, target, filter)) {
108 "TextureCollection::append cannot blit {} into {}",
109 vk::to_string(
image->get_format()), vk::to_string(target->get_format()));
114 return loom.blit_layer(
image, target, { .filter = filter });
116 return loom.blit_layer(
m_blank, target, { .filter = FilterMode::NEAREST })
117 && loom.blit_layer(
image, target,
118 { .dst = fitted(image->get_width(), image->get_height(), get_width(), get_height()), .filter = filter });
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
TextureCollection(const TextureCollectionSpec &spec)
bool is_full() const
True when a linear collection cannot take another layer.
bool copy_into(const std::shared_ptr< Core::VKImage > &image, const std::shared_ptr< Core::VKImage > &target)
bool append(const std::shared_ptr< Core::VKImage > &image)
Copy image into the next layer.
std::shared_ptr< Core::VKImage > m_blank
TextureCollectionSpec m_spec
void hold_layer(uint32_t layer)
Mark layer as held on the GPU after its image was rewritten.
uint32_t get_height() const
uint32_t append_image_layer(std::shared_ptr< Core::VKImage > image)
Append one layer held on the GPU by image.
std::shared_ptr< Core::VKImage > layer_image(uint32_t layer) const
The GPU image backing layer, without uploading CPU pixels.
ImageFormat get_format() const
uint32_t get_width() const
uint32_t get_layer_count() const
size_t byte_size() const
Total byte count of the pixel buffer.
SignalSourceContainer wrapping GPU texture data as addressable pixel bytes.
static TextureLoom & instance()
std::shared_ptr< Core::VKImage > create_2d(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr, uint32_t mip_levels=1)
Create a 2D texture.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
Tendency< D, float > scale(const Tendency< D, float > &t, float factor)
Uniform scaling of a scalar-output tendency.
FilterMode
Texture filtering mode.
Describes a TextureCollection so it can be built by designated initializer.
Exact layer count for subclasses, zero allowed.