diff --git a/libkwineffects/kwinglcolorcorrection.cpp b/libkwineffects/kwinglcolorcorrection.cpp index 6e4f778ffe..a389cc67ff 100644 --- a/libkwineffects/kwinglcolorcorrection.cpp +++ b/libkwineffects/kwinglcolorcorrection.cpp @@ -34,27 +34,6 @@ along with this program. If not, see . #include #include -#ifdef KWIN_HAVE_OPENGLES -#define CC_TEXTURE_INTERNAL_FORMAT GL_RGB - -/* - * A bit of ugliness to allow building with OpenGL ES < 3, without - * ifdef's everywhere in the code. These should not actually be used anywhere. - */ -#ifndef GL_TEXTURE_3D -#define GL_TEXTURE_3D 0x806F // From OES_texture_3D extension -#define GL_TEXTURE_WRAP_R 0x8072 // From OES_texture_3D extension -void glTexImage3D(GLenum, int, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *) -{ - Q_ASSERT(false); // Execution must not reach here -} -#endif // defined(GL_TEXTURE_3D) - -#else // KWIN_HAVE_OPENGLES -#define CC_TEXTURE_INTERNAL_FORMAT GL_RGB16 -#endif // KWIN_HAVE_OPENGLES - - namespace KWin { /* @@ -305,11 +284,14 @@ bool ColorCorrection::setEnabled(bool enabled) return false; } +#ifdef KWIN_HAVE_OPENGLES const GLPlatform *gl = GLPlatform::instance(); - if (enabled && gl->isGLES() && (gl->glVersion() >> 32) < 3) { - kError(1212) << "color correction is not supported with OpenGL ES < 3.0"; + if (enabled && gl->isGLES() && glTexImage3D == 0) { + kError(1212) << "color correction is not supported on OpenGL ES without OES_texture_3D"; + d->m_hasError = true; return false; } +#endif // KWIN_HAVE_OPENGLES if (enabled) { // Update all profiles and regions @@ -642,9 +624,22 @@ bool ColorCorrectionPrivate::setupCCTexture(GLuint texture, const Clut& clut) glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage3D(GL_TEXTURE_3D, 0, CC_TEXTURE_INTERNAL_FORMAT, +#ifndef KWIN_HAVE_OPENGLES + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16, LUT_GRID_POINTS, LUT_GRID_POINTS, LUT_GRID_POINTS, 0, GL_RGB, GL_UNSIGNED_SHORT, clut.data()); +#else + const int textureDataSize = clut.size(); + QVector textureData(textureDataSize); + quint8 *pTextureData = textureData.data(); + const quint16 *pClutData = clut.data(); + for (int i = 0; i < textureDataSize; ++i) + *(pTextureData++) = *(pClutData++) >> 8; + + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, + LUT_GRID_POINTS, LUT_GRID_POINTS, LUT_GRID_POINTS, + 0, GL_RGB, GL_UNSIGNED_BYTE, textureData.data()); +#endif // KWIN_HAVE_OPENGLES return !checkGLError("setupCCTexture"); } @@ -667,7 +662,16 @@ void ColorCorrectionPrivate::colorServerUpdateSucceededSlot() // Reload all shaders ShaderManager::cleanup(); - ShaderManager::instance(); + if (!ShaderManager::instance()->isValid()) { + kError(1212) << "Shader reinitialization failed, possible compile problems with the shaders " + "altered for color-correction"; + m_hasError = true; + kDebug(1212) << "Color correction has been disabled due to shader issues"; + m_enabled = false; + GLShader::sColorCorrect = false; + ShaderManager::cleanup(); + ShaderManager::instance(); + } } emit q->changed(); diff --git a/libkwineffects/kwinglutils_funcs.cpp b/libkwineffects/kwinglutils_funcs.cpp index da9ec2ea8d..cb5391e34c 100644 --- a/libkwineffects/kwinglutils_funcs.cpp +++ b/libkwineffects/kwinglutils_funcs.cpp @@ -268,6 +268,9 @@ glMapBuffer_func glMapBuffer; glUnmapBuffer_func glUnmapBuffer; glGetBufferPointerv_func glGetBufferPointerv; +// GL_OES_texture_3D +glTexImage3DOES_func glTexImage3D; + // GL_EXT_map_buffer_range glMapBufferRange_func glMapBufferRange; glFlushMappedBufferRange_func glFlushMappedBufferRange; @@ -731,6 +734,12 @@ void glResolveFunctions(OpenGLPlatformInterface platformInterface) glGetBufferPointerv = NULL; } + if (hasGLExtension("GL_OES_texture_3D")) { + glTexImage3D = (glTexImage3DOES_func)eglGetProcAddress("glTexImage3DOES"); + } else { + glTexImage3D = NULL; + } + if (hasGLExtension("GL_EXT_map_buffer_range")) { // See http://www.khronos.org/registry/gles/extensions/EXT/EXT_map_buffer_range.txt glMapBufferRange = (glMapBufferRange_func) eglGetProcAddress("glMapBufferRangeEXT"); diff --git a/libkwineffects/kwinglutils_funcs.h b/libkwineffects/kwinglutils_funcs.h index 7e79144ae2..d2248e52c5 100644 --- a/libkwineffects/kwinglutils_funcs.h +++ b/libkwineffects/kwinglutils_funcs.h @@ -538,6 +538,8 @@ extern KWIN_EXPORT glCopyBufferSubData_func glCopyBufferSubData; #define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 #define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 #define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#define GL_TEXTURE_3D 0x806F +#define GL_TEXTURE_WRAP_R 0x8072 #endif namespace KWin @@ -570,6 +572,10 @@ extern KWIN_EXPORT glMapBuffer_func glMapBuffer; extern KWIN_EXPORT glUnmapBuffer_func glUnmapBuffer; extern KWIN_EXPORT glGetBufferPointerv_func glGetBufferPointerv; +// GL_OES_texture_3D +typedef GLvoid(*glTexImage3DOES_func)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*); +extern KWIN_EXPORT glTexImage3DOES_func glTexImage3D; + // GL_EXT_map_buffer_range typedef GLvoid *(*glMapBufferRange_func)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); typedef void (*glFlushMappedBufferRange_func)(GLenum target, GLintptr offset, GLsizeiptr length);