diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2024-02-02 15:45:21 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2024-02-05 16:48:30 +0100 |
commit | 501fc71df69bf8b58eed9cf8af998edb3212c069 (patch) | |
tree | 9853210b2065ccfdf6eaaefef93fe57b14bd5213 | |
parent | fff13f885370c02e7b8696ecedbfafa436e48ace (diff) |
sg: Allow adopting foreign textures with GL_SRGB8_ALPHA8
Do what the other (Vulkan, D3D) paths do: set the appropriate
QRhiTexture flag while mapping to RGBA8. This has no visible effect,
but it avoids flooding the debug output with warnings in Quick 3D XR
applications on Android (Quest 3) when using OpenGL ES.
(because it hits the 'default' case that prints a warning and
continues with UnknownFormat; not having the correct enum value
in QRhiTexture has no effect in typical Qt Quick / 3D apps, but
nonetheless we should not hit that path)
The usage of sRGB formats is an interesting case with VR compositors:
with Vulkan and D3D12 we explicitly drop the _SRGB format in
Quick 3D XR (e.g. we change VK_FORMAT_R8G8B8A8_SRGB to
VK_FORMAT_R8G8B8A8_UNORM) before passing the native image
object to Qt Quick, but there this is necessary since having a
_SRGB format changes the behavior in shader writes (because the
image/render target views inherit the QRhiTexture format
in the QRhi backends), whereas Qt Quick 3D performs
linearization and sRGB conversion at the end of the pipeline,
so this would clash (like doing an additional unwanted
linear-sRGB conversion on the already sRGB data)
OpenGL is different, however, when it comes to the API: there is
no implicit behavior unless the appropriate state is enabled
(which we do not do), hence the OpenGL (ES) path in Quick 3D XR
does not need to perform the format demotion, but then it is
ideal if Qt Quick accepts those formats (which was missing
until now for some reason unknown). Regardless, the demotion
may still be implemented in Quick 3D XR separately later.
In practice this should remove the
"GL format 35907 is not supported"
messages appearing in the Android logs on every frame or so
with Quick 3D XR apps.
Change-Id: I3e9135f790be0eda51d3b1d68f6d115eb1a21000
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/quick/items/qquickrendertarget.cpp | 10 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgrhisupport.cpp | 20 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgrhisupport_p.h | 2 |
3 files changed, 24 insertions, 8 deletions
diff --git a/src/quick/items/qquickrendertarget.cpp b/src/quick/items/qquickrendertarget.cpp index 9c4f02b5ae..391b525114 100644 --- a/src/quick/items/qquickrendertarget.cpp +++ b/src/quick/items/qquickrendertarget.cpp @@ -212,8 +212,9 @@ QQuickRenderTarget QQuickRenderTarget::fromOpenGLTexture(uint textureId, uint fo d->pixelSize = pixelSize; d->sampleCount = qMax(1, sampleCount); - auto rhiFormat = QSGRhiSupport::toRhiTextureFormatFromGL(format); - d->u.nativeTexture = { textureId, 0, uint(rhiFormat), 0 }; + QRhiTexture::Flags rhiFlags; + auto rhiFormat = QSGRhiSupport::toRhiTextureFormatFromGL(format, &rhiFlags); + d->u.nativeTexture = { textureId, 0, uint(rhiFormat), uint(rhiFlags) }; return rt; } @@ -277,8 +278,9 @@ QQuickRenderTarget QQuickRenderTarget::fromOpenGLTextureMultiView(uint textureId d->pixelSize = pixelSize; d->sampleCount = qMax(1, sampleCount); - auto rhiFormat = QSGRhiSupport::toRhiTextureFormatFromGL(format); - d->u.nativeTextureArray = { textureId, 0, arraySize, uint(rhiFormat), 0 }; + QRhiTexture::Flags rhiFlags; + auto rhiFormat = QSGRhiSupport::toRhiTextureFormatFromGL(format, &rhiFlags); + d->u.nativeTextureArray = { textureId, 0, arraySize, uint(rhiFormat), uint(rhiFlags) }; return rt; } diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp index 8edbc28c4d..19e3d11223 100644 --- a/src/quick/scenegraph/qsgrhisupport.cpp +++ b/src/quick/scenegraph/qsgrhisupport.cpp @@ -215,12 +215,24 @@ void QSGRhiSupport::checkEnvQSgInfo() #define GL_RGB10_A2 0x8059 #endif -QRhiTexture::Format QSGRhiSupport::toRhiTextureFormatFromGL(uint format) +#ifndef GL_SRGB_ALPHA +#define GL_SRGB_ALPHA 0x8C42 +#endif + +#ifndef GL_SRGB8_ALPHA8 +#define GL_SRGB8_ALPHA8 0x8C43 +#endif + +QRhiTexture::Format QSGRhiSupport::toRhiTextureFormatFromGL(uint format, QRhiTexture::Flags *flags) { + bool sRGB = false; auto rhiFormat = QRhiTexture::UnknownFormat; switch (format) { - case GL_RGBA: + case GL_SRGB_ALPHA: + case GL_SRGB8_ALPHA8: + sRGB = true; Q_FALLTHROUGH(); + case GL_RGBA: case GL_RGBA8: case 0: rhiFormat = QRhiTexture::RGBA8; @@ -282,6 +294,8 @@ QRhiTexture::Format QSGRhiSupport::toRhiTextureFormatFromGL(uint format) qWarning("GL format %d is not supported", format); break; } + if (sRGB) + (*flags) |=(QRhiTexture::sRGB); return rhiFormat; } #endif @@ -1574,7 +1588,7 @@ QRhiTexture::Format QSGRhiSupport::toRhiTextureFormat(uint nativeFormat, QRhiTex #if QT_CONFIG(opengl) case QRhi::OpenGLES2: Q_UNUSED(flags); - return toRhiTextureFormatFromGL(nativeFormat); + return toRhiTextureFormatFromGL(nativeFormat, flags); #endif #ifdef Q_OS_WIN case QRhi::D3D11: diff --git a/src/quick/scenegraph/qsgrhisupport_p.h b/src/quick/scenegraph/qsgrhisupport_p.h index 41dae24ef5..1ca15f9076 100644 --- a/src/quick/scenegraph/qsgrhisupport_p.h +++ b/src/quick/scenegraph/qsgrhisupport_p.h @@ -45,7 +45,7 @@ public: static void checkEnvQSgInfo(); #if QT_CONFIG(opengl) - static QRhiTexture::Format toRhiTextureFormatFromGL(uint format); + static QRhiTexture::Format toRhiTextureFormatFromGL(uint format, QRhiTexture::Flags *flags); #endif #if QT_CONFIG(vulkan) |