MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GeometryBindingsProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
6class GeometryWriterNode;
7}
8
9namespace MayaFlux::Buffers {
10
11/**
12 * @class GeometryBindingsProcessor
13 * @brief BufferProcessor that uploads geometry node data to GPU vertex buffers
14 *
15 * Manages bindings between GeometryWriterNode instances (CPU-side) and GPU
16 * vertex buffers. Each frame, reads vertex data from nodes and uploads to
17 * corresponding GPU buffers via staging buffers.
18 *
19 * Behavior:
20 * - Uploads ALL bound geometries to their target vertex buffers
21 * - If target is device-local: uses staging buffer (auto-created)
22 * - If target is host-visible: direct upload (no staging)
23 * - If attached buffer is one of the targets: uploads its geometry
24 * - If attached buffer is NOT a target: uploads first geometry to it
25 *
26 * Usage:
27 * auto vertex_buffer = std::make_shared<VKBuffer>(
28 * 1000 * sizeof(Vertex),
29 * VKBuffer::Usage::VERTEX_BUFFER);
30 *
31 * auto processor = std::make_shared<GeometryBindingsProcessor>();
32 * processor->bind_geometry_node("particles", particle_node, vertex_buffer);
33 *
34 * vertex_buffer->set_default_processor(processor);
35 * vertex_buffer->process_default(); // Uploads geometry
36 */
37class MAYAFLUX_API GeometryBindingsProcessor : public VKBufferProcessor {
38public:
40 /**
41 * @brief Structure representing a geometry binding
42 */
44 std::shared_ptr<Nodes::GpuSync::GeometryWriterNode> node;
45 std::shared_ptr<VKBuffer> gpu_vertex_buffer; // Target vertex buffer
46 std::shared_ptr<VKBuffer> staging_buffer; // Staging (only if device-local)
47 };
48
49 /**
50 * @brief Bind a geometry node to a GPU vertex buffer
51 * @param name Logical name for this binding
52 * @param node GeometryWriterNode to read vertices from
53 * @param vertex_buffer GPU vertex buffer to upload to
54 *
55 * If vertex_buffer is device-local, a staging buffer is automatically created.
56 * If vertex_buffer is host-visible, no staging is needed.
57 */
58 void bind_geometry_node(
59 const std::string& name,
60 const std::shared_ptr<Nodes::GpuSync::GeometryWriterNode>& node,
61 const std::shared_ptr<VKBuffer>& vertex_buffer);
62
63 /**
64 * @brief Remove a geometry binding
65 * @param name Name of binding to remove
66 */
67 void unbind_geometry_node(const std::string& name);
68
69 /**
70 * @brief Check if a binding exists
71 * @param name Binding name
72 * @return True if binding exists
73 */
74 [[nodiscard]] bool has_binding(const std::string& name) const;
75
76 /**
77 * @brief Get all binding names
78 * @return Vector of binding names
79 */
80 [[nodiscard]] std::vector<std::string> get_binding_names() const;
81
82 /**
83 * @brief Get number of active bindings
84 * @return Binding count
85 */
86 [[nodiscard]] size_t get_binding_count() const;
87
88 /**
89 * @brief Get a specific binding
90 * @param name Binding name
91 * @return Optional containing binding if exists
92 */
93 [[nodiscard]] std::optional<GeometryBinding> get_binding(const std::string& name) const;
94
95 /**
96 * @brief BufferProcessor interface - uploads all bound geometries
97 * @param buffer The buffer this processor is attached to
98 *
99 * Uploads all geometry nodes to their target vertex buffers.
100 * Uses staging buffers for device-local targets.
101 */
102 void processing_function(std::shared_ptr<Buffer> buffer) override;
103
104private:
105 std::unordered_map<std::string, GeometryBinding> m_bindings;
106};
107
108} // namespace MayaFlux::Buffers
std::unordered_map< std::string, GeometryBinding > m_bindings
BufferProcessor that uploads geometry node data to GPU vertex buffers.
std::shared_ptr< Nodes::GpuSync::GeometryWriterNode > node