4 #include <Crousti/GfxNode.hpp>
9 template <
typename Node_T>
11 avnd::texture_input_introspection<Node_T>::size > 0
12 && avnd::texture_output_introspection<Node_T>::size == 0)
13 struct GfxRenderer<Node_T> final :
score::gfx::OutputNodeRenderer
15 using texture_inputs = avnd::texture_input_introspection<Node_T>;
16 const GfxNode<Node_T>& parent;
18 ossia::small_flat_map<const score::gfx::Port*, score::gfx::TextureRenderTarget, 2>
21 std::vector<QRhiReadbackResult> m_readbacks;
22 ossia::time_value m_last_time{-1};
24 GfxRenderer(
const GfxNode<Node_T>& p)
25 :
score::gfx::OutputNodeRenderer{}
27 , m_readbacks(texture_inputs::size)
29 prepareNewState(state, parent);
35 auto it = m_rts.find(&p);
36 SCORE_ASSERT(it != m_rts.end());
40 template <
typename Tex>
44 auto port = parent.input[k];
45 constexpr
auto flags = QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource;
46 auto texture = renderer.
state.rhi->newTexture(
47 gpp::qrhi::textureFormat<Tex>(), size, 1, flags);
48 SCORE_ASSERT(texture->create());
53 QRhiTexture* texture(
int k)
const noexcept
55 auto port = parent.input[k];
56 auto it = m_rts.find(port);
57 SCORE_ASSERT(it != m_rts.end());
58 SCORE_ASSERT(it->second.texture);
59 return it->second.texture;
62 void loadInputTexture(avnd::cpu_texture
auto& cpu_tex,
int k)
64 auto& buf = m_readbacks[k].data;
65 if(buf.size() != 4 * cpu_tex.width * cpu_tex.height)
67 cpu_tex.bytes =
nullptr;
71 cpu_tex.bytes =
reinterpret_cast<unsigned char*
>(buf.data());
72 cpu_tex.changed =
true;
78 if constexpr(requires { state.init(); })
80 parent.processControlIn(state, this->parent.last_message);
86 avnd::cpu_texture_input_introspection<Node_T>::for_all(
87 avnd::get_inputs<Node_T>(state), [&]<
typename F>(F& t) {
88 QSize sz = renderer.
state.renderSize;
89 if constexpr(requires {
94 sz.rwidth() = t.request_width;
95 sz.rheight() = t.request_height;
97 createInput(renderer, k, t.texture, sz);
98 t.texture.width = sz.width();
99 t.texture.height = sz.height();
105 bool updated =
false;
145 for(
auto [port, rt] : m_rts)
150 void inputAboutToFinish(
152 QRhiResourceUpdateBatch*& res)
override
154 res = renderer.
state.rhi->nextResourceUpdateBatch();
155 const auto& inputs = this->parent.input;
156 auto index_of_port = ossia::find(inputs, &p) - inputs.begin();
157 SCORE_ASSERT(index_of_port == 0);
159 auto tex = m_rts[&p].texture;
160 auto& readback = m_readbacks[index_of_port];
162 res->readBackTexture(QRhiReadbackDescription{tex}, &readback);
166 void runInitialPasses(
170 auto& rhi = *renderer.
state.rhi;
173 if(parent.last_message.token.date == m_last_time)
177 m_last_time = parent.last_message.token.date;
188 avnd::cpu_texture_input_introspection<Node_T>::for_all(
189 avnd::get_inputs<Node_T>(state), [&](
auto& t) {
190 loadInputTexture(t.texture, k);
195 parent.processControlIn(state, this->parent.last_message);
201 parent.processControlOut(this->state);
205 template <
typename Node_T>
207 avnd::texture_input_introspection<Node_T>::size > 0
208 && avnd::texture_output_introspection<Node_T>::size == 0)
209 struct GfxNode<Node_T> final : CustomGpuOutputNodeBase
214 std::weak_ptr<Execution::ExecutionCommandQueue> q, Gfx::exec_controls ctls,
int id)
215 : CustomGpuOutputNodeBase{std::move(q), std::move(ctls)}
216 , processModel{element}
220 using texture_inputs = avnd::texture_input_introspection<Node_T>;
223 for(std::size_t i = 0; i < texture_inputs::size; i++)
225 this->input.push_back(
233 return new GfxRenderer<Node_T>{*
this};
Definition: score-plugin-avnd/Crousti/ProcessModel.hpp:551
Definition: OutputNode.hpp:11
List of nodes to be rendered to an output.
Definition: RenderList.hpp:19
RenderState & state
RenderState corresponding to this RenderList.
Definition: RenderList.hpp:89
TextureRenderTarget createRenderTarget(const RenderState &state, QRhiTexture *tex, int samples)
Create a render target from a texture.
Definition: score-plugin-gfx/Gfx/Graph/Utils.cpp:10
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Connection between two score::gfx::Port.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:64
Port of a score::gfx::Node.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:46
Useful abstraction for storing all the data related to a render target.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:109