2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
21 static const constexpr auto frag = R
"_(#version 450
23)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
25layout(binding=3) uniform sampler2D y_tex;
26layout(binding=4) uniform sampler2D uv_tex;
27layout(binding=5) uniform sampler2D a_tex;
29layout(location = 0) in vec2 v_texcoord;
30layout(location = 0) out vec4 fragColor;
34vec4 processTexture(vec4 tex) {
35 vec4 processed = convert_to_rgb(tex);
41 vec2 tc = score_tc(v_texcoord);
42 float y = texture(y_tex, tc).r;
43 float u = texture(uv_tex, tc).r;
44 float v = texture(uv_tex, tc).g;
45 float a = texture(a_tex, tc).r;
47 vec4 rgb = processTexture(vec4(y, u, v, 1.));
48 fragColor = vec4(rgb.rgb, a);
61 auto& rhi = *r.
state.rhi;
62 const auto w = decoder.width, h = decoder.height;
64 auto mkSampler = [&] {
65 auto sampler = rhi.newSampler(
66 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
67 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
71 auto plane = [&](QRhiTexture::Format fmt, QSize sz) {
72 auto tex = rhi.newTexture(fmt, sz, 1, QRhiTexture::Flag{});
74 samplers.push_back({mkSampler(), tex});
77 plane(QRhiTexture::R16, {w, h});
78 plane(QRhiTexture::RG16, {w / 2, h});
79 plane(QRhiTexture::R16, {w, h});
82 r.
state, vertexShader(), QString(frag).arg(
"").arg(colorMatrix(decoder)));
85 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
87 const int widths[3] = {decoder.width, decoder.width / 2, decoder.width};
88 const int bpt[3] = {2, 4, 2};
89 for(
int i = 0; i < 3; i++)
91 const auto [rows, offset] = planeRows(decoder, frame, decoder.height);
93 frame.data[i], widths[i], rows, bpt[i], frame.linesize[i]);
94 sub.setDestinationTopLeft({0, offset});
95 res.uploadTexture(samplers[i].texture, QRhiTextureUploadDescription{{0, 0, sub}});
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:137
static QRhiTextureSubresourceUploadDescription createTextureUpload(uint8_t *pixels, int w, int h, int bytesPerPixel, int stride)
Utility method to create a QRhiTextureSubresourceUploadDescription.
Definition GPUVideoDecoder.cpp:22
List of nodes to be rendered to an output.
Definition RenderList.hpp:33
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:259
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:1303
NDI PA16: P216 with a full-resolution 16-bit alpha plane after it.
Definition PA16.hpp:20
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition PA16.hpp:59
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition PA16.hpp:85