diff --git a/libkwineffects/kwingltexture.cpp b/libkwineffects/kwingltexture.cpp index 78e21382fd..a84fddcef6 100644 --- a/libkwineffects/kwingltexture.cpp +++ b/libkwineffects/kwingltexture.cpp @@ -46,6 +46,7 @@ bool GLTexturePrivate::s_supportsFramebufferObjects = false; bool GLTexturePrivate::s_supportsARGB32 = false; bool GLTexturePrivate::s_supportsUnpack = false; bool GLTexturePrivate::s_supportsTextureStorage = false; +bool GLTexturePrivate::s_supportsTextureSwizzle = false; uint GLTexturePrivate::s_textureObjectCounter = 0; uint GLTexturePrivate::s_fbo = 0; @@ -234,11 +235,13 @@ void GLTexturePrivate::initStatic() s_supportsFramebufferObjects = hasGLVersion(3, 0) || 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")); 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); // QImage::Format_ARGB32_Premultiplied is a packed-pixel format, so it's only // equivalent to GL_BGRA/GL_UNSIGNED_BYTE on little-endian systems. @@ -551,6 +554,21 @@ void GLTexture::setYInverted(bool inverted) d->updateMatrix(); } +void GLTexture::setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha) +{ + Q_D(GLTexture); + + if (!GLPlatform::instance()->isGLES()) { + const GLuint swizzle[] = { red, green, blue, alpha }; + glTexParameteriv(d->m_target, GL_TEXTURE_SWIZZLE_RGBA, (const GLint *) swizzle); + } else { + glTexParameteri(d->m_target, GL_TEXTURE_SWIZZLE_R, red); + glTexParameteri(d->m_target, GL_TEXTURE_SWIZZLE_G, green); + glTexParameteri(d->m_target, GL_TEXTURE_SWIZZLE_B, blue); + glTexParameteri(d->m_target, GL_TEXTURE_SWIZZLE_A, alpha); + } +} + int GLTexture::width() const { Q_D(const GLTexture); @@ -574,4 +592,9 @@ bool GLTexture::framebufferObjectSupported() return GLTexturePrivate::s_supportsFramebufferObjects; } +bool GLTexture::supportsSwizzle() +{ + return GLTexturePrivate::s_supportsTextureSwizzle; +} + } // namespace KWin diff --git a/libkwineffects/kwingltexture.h b/libkwineffects/kwingltexture.h index 5d2e9e65be..250a273f71 100644 --- a/libkwineffects/kwingltexture.h +++ b/libkwineffects/kwingltexture.h @@ -74,6 +74,17 @@ public: **/ void setYInverted(bool inverted); + /** + * Specifies which component of a texel is placed in each respective + * component of the vector returned to the shader. + * + * Valid values are GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE and GL_ZERO. + * + * @see swizzleSupported() + * @since 5.2 + */ + void setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha); + /** * Returns a matrix that transforms texture coordinates of the given type, * taking the texture target and the y-inversion flag into account. @@ -107,6 +118,15 @@ public: static bool framebufferObjectSupported(); + /** + * Returns true if texture swizzle is supported, and false otherwise + * + * Texture swizzle requires OpenGL 3.3, GL_ARB_texture_swizzle, or OpenGL ES 3.0. + * + * @since 5.2 + */ + static bool supportsSwizzle(); + protected: QExplicitlySharedDataPointer d_ptr; GLTexture(GLTexturePrivate& dd); diff --git a/libkwineffects/kwingltexture_p.h b/libkwineffects/kwingltexture_p.h index 94189268f8..656f2944fa 100644 --- a/libkwineffects/kwingltexture_p.h +++ b/libkwineffects/kwingltexture_p.h @@ -73,6 +73,7 @@ public: static bool s_supportsARGB32; static bool s_supportsUnpack; static bool s_supportsTextureStorage; + static bool s_supportsTextureSwizzle; static GLuint s_fbo; static uint s_textureObjectCounter; private: