4#include <Crousti/GfxNode.hpp>
9template <
typename Node_T>
11 avnd::texture_input_introspection<Node_T>::size > 0
12 && avnd::texture_output_introspection<Node_T>::size == 0)
13struct GfxRenderer<Node_T>
final :
score::gfx::OutputNodeRenderer
15 using texture_inputs = avnd::texture_input_introspection<Node_T>;
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 const GfxNode<Node_T>& node() const noexcept
26 return static_cast<const GfxNode<Node_T>&
>(score::gfx::NodeRenderer::node);
28 GfxRenderer(
const GfxNode<Node_T>& p)
29 :
score::gfx::OutputNodeRenderer{p}
30 , m_readbacks(texture_inputs::size)
32 prepareNewState(state, p);
38 auto it = m_rts.find(&p);
39 SCORE_ASSERT(it != m_rts.end());
43 template <
typename Tex>
48 auto port = this->node().input[k];
49 static constexpr auto flags
50 = QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource;
51 auto texture = renderer.
state.rhi->newTexture(
52 gpp::qrhi::textureFormat<Tex>(), spec.size, 1, flags);
53 SCORE_ASSERT(texture->create());
58 QRhiTexture* texture(
int k)
const noexcept
60 auto port = this->node().input[k];
61 auto it = m_rts.find(port);
62 SCORE_ASSERT(it != m_rts.end());
63 SCORE_ASSERT(it->second.texture);
64 return it->second.texture;
67 void loadInputTexture(QRhi& rhi, avnd::cpu_texture
auto& cpu_tex,
int k)
69 auto& buf = m_readbacks[k].data;
70 if(buf.size() != 4 * cpu_tex.width * cpu_tex.height)
72 cpu_tex.bytes =
nullptr;
76 cpu_tex.bytes =
reinterpret_cast<unsigned char*
>(buf.data());
78 if(rhi.isYUpInFramebuffer())
79 if(cpu_tex.width * cpu_tex.height > 0)
80 inplaceMirror(cpu_tex.bytes, cpu_tex.width, cpu_tex.height);
82 cpu_tex.changed =
true;
88 if constexpr(
requires { state.prepare(); })
90 this->node().processControlIn(
91 *
this, state, m_last_message, this->node().last_message, this->node().m_ctx);
97 avnd::cpu_texture_input_introspection<Node_T>::for_all(
98 avnd::get_inputs<Node_T>(state), [&]<
typename F>(F& t) {
100 auto spec = this->node().resolveRenderTargetSpecs(k, renderer);
101 if constexpr(
requires {
106 spec.size.rwidth() = t.request_width;
107 spec.size.rheight() = t.request_height;
109 createInput(renderer, k, t.texture, spec);
110 if constexpr(avnd::cpu_fixed_format_texture<
decltype(t.texture)>)
112 t.texture.width = spec.size.width();
113 t.texture.height = spec.size.height();
123 bool updated =
false;
163 for(
auto [port, rt] : m_rts)
168 void inputAboutToFinish(
170 QRhiResourceUpdateBatch*& res)
override
172 auto& parent = this->node();
173 res = renderer.
state.rhi->nextResourceUpdateBatch();
174 const auto& inputs = parent.input;
175 auto index_of_port = ossia::find(inputs, &p) - inputs.begin();
176 SCORE_ASSERT(index_of_port == 0);
178 auto tex = m_rts[&p].texture;
179 auto& readback = m_readbacks[index_of_port];
181 res->readBackTexture(QRhiReadbackDescription{tex}, &readback);
185 void runInitialPasses(
189 auto& parent = this->node();
190 auto& rhi = *renderer.
state.rhi;
196 if(parent.last_message.token.date == m_last_time)
200 m_last_time = parent.last_message.token.date;
208 avnd::cpu_texture_input_introspection<Node_T>::for_all(
209 avnd::get_inputs<Node_T>(state), [&](
auto& t) {
210 loadInputTexture(rhi, t.texture, k);
215 parent.processControlIn(
216 *
this, state, m_last_message, parent.last_message, parent.m_ctx);
222 parent.processControlOut(this->state);
226 avnd::geometry_output_introspection<Node_T>::for_all_n2(
227 state.outputs, [&]<std::size_t F, std::size_t P>(
228 auto& t, avnd::predicate_index<P>, avnd::field_index<F>) {
229 postprocess_geometry(t);
232 template <avnd::geometry_port Field>
233 void postprocess_geometry(Field& ctrl)
235 using namespace avnd;
238 mesh_dirty = ctrl.dirty_mesh;
242 auto meshes = std::make_shared<ossia::mesh_list>();
243 auto& ossia_meshes = *meshes;
244 if constexpr(static_geometry_type<Field> || dynamic_geometry_type<Field>)
246 ossia_meshes.meshes.resize(1);
247 oscr::load_geometry(ctrl, ossia_meshes.meshes[0]);
250 static_geometry_type<
decltype(Field::mesh)>
251 || dynamic_geometry_type<
decltype(Field::mesh)>)
253 ossia_meshes.meshes.resize(1);
254 oscr::load_geometry(ctrl.mesh, ossia_meshes.meshes[0]);
258 oscr::load_geometry(ctrl, ossia_meshes);
261 ctrl.dirty_mesh =
false;
282template <
typename Node_T>
283 requires(avnd::texture_input_introspection<Node_T>::size > 0
284 && avnd::texture_output_introspection<Node_T>::size == 0)
285struct GfxNode<Node_T>
final
286 : CustomGpuOutputNodeBase
287 , GpuNodeElements<Node_T>
292 std::weak_ptr<Execution::ExecutionCommandQueue> q, Gfx::exec_controls ctls,
int id,
294 : CustomGpuOutputNodeBase{
std::move(q),
std::move(ctls), ctx}
295 , processModel{element}
299 initGfxPorts<Node_T>(
this, this->input, this->output);
305 return new GfxRenderer<Node_T>{*
this};
Definition score-plugin-avnd/Crousti/ProcessModel.hpp:79
Definition OutputNode.hpp:11
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
bool requiresDepth() const noexcept
Whether this list of rendering actions requires depth testing at all.
Definition RenderList.hpp:137
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:89
Definition Factories.hpp:19
TextureRenderTarget createRenderTarget(const RenderState &state, QRhiTexture *tex, int samples, bool depth)
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:97
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:50
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:48
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:57
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:111