From c262a698511519a57866b2c5fce386b0ec1e6905 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 11 Jan 2021 15:11:16 +0100 Subject: rhi: gl: Add some enablers for supporting GL_TEXTURE_EXTERNAL_OES From QRhi's perspective this consists of two things: - A shader with samplerExternalOES in it cannot go through the standard pipeline. Rather, a QShader with suitable GLSL code in it has to be constructed manually. As this is something useful as an autotest anyway, add a test case to the qshader autotest that demonstrates this. - When it comes to correctly calling glBindTexture, add a QRhiTexture flag. The expectation is that an OpenGL-only client sets this in combination with QRhiTexture::createFrom(), thus wrapping an existing texture that then gets bound to the GL_TEXTURE_EXTERNAL_OES target instead of our usual GL_TEXTURE_2D. For completeness we also add a SamplerExternalOES variable type to QShaderDescription, but the sampler type is not actually used by the QRhi OpenGL backend, as it is the QRhiTexture that defines the texture target. Change-Id: I36b52325deb3703b59186ee3d726d0c3015bfc4b Reviewed-by: Andy Nichols --- src/gui/rhi/qrhi.cpp | 3 +++ src/gui/rhi/qrhi_p.h | 3 ++- src/gui/rhi/qrhigles2.cpp | 7 +++++++ src/gui/rhi/qshaderdescription.cpp | 2 ++ src/gui/rhi/qshaderdescription_p.h | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 718835ad8f..838385aeed 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2311,6 +2311,9 @@ QRhiResource::Type QRhiRenderBuffer::resourceType() const \value UsedAsCompressedAtlas The texture has a compressed format and the dimensions of subresource uploads may not match the texture size. + + \value ExternalOES The texture should use the GL_TEXTURE_EXTERNAL_OES + target with OpenGL. This flag is ignored with other graphics APIs. */ /*! diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index fc65587408..647f469dcf 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -745,7 +745,8 @@ public: UsedAsTransferSource = 1 << 5, UsedWithGenerateMips = 1 << 6, UsedWithLoadStore = 1 << 7, - UsedAsCompressedAtlas = 1 << 8 + UsedAsCompressedAtlas = 1 << 8, + ExternalOES = 1 << 9 }; Q_DECLARE_FLAGS(Flags, Flag) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 014d603724..3c71086de0 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -305,6 +305,10 @@ QT_BEGIN_NAMESPACE #define GL_TEXTURE_2D_MULTISAMPLE 0x9100 #endif +#ifndef GL_TEXTURE_EXTERNAL_OES +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#endif + #ifndef GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS #define GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS 0x90EB #endif @@ -4134,6 +4138,9 @@ bool QGles2Texture::prepareCreate(QSize *adjustedSize) target = isCube ? GL_TEXTURE_CUBE_MAP : m_sampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; + if (m_flags.testFlag(ExternalOES)) + target = GL_TEXTURE_EXTERNAL_OES; + mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1; gltype = GL_UNSIGNED_BYTE; diff --git a/src/gui/rhi/qshaderdescription.cpp b/src/gui/rhi/qshaderdescription.cpp index b20ed8b178..08972587ed 100644 --- a/src/gui/rhi/qshaderdescription.cpp +++ b/src/gui/rhi/qshaderdescription.cpp @@ -218,6 +218,7 @@ QT_BEGIN_NAMESPACE \value SamplerCubeArray \value SamplerRect \value SamplerBuffer + \value SamplerExternalOES \value Image1D \value Image2D \value Image2DMS @@ -574,6 +575,7 @@ static struct TypeTab { { QLatin1String("samplerCubeArray"), QShaderDescription::SamplerCubeArray }, { QLatin1String("samplerRect"), QShaderDescription::SamplerRect }, { QLatin1String("samplerBuffer"), QShaderDescription::SamplerBuffer }, + { QLatin1String("samplerExternalOES"), QShaderDescription::SamplerExternalOES }, { QLatin1String("mat2x3"), QShaderDescription::Mat2x3 }, { QLatin1String("mat2x4"), QShaderDescription::Mat2x4 }, diff --git a/src/gui/rhi/qshaderdescription_p.h b/src/gui/rhi/qshaderdescription_p.h index 238efc2455..6879c531d3 100644 --- a/src/gui/rhi/qshaderdescription_p.h +++ b/src/gui/rhi/qshaderdescription_p.h @@ -133,6 +133,7 @@ public: SamplerCubeArray, SamplerRect, SamplerBuffer, + SamplerExternalOES, Image1D, Image2D, -- cgit v1.2.3