2#include <Gfx/Graph/decoders/ColorSpace.hpp>
3#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
22 static const constexpr auto frag = R
"_(#version 450
24)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
26layout(binding=3) uniform sampler2D y_tex;
27layout(binding=4) uniform sampler2D uv_tex;
28layout(binding=5) uniform sampler2D a_tex;
30layout(location = 0) in vec2 v_texcoord;
31layout(location = 0) out vec4 fragColor;
35vec4 processTexture(vec4 tex) {
36 vec4 processed = convert_to_rgb(tex);
42 vec2 tc = score_tc(v_texcoord);
43 // The colour planes are P216's, MSB-aligned 8-bit codes; the alpha plane is
44 // full range for its data type, so it is already 0..1.
45 const float s = )_" SCORE_GFX_MSB_ALIGNED_SCALE R"_(;
46 float y = s * texture(y_tex, tc).r;
47 float u = s * texture(uv_tex, tc).r;
48 float v = s * texture(uv_tex, tc).g;
49 float a = texture(a_tex, tc).r;
51 vec4 rgb = processTexture(vec4(y, u, v, 1.));
52 fragColor = vec4(rgb.rgb, a);
65 auto& rhi = *r.
state.rhi;
66 const auto w = decoder.width, h = decoder.height;
68 auto mkSampler = [&] {
69 auto sampler = rhi.newSampler(
70 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
71 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
75 auto plane = [&](QRhiTexture::Format fmt, QSize sz) {
76 auto tex = rhi.newTexture(fmt, sz, 1, QRhiTexture::Flag{});
78 samplers.push_back({mkSampler(), tex});
81 plane(QRhiTexture::R16, {w, h});
82 plane(QRhiTexture::RG16, {w / 2, h});
83 plane(QRhiTexture::R16, {w, h});
86 r.
state, vertexShader(), QString(frag).arg(
"").arg(colorMatrix(decoder)));
89 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
91 const int widths[3] = {decoder.width, decoder.width / 2, decoder.width};
92 const int bpt[3] = {2, 4, 2};
93 for(
int i = 0; i < 3; i++)
95 const auto [rows, offset] = planeRows(decoder, frame, decoder.height);
97 frame.data[i], widths[i], rows, bpt[i], frame.linesize[i]);
98 sub.setDestinationTopLeft({0, offset});
99 res.uploadTexture(samplers[i].texture, QRhiTextureUploadDescription{{0, 0, sub}});
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:161
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:36
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:299
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:1707
NDI PA16: P216 with a full-resolution 16-bit alpha plane after it.
Definition PA16.hpp:21
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition PA16.hpp:63
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition PA16.hpp:89