MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Element.cpp
Go to the documentation of this file.
1#include "Element.hpp"
2
6
8
9namespace {
10
11 /// @brief Four MeshVertex quads in TRIANGLE_LIST order (two triangles) with
12 /// weight=1 so forma_multi.frag samples textures[0].
13 std::array<Kakshya::MeshVertex, 6> textured_mesh_rect(
15 {
17 const glm::vec2 mn = region.min;
18 const glm::vec2 mx = region.max;
19 return { {
20 V { .position = { mn.x, mn.y, 0.F }, .weight = 1.F, .uv = { 0.F, 1.F } },
21 V { .position = { mx.x, mn.y, 0.F }, .weight = 1.F, .uv = { 1.F, 1.F } },
22 V { .position = { mn.x, mx.y, 0.F }, .weight = 1.F, .uv = { 0.F, 0.F } },
23 V { .position = { mx.x, mn.y, 0.F }, .weight = 1.F, .uv = { 1.F, 1.F } },
24 V { .position = { mx.x, mx.y, 0.F }, .weight = 1.F, .uv = { 1.F, 0.F } },
25 V { .position = { mn.x, mx.y, 0.F }, .weight = 1.F, .uv = { 0.F, 0.F } },
26 } };
27 }
28
29} // namespace
30
32 const std::shared_ptr<Core::VKImage>& image,
33 Kinesis::AABB2D region)
34{
35 if (!buffer)
36 return *this;
37
38 texture = image;
39 buffer->submit(textured_mesh_rect(region));
40 buffer->bind_texture(0, image);
41 return *this;
42}
43
45 const std::shared_ptr<Buffers::TextureBuffer>& buf,
46 Kinesis::AABB2D region)
47{
48 return with_texture(buf->get_texture(), region);
49}
50
52 std::string_view text,
53 std::optional<Portal::Text::PressParams> params,
54 Kinesis::AABB2D region)
55{
56 if (!buffer)
57 return *this;
58
59 if (!params.has_value())
60 params = Portal::Text::PressParams {};
61
62 texture = Portal::Text::press(text, params->render_bounds, *params);
63 buffer->submit(textured_mesh_rect(region));
64 buffer->bind_texture(0, texture);
65 return *this;
66}
67
68void Element::set_text(std::string_view text, std::optional<Portal::Text::PressParams> params)
69{
70 if (!texture)
71 return;
72
73 if (!params.has_value())
74 params = Portal::Text::PressParams {};
75
76 Portal::Text::repress(texture, text, *params);
77 if (buffer)
78 buffer->bind_texture(0, texture);
79}
80
81} // namespace MayaFlux::Portal::Forma
IO::ImageData image
Definition Decoder.cpp:57
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
std::shared_ptr< Buffers::TextBuffer > press(std::string_view text, const PressParams &params)
Composite a UTF-8 string into a new TextBuffer.
Definition InkPress.cpp:237
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
Element & with_text(std::string_view text, std::optional< Portal::Text::PressParams > params, Kinesis::AABB2D region={ .min=glm::vec2(-1.F),.max=glm::vec2(1.F) })
Press text into a new GPU texture and bind it to the attached FormaBuffer.
Definition Element.cpp:51
std::shared_ptr< Core::VKImage > texture
Optional GPU texture to bind to the attached buffer. Used for.
Definition Element.hpp:75
std::shared_ptr< Buffers::FormaBuffer > buffer
Buffer whose rendered output occupies this region.
Definition Element.hpp:72
Element & with_texture(const std::shared_ptr< Core::VKImage > &image, Kinesis::AABB2D region={ .min=glm::vec2(-1.F),.max=glm::vec2(1.F) })
Submit a UV quad covering region and bind image as "texSampler" on the attached FormaBuffer.
Definition Element.cpp:31
void set_text(std::string_view text, std::optional< Portal::Text::PressParams > params)
Re-composite text into the retained GPU texture.
Definition Element.cpp:68
A bounded, renderable region on a window surface.
Definition Element.hpp:58
Construction parameters for press().
Definition InkPress.hpp:48