MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ add_render_sink()

MAYAFLUX_API void MayaFlux::Nexus::add_render_sink ( std::vector< RenderSink > &  sinks,
Buffers::BufferManager mgr,
const Portal::Graphics::RenderConfig config,
RenderFn  fn = {},
std::string  fn_name = {},
const std::optional< glm::vec3 > &  initial_position = {} 
)

Create and register a render sink targeting window.

Allocates a VKBuffer (VERTEX, POINT_LIST), attaches a DataWriteProcessor and a RenderProcessor with point.vert.spv / point.frag.spv defaults, and registers the buffer with mgr.

Parameters
sinksSink vector owned by the calling Emitter or Agent.
mgrBufferManager to register the VKBuffer with.
windowTarget window for presentation.
fnOptional producer called each dispatch with InfluenceContext. Leave empty when geometry is supplied via push_geometry().
fn_nameOptional identifier for state encoding, empty if anonymous.
initial_positionOptional initial position to write if no producer fn is set.

Definition at line 95 of file Sinks.cpp.

102{
103 constexpr size_t k_initial_bytes = 4096;
104
105 auto buf = std::make_shared<Buffers::VKBuffer>(
106 k_initial_bytes,
107 Buffers::VKBuffer::Usage::VERTEX,
108 Kakshya::DataModality::VERTICES_3D);
109
110 auto writer = std::make_shared<Buffers::DataWriteProcessor>();
111 buf->set_default_processor(writer);
112 mgr.add_buffer(buf, Buffers::ProcessingToken::GRAPHICS_BACKEND);
113
114 std::string vert = config.vertex_shader;
115 std::string frag = config.fragment_shader;
116 std::string geom = config.geometry_shader;
117
118 if (vert.empty() || frag.empty()) {
119 switch (config.topology) {
120 case Portal::Graphics::PrimitiveTopology::LINE_LIST:
121 case Portal::Graphics::PrimitiveTopology::LINE_STRIP:
122 if (frag.empty())
123 frag = "line.frag.spv";
124#ifndef MAYAFLUX_PLATFORM_MACOS
125 if (vert.empty())
126 vert = "line.vert.spv";
127 if (geom.empty())
128 geom = "line.geom.spv";
129#else
130 if (vert.empty())
131 vert = "line_fallback.vert.spv";
132#endif
133 break;
134 case Portal::Graphics::PrimitiveTopology::TRIANGLE_LIST:
135 case Portal::Graphics::PrimitiveTopology::TRIANGLE_STRIP:
136 if (vert.empty())
137 vert = "triangle.vert.spv";
138 if (frag.empty())
139 frag = "triangle.frag.spv";
140 break;
141 default:
142 if (vert.empty())
143 vert = "point.vert.spv";
144 if (frag.empty())
145 frag = "point.frag.spv";
146 break;
147 }
148 }
149
150 auto renderer = std::make_shared<Buffers::RenderProcessor>(Buffers::ShaderConfig { vert });
151 renderer->set_fragment_shader(frag);
152
153 if (!geom.empty())
154 renderer->set_geometry_shader(geom);
155
156 renderer->set_primitive_topology(config.topology);
157 renderer->set_polygon_mode(config.polygon_mode);
158 renderer->set_cull_mode(config.cull_mode);
159
160 renderer->enable_depth_test();
161 buf->set_needs_depth_attachment(true);
162
163 renderer->set_target_window(config.target_window, buf);
164 buf->set_render_processor(renderer);
165 buf->get_processing_chain()->add_final_processor(renderer, buf);
166
167 auto& sink = sinks.emplace_back(RenderSink {
168 .buf = buf,
169 .writer = std::move(writer),
170 .renderer = std::move(renderer),
171 .fn = std::move(fn),
172 .fn_name = std::move(fn_name),
173 .window = config.target_window,
174 });
175
176 if (!sink.fn && initial_position.has_value()) {
177 sink.writer->set_data(std::vector<Kakshya::DataVariant> {
178 Kakshya::DataVariant { std::vector<glm::vec3> { *initial_position } },
179 });
180 }
181
182 MF_DEBUG(Journal::Component::Buffers, Journal::Context::Init,
183 "Nexus: render sink added");
184}
#define MF_DEBUG(comp, ctx,...)
void add_buffer(const std::shared_ptr< Buffer > &buffer, ProcessingToken token, uint32_t channel=0)
Adds a buffer to a token and channel.
std::shared_ptr< Core::Window > target_window

References MayaFlux::Buffers::BufferManager::add_buffer(), MayaFlux::Nexus::RenderSink::buf, MayaFlux::Journal::Buffers, MayaFlux::Portal::Graphics::RenderConfig::cull_mode, MayaFlux::Portal::Graphics::RenderConfig::fragment_shader, MayaFlux::Portal::Graphics::RenderConfig::geometry_shader, MayaFlux::Buffers::GRAPHICS_BACKEND, MayaFlux::Journal::Init, MayaFlux::Portal::Graphics::LINE_LIST, MayaFlux::Portal::Graphics::LINE_STRIP, MF_DEBUG, MayaFlux::Portal::Graphics::RenderConfig::polygon_mode, MayaFlux::Portal::Graphics::RenderConfig::target_window, MayaFlux::Portal::Graphics::RenderConfig::topology, MayaFlux::Portal::Graphics::TRIANGLE_LIST, MayaFlux::Portal::Graphics::TRIANGLE_STRIP, MayaFlux::Buffers::VKBuffer::VERTEX, MayaFlux::Portal::Graphics::RenderConfig::vertex_shader, and MayaFlux::Kakshya::VERTICES_3D.

Referenced by MayaFlux::Nexus::Agent::render(), MayaFlux::Nexus::Emitter::render(), MayaFlux::Nexus::Agent::render(), and MayaFlux::Nexus::Emitter::render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: