MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NodeTextureProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6class VKImage;
7}
8
10class TextureNode;
11}
12
13namespace MayaFlux::Buffers {
14
15class NodeTextureBuffer;
16
17/**
18 * @class NodeTextureProcessor
19 * @brief Uploads TextureNode pixel data to GPU textures via TextureLoom
20 *
21 * Manages one or more TextureNode → VKImage bindings. Each processing cycle:
22 * 1. Checks if node->needs_gpu_update()
23 * 2. Retrieves pixel data from node->get_pixel_buffer()
24 * 3. Uploads directly to GPU texture via TextureLoom
25 * 4. Clears node's dirty flag
26 *
27 * Philosophy:
28 * - Nodes generate pixels (CPU algorithms)
29 * - Processor orchestrates upload (delegates to TextureLoom)
30 * - Textures are VKImages, not VKBuffers
31 * - TextureLoom handles all staging buffer logistics internally
32 * - Multiple node→texture bindings share upload infrastructure
33 *
34 * Usage (single binding - typical):
35 * auto buffer = std::make_shared<NodeTextureBuffer>(node, "noise");
36 * buffer->setup_processors(Graphics);
37 * // Processor automatically created and bound
38 *
39 * Usage (multiple bindings - advanced):
40 * auto staging = std::make_shared<NodeTextureBuffer>(primary_node);
41 * auto processor = staging->get_texture_processor();
42 *
43 * processor->bind_texture_node("secondary", secondary_node, secondary_texture);
44 * processor->bind_texture_node("tertiary", tertiary_node, tertiary_texture);
45 *
46 * staging->process_default(); // Uploads all three textures
47 */
48class MAYAFLUX_API NodeTextureProcessor : public VKBufferProcessor {
49public:
50 /**
51 * @brief Represents a TextureNode → GPU texture binding
52 */
54 std::shared_ptr<Nodes::GpuSync::TextureNode> node; // Generates pixels
55 std::shared_ptr<Core::VKImage> gpu_texture; // Target GPU texture
56 };
57
59 ~NodeTextureProcessor() override = default;
60
61 /**
62 * @brief Bind a TextureNode to a GPU texture
63 * @param name Logical binding name
64 * @param node TextureNode to read pixels from
65 * @param texture GPU VKImage to upload to
66 *
67 * TextureLoom handles all staging buffer creation/cleanup internally.
68 */
69 void bind_texture_node(
70 const std::string& name,
71 const std::shared_ptr<Nodes::GpuSync::TextureNode>& node,
72 const std::shared_ptr<Core::VKImage>& texture);
73
74 /**
75 * @brief Remove a texture binding
76 * @param name Name of binding to remove
77 */
78 void unbind_texture_node(const std::string& name);
79
80 /**
81 * @brief Check if a binding exists
82 */
83 [[nodiscard]] bool has_binding(const std::string& name) const
84 {
85 return m_bindings.contains(name);
86 }
87
88 /**
89 * @brief Get all binding names
90 */
91 [[nodiscard]] std::vector<std::string> get_binding_names() const;
92
93 /**
94 * @brief Get number of active bindings
95 */
96 [[nodiscard]] size_t get_binding_count() const
97 {
98 return m_bindings.size();
99 }
100
101 /**
102 * @brief Get a specific binding
103 * @param name Binding name
104 * @return Optional containing binding if it exists
105 */
106 [[nodiscard]] std::optional<TextureBinding> get_binding(const std::string& name) const;
107
108 /**
109 * @brief Process all texture uploads
110 * @param buffer The staging buffer (VKBuffer) this processor is attached to
111 *
112 * Uploads all bound textures that have dirty flags set.
113 * Delegates actual upload to TextureLoom which handles staging internally.
114 */
115 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
116
117 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
118 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
119
120private:
121 std::unordered_map<std::string, TextureBinding> m_bindings;
122
123 std::shared_ptr<NodeTextureBuffer> m_attached_buffer;
124
125 void initialize_gpu_resources();
126};
127
128} // namespace MayaFlux::Buffers
size_t get_binding_count() const
Get number of active bindings.
std::shared_ptr< NodeTextureBuffer > m_attached_buffer
std::unordered_map< std::string, TextureBinding > m_bindings
bool has_binding(const std::string &name) const
Check if a binding exists.
Uploads TextureNode pixel data to GPU textures via TextureLoom.
std::shared_ptr< Nodes::GpuSync::TextureNode > node
Represents a TextureNode → GPU texture binding.