MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MeshProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7class MeshBuffer;
8
9/**
10 * @class MeshProcessor
11 * @brief Default processor for MeshBuffer: handles CPU-to-GPU upload of
12 * vertex and index data with selective dirty-flag re-upload.
13 *
14 * On on_attach: allocates both GPU buffers (VERTEX + INDEX), creates staging
15 * buffers, performs the initial upload of both streams, and calls
16 * set_index_resources() on the vertex buffer to link the two Vulkan handles
17 * in VKBufferResources. This mirrors GeometryBindingsProcessor::bind_geometry_node()
18 * but is driven directly from MeshBuffer's MeshData rather than from a node.
19 *
20 * On processing_function: checks MeshBuffer::m_vertices_dirty and
21 * MeshBuffer::m_indices_dirty independently. Re-uploads whichever stream
22 * has changed and clears the flag. No-op when both are clean, so the
23 * per-frame cost when a mesh is static is a single atomic load per flag.
24 *
25 * Users never instantiate this directly. MeshBuffer creates and sets it
26 * as its default processor inside setup_processors().
27 *
28 * Deformation path: call MeshBuffer::set_vertex_data() or
29 * MeshBuffer::set_index_data(), which set the respective dirty flag.
30 * MeshProcessor picks up the change on the next graphics cycle.
31 */
32class MAYAFLUX_API MeshProcessor : public VKBufferProcessor {
33public:
35 ~MeshProcessor() override = default;
36
37protected:
38 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
39 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
40 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
41
42private:
43 std::shared_ptr<MeshBuffer> m_mesh_buffer;
44
45 std::shared_ptr<VKBuffer> m_gpu_index_buffer;
46 std::shared_ptr<VKBuffer> m_vertex_staging;
47 std::shared_ptr<VKBuffer> m_index_staging;
48
49 void allocate_gpu_buffers(const std::shared_ptr<MeshBuffer>& buf);
50 void upload_vertices(const std::shared_ptr<MeshBuffer>& buf);
51 void upload_indices(const std::shared_ptr<MeshBuffer>& buf);
52 void link_index_resources();
53};
54
55} // namespace MayaFlux::Buffers
~MeshProcessor() override=default
std::shared_ptr< VKBuffer > m_vertex_staging
std::shared_ptr< VKBuffer > m_index_staging
std::shared_ptr< MeshBuffer > m_mesh_buffer
std::shared_ptr< VKBuffer > m_gpu_index_buffer
Default processor for MeshBuffer: handles CPU-to-GPU upload of vertex and index data with selective d...