MayaFlux 0.4.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
88 const uint32_t stride = Kakshya::VertexLayout::for_meshes().stride_bytes;
89 std::vector<uint8_t> bytes(static_cast<size_t>(12) * stride, 0);
90 write_row_quad(bytes, x_min, x_max, bot, top, bg);
91 row_buf.buf->submit(bytes);
92
94 row_buf.text_image->get_size_bytes());
95
97 .color = { 1.F, 1.F, 1.F, 1.F },
98 };
99
100 Element el;
101 el.buffer = row_buf.buf;
102 el.bounds_hint = Kinesis::AABB2D { .min = { x_min, bot }, .max = { x_max, top } };
103 el.interactive = false;
104 el.name = spec.label;
105 const uint32_t id = surface.layer().add(el);
106
107 Link link(
108 [] { },
109 [reader = spec.reader,
110 label = spec.label,
111 text_image = row_buf.text_image,
112 buf = row_buf.buf,
113 staging,
114 params]() mutable {
115 if (!buf || !reader)
116 return;
117
118 Portal::Text::repress(text_image,
119 label + ": " + reader(),
120 params, staging);
121 buf->bind_texture(0, text_image);
122 });
123
124 return ValueRow {
125 .element_id = id,
126 .buf = std::move(row_buf.buf),
127 .text = std::move(row_buf.text_image),
128 .link = std::move(link),
129 };
130}
131
133 std::span<const ValueSpec> values,
134 RowBuffer header_buf,
135 std::span<const RowBuffer> row_bufs,
136 Surface& surface,
137 LayoutCursor& cursor,
138 float x_min, float x_max, float row_h,
139 bool initially_open)
140{
141 auto header = Collapsible {}
142 .initially_open(initially_open)
143 .closed_color(glm::vec3(0.25F))
144 .open_color(glm::vec3(0.35F))
145 .label(header_buf.text_image)
146 .place(std::move(header_buf.buf), surface, cursor, x_min, x_max, row_h);
147
148 std::vector<ValueRow> rows;
149 rows.reserve(values.size());
150 for (size_t i = 0; i < values.size(); ++i) {
151 auto row = make_value_row(values[i], row_bufs[i], surface, cursor, x_min, x_max, row_h);
152 header.attach(surface.layer(), row.element_id);
153 rows.push_back(std::move(row));
154 }
155
156 header.cursor_out = cursor;
157
158 return ValueGroup {
159 .header = std::move(header),
160 .rows = std::move(rows),
161 };
162}
163
164} // 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