From d55a6891d18ee576a6f3e2c510eefee4a1639d7f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 16 Sep 2021 13:07:20 +0200 Subject: [PATCH] rhi: gl: Have a way to state GL_TEXTURE_RECTANGLE is wanted Added specifically to support the deprecated CVOpenGLTextureCache on macOS, because Qt Multimedia still needs a way to use that when the applications requests using OpenGL instead of Metal. Follow what we did for GL_TEXTURE_EXTERNAL_OES, and add a flag that simply makes all our glBindTexture calls use the GL_TEXTURE_RECTANGLE[_ARB] target. Pick-to: 6.2 Change-Id: If818b13a9f520cdb8bdc16de84a3ca0e18ad6c33 Reviewed-by: Lars Knoll --- src/gui/rhi/qrhi.cpp | 7 +++++++ src/gui/rhi/qrhi_p.h | 3 ++- src/gui/rhi/qrhigles2.cpp | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index f4855cd046..7c1e3811b1 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2444,6 +2444,13 @@ bool QRhiRenderBuffer::createFrom(NativeRenderBuffer src) render target's color attachment refers to a slice in range [0..depth-1]. The underlying graphics API may not support 3D textures at run time. Support is indicated by the QRhi::ThreeDimensionalTextures feature. + + \value TextureRectangleGL The texture should use the GL_TEXTURE_RECTANGLE + target with OpenGL. This flag is ignored with other graphics APIs. Just + like ExternalOES, this flag is useful when working with platform APIs where + native OpenGL texture objects received from the platform are wrapped in a + QRhiTexture, and the platform can only provide textures for a non-2D + texture target. */ /*! diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 527d72e486..d31838f52f 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -778,7 +778,8 @@ public: UsedWithLoadStore = 1 << 7, UsedAsCompressedAtlas = 1 << 8, ExternalOES = 1 << 9, - ThreeDimensional = 1 << 10 + ThreeDimensional = 1 << 10, + TextureRectangleGL = 1 << 11 }; Q_DECLARE_FLAGS(Flags, Flag) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 3e2e2ea2c8..31b4d8cd51 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -361,6 +361,10 @@ QT_BEGIN_NAMESPACE #define GL_TEXTURE_WRAP_R 0x8072 #endif +#ifndef GL_TEXTURE_RECTANGLE +#define GL_TEXTURE_RECTANGLE 0x84F5 +#endif + /*! Constructs a new QRhiGles2InitParams. @@ -4579,6 +4583,8 @@ bool QGles2Texture::prepareCreate(QSize *adjustedSize) : m_sampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : (is3D ? GL_TEXTURE_3D : GL_TEXTURE_2D); if (m_flags.testFlag(ExternalOES)) target = GL_TEXTURE_EXTERNAL_OES; + else if (m_flags.testFlag(TextureRectangleGL)) + target = GL_TEXTURE_RECTANGLE; mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1; gltype = GL_UNSIGNED_BYTE;