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;
19 ossia::time_value m_last_time{-1};
21 GfxRenderer(
const GfxNode<Node_T>& p)
22 :
score::gfx::GenericNodeRenderer{p}
25 prepareNewState(state, parent);
34 template <
typename Tex>
38 auto& rhi = *renderer.
state.rhi;
40 if(size.width() > 0 && size.height() > 0)
42 texture = rhi.newTexture(
43 gpp::qrhi::textureFormat<Tex>(), size, 1, QRhiTexture::Flag{});
48 auto sampler = rhi.newSampler(
49 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
50 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
53 this->m_samplers.push_back({sampler, texture});
56 template <avnd::cpu_texture Tex>
59 auto& [sampler, texture] = this->m_samplers[k];
62 auto sz = texture->pixelSize();
63 if(cpu_tex.width == sz.width() && cpu_tex.height == sz.height())
68 if(cpu_tex.width > 0 && cpu_tex.height > 0)
70 QRhiTexture* oldtex = texture;
71 QRhiTexture* newtex = renderer.
state.rhi->newTexture(
72 gpp::qrhi::textureFormat<Tex>(), QSize{cpu_tex.width, cpu_tex.height}, 1,
75 for(
auto& [edge, pass] : this->m_p)
77 score::gfx::replaceTexture(*pass.srb, sampler, newtex);
82 oldtex->deleteLater();
89 for(
auto& [edge, pass] : this->m_p)
91 score::gfx::replaceTexture(*pass.srb, sampler, &renderer.
emptyTexture());
97 void uploadOutputTexture(
99 QRhiResourceUpdateBatch* res)
103 if(
auto texture = updateTexture(renderer, k, cpu_tex))
107 QRhiTextureSubresourceUploadDescription sd(
108 cpu_tex.bytes, cpu_tex.width * cpu_tex.height * 4);
109 QRhiTextureUploadDescription desc{QRhiTextureUploadEntry{0, 0, sd}};
111 res->uploadTexture(texture, desc);
114 cpu_tex.changed =
false;
122 if constexpr(requires { state.prepare(); })
124 parent.processControlIn(
125 *
this, state, m_last_message, this->parent.last_message, this->parent.m_ctx);
130 this->defaultMeshInit(renderer, mesh, res);
131 this->processUBOInit(renderer);
132 this->m_material.init(renderer, this->node.input, this->m_samplers);
133 std::tie(this->m_vertexS, this->m_fragmentS)
137 avnd::cpu_texture_output_introspection<Node_T>::for_all(
138 avnd::get_outputs<Node_T>(state), [&](
auto& t) {
139 createOutput(renderer, t.texture, QSize{t.texture.width, t.texture.height});
142 this->defaultPassesInit(renderer, mesh);
147 this->defaultUBOUpdate(renderer, res);
153 for(
auto& [sampl, texture] : this->m_samplers)
156 texture->deleteLater();
160 this->defaultRelease(r);
163 void runInitialPasses(
168 if(parent.last_message.token.date == m_last_time)
172 m_last_time = parent.last_message.token.date;
174 parent.processControlIn(
175 *
this, state, m_last_message, this->parent.last_message, parent.m_ctx);
182 avnd::cpu_texture_output_introspection<Node_T>::for_all(
183 avnd::get_outputs<Node_T>(state), [&](
auto& t) {
184 uploadOutputTexture(renderer, k, t.texture, res);
188 commands.resourceUpdate(res);
189 res = renderer.
state.rhi->nextResourceUpdateBatch();
192 parent.processControlOut(this->state);
196 template <
typename Node_T>
197 requires(avnd::texture_input_introspection<Node_T>::size == 0
198 && avnd::texture_output_introspection<Node_T>::size > 0)
199 struct GfxNode<Node_T> final
204 , GpuNodeElements<Node_T>
209 std::weak_ptr<Execution::ExecutionCommandQueue> q, Gfx::exec_controls ctls,
int id,
211 : CustomGfxNodeBase{ctx}
212 , GpuControlOuts{std::move(q), std::move(ctls)}
213 , processModel{element}
217 using texture_outputs = avnd::texture_output_introspection<Node_T>;
220 for(std::size_t i = 0; i < texture_outputs::size; i++)
222 this->output.push_back(
230 return new GfxRenderer<Node_T>{*
this};
Definition: score-plugin-avnd/Crousti/ProcessModel.hpp:77
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:250
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
Definition: Factories.hpp:19
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:342
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