From cd66b01da3607fd24e7460f5a809408701408b26 Mon Sep 17 00:00:00 2001 From: vrld Date: Wed, 26 Oct 2011 21:17:40 +0200 Subject: [PATCH] Add GLSL version number check to PixelEffect::isSupported() --- src/modules/graphics/opengl/PixelEffect.cpp | 21 +++++++++++++++++++-- src/modules/graphics/opengl/PixelEffect.h | 1 + src/modules/graphics/opengl/wrap_Graphics.h | 1 - 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/opengl/PixelEffect.cpp b/src/modules/graphics/opengl/PixelEffect.cpp index 91f00c159..7f894b3a1 100644 --- a/src/modules/graphics/opengl/PixelEffect.cpp +++ b/src/modules/graphics/opengl/PixelEffect.cpp @@ -2,6 +2,7 @@ #include "GLee.h" #include #include +#include namespace { @@ -44,7 +45,6 @@ namespace opengl return _current_texture_unit; } - PixelEffect::PixelEffect(const std::string& code) : _program(0), _code(code) { @@ -120,9 +120,26 @@ namespace opengl glDeleteProgram(_program); } + std::string PixelEffect::getGLSLVersion() + { + // GL_SHADING_LANGUAGE_VERSION is not available in OpenGL < 2.1. + // Be very pessimistic about the GLSL version in that case. + if (!GLEE_VERSION_2_1) + return "0.0"; + + // the version string always begins with a version number of the format + // major_number.minor_number + // or + // major_number.minor_number.release_number + std::string versionString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)); + size_t minorEndPos = versionString.find(" "); + return versionString.substr(0, minorEndPos); + } + + bool PixelEffect::isSupported() { - return GLEE_VERSION_2_0 && GLEE_ARB_shader_objects && GLEE_ARB_fragment_shader; + return GLEE_VERSION_2_0 && GLEE_ARB_shader_objects && GLEE_ARB_fragment_shader && getGLSLVersion() >= "1.2"; } std::string PixelEffect::getWarnings() const diff --git a/src/modules/graphics/opengl/PixelEffect.h b/src/modules/graphics/opengl/PixelEffect.h index 4d34190e4..79f6e8941 100644 --- a/src/modules/graphics/opengl/PixelEffect.h +++ b/src/modules/graphics/opengl/PixelEffect.h @@ -26,6 +26,7 @@ namespace opengl void attach(); static void detach(); + static std::string getGLSLVersion(); static bool isSupported(); void sendFloat(const std::string& name, int size, const GLfloat* vec, int count); diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 74f862006..c64781b2a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -93,7 +93,6 @@ namespace opengl int w_getRenderTarget(lua_State * L); int w_setPixelEffect(lua_State * L); int w_isSupported(lua_State * L); - int w_getGLSLVersion(lua_State * L); int w_draw(lua_State * L); int w_drawq(lua_State * L); int w_drawTest(lua_State * L);