2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
4#include <libavformat/avformat.h>
21 static const constexpr auto frag = R
"_(#version 450
23)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
25layout(binding=3) uniform sampler2D u_tex;
27layout(location = 0) in vec2 v_texcoord;
28layout(location = 0) out vec4 fragColor;
30vec4 processTexture(vec4 tex) {
37 int x = int(floor(v_texcoord.x * mat.texSz.x));
38 int y = int(floor(v_texcoord.y * mat.texSz.y));
39 vec4 t = texelFetch(u_tex, ivec2(x, y), 0);
40 uint b0 = uint(t.r * 255.0 + 0.5);
41 uint b1 = uint(t.g * 255.0 + 0.5);
42 uint b2 = uint(t.b * 255.0 + 0.5);
43 uint b3 = uint(t.a * 255.0 + 0.5);
44 uint w = (b0 << 24u) | (b1 << 16u) | (b2 << 8u) | b3; // big-endian word
45 float r = float((w >> 20u) & 0x3FFu);
46 float g = float((w >> 10u) & 0x3FFu);
47 float b = float( w & 0x3FFu);
48 fragColor = processTexture(vec4(r, g, b, 1023.0) / 1023.0);
59 static constexpr int rowBytesFor(
int w)
noexcept
61 return ((w + 63) / 64) * 256;
66 auto& rhi = *r.
state.rhi;
67 const auto w = decoder.width, h = decoder.height;
70 const int texW = rowBytesFor(w) / 4;
73 = rhi.newTexture(QRhiTexture::RGBA8, {texW, h}, 1, QRhiTexture::Flag{});
76 auto sampler = rhi.newSampler(
77 QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
78 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
81 samplers.push_back({sampler, tex});
85 r.
state, vertexShader(), QString(frag).arg(
""));
88 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
90 const int texW = rowBytesFor(decoder.width) / 4;
91 auto tex = samplers[0].texture;
92 QRhiTextureUploadEntry entry{
95 frame.data[0], texW, decoder.height, 4, frame.linesize[0])};
96 QRhiTextureUploadDescription desc{entry};
97 res.uploadTexture(tex, desc);
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:90
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:30
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:169
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
Decodes 10-bit RGB packed in r210 (DeckLink bmdFormat10BitRGB).
Definition R210.hpp:19
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition R210.hpp:64
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition R210.hpp:88