MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Forma.cpp
Go to the documentation of this file.
1#include "Forma.hpp"
2
9
11
12#include "Inspect/Inspector.hpp"
13
15
17
19
20namespace {
21
22 std::shared_ptr<Core::Window> g_inspect_nodes_window;
23 std::shared_ptr<Core::Window> g_inspect_buffers_window;
24 std::shared_ptr<Core::Window> g_inspect_scheduler_window;
25 std::shared_ptr<Core::Window> g_inspect_events_window;
26
27 constexpr uint32_t k_inspect_w = 480;
28 constexpr uint32_t k_inspect_h = 900;
29
30} // namespace
31
32// =============================================================================
33// Lifecycle
34// =============================================================================
35
37 std::shared_ptr<Nodes::NodeGraphManager> node_graph_manager,
38 std::shared_ptr<Buffers::BufferManager> buffer_manager,
39 std::shared_ptr<Vruta::TaskScheduler> scheduler,
40 std::shared_ptr<Vruta::EventManager> event_manager,
41 std::shared_ptr<Core::WindowManager> window_manager)
42{
44 std::move(node_graph_manager), std::move(buffer_manager),
45 std::move(scheduler), std::move(event_manager), std::move(window_manager));
46}
47
49{
51
52 g_inspect_nodes_window.reset();
53 g_inspect_buffers_window.reset();
54 g_inspect_scheduler_window.reset();
55 g_inspect_events_window.reset();
56}
57
59
61
63
64// =============================================================================
65// Layer
66// =============================================================================
67
68std::pair<std::shared_ptr<Layer>, std::shared_ptr<Context>>
69create_layer(const std::shared_ptr<Core::Window>& window, std::string name)
70{
71 return internal::atelier().create_layer(window, std::move(name));
72}
73
74Surface create_surface(std::shared_ptr<Core::Window> window, std::string name)
75{
76 return internal::atelier().create_surface(std::move(window), std::move(name));
77}
78
79// =============================================================================
80// Standalone buffer
81// =============================================================================
82
83std::shared_ptr<Buffers::FormaBuffer> create_buffer(
84 std::shared_ptr<Core::Window> window,
86 const std::string& texture_binding)
87{
89 std::move(window), internal::k_capacity_bytes, topology, texture_binding);
90}
91
92std::shared_ptr<Buffers::FormaBuffer> create_buffer(
93 std::shared_ptr<Core::Window> window,
95 std::vector<std::pair<std::string, std::shared_ptr<Core::VKImage>>> additional_textures)
96{
98 std::move(window), internal::k_capacity_bytes, topology, {},
99 std::move(additional_textures));
100}
101
102// =============================================================================
103// Plot
104// =============================================================================
105
106std::pair<Mapped<std::shared_ptr<Kakshya::PlotContainer>>, Surface>
108 std::string title,
109 uint32_t width,
110 uint32_t height,
111 std::shared_ptr<Kakshya::PlotContainer> container,
112 Plot::SeriesSpec spec)
113{
114 const uint64_t N = container->series_count() > 0
115 ? container->series_size(0)
116 : 0;
117
118 auto& atelier = internal::atelier();
119
120 auto window = atelier.create_window(
121 Core::WindowCreateInfo { .title = std::move(title), .width = width, .height = height });
122
123 auto surface = atelier.create_surface(window, window->get_create_info().title);
124
125 if (spec.background_fn) {
126 auto bg = atelier.create_element<float>(
127 surface.layer(), window,
128 *spec.background_fn,
129 0.F,
131 static_cast<size_t>(4) * Kakshya::VertexLayout::for_meshes().stride_bytes);
132
133 const auto bg_id = bg.element.id;
134 auto buf = atelier.create_buffer(window, spec.capacity_for(N), spec.topology);
135 auto mapped = Plot::place(surface, std::move(buf), spec, std::move(container));
136 surface.layer().relate(mapped.element.id, bg_id);
137 surface.layer().send_to_back(bg_id);
138
139 internal::atelier().place_adornments(surface, spec, mapped.element.id);
140
141 return { std::move(mapped), std::move(surface) };
142 }
143
144 auto buf = atelier.create_buffer(window, spec.capacity_for(N), spec.topology);
145 auto mapped = Plot::place(surface, std::move(buf), spec, std::move(container));
146
147 internal::atelier().place_adornments(surface, spec, mapped.element.id);
148
149 return { std::move(mapped), std::move(surface) };
150}
151
152// =============================================================================
153// Bridge
154// =============================================================================
155
157{
158 if (g_inspect_nodes_window) {
159 g_inspect_nodes_window->show();
160 return;
161 }
162
163 auto& atelier = internal::atelier();
164
165 g_inspect_nodes_window = atelier.create_window(
166 Core::WindowCreateInfo { .title = "NodeGraphManager", .width = k_inspect_w, .height = k_inspect_h });
167
168 auto surface = atelier.create_surface(g_inspect_nodes_window, "NodeGraphManager");
169 LayoutCursor cursor;
170 auto& result = atelier.inspector().node_graph_manager(surface, cursor);
171 atelier.bridge().spawn_sync(result.group.header.header_id, [&result] { result.tap_all(); });
172}
173
175{
176 if (g_inspect_buffers_window) {
177 g_inspect_buffers_window->show();
178 return;
179 }
180
181 auto& atelier = internal::atelier();
182
183 g_inspect_buffers_window = atelier.create_window(
184 Core::WindowCreateInfo { .title = "BufferManager", .width = k_inspect_w, .height = k_inspect_h });
185
186 auto surface = atelier.create_surface(g_inspect_buffers_window, "BufferManager");
187 LayoutCursor cursor;
188 auto& result = atelier.inspector().buffer_manager(surface, cursor);
189 atelier.bridge().spawn_sync(result.group.header.header_id, [&result] { result.tap_all(); });
190}
191
193{
194 if (g_inspect_scheduler_window) {
195 g_inspect_scheduler_window->show();
196 return;
197 }
198
199 auto& atelier = internal::atelier();
200
201 g_inspect_scheduler_window = atelier.create_window(
202 Core::WindowCreateInfo { .title = "TaskScheduler", .width = k_inspect_w, .height = k_inspect_h });
203
204 auto surface = atelier.create_surface(g_inspect_scheduler_window, "TaskScheduler");
205 LayoutCursor cursor;
206 auto& result = atelier.inspector().scheduler(surface, cursor);
207 atelier.bridge().spawn_sync(result.group.header.header_id, [&result] { result.tap_all(); });
208}
209
211{
212 if (g_inspect_events_window) {
213 g_inspect_events_window->show();
214 return;
215 }
216
217 auto& atelier = internal::atelier();
218
219 g_inspect_events_window = atelier.create_window(
220 Core::WindowCreateInfo { .title = "EventManager", .width = k_inspect_w, .height = k_inspect_h });
221
222 auto surface = atelier.create_surface(g_inspect_events_window, "EventManager");
223 LayoutCursor cursor;
224 auto& result = atelier.inspector().event_manager(surface, cursor);
225 atelier.bridge().spawn_sync(result.group.header.header_id, [&result] { result.tap_all(); });
226}
227
228void inspect(const std::shared_ptr<Nodes::Node>& node)
229{
230 auto& atelier = internal::atelier();
231 const std::string title = Reflect::short_dynamic_type_name(node);
232
233 auto window = atelier.create_window(
234 Core::WindowCreateInfo { .title = title, .width = k_inspect_w, .height = k_inspect_h });
235
236 auto surface = atelier.create_surface(window, title);
237 LayoutCursor cursor;
238 auto result = std::make_shared<InspectResult>(atelier.inspector().node(node, surface, cursor));
239 atelier.bridge().spawn_sync(result->group.header.header_id, [result] { result->tap_all(); });
240}
241
242void inspect(const std::shared_ptr<Buffers::Buffer>& buf)
243{
244 auto& atelier = internal::atelier();
245 const std::string title = Reflect::short_dynamic_type_name(buf);
246
247 auto window = atelier.create_window(
248 Core::WindowCreateInfo { .title = title, .width = k_inspect_w, .height = k_inspect_h });
249
250 auto surface = atelier.create_surface(window, title);
251 LayoutCursor cursor;
252 auto result = std::make_shared<InspectResult>(atelier.inspector().buffer(buf, surface, cursor));
253 atelier.bridge().spawn_sync(result->group.header.header_id, [result] { result->tap_all(); });
254}
255
256void inspect(const std::shared_ptr<Nodes::Network::NodeNetwork>& net)
257{
258 auto& atelier = internal::atelier();
259
260 auto window = atelier.create_window(
261 Core::WindowCreateInfo { .title = "NodeNetwork", .width = k_inspect_w, .height = k_inspect_h });
262
263 auto surface = atelier.create_surface(window, "NodeNetwork");
264 LayoutCursor cursor;
265 auto result = std::make_shared<InspectResult>(atelier.inspector().node_network(net, surface, cursor));
266 atelier.bridge().spawn_sync(result->group.header.header_id, [result] { result->tap_all(); });
267}
268
269void inspect(const std::shared_ptr<Vruta::Event>& ev, std::string_view name)
270{
271 auto& atelier = internal::atelier();
272 const std::string title = name.empty() ? "Event" : "Event: " + std::string(name);
273
274 auto window = atelier.create_window(
275 Core::WindowCreateInfo { .title = title, .width = k_inspect_w, .height = k_inspect_h });
276
277 auto surface = atelier.create_surface(window, title);
278 LayoutCursor cursor;
279 auto result = std::make_shared<InspectResult>(atelier.inspector().event(ev, name, surface, cursor));
280 atelier.bridge().spawn_sync(result->group.header.header_id, [result] { result->tap_all(); });
281}
282
283} // namespace MayaFlux::Portal::Forma
#define N(method_name, full_type_name)
Definition Creator.hpp:106
Factory free functions for the Forma surface system.
std::string name
Definition VKDevice.cpp:143
uint32_t width
uint32_t height
void spawn_sync(uint32_t id, std::function< void()> sync_fn)
Spawn a per-frame GraphicsRoutine that calls sync_fn each tick.
Definition Bridge.cpp:368
Two-way binding orchestrator for Forma elements.
Definition Bridge.hpp:65
InspectResult & buffer_manager(Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F)
Inspect the full BufferManager state across all active tokens.
InspectResult & node_graph_manager(Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F)
Inspect the full NodeGraphManager state across all active tokens.
InspectResult event(const std::shared_ptr< Vruta::Event > &ev, std::string_view name, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F)
Inspect a single Event by name and pointer.
InspectResult & event_manager(Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F)
Inspect the full EventManager state.
InspectResult node_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &net, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F, int depth=0)
Inspect a NodeNetwork and its per-network metadata.
InspectResult & scheduler(Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F)
Inspect the full TaskScheduler state.
InspectResult node(const std::shared_ptr< Nodes::Node > &n, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F, int depth=0)
Inspect a single Node and its full modulator tree.
Definition NodeQuery.cpp:85
InspectResult buffer(const std::shared_ptr< Buffers::Buffer > &buf, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F, int depth=0)
Inspect a single Buffer: default processor and full processing chain.
Forma subsystem for live introspection.
Definition Inspector.hpp:39
Reactive Y-position accumulator for vertical primitive stacking.
Named owner of a (Window, Layer, Context) triple - the Forma canvas.
Definition Surface.hpp:58
std::shared_ptr< Buffers::FormaBuffer > create_buffer(std::shared_ptr< Core::Window > window, size_t capacity, Graphics::PrimitiveTopology topology, const std::string &texture_binding={}, std::vector< std::pair< std::string, std::shared_ptr< Core::VKImage > > > additional_textures={})
Capacity-explicit FormaBuffer construction.
Definition Atelier.cpp:108
bool initialize(std::shared_ptr< Nodes::NodeGraphManager > node_graph_manager, std::shared_ptr< Buffers::BufferManager > buffer_manager, std::shared_ptr< Vruta::TaskScheduler > scheduler, std::shared_ptr< Vruta::EventManager > event_manager, std::shared_ptr< Core::WindowManager > window_manager)
Definition Atelier.cpp:27
std::shared_ptr< Core::Window > create_window(const Core::WindowCreateInfo &info)
Create a window through the stored WindowManager and show it.
Definition Atelier.cpp:101
void place_adornments(Surface &surface, const Plot::SeriesSpec &spec, uint32_t relate_to)
Create and place every adornment declared on spec.
Definition Atelier.cpp:152
Mapped< T > create_element(Layer &layer, std::shared_ptr< Core::Window > window, GeometryFn< T > geom, T initial, Graphics::PrimitiveTopology topology=Graphics::PrimitiveTopology::TRIANGLE_STRIP, size_t capacity=k_capacity_bytes, std::function< float(T)> project={})
Build a FormaBuffer, construct a Mapped<T>, register the element on layer, and register it with the B...
Definition Atelier.hpp:146
Inspector & inspector()
Inspector instance constructed during initialize.
Definition Atelier.cpp:87
Surface create_surface(std::shared_ptr< Core::Window > window, std::string name)
create_layer plus ownership of the window, as a Surface.
Definition Atelier.cpp:146
Bridge & bridge()
Bridge instance constructed during initialize.
Definition Atelier.cpp:77
std::pair< std::shared_ptr< Layer >, std::shared_ptr< Context > > create_layer(const std::shared_ptr< Core::Window > &window, std::string name)
Construct a Layer and a Context wired to window.
Definition Atelier.cpp:136
void initialize()
Definition main.cpp:11
Mapped< std::shared_ptr< Kakshya::PlotContainer > > place(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, SeriesSpec spec, std::shared_ptr< Kakshya::PlotContainer > container)
Place a plot element onto a Surface using a pre-built FormaBuffer.
Definition Plot.cpp:81
Atelier & atelier()
Accessor for the process-wide Atelier.
Definition Atelier.hpp:227
constexpr size_t k_capacity_bytes
Definition Atelier.hpp:34
std::pair< Mapped< std::shared_ptr< Kakshya::PlotContainer > >, Surface > plot(std::string title, uint32_t width, uint32_t height, std::shared_ptr< Kakshya::PlotContainer > container, Plot::SeriesSpec spec)
Create a live plot in a new window.
Definition Forma.cpp:107
void inspect_buffers()
Open or show the BufferManager inspection window.
Definition Forma.cpp:174
void shutdown()
Release stored references.
Definition Forma.cpp:48
std::shared_ptr< Buffers::FormaBuffer > create_buffer(std::shared_ptr< Core::Window > window, Graphics::PrimitiveTopology topology, const std::string &texture_binding)
Construct and register a FormaBuffer without creating a Mapped<T>.
Definition Forma.cpp:83
void inspect_node_graph()
Open or show the NodeGraphManager inspection window.
Definition Forma.cpp:156
bool is_initialized()
Whether initialize() has been called successfully.
Definition Forma.cpp:58
Surface create_surface(std::shared_ptr< Core::Window > window, std::string name)
Construct a Surface, creating Layer and Context internally.
Definition Forma.cpp:74
Inspector & inspector()
Access the Forma introspection subsystem.
Definition Forma.cpp:62
void inspect_scheduler()
Open or show the TaskScheduler inspection window.
Definition Forma.cpp:192
std::pair< std::shared_ptr< Layer >, std::shared_ptr< Context > > create_layer(const std::shared_ptr< Core::Window > &window, std::string name)
Construct a Layer and a Context wired to window.
Definition Forma.cpp:69
Bridge & bridge()
Return the application-level Bridge instance.
Definition Forma.cpp:60
void inspect(const std::shared_ptr< Nodes::Node > &node)
Open a dedicated window inspecting a single Node and its modulator tree.
Definition Forma.cpp:228
void inspect_events()
Open or show the EventManager inspection window.
Definition Forma.cpp:210
PrimitiveTopology
Vertex assembly primitive topology.
std::string short_dynamic_type_name(const T &obj) noexcept
Returns the unqualified dynamic type name of obj.
Definition TypeInfo.hpp:95
std::string title
Window title/identifier.
Configuration for creating a single window instance.
uint32_t stride_bytes
Total bytes per vertex (stride in Vulkan terms) e.g., 3 floats (position) + 3 floats (normal) = 24 by...
static VertexLayout for_meshes(uint32_t stride=60)
Factory: layout for MeshVertex (position, color, weight, uv, normal, tangent)
std::optional< GeometryFn< float > > background_fn
std::function< size_t(uint64_t sample_count)> capacity_for