Use GLPlatform to decide whether shaders are supported

Dropping the static methods from GLShader and use supports()
where it was used before.
This commit is contained in:
Martin Gräßlin 2011-02-19 11:08:43 +01:00
parent 2920715d4d
commit 0827c2903b
8 changed files with 12 additions and 37 deletions

View file

@ -20,6 +20,7 @@
#include "blurshader.h"
#include <kwineffects.h>
#include <kwinglplatform.h>
#include <QByteArray>
#include <QMatrix4x4>
@ -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

View file

@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <math.h>
#include <kwinglutils.h>
#include <kwinglplatform.h>
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");

View file

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "explosion.h"
#include <kwinglutils.h>
#include <kwinglplatform.h>
#include <QMatrix4x4>
@ -56,7 +57,7 @@ ExplosionEffect::~ExplosionEffect()
bool ExplosionEffect::supported()
{
return GLShader::fragmentShaderSupported() &&
return GLPlatform::instance()->supports(GLSL) &&
(effects->compositingType() == OpenGLCompositing);
}

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "invert.h"
#include <kwinglutils.h>
#include <kwinglplatform.h>
#include <kactioncollection.h>
#include <kaction.h>
#include <klocale.h>
@ -62,8 +63,7 @@ InvertEffect::~InvertEffect()
bool InvertEffect::supported()
{
return GLRenderTarget::supported() &&
GLShader::fragmentShaderSupported() &&
return GLPlatform::instance()->supports(GLSL) &&
(effects->compositingType() == OpenGLCompositing);
}

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "lookingglass.h"
#include <kwinglutils.h>
#include <kwinglplatform.h>
#include <kactioncollection.h>
#include <kaction.h>
@ -78,7 +79,7 @@ LookingGlassEffect::~LookingGlassEffect()
bool LookingGlassEffect::supported()
{
return GLRenderTarget::supported() &&
GLShader::fragmentShaderSupported() &&
GLPlatform::instance()->supports(GLSL) &&
(effects->compositingType() == OpenGLCompositing);
}

View file

@ -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");

View file

@ -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;
}

View file

@ -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;
};