20 static const constexpr auto frag = R
"_(#version 450
22)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
24layout(binding=3) uniform sampler2D y_tex;
25layout(binding=4) uniform sampler2D u_tex;
26layout(binding=5) uniform sampler2D v_tex;
28layout(location = 0) in vec2 v_texcoord;
29layout(location = 0) out vec4 fragColor;
33vec4 processTexture(vec4 tex) {
34 vec4 processed = convert_to_rgb(tex);
41 float y = texture(y_tex, v_texcoord).r;
42 float u = texture(%3_tex, v_texcoord).r;
43 float v = texture(%4_tex, v_texcoord).r;
45 fragColor = processTexture(vec4(y,u,v, 1.));
61 auto& rhi = *r.
state.rhi;
62 const auto w = decoder.width, h = decoder.height;
63 const auto fmt = QRhiTexture::R8;
67 auto tex = rhi.newTexture(fmt, {w, h}, 1, QRhiTexture::Flag{});
70 auto sampler = rhi.newSampler(
71 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
72 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
74 samplers.push_back({sampler, tex});
79 auto tex = rhi.newTexture(fmt, {w / 2, h / 2}, 1, QRhiTexture::Flag{});
82 auto sampler = rhi.newSampler(
83 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
84 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
86 samplers.push_back({sampler, tex});
91 auto tex = rhi.newTexture(fmt, {w / 2, h / 2}, 1, QRhiTexture::Flag{});
94 auto sampler = rhi.newSampler(
95 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
96 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
98 samplers.push_back({sampler, tex});
102 r.
state, vertexShader(),
105 .arg(colorMatrix(decoder))
106 .arg(yv12 ?
"v" :
"u")
107 .arg(yv12 ?
"u" :
"v"));
112 setYPixels(res, frame.data[0], frame.linesize[0]);
113 setUPixels(res, frame.data[1], frame.linesize[1]);
114 setVPixels(res, frame.data[2], frame.linesize[2]);
118 setYPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
120 const auto w = decoder.width, h = decoder.height;
121 auto y_tex = samplers[0].texture;
124 QRhiTextureUploadDescription desc{entry};
126 res.uploadTexture(y_tex, desc);
130 setUPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
132 const auto w = decoder.width / 2, h = decoder.height / 2;
133 auto u_tex = samplers[1].texture;
136 QRhiTextureUploadDescription desc{entry};
138 res.uploadTexture(u_tex, desc);
142 setVPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
144 const auto w = decoder.width / 2, h = decoder.height / 2;
145 auto v_tex = samplers[2].texture;
148 QRhiTextureUploadDescription desc{entry};
149 res.uploadTexture(v_tex, desc);
static QRhiTextureSubresourceUploadDescription createTextureUpload(uint8_t *pixels, int w, int h, int bytesPerPixel, int stride)
Utility method to create a QRhiTextureSubresourceUploadDescription.
Definition GPUVideoDecoder.cpp:22
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
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition YUV420.hpp:110