From 0827c2903b4249a90b1a5f52f913eaa797a007c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 19 Feb 2011 11:08:43 +0100 Subject: [PATCH] Use GLPlatform to decide whether shaders are supported Dropping the static methods from GLShader and use supports() where it was used before. --- effects/blur/blurshader.cpp | 3 ++- effects/cube/cube.cpp | 3 ++- effects/explosion/explosion.cpp | 3 ++- effects/invert/invert.cpp | 4 ++-- effects/lookingglass/lookingglass.cpp | 3 ++- lanczosfilter.cpp | 3 +-- libkwineffects/kwinglutils.cpp | 18 +----------------- libkwineffects/kwinglutils.h | 12 ------------ 8 files changed, 12 insertions(+), 37 deletions(-) diff --git a/effects/blur/blurshader.cpp b/effects/blur/blurshader.cpp index 516fece1d7..1542578e15 100644 --- a/effects/blur/blurshader.cpp +++ b/effects/blur/blurshader.cpp @@ -20,6 +20,7 @@ #include "blurshader.h" #include +#include #include #include @@ -126,7 +127,7 @@ void GLSLBlurShader::reset() bool GLSLBlurShader::supported() { - if (!GLShader::fragmentShaderSupported() || !GLShader::vertexShaderSupported()) + if (!GLPlatform::instance()->supports(GLSL)) return false; (void) glGetError(); // Clear the error state diff --git a/effects/cube/cube.cpp b/effects/cube/cube.cpp index 5608ed5f30..89edf32b41 100644 --- a/effects/cube/cube.cpp +++ b/effects/cube/cube.cpp @@ -39,6 +39,7 @@ along with this program. If not, see . #include #include +#include namespace KWin { @@ -258,7 +259,7 @@ CubeEffect::~CubeEffect() bool CubeEffect::loadShader() { - if (!(GLShader::fragmentShaderSupported() && + if (!(GLPlatform::instance()->supports(GLSL) && (effects->compositingType() == OpenGLCompositing))) return false; QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/cylinder.frag"); diff --git a/effects/explosion/explosion.cpp b/effects/explosion/explosion.cpp index 19c77a992b..8945da164e 100644 --- a/effects/explosion/explosion.cpp +++ b/effects/explosion/explosion.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . #include "explosion.h" #include +#include #include @@ -56,7 +57,7 @@ ExplosionEffect::~ExplosionEffect() bool ExplosionEffect::supported() { - return GLShader::fragmentShaderSupported() && + return GLPlatform::instance()->supports(GLSL) && (effects->compositingType() == OpenGLCompositing); } diff --git a/effects/invert/invert.cpp b/effects/invert/invert.cpp index fecac5dca0..f7f4315494 100644 --- a/effects/invert/invert.cpp +++ b/effects/invert/invert.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "invert.h" #include +#include #include #include #include @@ -62,8 +63,7 @@ InvertEffect::~InvertEffect() bool InvertEffect::supported() { - return GLRenderTarget::supported() && - GLShader::fragmentShaderSupported() && + return GLPlatform::instance()->supports(GLSL) && (effects->compositingType() == OpenGLCompositing); } diff --git a/effects/lookingglass/lookingglass.cpp b/effects/lookingglass/lookingglass.cpp index 024e86585f..610e261a36 100644 --- a/effects/lookingglass/lookingglass.cpp +++ b/effects/lookingglass/lookingglass.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "lookingglass.h" #include +#include #include #include @@ -78,7 +79,7 @@ LookingGlassEffect::~LookingGlassEffect() bool LookingGlassEffect::supported() { return GLRenderTarget::supported() && - GLShader::fragmentShaderSupported() && + GLPlatform::instance()->supports(GLSL) && (effects->compositingType() == OpenGLCompositing); } diff --git a/lanczosfilter.cpp b/lanczosfilter.cpp index cbd4aa04be..879695e7af 100644 --- a/lanczosfilter.cpp +++ b/lanczosfilter.cpp @@ -610,8 +610,7 @@ void LanczosShader::setUniforms() bool LanczosShader::init() { GLPlatform *gl = GLPlatform::instance(); - if (GLShader::fragmentShaderSupported() && - GLShader::vertexShaderSupported() && + if (gl->supports(GLSL) && GLRenderTarget::supported() && !(gl->isRadeon() && gl->chipClass() < R600)) { m_shader = ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, ":/resources/lanczos-fragment.glsl"); diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index c7571b6188..f8ddb693ff 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -106,7 +106,6 @@ void initGL() glResolveFunctions(); GLTexture::initStatic(); - GLShader::initStatic(); GLRenderTarget::initStatic(); GLVertexBuffer::initStatic(); } @@ -688,21 +687,6 @@ QImage GLTexture::convertToGLFormat(const QImage& img) const // GLShader //**************************************** -bool GLShader::sFragmentShaderSupported = false; -bool GLShader::sVertexShaderSupported = false; - -void GLShader::initStatic() -{ -#ifdef KWIN_HAVE_OPENGLES - sFragmentShaderSupported = sVertexShaderSupported = true; -#else - sFragmentShaderSupported = sVertexShaderSupported = - hasGLExtension("GL_ARB_shader_objects") && hasGLExtension("GL_ARB_shading_language_100"); - sVertexShaderSupported &= hasGLExtension("GL_ARB_vertex_shader"); - sFragmentShaderSupported &= hasGLExtension("GL_ARB_fragment_shader"); -#endif -} - GLShader::GLShader() : mProgram(0) , mValid(false) @@ -792,7 +776,7 @@ bool GLShader::compile(GLuint program, GLenum shaderType, const QByteArray &sour bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSource) { // Make sure shaders are actually supported - if (!vertexShaderSupported() || !fragmentShaderSupported()) { + if (!GLPlatform::instance()->supports(GLSL)) { kError(1212) << "Shaders are not supported"; return false; } diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h index 5f331ea269..135b02eae9 100644 --- a/libkwineffects/kwinglutils.h +++ b/libkwineffects/kwinglutils.h @@ -320,15 +320,6 @@ public: bool setUniform(FloatUniform uniform, float value); bool setUniform(IntUniform uniform, int value); - static void initStatic(); - static bool fragmentShaderSupported() { - return sFragmentShaderSupported; - } - static bool vertexShaderSupported() { - return sVertexShaderSupported; - } - - protected: GLShader(); bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile); @@ -350,9 +341,6 @@ private: float mTextureWidth; float mTextureHeight; - static bool sFragmentShaderSupported; - static bool sVertexShaderSupported; - friend class ShaderManager; };