MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
QueryUtils.cpp
Go to the documentation of this file.
1#include "QueryUtils.hpp"
2
4
6
10
12
14
16
17namespace {
18
19 void write_row_quad(
20 std::vector<uint8_t>& bytes,
21 float x_min, float x_max, float bot, float top,
22 glm::vec3 bg)
23 {
24 const uint32_t stride = Kakshya::VertexLayout::for_meshes().stride_bytes;
25
26 const glm::vec3 bl { x_min, bot, 0.F };
27 const glm::vec3 br { x_max, bot, 0.F };
28 const glm::vec3 tl { x_min, top, 0.F };
29 const glm::vec3 tr { x_max, top, 0.F };
30 constexpr glm::vec3 white { 1.F, 1.F, 1.F };
31
32 auto write = [&](size_t i, glm::vec3 p, glm::vec3 c, float w, glm::vec2 uv) {
33 auto* v = bytes.data() + i * stride;
34 std::memcpy(v, &p, 12);
35 std::memcpy(v + 12, &c, 12);
36 std::memcpy(v + 24, &w, 4);
37 std::memcpy(v + 28, &uv, 8);
38 };
39
40 write(0, bl, bg, 0.F, {});
41 write(1, br, bg, 0.F, {});
42 write(2, tl, bg, 0.F, {});
43 write(3, br, bg, 0.F, {});
44 write(4, tr, bg, 0.F, {});
45 write(5, tl, bg, 0.F, {});
46
47 write(6, bl, white, 1.F, { 0.F, 1.F });
48 write(7, br, white, 1.F, { 1.F, 1.F });
49 write(8, tl, white, 1.F, { 0.F, 0.F });
50 write(9, br, white, 1.F, { 1.F, 1.F });
51 write(10, tr, white, 1.F, { 1.F, 0.F });
52 write(11, tl, white, 1.F, { 0.F, 0.F });
53 }
54
55} // namespace
56
57glm::uvec2 row_pixel_dims(
58 const std::shared_ptr<Core::Window>& window,
59 float x_min, float x_max, float row_h)
60{
61 const auto& ws = window->get_state();
62 const auto w = static_cast<uint32_t>(
63 (x_max - x_min) * 0.5F * static_cast<float>(ws.current_width));
64 const auto h = static_cast<uint32_t>(
65 row_h * 0.5F * static_cast<float>(ws.current_height));
67 if (!atlas) {
69 std::source_location::current(),
70 "Failed to get default glyph atlas for row pixel dimension calculation");
71 }
72 const uint32_t min_h = atlas->pixel_size();
73 return { std::max(w, 1U), std::max(h, min_h) };
74}
75
77 const ValueSpec& spec,
78 RowBuffer row_buf,
79 Surface& surface,
80 LayoutCursor& cursor,
81 float x_min, float x_max, float row_h,
82 glm::vec3 bg)
83{
84 const float top = cursor.y();
85 const float bot = top - row_h;
86 cursor.advance(row_h);
87 const Kinesis::AABB2D row_rect { .min = { x_min, bot }, .max = { x_max, top } };
88
89 const uint32_t stride = Kakshya::VertexLayout::for_meshes().stride_bytes;
90 std::vector<uint8_t> bytes(static_cast<size_t>(12) * stride, 0);
91 write_row_quad(bytes, x_min, x_max, bot, top, bg);
92 row_buf.buf->submit(bytes);
93
95 row_buf.text_image->get_size_bytes());
96
98 .color = { 1.F, 1.F, 1.F, 1.F },
99 };
100
101 Element el;
102 el.buffer = row_buf.buf;
103 el.bounds_hint = row_rect;
104 el.interactive = false;
105 el.name = spec.label;
106 const uint32_t id = surface.layer().add(el);
107
108 Link link(
109 [] { },
110 [reader = spec.reader,
111 label = spec.label,
112 text_image = row_buf.text_image,
113 buf = row_buf.buf,
114 staging,
115 params]() mutable {
116 if (!buf || !reader)
117 return;
118
119 Portal::Text::repress(text_image,
120 label + ": " + reader(),
121 params, staging);
122 buf->bind_texture(0, text_image);
123 });
124
125 return ValueRow {
126 .element_id = id,
127 .buf = std::move(row_buf.buf),
128 .text = std::move(row_buf.text_image),
129 .link = std::move(link),
130 .row_bounds = row_rect,
131 };
132}
133
135 const ValueSpec& spec,
136 RowBuffer row_buf,
137 Surface& surface,
138 LayoutCursor& cursor,
139 float row_h,
140 glm::vec3 bg)
141{
142 return make_value_row(spec, std::move(row_buf), surface, cursor,
143 cursor.x_min(), cursor.x_max(), row_h, bg);
144}
145
147 std::span<const ValueSpec> values,
148 RowBuffer header_buf,
149 std::span<const RowBuffer> row_bufs,
150 Surface& surface,
151 LayoutCursor& cursor,
152 float x_min, float x_max, float row_h,
153 bool initially_open)
154{
155 auto header = Collapsible {}
156 .initially_open(initially_open)
157 .closed_color(glm::vec3(0.25F))
158 .open_color(glm::vec3(0.35F))
159 .label(header_buf.text_image)
160 .place(std::move(header_buf.buf), surface, cursor, x_min, x_max, row_h);
161
162 std::vector<ValueRow> rows;
163 rows.reserve(values.size());
164 for (size_t i = 0; i < values.size(); ++i) {
165 auto row = make_value_row(values[i], row_bufs[i], surface, cursor, x_min, x_max, row_h);
166 header.attach(surface.layer(), row.element_id);
167 rows.push_back(std::move(row));
168 }
169
170 header.cursor_out = cursor;
171
172 return ValueGroup {
173 .header = std::move(header),
174 .rows = std::move(rows),
175 };
176}
177
179 std::span<const ValueSpec> values,
180 RowBuffer header_buf,
181 std::span<const RowBuffer> row_bufs,
182 Surface& surface,
183 LayoutCursor& cursor,
184 float row_h,
185 bool initially_open)
186{
187 return make_value_group(values, std::move(header_buf), row_bufs,
188 surface, cursor, cursor.x_min(), cursor.x_max(), row_h, initially_open);
189}
190
191} // namespace MayaFlux::Portal::Forma
uint32_t h
Definition InkPress.cpp:28
Slot add(Element element)
Add an element to the layer.
Definition Layer.cpp:9
Kinesis::AABB2D advance(float height)
Advance the cursor downward by height and return the NDC AABB occupied by the primitive just placed,...
Reactive Y-position accumulator for vertical primitive stacking.
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
GlyphAtlas * get_default_glyph_atlas() const
Return the default GlyphAtlas, or nullptr if set_default_font() has not been called successfully.
std::shared_ptr< VKBuffer > create_image_staging_buffer(size_t size)
Allocate a persistent host-visible staging buffer sized for repeated streaming uploads to an image of...
@ Runtime
General runtime operations (default fallback)
@ Portal
High-level user-facing API layer.
ValueGroup make_value_group(std::span< const ValueSpec > values, RowBuffer header_buf, std::span< const RowBuffer > row_bufs, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, bool initially_open)
Construct a collapsible header followed by N value rows under it.
ValueRow make_value_row(const ValueSpec &spec, RowBuffer row_buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, glm::vec3 bg)
Construct one labeled value row, advance the cursor, and return it.
glm::uvec2 row_pixel_dims(const std::shared_ptr< Core::Window > &window, float x_min, float x_max, float row_h)
Convert an NDC row rect into integer pixel dimensions.
bool repress(const std::shared_ptr< Buffers::TextBuffer > &target, std::string_view text, glm::vec4 color, RedrawPolicy policy)
Re-composite a UTF-8 string into an existing TextBuffer.
Definition InkPress.cpp:316
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)
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
Collapsible & closed_color(glm::vec3 c)
Collapsible & open_color(glm::vec3 c)
Collapsible & label(std::shared_ptr< Core::VKImage > img)
Attach a GPU image overlaid on the header as a text label.
MAYAFLUX_API Collapsible & place(std::shared_ptr< Buffers::FormaBuffer > buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h)
Register the header element and wire the toggle callback.
Collapsible & initially_open(bool v)
A collapsible header strip.
std::shared_ptr< Buffers::FormaBuffer > buffer
Buffer whose rendered output occupies this region.
Definition Element.hpp:72
std::string name
Optional human-readable label for Lila introspection and debug logging.
Definition Element.hpp:85
std::optional< Kinesis::AABB2D > bounds_hint
Optional fast-reject bounds in NDC space.
Definition Element.hpp:64
bool interactive
When false, hit testing skips this element.
Definition Element.hpp:78
A bounded, renderable region on a window surface.
Definition Element.hpp:58
std::shared_ptr< Buffers::FormaBuffer > buf
std::shared_ptr< Core::VKImage > text_image
A pre-created buffer and its bound text image, passed to make_value_row.
Header collapsible with N value rows related to it.
One value row in a ValueGroup body.
std::function< std::string()> reader
A single value to display in a ValueGroup body row.
glm::vec4 color
RGBA color applied to all glyphs.
Definition InkPress.hpp:53
Construction parameters for press().
Definition InkPress.hpp:48