MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Atelier.hpp
Go to the documentation of this file.
1#pragma once
2
6
8
9namespace MayaFlux::Nodes {
10class NodeGraphManager;
11}
12
13namespace MayaFlux::Core {
14class Window;
15class WindowManager;
16struct WindowCreateInfo;
17}
18
19namespace MayaFlux::Vruta {
20class TaskScheduler;
21class EventManager;
22}
23
24namespace MayaFlux::Buffers {
25class BufferManager;
26}
27
29
30class Inspector;
31
32namespace internal {
33
34 constexpr size_t k_capacity_bytes = 4096;
35
36 /**
37 * @class Atelier
38 * @brief Process-wide Forma workshop. Not part of the public surface.
39 *
40 * Holds the engine references stored by Portal::Forma::initialize and
41 * owns every construction path that depends on them: buffers, layers,
42 * contexts, surfaces, elements, windows.
43 *
44 * Everything under Internal/ is implementation detail and carries no
45 * stability guarantee. The public entry points in Forma.hpp are thin
46 * wrappers over the methods here. User code calls those, not these.
47 *
48 * Lifetime follows the Portal::Graphics singleton contract: the Meyers
49 * instance is never destroyed, and shutdown() releases the held
50 * references explicitly before static teardown.
51 */
52 class MAYAFLUX_API Atelier {
53 public:
54 static Atelier& instance()
55 {
56 static Atelier a;
57 return a;
58 }
59
60 Atelier(const Atelier&) = delete;
61 Atelier& operator=(const Atelier&) = delete;
62 Atelier(Atelier&&) = delete;
64
65 // =====================================================================
66 // Lifecycle
67 // =====================================================================
68
69 bool initialize(
70 std::shared_ptr<Nodes::NodeGraphManager> node_graph_manager,
71 std::shared_ptr<Buffers::BufferManager> buffer_manager,
72 std::shared_ptr<Vruta::TaskScheduler> scheduler,
73 std::shared_ptr<Vruta::EventManager> event_manager,
74 std::shared_ptr<Core::WindowManager> window_manager);
75
76 void shutdown();
77
78 [[nodiscard]] bool is_initialized() const noexcept { return m_initialized; }
79
80 /**
81 * @brief Bridge instance constructed during initialize.
82 * @throws std::runtime_error if called before initialize().
83 */
84 [[nodiscard]] Bridge& bridge();
85
86 /**
87 * @brief Inspector instance constructed during initialize.
88 * @throws std::runtime_error if called before initialize().
89 */
90 [[nodiscard]] Inspector& inspector();
91
92 // =====================================================================
93 // Construction
94 // =====================================================================
95
96 /**
97 * @brief Create a window through the stored WindowManager and show it.
98 *
99 * Present so that callers needing a window do not reach the manager
100 * directly.
101 */
102 [[nodiscard]] std::shared_ptr<Core::Window> create_window(
103 const Core::WindowCreateInfo& info);
104
105 /**
106 * @brief Capacity-explicit FormaBuffer construction.
107 *
108 * The single buffer construction path. Registers with the stored
109 * BufferManager under GRAPHICS_BACKEND and calls setup_rendering
110 * with whichever texture configuration was requested.
111 */
112 [[nodiscard]] std::shared_ptr<Buffers::FormaBuffer> create_buffer(
113 std::shared_ptr<Core::Window> window,
114 size_t capacity,
116 const std::string& texture_binding = {},
117 std::vector<std::pair<std::string, std::shared_ptr<Core::VKImage>>>
118 additional_textures = {});
119
120 /**
121 * @brief Construct a Layer and a Context wired to @p window.
122 *
123 * The Context is stored so its event coroutines outlive the call.
124 */
125 [[nodiscard]] std::pair<std::shared_ptr<Layer>, std::shared_ptr<Context>>
126 create_layer(const std::shared_ptr<Core::Window>& window, std::string name);
127
128 /// @brief create_layer plus ownership of the window, as a Surface.
129 [[nodiscard]] Surface create_surface(
130 std::shared_ptr<Core::Window> window, std::string name);
131
132 /**
133 * @brief Build a FormaBuffer, construct a Mapped<T>, register the
134 * element on @p layer, and register it with the Bridge.
135 *
136 * @tparam T MappedState value type.
137 * @param layer Layer to register the element on.
138 * @param window Target window for rendering.
139 * @param geom Geometry function producing vertex bytes from T.
140 * @param initial Starting value written into MappedState.
141 * @param topology Primitive topology for the FormaBuffer.
142 * @param capacity Initial FormaBuffer capacity in bytes.
143 * @param project Optional T to float projection for outbound readers.
144 */
145 template <typename T>
147 Layer& layer,
148 std::shared_ptr<Core::Window> window,
149 GeometryFn<T> geom,
150 T initial,
151 Graphics::PrimitiveTopology topology = Graphics::PrimitiveTopology::TRIANGLE_STRIP,
152 size_t capacity = k_capacity_bytes,
153 std::function<float(T)> project = {})
154 {
155 auto buf = create_buffer(std::move(window), capacity, topology);
156 auto mapped = make_mapped<T>(std::move(initial), std::move(geom), std::move(buf));
157 mapped.element.id = layer.add(mapped.element);
158 bridge().register_element(mapped, std::move(project));
159 return mapped;
160 }
161
162 /**
163 * @brief create_element against a Surface, followed by one sync so
164 * bounds_hint and contains from the geometry function reach
165 * the Layer before the first frame.
166 */
167 template <typename T>
169 Surface& surface,
170 GeometryFn<T> geom,
171 T initial,
172 Graphics::PrimitiveTopology topology = Graphics::PrimitiveTopology::TRIANGLE_STRIP,
173 std::function<float(T)> project = {})
174 {
175 auto mapped = create_element<T>(
176 surface.layer(), surface.window(),
177 std::move(geom), std::move(initial),
178 topology, k_capacity_bytes, std::move(project));
179
180 mapped.sync();
181 if (mapped.element.bounds_hint)
182 surface.layer().set_bounds(mapped.element.id, *mapped.element.bounds_hint);
183 if (mapped.element.contains)
184 surface.layer().set_contains(mapped.element.id, mapped.element.contains);
185
186 return mapped;
187 }
188
189 /**
190 * @brief Create and place every adornment declared on @p spec.
191 *
192 * Builds one buffer per axis label, tick label, legend swatch, and
193 * legend label, then hands each to the corresponding Plot placement
194 * function. Each adornment is related to @p relate_to so removal and
195 * visibility cascade from the series element.
196 *
197 * Lives here rather than in Plot because it constructs buffers,
198 * which requires the BufferManager. Plot composes placement from
199 * arguments it is given.
200 *
201 * @param surface Surface to place on.
202 * @param spec Series spec carrying the adornment declarations.
203 * @param relate_to Element id the adornments are related to.
204 */
205 void place_adornments(
206 Surface& surface,
207 const Plot::SeriesSpec& spec,
208 uint32_t relate_to);
209
210 private:
213
214 std::shared_ptr<Nodes::NodeGraphManager> m_node_graph_manager;
215 std::shared_ptr<Buffers::BufferManager> m_buffer_manager;
216 std::shared_ptr<Vruta::TaskScheduler> m_scheduler;
217 std::shared_ptr<Vruta::EventManager> m_event_manager;
218 std::shared_ptr<Core::WindowManager> m_window_manager;
219
220 std::unique_ptr<Bridge> m_bridge;
221 std::unique_ptr<Inspector> m_inspect;
222
223 bool m_initialized {};
224 };
225
226 /// @brief Accessor for the process-wide Atelier.
227 inline Atelier& atelier() { return Atelier::instance(); }
228
229} // namespace internal
230} // namespace MayaFlux::Portal::Forma
size_t a
std::string name
Definition VKDevice.cpp:143
void register_element(std::shared_ptr< MappedState< T > > state, uint32_t id, std::shared_ptr< Buffers::FormaBuffer > buffer, std::function< float(T)> project={})
Register a MappedState<T> so that MappedState overloads and outbound bindings can resolve to the corr...
Definition Bridge.hpp:280
Two-way binding orchestrator for Forma elements.
Definition Bridge.hpp:65
Forma subsystem for live introspection.
Definition Inspector.hpp:39
bool set_bounds(uint32_t id, Kinesis::AABB2D bounds)
Replace the bounds_hint on an existing element.
Definition Layer.cpp:36
Slot add(Element element)
Add an element to the layer.
Definition Layer.cpp:9
bool set_contains(uint32_t id, std::function< bool(glm::vec2)> fn)
Replace the contains callable on an existing element.
Definition Layer.cpp:45
Flat registry of Elements on a surface.
Definition Layer.hpp:21
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:126
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:107
Named owner of a (Window, Layer, Context) triple - the Forma canvas.
Definition Surface.hpp:58
std::shared_ptr< Buffers::BufferManager > m_buffer_manager
Definition Atelier.hpp:215
std::shared_ptr< Nodes::NodeGraphManager > m_node_graph_manager
Definition Atelier.hpp:214
std::shared_ptr< Vruta::TaskScheduler > m_scheduler
Definition Atelier.hpp:216
Atelier & operator=(Atelier &&)=delete
std::unique_ptr< Bridge > m_bridge
Definition Atelier.hpp:220
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
Mapped< T > create_element(Surface &surface, GeometryFn< T > geom, T initial, Graphics::PrimitiveTopology topology=Graphics::PrimitiveTopology::TRIANGLE_STRIP, std::function< float(T)> project={})
create_element against a Surface, followed by one sync so bounds_hint and contains from the geometry ...
Definition Atelier.hpp:168
std::unique_ptr< Inspector > m_inspect
Definition Atelier.hpp:221
std::shared_ptr< Core::WindowManager > m_window_manager
Definition Atelier.hpp:218
Atelier & operator=(const Atelier &)=delete
std::shared_ptr< Vruta::EventManager > m_event_manager
Definition Atelier.hpp:217
Process-wide Forma workshop.
Definition Atelier.hpp:52
void initialize()
Definition main.cpp:11
Contains the node-based computational processing system components.
Definition Chronie.hpp:14
Atelier & atelier()
Accessor for the process-wide Atelier.
Definition Atelier.hpp:227
constexpr size_t k_capacity_bytes
Definition Atelier.hpp:34
void shutdown()
Release stored references.
Definition Forma.cpp:48
Inspector & inspector()
Access the Forma introspection subsystem.
Definition Forma.cpp:62
Bridge & bridge()
Return the application-level Bridge instance.
Definition Forma.cpp:60
std::function< void(T value, std::vector< uint8_t > &out_bytes, Element &element)> GeometryFn
Geometry function signature.
Definition Mapped.hpp:64
PrimitiveTopology
Vertex assembly primitive topology.
std::shared_ptr< Core::Window > create_window(const Core::WindowCreateInfo &create_info)
Create a new window with specified parameters.
Definition Windowing.cpp:14
auto create_buffer(uint32_t channel, uint32_t buffer_size, Args &&... args) -> std::shared_ptr< BufferType >
creates a new buffer of the specified type and registers it
Definition Graph.hpp:339
Configuration for creating a single window instance.
Infrastructure for a continuously-mapped value whose GPU geometry tracks it.
Definition Mapped.hpp:89