MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextureCollection.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @struct TextureCollectionSpec
9 * @brief Describes a TextureCollection so it can be built by designated
10 * initializer.
11 *
12 * Sizes and format are those of every layer. @c max_bytes caps the GPU memory
13 * the layers may take, 512 MiB by default; 0 removes the cap. A ring size above
14 * zero enables circular mode, where the collection keeps only the most recent
15 * layers and @c max_bytes does not apply.
16 */
18 uint32_t width {};
19 uint32_t height {};
21 uint64_t max_bytes { 512ULL << 20 };
22 uint32_t ring_layers {};
23};
24
25/**
26 * @class TextureCollection
27 * @brief TextureContainer that starts empty and gains one layer per appended
28 * GPU image.
29 *
30 * The layers are independent images of one size and format, such as one
31 * result per frame. Each append copies the image on the GPU, so the source
32 * can be reused or overwritten right after. Layers stay on the GPU:
33 * to_image() returns a layer's own image, and a CPU accessor downloads a
34 * layer once, the first time it reads it.
35 *
36 * In linear mode appends stop once the next layer would exceed the byte cap.
37 * In circular mode append i is written to layer i % ring_layers, replacing
38 * the oldest; get_write_head() keeps counting past the ring size.
39 *
40 * Every layer is a GPU image that stays allocated for the life of the
41 * process, even after the collection is destroyed. Appending is not safe
42 * while another thread reads the collection.
43 */
44class MAYAFLUX_API TextureCollection : public TextureContainer {
45public:
46 explicit TextureCollection(const TextureCollectionSpec& spec);
47
48 /**
49 * @brief Copy @p image into the next layer.
50 *
51 * An image of another size is scaled to fit inside the layer, keeping its
52 * aspect ratio, centred on a zeroed background. The format is converted.
53 *
54 * @return True when the image was stored. False for a null image, when
55 * the device cannot blit its format into the collection's, or
56 * when a linear collection is full.
57 */
58 bool append(const std::shared_ptr<Core::VKImage>& image);
59
60 /** @brief Number of images appended so far, including overwritten ones. */
61 [[nodiscard]] uint64_t get_write_head() const { return m_write_head; }
62
63 /** @brief True when a linear collection cannot take another layer. */
64 [[nodiscard]] bool is_full() const;
65
66 [[nodiscard]] const TextureCollectionSpec& get_spec() const { return m_spec; }
67
68private:
69 bool copy_into(const std::shared_ptr<Core::VKImage>& image, const std::shared_ptr<Core::VKImage>& target);
70
72 uint64_t m_write_head {};
73 bool m_full_reported {};
74 std::shared_ptr<Core::VKImage> m_blank;
75};
76
77} // namespace MayaFlux::Kakshya
IO::ImageData image
Definition Decoder.cpp:47
const TextureCollectionSpec & get_spec() const
uint64_t get_write_head() const
Number of images appended so far, including overwritten ones.
std::shared_ptr< Core::VKImage > m_blank
TextureContainer that starts empty and gains one layer per appended GPU image.
SignalSourceContainer wrapping GPU texture data as addressable pixel bytes.
ImageFormat
User-friendly image format enum.
Definition ImageData.hpp:12
@ RGBA8
Four channel 8-bit.
Describes a TextureCollection so it can be built by designated initializer.