diff --git a/libkwineffects/kwingltexture.cpp b/libkwineffects/kwingltexture.cpp index ab38883d88..06c2ed8246 100644 --- a/libkwineffects/kwingltexture.cpp +++ b/libkwineffects/kwingltexture.cpp @@ -47,6 +47,7 @@ bool GLTexturePrivate::s_supportsARGB32 = false; bool GLTexturePrivate::s_supportsUnpack = false; bool GLTexturePrivate::s_supportsTextureStorage = false; bool GLTexturePrivate::s_supportsTextureSwizzle = false; +bool GLTexturePrivate::s_supportsTextureFormatRG = false; uint GLTexturePrivate::s_textureObjectCounter = 0; uint GLTexturePrivate::s_fbo = 0; @@ -290,12 +291,16 @@ void GLTexturePrivate::initStatic() hasGLExtension("GL_ARB_framebuffer_object") || hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_object")); s_supportsTextureStorage = hasGLVersion(4, 2) || hasGLExtension(QByteArrayLiteral("GL_ARB_texture_storage")); s_supportsTextureSwizzle = hasGLVersion(3, 3) || hasGLExtension(QByteArrayLiteral("GL_ARB_texture_swizzle")); + // see https://www.opengl.org/registry/specs/ARB/texture_rg.txt + s_supportsTextureFormatRG = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_texture_rg")); s_supportsARGB32 = true; s_supportsUnpack = true; } else { s_supportsFramebufferObjects = true; s_supportsTextureStorage = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_EXT_texture_storage")); s_supportsTextureSwizzle = hasGLVersion(3, 0); + // see https://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_rg.txt + s_supportsTextureFormatRG = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_EXT_texture_rg")); // QImage::Format_ARGB32_Premultiplied is a packed-pixel format, so it's only // equivalent to GL_BGRA/GL_UNSIGNED_BYTE on little-endian systems. @@ -653,4 +658,9 @@ bool GLTexture::supportsSwizzle() return GLTexturePrivate::s_supportsTextureSwizzle; } +bool GLTexture::supportsFormatRG() +{ + return GLTexturePrivate::s_supportsTextureFormatRG; +} + } // namespace KWin diff --git a/libkwineffects/kwingltexture.h b/libkwineffects/kwingltexture.h index 250a273f71..3cd8f1996b 100644 --- a/libkwineffects/kwingltexture.h +++ b/libkwineffects/kwingltexture.h @@ -127,6 +127,15 @@ public: */ static bool supportsSwizzle(); + /** + * Returns @c true if texture formats R* are supported, and @c false otherwise. + * + * This requires OpenGL 3.0, GL_ARB_texture_rg or OpenGL ES 3.0 or GL_EXT_texture_rg. + * + * @since 5.2.1 + **/ + static bool supportsFormatRG(); + protected: QExplicitlySharedDataPointer d_ptr; GLTexture(GLTexturePrivate& dd); diff --git a/libkwineffects/kwingltexture_p.h b/libkwineffects/kwingltexture_p.h index 656f2944fa..440d2ce942 100644 --- a/libkwineffects/kwingltexture_p.h +++ b/libkwineffects/kwingltexture_p.h @@ -74,6 +74,7 @@ public: static bool s_supportsUnpack; static bool s_supportsTextureStorage; static bool s_supportsTextureSwizzle; + static bool s_supportsTextureFormatRG; static GLuint s_fbo; static uint s_textureObjectCounter; private: diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 7584dd5c54..cb0f469e0a 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -2252,7 +2252,7 @@ bool SceneOpenGLShadow::prepareBackend() p.end(); // Check if the image is alpha-only in practice, and if so convert it to an 8-bpp format - if (!GLPlatform::instance()->isGLES() && GLTexture::supportsSwizzle()) { + if (!GLPlatform::instance()->isGLES() && GLTexture::supportsSwizzle() && GLTexture::supportsFormatRG()) { QImage alphaImage(image.size(), QImage::Format_Indexed8); // Change to Format_Alpha8 w/ Qt 5.5 bool alphaOnly = true;