MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FormaProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Buffers {
7
8/**
9 * @class FormaProcessor
10 * @brief Default processor for FormaBuffer.
11 *
12 * Owns the CPU-to-GPU upload cycle for Forma geometry. Accepts raw
13 * interleaved vertex bytes via set_bytes(), stores them behind an
14 * atomic dirty flag, and uploads to the device-local buffer each
15 * graphics tick via a persistent staging buffer. Updates vertex_count
16 * in the buffer's VertexLayout after every upload so RenderProcessor
17 * draws the correct number of vertices.
18 *
19 * Mirrors DataWriteProcessor in structure. The topology is fixed
20 * at construction to derive the correct per-vertex stride for the
21 * vertex_count calculation.
22 */
23class MAYAFLUX_API FormaProcessor : public VKBufferProcessor {
24public:
26 ~FormaProcessor() override = default;
27
28 /**
29 * @brief Supply new vertex bytes for the next graphics tick.
30 *
31 * Thread-safe via atomic_flag. Called from Mapped::sync() on the
32 * scheduler tick. The bytes are swapped into the active slot on the
33 * next processing_function call.
34 *
35 * @param bytes Raw interleaved vertex bytes matching the topology's
36 * vertex type (PointVertex, LineVertex, or MeshVertex).
37 */
38 void set_bytes(std::vector<uint8_t> bytes);
39
40 [[nodiscard]] bool has_pending() const noexcept;
41
42 /**
43 * @brief Supply a texture to bind on the next graphics tick.
44 *
45 * Stores the image and binding name behind an atomic dirty flag.
46 * On the next processing_function call the image is bound to the
47 * RenderProcessor via bind_texture(). Calling again replaces the
48 * pending binding before it has been consumed.
49 *
50 * @param image GPU image. nullptr clears the binding.
51 * @param binding Descriptor name matching the fragment shader.
52 */
53 void set_texture(std::shared_ptr<Core::VKImage> image, std::string binding);
54
55protected:
56 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
57 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
58 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
59
60private:
62 std::shared_ptr<Core::VKImage> image;
63 std::string binding;
64 };
65
67 uint32_t m_stride { 0 };
68
69 std::vector<uint8_t> m_pending_geometry;
70 std::vector<uint8_t> m_active;
71 std::atomic_flag m_geometry_dirty;
72 std::optional<PendingTexture> m_pending_texture;
73 std::atomic_flag m_texture_dirty;
74
75 std::shared_ptr<VKBuffer> m_staging;
76
77 [[nodiscard]] uint32_t vertex_count(size_t byte_count) const noexcept;
78};
79
80} // namespace MayaFlux::Buffers
IO::ImageData image
Definition Decoder.cpp:57
Backend-agnostic interface for sequential data storage and transformation.
Definition Buffer.hpp:37
Portal::Graphics::PrimitiveTopology m_topology
std::vector< uint8_t > m_pending_geometry
~FormaProcessor() override=default
std::shared_ptr< VKBuffer > m_staging
std::optional< PendingTexture > m_pending_texture
Default processor for FormaBuffer.
PrimitiveTopology
Vertex assembly primitive topology.