MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextureBindingsProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
6class TextureNode;
7} // namespace MayaFlux::Nodes
8
9namespace MayaFlux::Buffers {
10
11/**
12 * @class TextureBindingsProcessor
13 * @brief BufferProcessor that uploads multiple texture nodes to GPU
14 *
15 * Manages bindings between TextureNode instances and GPU texture buffers.
16 * Each frame, reads pixel data from nodes and uploads to corresponding GPU textures.
17 *
18 * Behavior:
19 * - If ATTACHED buffer is host-visible: uploads all textures to their targets + attached buffer
20 * - If ATTACHED buffer is device-local: uploads all textures via staging buffers
21 *
22 * Usage:
23 * auto texture_buffer = std::make_shared<VKBuffer>(...);
24 * auto processor = std::make_shared<TextureBindingsProcessor>();
25 *
26 * processor->bind_texture_node("spectrum", spectrum_node, spectrum_texture);
27 * processor->bind_texture_node("waveform", waveform_node, waveform_texture);
28 *
29 * texture_buffer->set_default_processor(processor);
30 * texture_buffer->process_default(); // Uploads all bound textures
31 */
32class MAYAFLUX_API TextureBindingsProcessor : public VKBufferProcessor {
33public:
35 std::shared_ptr<Nodes::GpuSync::TextureNode> node;
36 std::shared_ptr<VKBuffer> gpu_texture; // Target texture buffer
37 std::shared_ptr<VKBuffer> staging_buffer; // Staging (only if gpu_texture is device-local)
38 };
39
40 /**
41 * @brief Bind a texture node to a GPU texture buffer
42 * @param name Logical name for this binding
43 * @param node TextureNode to read pixels from
44 * @param texture GPU texture buffer to upload to
45 *
46 * If texture is device-local, a staging buffer is automatically created.
47 * If texture is host-visible, no staging is needed.
48 */
49 void bind_texture_node(
50 const std::string& name,
51 const std::shared_ptr<Nodes::GpuSync::TextureNode>& node,
52 const std::shared_ptr<VKBuffer>& texture);
53
54 /**
55 * @brief Remove a texture binding
56 * @param name Name of binding to remove
57 */
58 void unbind_texture_node(const std::string& name);
59
60 /**
61 * @brief Check if a binding exists
62 * @param name Binding name
63 * @return True if binding exists
64 */
65 bool has_binding(const std::string& name) const { return m_bindings.contains(name); }
66
67 /**
68 * @brief Get all binding names
69 * @return Vector of binding names
70 */
71 std::vector<std::string> get_binding_names() const;
72
73 /**
74 * @brief Get number of active bindings
75 * @return Binding count
76 */
77 size_t get_binding_count() const { return m_bindings.size(); }
78
79 void processing_function(std::shared_ptr<Buffer> buffer) override;
80
81private:
82 std::unordered_map<std::string, TextureBinding> m_bindings;
83};
84} // namespace MayaFlux::Buffers
size_t get_binding_count() const
Get number of active bindings.
bool has_binding(const std::string &name) const
Check if a binding exists.
std::unordered_map< std::string, TextureBinding > m_bindings
BufferProcessor that uploads multiple texture nodes to GPU.