MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
RenderProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "ShaderProcessor.hpp"
6
7namespace MayaFlux::Core {
8class VKImage;
9}
10
11namespace MayaFlux::Buffers {
12
13/**
14 * @class RenderShaderProcessor
15 * @brief Graphics rendering processor - inherits from ShaderProcessor
16 *
17 * Overrides pipeline creation to use RenderFlow instead of ComputePress.
18 * Records draw commands but does NOT submit/present.
19 */
20class MAYAFLUX_API RenderProcessor : public ShaderProcessor {
21public:
22 RenderProcessor(const ShaderConfig& config);
23
25 {
26 cleanup();
27 }
28
29 void set_geometry_shader(const std::string& geometry_path);
30 void set_tess_control_shader(const std::string& tess_control_path);
31 void set_tess_eval_shader(const std::string& tess_eval_path);
32 void set_fragment_shader(const std::string& fragment_path);
33 void set_target_window(const std::shared_ptr<Core::Window>& window, const std::shared_ptr<VKBuffer>& buffer);
34
36
37 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
38
39 /// Set primitive topology (e.g., triangle list, line list, point list)
41 {
42 m_primitive_topology = topology;
43 m_needs_pipeline_rebuild = true;
44 }
45
46 /// Set polygon mode (e.g., fill, line, point)
48 {
49 m_polygon_mode = mode;
50 m_needs_pipeline_rebuild = true;
51 }
52
53 /// Set cull mode (e.g., none, front, back)
55 {
56 m_cull_mode = mode;
57 m_needs_pipeline_rebuild = true;
58 }
59
60 /**
61 * @brief Bind a texture to a descriptor binding point
62 * @param binding Binding index (matches shader layout(binding = N))
63 * @param texture VKImage texture to bind
64 * @param sampler Optional sampler (uses default linear if null)
65 */
66 void bind_texture(
67 uint32_t binding,
68 const std::shared_ptr<Core::VKImage>& texture,
69 vk::Sampler sampler = nullptr);
70
71 /**
72 * @brief Bind a texture to a named descriptor
73 * @param descriptor_name Logical name (must be in config.bindings)
74 * @param texture VKImage texture to bind
75 * @param sampler Optional sampler (uses default linear if null)
76 */
77 void bind_texture(
78 const std::string& descriptor_name,
79 const std::shared_ptr<Core::VKImage>& texture,
80 vk::Sampler sampler = nullptr);
81
82 /**
83 * @brief Check if pipeline is created
84 */
85 bool is_pipeline_ready() const { return m_pipeline_id != Portal::Graphics::INVALID_RENDER_PIPELINE; }
86
87 /**
88 * @brief Set vertex range for drawing subset of buffer
89 * @param first_vertex Starting vertex index in buffer
90 * @param vertex_count Number of vertices to draw
91 *
92 * Enables drawing a specific range of vertices from the bound buffer.
93 * Used for composite geometry where multiple collections are aggregated
94 * into a single buffer but rendered with different topologies.
95 *
96 * Default: draws all vertices (first_vertex=0, vertex_count=0 means "use layout count")
97 */
98 void set_vertex_range(uint32_t first_vertex, uint32_t vertex_count);
99
100 /**
101 * @brief Override the vertex layout used when building the pipeline for buffer
102 * @param buffer Target buffer (key into m_buffer_info)
103 * @param layout Layout specific to this processor's topology
104 *
105 * Called by CompositeGeometryBuffer to give each RenderProcessor its own
106 * topology-specific layout rather than the shared aggregate on the VKBuffer.
107 * Triggers a pipeline rebuild on the next execute_shader() call.
108 */
109 void set_buffer_vertex_layout(
110 const std::shared_ptr<VKBuffer>& buffer,
111 const Kakshya::VertexLayout& layout);
112
113 /**
114 * @brief Set blend mode for color attachment
115 * @param config Blend attachment configuration
116 */
118 {
119 m_blend_attachment = config;
120 m_needs_pipeline_rebuild = true;
121 }
122
123 /** @brief Enable standard alpha blending (src_alpha, one_minus_src_alpha) */
124 void enable_alpha_blending();
125
126 /**
127 * @brief Enable depth testing for this processor's pipeline
128 * @param compare_op Depth comparison operation (default: LESS)
129 *
130 * Marks the owning buffer as requiring a depth attachment.
131 * Pipeline will be created with D32_SFLOAT depth format.
132 */
133 void enable_depth_test(Portal::Graphics::CompareOp compare_op = Portal::Graphics::CompareOp::LESS);
134
135 /**
136 * @brief Set static view transform (evaluated once)
137 * @param vt View and projection matrices
138 *
139 * Automatically enables depth testing and configures push
140 * constant size for the 128-byte ViewTransform block.
141 */
142 void set_view_transform(const Kinesis::ViewTransform& vt);
143
144 /**
145 * @brief Set dynamic view transform source (evaluated every frame)
146 * @param fn Callable returning ViewTransform, invoked each execute_shader
147 *
148 * Automatically enables depth testing and configures push
149 * constant size for the 128-byte ViewTransform block.
150 */
151 void set_view_transform_source(std::function<Kinesis::ViewTransform()> fn);
152
153protected:
154 void initialize_pipeline(const std::shared_ptr<VKBuffer>& buffer) override;
155 void execute_shader(const std::shared_ptr<VKBuffer>& buffer) override;
156 void initialize_descriptors(const std::shared_ptr<VKBuffer>& buffer) override;
157
158 bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr<VKBuffer>& buffer) override;
159
160 void cleanup() override;
161
162private:
163 struct VertexInfo {
165 bool use_reflection {};
166 };
167
168 Portal::Graphics::RenderPipelineID m_pipeline_id = Portal::Graphics::INVALID_RENDER_PIPELINE;
169 Portal::Graphics::ShaderID m_geometry_shader_id = Portal::Graphics::INVALID_SHADER;
170 Portal::Graphics::ShaderID m_tess_control_shader_id = Portal::Graphics::INVALID_SHADER;
171 Portal::Graphics::ShaderID m_tess_eval_shader_id = Portal::Graphics::INVALID_SHADER;
172 Portal::Graphics::ShaderID m_fragment_shader_id = Portal::Graphics::INVALID_SHADER;
173 std::shared_ptr<Core::Window> m_target_window;
174
175 std::unordered_map<std::shared_ptr<VKBuffer>, VertexInfo> m_buffer_info;
176 Registry::Service::DisplayService* m_display_service = nullptr;
177
178 Portal::Graphics::PrimitiveTopology m_primitive_topology { Portal::Graphics::PrimitiveTopology::TRIANGLE_LIST };
179 Portal::Graphics::PolygonMode m_polygon_mode { Portal::Graphics::PolygonMode::FILL };
180 Portal::Graphics::CullMode m_cull_mode { Portal::Graphics::CullMode::NONE };
181
183 std::shared_ptr<Core::VKImage> texture;
184 vk::Sampler sampler;
185 };
186 std::unordered_map<uint32_t, TextureBinding> m_texture_bindings;
187
188 std::optional<Portal::Graphics::BlendAttachmentConfig> m_blend_attachment;
189
191
192 bool m_depth_enabled {};
193 uint32_t m_first_vertex { 0 };
194 uint32_t m_vertex_count { 0 };
195
196 std::optional<Kinesis::ViewTransform> m_view_transform;
198
199 const Kakshya::VertexLayout* get_or_cache_vertex_layout(
200 std::unordered_map<std::shared_ptr<VKBuffer>, VertexInfo>& buffer_info,
201 const std::shared_ptr<VKBuffer>& buffer);
202};
203
204} // namespace MayaFlux::Buffers
void set_cull_mode(Portal::Graphics::CullMode mode)
Set cull mode (e.g., none, front, back)
void set_primitive_topology(Portal::Graphics::PrimitiveTopology topology)
Set primitive topology (e.g., triangle list, line list, point list)
void set_blend_attachment(const Portal::Graphics::BlendAttachmentConfig &config)
Set blend mode for color attachment.
std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > m_buffer_info
std::optional< Portal::Graphics::BlendAttachmentConfig > m_blend_attachment
std::function< Kinesis::ViewTransform()> m_view_transform_source
bool is_pipeline_ready() const
Check if pipeline is created.
std::optional< Kinesis::ViewTransform > m_view_transform
Portal::Graphics::DepthStencilConfig m_depth_stencil
std::unordered_map< uint32_t, TextureBinding > m_texture_bindings
Portal::Graphics::RenderPipelineID get_render_pipeline_id() const
void set_polygon_mode(Portal::Graphics::PolygonMode mode)
Set polygon mode (e.g., fill, line, point)
std::shared_ptr< Core::Window > m_target_window
Abstract base class for shader-based buffer processing.
PolygonMode
Rasterization polygon mode.
PrimitiveTopology
Vertex assembly primitive topology.
CompareOp
Depth/stencil comparison operation.
Complete description of vertex data layout in a buffer.
View and projection matrices as a named push constant slot.
Per-attachment blend configuration.
Depth and stencil test configuration.
Backend display and presentation service interface.