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.);
32// The uploaded buffer's row 0 is its top, and it must come out at the top on
33// every backend. Vulkan was left out of this correction, so a JIT Texgen -- and
34// anything else painting a texture from C++ -- came out upside down there,
35// through every sink: the window, the readback outputs and the GPU encoders
37#if !(defined(QSHADER_HLSL) || defined(QSHADER_MSL))
38 gl_Position.y = - gl_Position.y;
43 static const constexpr auto filter = R
"_(#version 450
44 layout(location = 0) in vec2 v_texcoord;
45 layout(location = 0) out vec4 fragColor;
47 layout(std140, binding = 0) uniform renderer_t {
48 mat4 clipSpaceCorrMatrix;
52 layout(binding=3) uniform sampler2D y_tex;
57 fragColor = texture(y_tex, v_texcoord);
63 int currentImageIndex{};
70 using GenericNodeRenderer::GenericNodeRenderer;
74 QRhiTexture* texture{};
78 defaultMeshInit(renderer, *m_mesh, res);
79 processUBOInit(renderer);
80 m_material.init(renderer, node.
input, m_samplers);
81 std::tie(m_vertexS, m_fragmentS)
84 auto& rhi = *renderer.
state.rhi;
86 vec.resize(640 * 480 * 4);
87 texture = rhi.newTexture(
88 QRhiTexture::RGBA8, QSize(640, 480), 1, QRhiTexture::Flag{});
94 auto sampler = rhi.newSampler(
95 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
96 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
99 m_samplers.push_back({sampler, texture});
106 RenderList& renderer, QRhiResourceUpdateBatch& res,
113 defaultUBOUpdate(renderer, res);
114 auto sz = renderer.renderSize(edge);
115 auto bytes = sz.width() * sz.height() * 4;
116 if(bytes != vec.size())
118 vec.resize(bytes, boost::container::default_init);
120 QRhiTexture* oldtex = texture;
121 QRhiTexture* newtex = renderer.
state.rhi->newTexture(
122 QRhiTexture::RGBA8, sz, 1, QRhiTexture::Flag{});
124 for(
auto& [edge, pass] : this->m_p)
126 score::gfx::replaceTexture(*pass.p.srb, m_samplers[0].sampler, newtex);
131 oldtex->deleteLater();
135 if(func_t f = n.function.load())
137 f(vec.data(), sz.width(), sz.height(), t++);
139 QRhiTextureSubresourceUploadDescription subdesc{
140 QByteArray::fromRawData((
const char*)vec.data(), vec.size())};
141 QRhiTextureUploadEntry entry{0, 0, subdesc};
142 QRhiTextureUploadDescription desc{entry};
144 res.uploadTexture(texture, desc);
152 texture->deleteLater();
160 boost::container::vector<unsigned char> vec;
164 virtual ~TexgenNode()
166 m_materialData.release();
169 using func_t = void (*)(
unsigned char* rgb,
int width,
int height,
int t);
170 std::atomic<func_t> function{};
Generic renderer.
Definition NodeRenderer.hpp:311
void releaseState(RenderList &renderer) override
Definition NodeRenderer.cpp:333
std::vector< Port * > input
Input ports of that node.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:103
ossia::small_pod_vector< Port *, 1 > output
Output ports of that node.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:109
Common base class for most single-pass, simple nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:228
Renderer for a given node.
Definition NodeRenderer.hpp:11
bool m_initialized
Definition NodeRenderer.hpp:237
List of nodes to be rendered to an output.
Definition RenderList.hpp:30
const score::gfx::Mesh & defaultTriangle() const noexcept
A triangle mesh correct for this API.
Definition RenderList.cpp:984
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:169
QRhiTexture & emptyTexture() const noexcept
Texture to use when a texture is missing (2D)
Definition RenderList.hpp:192
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag, int multiViewCount)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1238
Base toolkit upon which the software is built.
Definition Application.cpp:117
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:103
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:82
Definition TexgenNode.hpp:69
void initState(RenderList &renderer, QRhiResourceUpdateBatch &res) override
Definition TexgenNode.hpp:75
void releaseState(RenderList &r) override
Definition TexgenNode.hpp:148
Definition TexgenNode.hpp:62
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:172