Loading...
Searching...
No Matches
GPUVideoEncoder.hpp
1#pragma once
2#include <Gfx/Graph/RenderList.hpp>
3#include <Gfx/Graph/RenderState.hpp>
4#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
6
7namespace score::gfx
8{
9
30{
31 virtual ~GPUVideoEncoder() = default;
32
41 virtual void init(
42 QRhi& rhi, const RenderState& state, QRhiTexture* inputRGBA, int width, int height,
43 const QString& colorConversion = colorMatrixOut())
44 = 0;
45
48 virtual void exec(QRhi& rhi, QRhiCommandBuffer& cb) = 0;
49
51 virtual int planeCount() const = 0;
52
54 virtual const QRhiReadbackResult& readback(int plane) const = 0;
55
57 virtual void release() = 0;
58
63 static constexpr const char* vertex_shader = R"_(#version 450
64 layout(location = 0) out vec2 v_texcoord;
65 out gl_PerVertex { vec4 gl_Position; };
66 void main() {
67 vec2 pos = vec2(
68 float((gl_VertexIndex & 1) * 4 - 1),
69 float((gl_VertexIndex & 2) * 2 - 1)
70 );
71 v_texcoord = pos * 0.5 + 0.5;
72 gl_Position = vec4(pos, 0.0, 1.0);
73 }
74 )_";
75
80 static constexpr const char* rgb_to_yuv_glsl = R"_(
81 const vec3 yuv_offset = vec3(0.0, 0.5, 0.5);
82 vec3 rgb_to_yuv(vec3 rgb) {
83 return vec3(
84 dot(rgb, vec3( 0.2126, 0.7152, 0.0722)),
85 dot(rgb, vec3(-0.1146, -0.3854, 0.5 )),
86 dot(rgb, vec3( 0.5, -0.4542, -0.0458))
87 ) + yuv_offset;
88 }
89 )_";
90
92 static constexpr const char* y_flip_glsl = R"_(
93 vec2 flip_y(vec2 tc) {
94 #if defined(QSHADER_MSL) || defined(QSHADER_HLSL)
95 return tc;
96 #else
97 return vec2(tc.x, 1.0 - tc.y);
98 #endif
99 }
100 )_";
101};
102
103} // namespace score::gfx
GPU shader generation for RGB->YUV color space conversion (output/encoding).
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
Base class for GPU-side video format conversion (RGBA to YUV).
Definition GPUVideoEncoder.hpp:30
static constexpr const char * y_flip_glsl
Fragment shader Y-flip: on GL, flip v_texcoord.y. On Metal/HLSL, no flip.
Definition GPUVideoEncoder.hpp:92
static constexpr const char * vertex_shader
Definition GPUVideoEncoder.hpp:63
static constexpr const char * rgb_to_yuv_glsl
Definition GPUVideoEncoder.hpp:80
virtual const QRhiReadbackResult & readback(int plane) const =0
Get the readback result for a given plane. Valid after endOffscreenFrame.
virtual void exec(QRhi &rhi, QRhiCommandBuffer &cb)=0
virtual int planeCount() const =0
Number of readback planes (1 for UYVY, 2 for NV12, 3 for I420).
virtual void init(QRhi &rhi, const RenderState &state, QRhiTexture *inputRGBA, int width, int height, const QString &colorConversion=colorMatrixOut())=0
virtual void release()=0
Release all GPU resources.
Global state associated to a rendering context.
Definition RenderState.hpp:37