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;
19 ossia::small_flat_map<const score::gfx::Port*, score::gfx::TextureRenderTarget, 2>
22 std::vector<QRhiReadbackResult> m_readbacks;
23 ossia::time_value m_last_time{-1};
25 GfxRenderer(
const GfxNode<Node_T>& p)
26 :
score::gfx::OutputNodeRenderer{}
28 , m_readbacks(texture_inputs::size)
30 prepareNewState(state, parent);
36 auto it = m_rts.find(&p);
37 SCORE_ASSERT(it != m_rts.end());
41 template <
typename Tex>
45 auto port = parent.input[k];
46 static constexpr
auto flags
47 = QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource;
48 auto texture = renderer.
state.rhi->newTexture(
49 gpp::qrhi::textureFormat<Tex>(), size, 1, flags);
50 SCORE_ASSERT(texture->create());
55 QRhiTexture* texture(
int k)
const noexcept
57 auto port = parent.input[k];
58 auto it = m_rts.find(port);
59 SCORE_ASSERT(it != m_rts.end());
60 SCORE_ASSERT(it->second.texture);
61 return it->second.texture;
64 void loadInputTexture(avnd::cpu_texture
auto& cpu_tex,
int k)
66 auto& buf = m_readbacks[k].data;
67 if(buf.size() != 4 * cpu_tex.width * cpu_tex.height)
69 cpu_tex.bytes =
nullptr;
73 cpu_tex.bytes =
reinterpret_cast<unsigned char*
>(buf.data());
74 cpu_tex.changed =
true;
80 if constexpr(requires { state.prepare(); })
82 parent.processControlIn(
83 *
this, state, m_last_message, this->parent.last_message, this->parent.m_ctx);
89 avnd::cpu_texture_input_introspection<Node_T>::for_all(
90 avnd::get_inputs<Node_T>(state), [&]<
typename F>(F& t) {
91 QSize sz = renderer.
state.renderSize;
92 if constexpr(requires {
97 sz.rwidth() = t.request_width;
98 sz.rheight() = t.request_height;
100 createInput(renderer, k, t.texture, sz);
101 t.texture.width = sz.width();
102 t.texture.height = sz.height();
108 bool updated =
false;
148 for(
auto [port, rt] : m_rts)
153 void inputAboutToFinish(
155 QRhiResourceUpdateBatch*& res)
override
157 res = renderer.
state.rhi->nextResourceUpdateBatch();
158 const auto& inputs = this->parent.input;
159 auto index_of_port = ossia::find(inputs, &p) - inputs.begin();
160 SCORE_ASSERT(index_of_port == 0);
162 auto tex = m_rts[&p].texture;
163 auto& readback = m_readbacks[index_of_port];
165 res->readBackTexture(QRhiReadbackDescription{tex}, &readback);
169 void runInitialPasses(
173 auto& rhi = *renderer.
state.rhi;
176 if(parent.last_message.token.date == m_last_time)
180 m_last_time = parent.last_message.token.date;
191 avnd::cpu_texture_input_introspection<Node_T>::for_all(
192 avnd::get_inputs<Node_T>(state), [&](
auto& t) {
193 loadInputTexture(t.texture, k);
198 parent.processControlIn(
199 *
this, state, m_last_message, this->parent.last_message, this->parent.m_ctx);
205 parent.processControlOut(this->state);
209 template <
typename Node_T>
210 requires(avnd::texture_input_introspection<Node_T>::size > 0
211 && avnd::texture_output_introspection<Node_T>::size == 0)
212 struct GfxNode<Node_T> final
213 : CustomGpuOutputNodeBase
214 , GpuNodeElements<Node_T>
219 std::weak_ptr<Execution::ExecutionCommandQueue> q, Gfx::exec_controls ctls,
int id,
221 : CustomGpuOutputNodeBase{std::move(q), std::move(ctls), ctx}
222 , processModel{element}
226 using texture_inputs = avnd::texture_input_introspection<Node_T>;
229 for(std::size_t i = 0; i < texture_inputs::size; i++)
231 this->input.push_back(
239 return new GfxRenderer<Node_T>{*
this};
Definition: score-plugin-avnd/Crousti/ProcessModel.hpp:77
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
Definition: Factories.hpp:19
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
Definition: DocumentContext.hpp:18
Connection between two score::gfx::Port.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:66
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:51
Port of a score::gfx::Node.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:48
Useful abstraction for storing all the data related to a render target.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:111