MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextureBindBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace MayaFlux::Buffers {
8
9/**
10 * @class TextureBindBuffer
11 * @brief Specialized buffer for generative texture/pixel data from TextureNode
12 *
13 * Automatically handles CPU→GPU upload of procedurally generated pixels.
14 * Designed for algorithmic image generation: fractals, noise fields,
15 * audio visualizations, data mappings, etc.
16 *
17 * Philosophy:
18 * - Textures are GENERATED, not loaded from files
19 * - Data flows from algorithm → GPU → screen/shader
20 * - Pixels are just numbers - transform and visualize data freely
21 *
22 * Usage:
23 * class PerlinNoise : public TextureNode {
24 * void compute_frame() override {
25 * for (uint32_t y = 0; y < m_height; y++) {
26 * for (uint32_t x = 0; x < m_width; x++) {
27 * float noise_val = perlin(x, y, m_time);
28 * set_pixel(x, y, noise_val, noise_val, noise_val, 1.0f);
29 * }
30 * }
31 * m_time += 0.016f;
32 * }
33 * };
34 *
35 * auto noise = std::make_shared<PerlinNoise>(512, 512);
36 * auto buffer = std::make_shared<TextureBindBuffer>(noise);
37 *
38 * auto render = std::make_shared<RenderProcessor>(config);
39 * buffer->add_processor(render) | Graphics;
40 */
41class MAYAFLUX_API TextureBindBuffer : public VKBuffer {
42public:
43 /**
44 * @brief Create texture buffer from generative node
45 * @param node TextureNode that generates pixels each frame
46 * @param binding_name Logical name for this texture binding (default: "texture")
47 *
48 * Buffer size is automatically calculated from texture dimensions:
49 * width * height * 4 channels * sizeof(float)
50 */
51 explicit TextureBindBuffer(
52 std::shared_ptr<Nodes::GpuSync::TextureNode> node,
53 std::string binding_name = "texture");
54
55 ~TextureBindBuffer() override = default;
56
57 /**
58 * @brief Initialize the buffer and its processors
59 */
60 void setup_processors(Buffers::ProcessingToken token) override;
61
62 /**
63 * @brief Get the texture node driving this buffer
64 */
65 [[nodiscard]] std::shared_ptr<Nodes::GpuSync::TextureNode> get_texture_node() const
66 {
67 return m_texture_node;
68 }
69
70 /**
71 * @brief Get the bindings processor managing uploads
72 */
73 [[nodiscard]] std::shared_ptr<TextureBindingsProcessor> get_bindings_processor() const
74 {
75 return m_bindings_processor;
76 }
77
78 /**
79 * @brief Get the logical binding name
80 */
81 [[nodiscard]] const std::string& get_binding_name() const
82 {
83 return m_binding_name;
84 }
85
86 /**
87 * @brief Get texture dimensions
88 */
89 [[nodiscard]] std::pair<uint32_t, uint32_t> get_dimensions() const
90 {
91 return m_texture_node ? std::make_pair(m_texture_node->get_width(), m_texture_node->get_height()) : std::make_pair(0U, 0U);
92 }
93
94 /**
95 * @brief Trigger pixel computation on the node
96 *
97 * Calls node->compute_frame() to regenerate pixels.
98 * Useful for explicit frame updates when not using domain-driven processing.
99 */
101 {
102 if (m_texture_node) {
103 m_texture_node->compute_frame();
104 }
105 }
106
107private:
108 std::shared_ptr<Nodes::GpuSync::TextureNode> m_texture_node;
109 std::shared_ptr<TextureBindingsProcessor> m_bindings_processor;
110 std::string m_binding_name;
111
112 /**
113 * @brief Calculate texture buffer size from node dimensions
114 */
115 static size_t calculate_buffer_size(const std::shared_ptr<Nodes::GpuSync::TextureNode>& node);
116};
117
118} // namespace MayaFlux::Buffers
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
void update_texture()
Trigger pixel computation on the node.
std::shared_ptr< TextureBindingsProcessor > get_bindings_processor() const
Get the bindings processor managing uploads.
std::shared_ptr< Nodes::GpuSync::TextureNode > get_texture_node() const
Get the texture node driving this buffer.
std::shared_ptr< Nodes::GpuSync::TextureNode > m_texture_node
const std::string & get_binding_name() const
Get the logical binding name.
std::shared_ptr< TextureBindingsProcessor > m_bindings_processor
std::pair< uint32_t, uint32_t > get_dimensions() const
Get texture dimensions.
Specialized buffer for generative texture/pixel data from TextureNode.
Vulkan-backed buffer wrapper used in processing chains.
Definition VKBuffer.hpp:52
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.