MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Atelier.cpp
Go to the documentation of this file.
1#include "Atelier.hpp"
2
4
12
14
15namespace {
16 constexpr size_t k_text_label_capacity = static_cast<size_t>(6) * sizeof(Kakshya::MeshVertex);
17 constexpr size_t k_rect_capacity = static_cast<size_t>(4) * sizeof(Kakshya::Vertex);
18}
19
20// =============================================================================
21// Lifecycle
22// =============================================================================
23
24Atelier::Atelier() = default;
25Atelier::~Atelier() = default;
26
28 std::shared_ptr<Nodes::NodeGraphManager> node_graph_manager,
29 std::shared_ptr<Buffers::BufferManager> buffer_manager,
30 std::shared_ptr<Vruta::TaskScheduler> scheduler,
31 std::shared_ptr<Vruta::EventManager> event_manager,
32 std::shared_ptr<Core::WindowManager> window_manager)
33{
34 if (m_initialized) {
36 "Portal::Forma already initialized");
37 return true;
38 }
39
40 m_node_graph_manager = std::move(node_graph_manager);
41 m_buffer_manager = std::move(buffer_manager);
42 m_scheduler = std::move(scheduler);
43 m_event_manager = std::move(event_manager);
44 m_window_manager = std::move(window_manager);
45
46 m_bridge = std::make_unique<Bridge>(*m_scheduler, *m_buffer_manager);
47 m_inspect = std::make_unique<Inspector>(
49
50 m_initialized = true;
51
53 "Portal::Forma initialized");
54 return true;
55}
56
58{
59 if (!m_initialized)
60 return;
61
62 m_bridge.reset();
63 m_inspect.reset();
64
65 m_node_graph_manager = nullptr;
66 m_buffer_manager = nullptr;
67 m_scheduler = nullptr;
68 m_event_manager = nullptr;
69 m_window_manager = nullptr;
70
71 m_initialized = false;
72
74 "Portal::Forma shutdown");
75}
76
78{
79 if (!m_initialized) {
80 error<std::runtime_error>(Journal::Component::Portal, Journal::Context::API,
81 std::source_location::current(),
82 "Portal::Forma not initialized - cannot get bridge");
83 }
84 return *m_bridge;
85}
86
88{
89 if (!m_initialized) {
90 error<std::runtime_error>(Journal::Component::Portal, Journal::Context::API,
91 std::source_location::current(),
92 "Portal::Forma not initialized - cannot get inspector");
93 }
94 return *m_inspect;
95}
96
97// =============================================================================
98// Construction
99// =============================================================================
100
101std::shared_ptr<Core::Window> Atelier::create_window(const Core::WindowCreateInfo& info)
102{
103 auto window = m_window_manager->create_window(info);
104 window->show();
105 return window;
106}
107
108std::shared_ptr<Buffers::FormaBuffer> Atelier::create_buffer(
109 std::shared_ptr<Core::Window> window,
110 size_t capacity,
112 const std::string& texture_binding,
113 std::vector<std::pair<std::string, std::shared_ptr<Core::VKImage>>> additional_textures)
114{
115 auto buf = std::make_shared<Buffers::FormaBuffer>(capacity, topology);
117
118 if (!additional_textures.empty()) {
119 buf->setup_rendering({
120 .target_window = std::move(window),
121 .additional_textures = std::move(additional_textures),
122 });
123 } else if (!texture_binding.empty()) {
124 buf->setup_rendering({
125 .target_window = std::move(window),
126 .default_texture_binding = texture_binding,
127 });
128 } else {
129 buf->setup_rendering({ .target_window = std::move(window) });
130 }
131
132 return buf;
133}
134
135std::pair<std::shared_ptr<Layer>, std::shared_ptr<Context>>
136Atelier::create_layer(const std::shared_ptr<Core::Window>& window, std::string name)
137{
138 auto layer = std::make_shared<Layer>();
139 auto ctx = std::make_shared<Context>(layer, window, *m_event_manager, std::move(name));
140
141 MayaFlux::store(ctx);
142
143 return { std::move(layer), std::move(ctx) };
144}
145
146Surface Atelier::create_surface(std::shared_ptr<Core::Window> window, std::string name)
147{
148 auto [layer, ctx] = create_layer(window, std::move(name));
149 return { std::move(window), std::move(layer), std::move(ctx) };
150}
151
153 Surface& surface,
154 const Plot::SeriesSpec& spec,
155 uint32_t relate_to)
156{
157 const auto& win = surface.window();
158
159 for (const auto& label : spec.labels) {
160 auto buf = create_buffer(
161 win,
162 k_text_label_capacity,
164 {},
165 { { "text", nullptr } });
166 (void)Plot::place_label(surface, std::move(buf), label, relate_to);
167 }
168
169 for (const auto& ticks : spec.tick_labels) {
170 for (const auto& label : Plot::plot_tick_labels(ticks)) {
171 auto buf = create_buffer(
172 win,
173 k_text_label_capacity,
175 {},
176 { { "text", nullptr } });
177 (void)Plot::place_label(surface, std::move(buf), label, relate_to);
178 }
179 }
180
181 if (spec.legend) {
182 auto layout = Plot::layout_legend(*spec.legend);
183
184 for (const auto& swatch : layout.swatches) {
185 auto buf = create_buffer(
186 win,
187 k_rect_capacity,
189 (void)Plot::place_rect(surface, std::move(buf), swatch, relate_to);
190 }
191
192 for (const auto& label : layout.labels) {
193 auto buf = create_buffer(
194 win,
195 k_text_label_capacity,
197 {},
198 { { "text", nullptr } });
199 (void)Plot::place_label(surface, std::move(buf), label, relate_to);
200 }
201 }
202}
203
204} // namespace MayaFlux::Portal::Forma::internal
#define MF_INFO(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::string name
Definition VKDevice.cpp:143
Two-way binding orchestrator for Forma elements.
Definition Bridge.hpp:65
Forma subsystem for live introspection.
Definition Inspector.hpp:39
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:126
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
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
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
std::unique_ptr< Bridge > m_bridge
Definition Atelier.hpp:220
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
std::unique_ptr< Inspector > m_inspect
Definition Atelier.hpp:221
std::shared_ptr< Core::WindowManager > m_window_manager
Definition Atelier.hpp:218
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::shared_ptr< Vruta::EventManager > m_event_manager
Definition Atelier.hpp:217
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
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
@ API
API calls from external code.
@ Portal
High-level user-facing API layer.
LegendLayout layout_legend(const LegendSpec &spec)
Expand a legend spec into swatch rectangle specs and text label specs.
Definition PlotSpec.cpp:346
std::vector< LabelSpec > plot_tick_labels(const TickLabelsSpec &spec)
Generate construction-free tick label specs.
Definition PlotSpec.cpp:237
uint32_t place_label(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, const LabelSpec &spec, uint32_t relate_to)
Place a text label element onto surface using a pre-built buffer.
Definition Plot.cpp:15
uint32_t place_rect(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, const RectSpec &spec, uint32_t relate_to)
Place a filled rectangle element onto surface using a pre-built buffer.
Definition Plot.cpp:53
PrimitiveTopology
Vertex assembly primitive topology.
std::shared_ptr< T > store(std::shared_ptr< T > obj)
Transfer ownership of an existing object to the persistent store for process lifetime.
Definition Persist.hpp:28
Configuration for creating a single window instance.
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)
Type-neutral vertex carrying the universal 60-byte attribute layout.
std::optional< LegendSpec > legend
Optional legend to materialize when the plot is placed.
std::vector< TickLabelsSpec > tick_labels
Concrete tick label generation specs resolved at done() time.
std::vector< LabelSpec > labels
Explicit text labels to materialize when the plot is placed.