Add static bool fragmentShaderSupported() and vertexShaderSupported() methods to GLShader.
Make sure shaders are supported before trying to load them. svn path=/branches/work/kwin_composite/; revision=645060
This commit is contained in:
parent
da02ba11ca
commit
d72a9239b4
2 changed files with 29 additions and 0 deletions
22
glutils.cpp
22
glutils.cpp
|
@ -61,6 +61,8 @@ void initGL()
|
|||
|
||||
// handle OpenGL extensions functions
|
||||
glResolveFunctions();
|
||||
|
||||
GLShader::initStatic();
|
||||
#else
|
||||
glVersion = MAKE_GL_VERSION( 0, 0, 0 );
|
||||
#endif
|
||||
|
@ -84,6 +86,18 @@ bool hasGLExtension(const QString& extension)
|
|||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
bool GLShader::mFragmentShaderSupported = false;
|
||||
bool GLShader::mVertexShaderSupported = false;
|
||||
|
||||
void GLShader::initStatic()
|
||||
{
|
||||
mFragmentShaderSupported = mVertexShaderSupported =
|
||||
hasGLExtension("GL_ARB_shader_objects") && hasGLExtension("GL_ARB_shading_language_100");
|
||||
mVertexShaderSupported &= hasGLExtension("GL_ARB_vertex_shader");
|
||||
mFragmentShaderSupported &= hasGLExtension("GL_ARB_fragment_shader");
|
||||
}
|
||||
|
||||
|
||||
GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile)
|
||||
{
|
||||
mValid = false;
|
||||
|
@ -115,6 +129,14 @@ bool GLShader::loadFromFiles(const QString& vertexfile, const QString& fragmentf
|
|||
|
||||
bool GLShader::load(const QString& vertexsource, const QString& fragmentsource)
|
||||
{
|
||||
// Make sure shaders are actually supported
|
||||
if(( !vertexsource.isEmpty() && !vertexShaderSupported() ) ||
|
||||
( !fragmentsource.isEmpty() && !fragmentShaderSupported() ))
|
||||
{
|
||||
kDebug(1212) << k_funcinfo << "Shaders not supported" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
GLuint vertexshader;
|
||||
GLuint fragmentshader;
|
||||
|
||||
|
|
|
@ -68,6 +68,11 @@ class GLShader
|
|||
bool setAttribute(const QString& name, float value);
|
||||
|
||||
|
||||
static void initStatic();
|
||||
static bool fragmentShaderSupported() { return mFragmentShaderSupported; }
|
||||
static bool vertexShaderSupported() { return mVertexShaderSupported; }
|
||||
|
||||
|
||||
protected:
|
||||
bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile);
|
||||
bool load(const QString& vertexsource, const QString& fragmentsource);
|
||||
|
@ -77,6 +82,8 @@ class GLShader
|
|||
unsigned int mProgram;
|
||||
bool mValid;
|
||||
QHash< QString, int >* mVariableLocations;
|
||||
static bool mFragmentShaderSupported;
|
||||
static bool mVertexShaderSupported;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue