MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MeshNetworkBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6class VKImage;
7}
8
10class MeshNetwork;
11}
12
13namespace MayaFlux::Buffers {
14
15class RenderProcessor;
16
17/**
18 * @class MeshNetworkBuffer
19 * @brief VKBuffer that renders a MeshNetwork as a single indexed draw call.
20 *
21 * Analogous to MeshBuffer but driven by a MeshNetwork rather than a single
22 * MeshData. All slots are concatenated by MeshNetworkProcessor into one
23 * combined vertex buffer and one combined index buffer, with per-slot index
24 * rebasing so the topology is correct across slot boundaries.
25 *
26 * Texture support follows MeshBuffer's model exactly:
27 * - bind_diffuse_texture() binds one shared diffuse texture for all slots.
28 * - RenderConfig::additional_textures carries any further bindings.
29 * - Per-slot distinct textures (texture array path) are deferred.
30 *
31 * Usage:
32 * @code
33 * auto net = std::make_shared<MeshNetwork>();
34 * // ... add slots ...
35 *
36 * auto buf = std::make_shared<MeshNetworkBuffer>(net);
37 * buf->bind_diffuse_texture(image);
38 * buf->setup_processors(ProcessingToken::GRAPHICS_BACKEND);
39 * buf->setup_rendering({ .target_window = window });
40 * @endcode
41 */
42class MAYAFLUX_API MeshNetworkBuffer : public VKBuffer {
43public:
44 /**
45 * @brief Construct from an existing MeshNetwork.
46 * @param network Must be non-null and have at least one slot before
47 * setup_processors() is called.
48 * @param over_allocate_factor Initial buffer size multiplier. Applied to
49 * the estimated total vertex byte count.
50 */
51 explicit MeshNetworkBuffer(
52 std::shared_ptr<Nodes::Network::MeshNetwork> network,
53 float over_allocate_factor = 1.5F);
54
55 ~MeshNetworkBuffer() override = default;
56
57 /**
58 * @brief Create and attach MeshNetworkProcessor as the default processor.
59 */
60 void setup_processors(ProcessingToken token) override;
61
62 /**
63 * @brief Attach a RenderProcessor with optional texture support.
64 *
65 * Mirrors MeshBuffer::setup_rendering:
66 * - Topology is always TRIANGLE_LIST.
67 * - Defaults to triangle.vert.spv / triangle.frag.spv (untextured)
68 * or mesh_textured.frag.spv when a diffuse texture is bound.
69 * - RenderConfig::additional_textures registers extra texture slots.
70 */
71 void setup_rendering(const RenderConfig& config);
72
73 // -------------------------------------------------------------------------
74 // Texture binding
75 // -------------------------------------------------------------------------
76
77 /**
78 * @brief Bind a single shared diffuse texture for all slots.
79 * @param image GPU image to bind. Pass nullptr to unbind.
80 * @param binding_name Shader descriptor name (default: "diffuseTex").
81 *
82 * Must be called before setup_rendering() for the ShaderConfig to include
83 * the descriptor slot. Calling after setup_rendering() updates the binding
84 * on the existing RenderProcessor but will warn if the pipeline was
85 * compiled without the binding.
86 */
87 void bind_diffuse_texture(
88 std::shared_ptr<Core::VKImage> image,
89 std::string_view binding_name = "diffuseTex");
90
91 [[nodiscard]] bool has_diffuse_texture() const noexcept
92 {
93 return m_diffuse_texture != nullptr;
94 }
95
96 [[nodiscard]] std::shared_ptr<Core::VKImage> get_diffuse_texture() const noexcept
97 {
98 return m_diffuse_texture;
99 }
100
101 // -------------------------------------------------------------------------
102 // Accessors
103 // -------------------------------------------------------------------------
104
105 [[nodiscard]] std::shared_ptr<Nodes::Network::MeshNetwork> get_network() const
106 {
107 return m_network;
108 }
109
110 [[nodiscard]] std::shared_ptr<MeshNetworkProcessor> get_mesh_processor() const
111 {
112 return m_processor;
113 }
114
115 [[nodiscard]] std::shared_ptr<RenderProcessor> get_render_processor() const override
116 {
117 return m_render_processor;
118 }
119
120private:
121 std::shared_ptr<Nodes::Network::MeshNetwork> m_network;
122 std::shared_ptr<MeshNetworkProcessor> m_processor;
123 std::shared_ptr<RenderProcessor> m_render_processor;
124
125 std::shared_ptr<Core::VKImage> m_diffuse_texture;
126 std::string m_diffuse_binding { "diffuseTex" };
127
129
130 static size_t estimate_vertex_bytes(
131 const std::shared_ptr<Nodes::Network::MeshNetwork>& network,
132 float over_allocate_factor);
133};
134
135} // namespace MayaFlux::Buffers
IO::ImageData image
std::shared_ptr< Core::VKImage > m_diffuse_texture
std::shared_ptr< RenderProcessor > m_render_processor
std::shared_ptr< MeshNetworkProcessor > m_processor
std::shared_ptr< Nodes::Network::MeshNetwork > m_network
std::shared_ptr< RenderProcessor > get_render_processor() const override
Get a RenderProcessor suitable for rendering this buffer.
std::shared_ptr< Core::VKImage > get_diffuse_texture() const noexcept
std::shared_ptr< Nodes::Network::MeshNetwork > get_network() const
std::shared_ptr< MeshNetworkProcessor > get_mesh_processor() const
VKBuffer that renders a MeshNetwork as a single indexed draw call.
Vulkan-backed buffer wrapper used in processing chains.
Definition VKBuffer.hpp:67
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
Unified rendering configuration for graphics buffers.