2 #include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
4 #include <libavformat/avformat.h>
11 static const constexpr
auto rgb_filter = R
"_(#version 450
13 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
15 layout(binding=3) uniform sampler2D y_tex;
17 layout(location = 0) in vec2 v_texcoord;
18 layout(location = 0) out vec4 fragColor;
20 vec4 processTexture(vec4 tex) {
28 fragColor = processTexture(texture(y_tex, v_texcoord));
35 , bytes_per_pixel{bytes_per_pixel}
37 , filter{std::move(f)}
40 QRhiTexture::Format format;
41 int bytes_per_pixel{};
47 auto& rhi = *r.
state.rhi;
48 const auto w = decoder.width, h = decoder.height;
52 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
56 auto sampler = rhi.newSampler(
57 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
58 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
62 samplers.push_back({sampler, tex});
66 r.
state, vertexShader(), QString(rgb_filter).arg(filter));
69 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
72 setPixels(res, frame.data[0], frame.linesize[0]);
76 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
78 const auto w = decoder.width, h = decoder.height;
79 auto y_tex = samplers[0].texture;
81 QRhiTextureUploadEntry entry{
84 QRhiTextureUploadDescription desc{entry};
85 res.uploadTexture(y_tex, desc);
91 static const constexpr
auto rgb_filter = R
"_(#version 450
93 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
96 layout(location = 0) in vec2 v_texcoord;
97 layout(location = 0) out vec4 fragColor;
99 vec4 processTexture(vec4 tex) {
100 vec4 processed = tex;
109 fragColor = processTexture(tex);
113 QRhiTexture::Format fmt, int bytes_per_pixel, QString planes,
116 , bytes_per_pixel{bytes_per_pixel}
119 , filter{std::move(f)}
122 QRhiTexture::Format format;
123 int bytes_per_pixel{};
130 auto& rhi = *r.
state.rhi;
131 const auto w = decoder.width, h = decoder.height;
133 QString samplers_code;
134 QString read_texture_code;
136 const int binding_orig = 3;
137 for(
int i = 0; i < planes.size(); i++)
139 samplers_code += QString(
" layout(binding=%1) uniform sampler2D t%2;\n")
140 .arg(binding_orig + i)
142 read_texture_code += QString(
" tex.%1 = texture(t%2, v_texcoord).r;\n")
147 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
151 auto sampler = rhi.newSampler(
152 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
153 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
157 samplers.push_back({sampler, tex});
161 r.
state, vertexShader(),
162 QString(rgb_filter).arg(samplers_code).arg(filter).arg(read_texture_code));
168 for(
int i = 0; i < planes.size(); i++)
170 setPixels(res, samplers[i].texture, frame.data[i], frame.linesize[i]);
175 QRhiResourceUpdateBatch& res, QRhiTexture* tex, uint8_t* pixels,
176 int stride)
const noexcept
178 const auto w = decoder.width, h = decoder.height;
180 QRhiTextureUploadEntry entry{
183 QRhiTextureUploadDescription desc{entry};
184 res.uploadTexture(tex, desc);
190 static const constexpr
auto rgb_filter = R
"_(#version 450
192 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
194 layout(binding=3) uniform sampler2DRect y_tex;
196 layout(location = 0) in vec2 v_texcoord;
197 layout(location = 0) out vec4 fragColor;
199 vec4 processTexture(vec4 tex) {
200 vec4 processed = tex;
207 fragColor = processTexture(texture(y_tex, v_texcoord));
210 static constexpr
const char* vertex = R
"_(#version 450
211 layout(location = 0) in vec2 position;
212 layout(location = 1) in vec2 texcoord;
214 layout(location = 0) out vec2 v_texcoord;
216 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
218 out gl_PerVertex { vec4 gl_Position; };
222 v_texcoord = texcoord * mat.texSz.xy;
223 gl_Position = renderer.clipSpaceCorrMatrix * vec4(position.x * mat.scale.x, position.y * mat.scale.y, 0.0, 1.);
231 , bytes_per_pixel{bytes_per_pixel}
233 , filter{std::move(f)}
236 QRhiTexture::Format format;
237 int bytes_per_pixel{};
243 auto& rhi = *r.
state.rhi;
244 const auto w = decoder.width, h = decoder.height;
248 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
252 auto sampler = rhi.newSampler(
253 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
254 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
258 samplers.push_back({sampler, tex});
267 setPixels(res, frame.data[0], frame.linesize[0]);
271 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
273 const auto w = decoder.width, h = decoder.height;
274 auto y_tex = samplers[0].texture;
276 QRhiTextureUploadEntry entry{
279 QRhiTextureUploadDescription desc{entry};
280 res.uploadTexture(y_tex, desc);
Processes and renders a video frame on the GPU.
Definition: GPUVideoDecoder.hpp:43
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:19
RenderState & state
RenderState corresponding to this RenderList.
Definition: RenderList.hpp:89
Graphics rendering pipeline for ossia score.
Definition: PreviewWidget.hpp:12
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition: score-plugin-gfx/Gfx/Graph/Utils.cpp:334
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition: RGBA.hpp:69
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: RGBA.hpp:45
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition: RGBA.hpp:264
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: RGBA.hpp:241
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition: RGBA.hpp:165
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: RGBA.hpp:128