From ebb4b2cd47dde5b343c1e53104e8cd5aa426a09c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 4 Apr 2021 17:49:48 +0200 Subject: Add a colorMatrix to the rgb shaders This unifies the uniform layout for all pixel formats, and has the advantage that we can now use the color matrix to do brightness adjustments if required by the sink. Fix the rgb pixel shaders and add a missing one for ABGR. Change-Id: I545b4e0f0c067501903ee5f7af1f0f1f80b2b0bb Reviewed-by: Doris Verria Reviewed-by: Lars Knoll --- src/multimedia/CMakeLists.txt | 7 ++++--- src/multimedia/shaders/abgr.frag | 17 +++++++++++++++++ src/multimedia/shaders/argb.frag | 17 +++++++++++++++++ src/multimedia/shaders/bgra.frag | 3 ++- src/multimedia/shaders/rgb.vert | 19 +++++++++++++++++++ src/multimedia/shaders/rgba.frag | 16 ---------------- src/multimedia/shaders/rgba.vert | 18 ------------------ src/multimedia/video/qvideotexturehelper.cpp | 20 +++++++++----------- 8 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 src/multimedia/shaders/abgr.frag create mode 100644 src/multimedia/shaders/argb.frag create mode 100644 src/multimedia/shaders/rgb.vert delete mode 100644 src/multimedia/shaders/rgba.frag delete mode 100644 src/multimedia/shaders/rgba.vert diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt index ff924771b..6cf4a6e6d 100644 --- a/src/multimedia/CMakeLists.txt +++ b/src/multimedia/CMakeLists.txt @@ -476,13 +476,14 @@ qt_internal_add_shaders(Multimedia "shaders" PREFIX "/qt-project.org/multimedia/shaders" FILES + "shaders/rgb.vert" + "shaders/abgr.frag" + "shaders/argb.frag" "shaders/bgra.frag" + "shaders/yuv.vert" "shaders/nv12.frag" "shaders/nv21.frag" - "shaders/rgba.frag" - "shaders/rgba.vert" "shaders/uyvy.frag" - "shaders/yuv.vert" "shaders/yuv_yv.frag" "shaders/yuyv.frag" "shaders/ayuv.frag" diff --git a/src/multimedia/shaders/abgr.frag b/src/multimedia/shaders/abgr.frag new file mode 100644 index 000000000..207993584 --- /dev/null +++ b/src/multimedia/shaders/abgr.frag @@ -0,0 +1,17 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; + mat4 colorMatrix; + float opacity; +} ubuf; + +layout(binding = 1) uniform sampler2D rgbTexture; + +void main() +{ + fragColor = texture(rgbTexture, qt_TexCoord).bgra * ubuf.colorMatrix * ubuf.opacity; +} diff --git a/src/multimedia/shaders/argb.frag b/src/multimedia/shaders/argb.frag new file mode 100644 index 000000000..1fd7d1bdf --- /dev/null +++ b/src/multimedia/shaders/argb.frag @@ -0,0 +1,17 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; + mat4 colorMatrix; + float opacity; +} ubuf; + +layout(binding = 1) uniform sampler2D rgbTexture; + +void main() +{ + fragColor = texture(rgbTexture, qt_TexCoord) * ubuf.colorMatrix * ubuf.opacity; +} diff --git a/src/multimedia/shaders/bgra.frag b/src/multimedia/shaders/bgra.frag index f04e3e721..c63908c42 100644 --- a/src/multimedia/shaders/bgra.frag +++ b/src/multimedia/shaders/bgra.frag @@ -5,6 +5,7 @@ layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { mat4 matrix; + mat4 colorMatrix; float opacity; } ubuf; @@ -12,5 +13,5 @@ layout(binding = 1) uniform sampler2D rgbTexture; void main() { - fragColor = texture(rgbTexture, qt_TexCoord).bgra * ubuf.opacity; + fragColor = texture(rgbTexture, qt_TexCoord).grab * ubuf.colorMatrix * ubuf.opacity; } diff --git a/src/multimedia/shaders/rgb.vert b/src/multimedia/shaders/rgb.vert new file mode 100644 index 000000000..db88cb0b8 --- /dev/null +++ b/src/multimedia/shaders/rgb.vert @@ -0,0 +1,19 @@ +#version 440 + +layout(location = 0) in vec4 qt_VertexPosition; +layout(location = 1) in vec2 qt_VertexTexCoord; + +layout(location = 0) out vec2 qt_TexCoord; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; + mat4 colorMatrix; + float opacity; +} ubuf; + +out gl_PerVertex { vec4 gl_Position; }; + +void main() { + qt_TexCoord = qt_VertexTexCoord; + gl_Position = ubuf.matrix * qt_VertexPosition; +} diff --git a/src/multimedia/shaders/rgba.frag b/src/multimedia/shaders/rgba.frag deleted file mode 100644 index 1623c2cc7..000000000 --- a/src/multimedia/shaders/rgba.frag +++ /dev/null @@ -1,16 +0,0 @@ -#version 440 - -layout(location = 0) in vec2 qt_TexCoord; -layout(location = 0) out vec4 fragColor; - -layout(std140, binding = 0) uniform buf { - mat4 matrix; - float opacity; -} ubuf; - -layout(binding = 1) uniform sampler2D rgbTexture; - -void main() -{ - fragColor = texture(rgbTexture, qt_TexCoord) * ubuf.opacity; -} diff --git a/src/multimedia/shaders/rgba.vert b/src/multimedia/shaders/rgba.vert deleted file mode 100644 index ebc53a65f..000000000 --- a/src/multimedia/shaders/rgba.vert +++ /dev/null @@ -1,18 +0,0 @@ -#version 440 - -layout(location = 0) in vec4 qt_VertexPosition; -layout(location = 1) in vec2 qt_VertexTexCoord; - -layout(location = 0) out vec2 qt_TexCoord; - -layout(std140, binding = 0) uniform buf { - mat4 matrix; - float opacity; -} ubuf; - -out gl_PerVertex { vec4 gl_Position; }; - -void main() { - qt_TexCoord = qt_VertexTexCoord; - gl_Position = ubuf.matrix * qt_VertexPosition; -} diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp index e57e2f615..b9db64c5f 100644 --- a/src/multimedia/video/qvideotexturehelper.cpp +++ b/src/multimedia/video/qvideotexturehelper.cpp @@ -234,7 +234,7 @@ QString vertexShaderFileName(QVideoSurfaceFormat::PixelFormat format) case QVideoSurfaceFormat::Format_BGRA32_Premultiplied: case QVideoSurfaceFormat::Format_ABGR32: case QVideoSurfaceFormat::Format_BGR32: - return QStringLiteral(":/qt-project.org/multimedia/shaders/rgba.vert.qsb"); + return QStringLiteral(":/qt-project.org/multimedia/shaders/rgb.vert.qsb"); case QVideoSurfaceFormat::Format_YUV420P: case QVideoSurfaceFormat::Format_YUV422P: case QVideoSurfaceFormat::Format_YV12: @@ -273,11 +273,13 @@ QString fragmentShaderFileName(QVideoSurfaceFormat::PixelFormat format) case QVideoSurfaceFormat::Format_ARGB32: case QVideoSurfaceFormat::Format_ARGB32_Premultiplied: case QVideoSurfaceFormat::Format_RGB32: + return QStringLiteral(":/qt-project.org/multimedia/shaders/argb.frag.qsb"); case QVideoSurfaceFormat::Format_BGRA32: case QVideoSurfaceFormat::Format_BGRA32_Premultiplied: + return QStringLiteral(":/qt-project.org/multimedia/shaders/bgra.frag.qsb"); case QVideoSurfaceFormat::Format_ABGR32: case QVideoSurfaceFormat::Format_BGR32: - return QStringLiteral(":/qt-project.org/multimedia/shaders/rgba.frag.qsb"); + return QStringLiteral(":/qt-project.org/multimedia/shaders/abgr.frag.qsb"); case QVideoSurfaceFormat::Format_YUV420P: case QVideoSurfaceFormat::Format_YUV422P: case QVideoSurfaceFormat::Format_YV12: @@ -324,6 +326,7 @@ static QMatrix4x4 colorMatrix(QVideoSurfaceFormat::YCbCrColorSpace colorSpace) QByteArray uniformData(const QVideoSurfaceFormat &format, const QMatrix4x4 &transform, float opacity) { + QMatrix4x4 cmat; switch (format.pixelFormat()) { case QVideoSurfaceFormat::Format_Invalid: case QVideoSurfaceFormat::Format_Jpeg: @@ -347,14 +350,8 @@ QByteArray uniformData(const QVideoSurfaceFormat &format, const QMatrix4x4 &tran case QVideoSurfaceFormat::Format_BGRA32: case QVideoSurfaceFormat::Format_BGRA32_Premultiplied: case QVideoSurfaceFormat::Format_ABGR32: - case QVideoSurfaceFormat::Format_BGR32: { - // { matrix4x4, opacity } - QByteArray buf(16*4 + 4, Qt::Uninitialized); - char *data = buf.data(); - memcpy(data, transform.constData(), 64); - memcpy(data + 64, &opacity, 4); - return buf; - } + case QVideoSurfaceFormat::Format_BGR32: + break; case QVideoSurfaceFormat::Format_AYUV444: case QVideoSurfaceFormat::Format_AYUV444_Premultiplied: case QVideoSurfaceFormat::Format_YUV420P: @@ -366,13 +363,14 @@ QByteArray uniformData(const QVideoSurfaceFormat &format, const QMatrix4x4 &tran case QVideoSurfaceFormat::Format_NV21: case QVideoSurfaceFormat::Format_P010: case QVideoSurfaceFormat::Format_P016: + cmat = colorMatrix(format.yCbCrColorSpace()); break; } // { matrix4x4, colorMatrix, opacity, planeWidth[3] } QByteArray buf(64*2 + 4, Qt::Uninitialized); char *data = buf.data(); memcpy(data, transform.constData(), 64); - memcpy(data + 64, colorMatrix(format.yCbCrColorSpace()).constData(), 64); + memcpy(data + 64, cmat.constData(), 64); memcpy(data + 64 + 64, &opacity, 4); return buf; } -- cgit v1.2.3