MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Target.cpp
Go to the documentation of this file.
1#include "Target.hpp"
2
4
6
7FormaTarget::FormaTarget(std::shared_ptr<Buffers::FormaBuffer> buffer)
8 : FormaTarget(std::move(buffer), 0)
9{
10}
11
12FormaTarget::FormaTarget(std::shared_ptr<Buffers::FormaBuffer> buffer, SliceId slice)
13{
14 if (buffer) {
15 m_state = std::make_shared<State>(State { .buffer = std::move(buffer), .slice = slice });
16 }
17}
18
20 const std::shared_ptr<Buffers::FormaBuffer>& buffer,
21 std::optional<Graphics::PrimitiveTopology> topology)
22{
23 if (!buffer) {
24 return {};
25 }
26 const auto slice = buffer->add_slice({}, topology);
27 return slice == 0 ? FormaTarget {} : FormaTarget(buffer, slice);
28}
29
31{
32 return m_state ? m_state->buffer.get() : nullptr;
33}
34
36{
37 return *m_state->buffer;
38}
39
40const std::shared_ptr<Buffers::FormaBuffer>& FormaTarget::buffer() const noexcept
41{
42 static const std::shared_ptr<Buffers::FormaBuffer> none;
43 return m_state ? m_state->buffer : none;
44}
45
47{
48 return m_state ? m_state->slice : 0;
49}
50
51void FormaTarget::submit(const std::vector<uint8_t>& bytes) const
52{
53 if (!m_state)
54 return;
55
56 if (m_state->slice != 0) {
57 m_state->buffer->update_slice(m_state->slice, bytes);
58 return;
59 }
60 m_state->buffer->submit(bytes);
61}
62
63void FormaTarget::bind_texture(uint32_t array_index, const std::shared_ptr<Core::VKImage>& image) const
64{
65 if (m_state)
66 m_state->buffer->bind_texture(array_index, image);
67}
68
69void FormaTarget::set_visible(bool visible) const
70{
71 if (!m_state)
72 return;
73
74 if (m_state->slice != 0) {
75 m_state->buffer->set_slice_visible(m_state->slice, visible);
76 return;
77 }
78
79 if (auto render = m_state->buffer->get_render_processor())
80 render->set_visible(visible, m_state->buffer);
81}
82
83void FormaTarget::bring_to_front(int64_t priority) const
84{
85 if (!m_state)
86 return;
87
88 if (m_state->slice != 0) {
89 m_state->buffer->bring_slice_to_front(m_state->slice);
90 return;
91 }
92
93 auto config = m_state->buffer->get_render_config();
94 config.draw_priority = priority;
95 m_state->buffer->set_render_config(config);
96}
97
98void FormaTarget::send_to_back(int64_t priority) const
99{
100 if (!m_state)
101 return;
102
103 if (m_state->slice != 0) {
104 m_state->buffer->send_slice_to_back(m_state->slice);
105 return;
106 }
107
108 auto config = m_state->buffer->get_render_config();
109 config.draw_priority = priority;
110 m_state->buffer->set_render_config(config);
111}
112
114{
115 if (!m_state)
116 return;
117
118 if (m_state->slice != 0) {
119 m_state->buffer->remove_slice(m_state->slice);
120 if (m_state->buffer->slice_count() == 0)
121 m_state->buffer->mark_for_removal();
122 return;
123 }
124 m_state->buffer->mark_for_removal();
125}
126
127} // namespace MayaFlux::Portal::Forma
IO::ImageData image
Definition Decoder.cpp:47
std::shared_ptr< NetworkGeometryBuffer > buffer
PrimitiveTopology topology
void update_slice(SliceId id, const std::vector< uint8_t > &bytes)
Replace a block's vertices; later blocks shift if the size changes.
SliceId add_slice(const std::vector< uint8_t > &bytes, std::optional< Portal::Graphics::PrimitiveTopology > topology=std::nullopt)
Add a block of vertices that shares this buffer with the others.
VKBuffer for 2D screen-space Forma geometry.
void set_visible(bool visible) const
Show or hide this target's output.
Definition Target.cpp:69
Buffers::FormaBuffer * operator->() const noexcept
Definition Target.cpp:30
static FormaTarget slice_of(const std::shared_ptr< Buffers::FormaBuffer > &buffer, std::optional< Graphics::PrimitiveTopology > topology=std::nullopt)
A new empty slice of buffer, drawn after the others.
Definition Target.cpp:19
void submit(const std::vector< uint8_t > &bytes) const
Replace this target's geometry.
Definition Target.cpp:51
std::shared_ptr< State > m_state
Definition Target.hpp:126
void retire() const
Release this target: retire a whole buffer, or remove a slice.
Definition Target.cpp:113
SliceId slice() const noexcept
Slice id, 0 when the handle means the whole buffer.
Definition Target.cpp:46
void bring_to_front(int64_t priority) const
Draw this target after the others.
Definition Target.cpp:83
Buffers::FormaBuffer::SliceId SliceId
Definition Target.hpp:24
const std::shared_ptr< Buffers::FormaBuffer > & buffer() const noexcept
The underlying buffer; null for an empty handle.
Definition Target.cpp:40
void send_to_back(int64_t priority) const
Draw this target before the others.
Definition Target.cpp:98
Buffers::FormaBuffer & operator*() const noexcept
Definition Target.cpp:35
void bind_texture(uint32_t array_index, const std::shared_ptr< Core::VKImage > &image) const
Bind a texture in the buffer's texture array.
Definition Target.cpp:63
Where an element's geometry and texture are written.
Definition Target.hpp:22
std::shared_ptr< Buffers::FormaBuffer > buffer
Definition Target.hpp:122