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::GenericNodeRenderer
15 using texture_outputs = avnd::texture_output_introspection<Node_T>;
16 const GfxNode<Node_T>& parent;
18 ossia::time_value m_last_time{-1};
20 GfxRenderer(
const GfxNode<Node_T>& p)
21 :
score::gfx::GenericNodeRenderer{p}
24 prepareNewState(state, parent);
33 template <
typename Tex>
37 auto& rhi = *renderer.
state.rhi;
39 if(size.width() > 0 && size.height() > 0)
41 texture = rhi.newTexture(
42 gpp::qrhi::textureFormat<Tex>(), size, 1, QRhiTexture::Flag{});
47 auto sampler = rhi.newSampler(
48 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
49 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
52 this->m_samplers.push_back({sampler, texture});
55 template <avnd::cpu_texture Tex>
58 auto& [sampler, texture] = this->m_samplers[k];
61 auto sz = texture->pixelSize();
62 if(cpu_tex.width == sz.width() && cpu_tex.height == sz.height())
67 if(cpu_tex.width > 0 && cpu_tex.height > 0)
69 QRhiTexture* oldtex = texture;
70 QRhiTexture* newtex = renderer.
state.rhi->newTexture(
71 gpp::qrhi::textureFormat<Tex>(), QSize{cpu_tex.width, cpu_tex.height}, 1,
74 for(
auto& [edge, pass] : this->m_p)
76 score::gfx::replaceTexture(*pass.srb, sampler, newtex);
81 oldtex->deleteLater();
88 for(
auto& [edge, pass] : this->m_p)
90 score::gfx::replaceTexture(*pass.srb, sampler, &renderer.
emptyTexture());
96 void uploadOutputTexture(
98 QRhiResourceUpdateBatch* res)
102 if(
auto texture = updateTexture(renderer, k, cpu_tex))
106 QRhiTextureSubresourceUploadDescription sd(
107 cpu_tex.bytes, cpu_tex.width * cpu_tex.height * 4);
108 QRhiTextureUploadDescription desc{QRhiTextureUploadEntry{0, 0, sd}};
110 res->uploadTexture(texture, desc);
113 cpu_tex.changed =
false;
121 if constexpr(requires { state.init(); })
127 this->defaultMeshInit(renderer, mesh, res);
128 this->processUBOInit(renderer);
129 this->m_material.init(renderer, this->node.input, this->m_samplers);
130 std::tie(this->m_vertexS, this->m_fragmentS)
134 avnd::cpu_texture_output_introspection<Node_T>::for_all(
135 avnd::get_outputs<Node_T>(state), [&](
auto& t) {
136 createOutput(renderer, t.texture, QSize{t.texture.width, t.texture.height});
139 this->defaultPassesInit(renderer, mesh);
144 this->defaultUBOUpdate(renderer, res);
150 for(
auto& [sampl, texture] : this->m_samplers)
153 texture->deleteLater();
157 this->defaultRelease(r);
160 void runInitialPasses(
165 if(parent.last_message.token.date == m_last_time)
169 m_last_time = parent.last_message.token.date;
171 parent.processControlIn(state, this->parent.last_message);
178 avnd::cpu_texture_output_introspection<Node_T>::for_all(
179 avnd::get_outputs<Node_T>(state), [&](
auto& t) {
180 uploadOutputTexture(renderer, k, t.texture, res);
184 commands.resourceUpdate(res);
185 res = renderer.
state.rhi->nextResourceUpdateBatch();
188 parent.processControlOut(this->state);
192 template <
typename Node_T>
193 requires(avnd::texture_input_introspection<Node_T>::size == 0
194 && avnd::texture_output_introspection<Node_T>::size > 0)
195 struct GfxNode<Node_T> final
204 std::weak_ptr<Execution::ExecutionCommandQueue> q, Gfx::exec_controls ctls,
int id)
205 : GpuControlOuts{std::move(q), std::move(ctls)}
206 , processModel{element}
210 using texture_outputs = avnd::texture_output_introspection<Node_T>;
213 for(std::size_t i = 0; i < texture_outputs::size; i++)
215 this->output.push_back(
223 return new GfxRenderer<Node_T>{*
this};
Definition: score-plugin-avnd/Crousti/ProcessModel.hpp:551
Renderer for a given node.
Definition: NodeRenderer.hpp:11
List of nodes to be rendered to an output.
Definition: RenderList.hpp:19
const score::gfx::Mesh & defaultTriangle() const noexcept
A triangle mesh correct for this API.
Definition: RenderList.cpp:247
RenderState & state
RenderState corresponding to this RenderList.
Definition: RenderList.hpp:89
QRhiTexture & emptyTexture() const noexcept
Texture to use when a texture is missing.
Definition: RenderList.hpp:111
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition: score-plugin-gfx/Gfx/Graph/Utils.cpp:334
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