3 #include <Gfx/Graph/Node.hpp>
4 #include <Gfx/Graph/NodeRenderer.hpp>
5 #include <Gfx/Graph/RenderList.hpp>
6 #include <Gfx/Graph/RenderState.hpp>
7 #include <Gfx/Graph/Uniforms.hpp>
14 static const constexpr
auto vertex = R
"_(#version 450
15 layout(location = 0) in vec2 position;
16 layout(location = 1) in vec2 texcoord;
18 layout(binding = 3) uniform sampler2D y_tex;
19 layout(location = 0) out vec2 v_texcoord;
21 layout(std140, binding = 0) uniform renderer_t {
22 mat4 clipSpaceCorrMatrix;
26 out gl_PerVertex { vec4 gl_Position; };
30 v_texcoord = texcoord;
31 gl_Position = renderer.clipSpaceCorrMatrix * vec4(position.xy, 0.0, 1.);
35 static const constexpr
auto filter = R
"_(#version 450
36 layout(location = 0) in vec2 v_texcoord;
37 layout(location = 0) out vec4 fragColor;
39 layout(std140, binding = 0) uniform renderer_t {
40 mat4 clipSpaceCorrMatrix;
44 layout(binding=3) uniform sampler2D y_tex;
49 fragColor = texture(y_tex, v_texcoord);
55 int currentImageIndex{};
62 using GenericNodeRenderer::GenericNodeRenderer;
66 QRhiTexture* texture{};
67 void init(
RenderList& renderer, QRhiResourceUpdateBatch& res)
override
70 defaultMeshInit(renderer, mesh, res);
71 processUBOInit(renderer);
72 m_material.init(renderer, node.
input, m_samplers);
73 std::tie(m_vertexS, m_fragmentS)
76 auto& n =
static_cast<const TexgenNode&
>(this->node);
77 auto& rhi = *renderer.
state.rhi;
80 = rhi.newTexture(QRhiTexture::RGBA8, n.image.size(), 1, QRhiTexture::Flag{});
86 auto sampler = rhi.newSampler(
87 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
88 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
91 m_samplers.push_back({sampler, texture});
93 defaultPassesInit(renderer, mesh);
96 void update(
RenderList& renderer, QRhiResourceUpdateBatch& res)
override
98 defaultUBOUpdate(renderer, res);
99 auto& n =
static_cast<const TexgenNode&
>(this->node);
100 if(func_t f = n.function.load())
102 f(
const_cast<uchar*
>(n.image.bits()), n.image.width(), n.image.height(), t++);
103 res.uploadTexture(texture, n.image);
109 texture->deleteLater();
121 image = QImage{QSize(640, 480), QImage::Format_ARGB32_Premultiplied};
122 output.push_back(
new Port{
this, {}, Types::Image, {}});
124 virtual ~TexgenNode()
126 m_materialData.release();
129 using func_t = void (*)(
unsigned char* rgb,
int width,
int height,
int t);
130 std::atomic<func_t>
function{};
Generic renderer.
Definition: NodeRenderer.hpp:61
std::vector< Port * > input
Input ports of that node.
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:89
ossia::small_pod_vector< Port *, 1 > output
Output ports of that node.
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:95
Common base class for most single-pass, simple nodes.
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:181
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
Graphics rendering pipeline for ossia score.
Definition: Filter/PreviewWidget.hpp:12
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
Port of a score::gfx::Node.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:48
Definition: TexgenNode.hpp:61
Definition: TexgenNode.hpp:54
Definition: TexgenNode.hpp:13
score::gfx::NodeRenderer * createRenderer(RenderList &r) const noexcept override
Create a renderer in a given context for this node.
Definition: TexgenNode.hpp:132
Definition: Uniforms.hpp:5