Commit 09129e4e authored by Robert Menzel's avatar Robert Menzel

Improved compatibility for AutoShader

* ShaderProgramControlAutoFiles now only tries to (re)load geometry and tessellation shaders if
  they are supported
* desktop support is checked at runtime, OpenGL ES does not compile support for these stages at all
parent ba25d665
......@@ -39,6 +39,9 @@ uint32_t getOpenGLMajorVersionNumber();
// returns the combined version number as 10*major + minor for easy comparing
uint32_t getOpenGLVersionNumber();
bool doesSupportGeometryShader();
bool doesSupportTessellationShader();
// for every OpenGL error enum this will return a human readable version of it
// similar to gluErrorString, but that function is not available on all plattforms
// (read: iOS)
......
......@@ -106,7 +106,7 @@ namespace FileHelpers
bool fileExists(const std::string &fileName)
{
std::ifstream file(fileName);
std::ifstream file( fileName.c_str() );
return file.good();
}
}
......
......@@ -12,7 +12,6 @@
using namespace ACGL::Base;
using namespace ACGL::OpenGL;
//using namespace ACGL::Resource;
SharedShaderProgram ShaderProgramControlAutoFiles::create(void)
{
......@@ -20,17 +19,39 @@ SharedShaderProgram ShaderProgramControlAutoFiles::create(void)
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".vsh").type(GL_VERTEX_SHADER)))
shaderProgram->attachShader(shader);
if(FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".tcsh"))
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".tcsh").type(GL_TESS_CONTROL_SHADER)))
shaderProgram->attachShader(shader);
#ifndef ACGL_OPENGL_ES
// this shader types are not defined for ES
if(FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".tesh"))
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".tesh").type(GL_TESS_EVALUATION_SHADER)))
shaderProgram->attachShader(shader);
bool tessellationControlShaderPresent = FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".tcsh");
bool tessellationEvaluationShaderPresent = FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".tesh");
if(FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".gsh"))
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".gsh").type(GL_GEOMETRY_SHADER)))
shaderProgram->attachShader(shader);
if (OpenGL::doesSupportTessellationShader()) {
if(tessellationControlShaderPresent && tessellationEvaluationShaderPresent) {
// both tessellation stages are present -> load them
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".tcsh").type(GL_TESS_CONTROL_SHADER)))
shaderProgram->attachShader(shader);
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".tesh").type(GL_TESS_EVALUATION_SHADER)))
shaderProgram->attachShader(shader);
} else {
if (tessellationControlShaderPresent || tessellationEvaluationShaderPresent) {
// only ONE tessellation stage is present -> somethings wrong
ACGL::Utils::warning() << "only one of two tessellation shaders are present - ignored" << std::endl;
}
}
} else if (tessellationControlShaderPresent || tessellationEvaluationShaderPresent) {
ACGL::Utils::warning() << "tessellation shader present but hardware doesn't support those - ignored" << std::endl;
}
bool geometryShaderPresent = FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".gsh");
if (OpenGL::doesSupportGeometryShader()) {
if(geometryShaderPresent)
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".gsh").type(GL_GEOMETRY_SHADER)))
shaderProgram->attachShader(shader);
} else if (geometryShaderPresent) {
ACGL::Utils::warning() << "geometry shader present but hardware doesn't support it - ignored" << std::endl;
}
#endif
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".fsh").type(GL_FRAGMENT_SHADER)))
shaderProgram->attachShader(shader);
......@@ -50,8 +71,17 @@ bool ShaderProgramControlAutoFiles::update(SharedShaderProgram& shaderProgram)
{
bool update = false;
update |= ShaderFileManager::the()->update(mFilename + ".vsh");
update |= ShaderFileManager::the()->update(mFilename + ".gsh");
update |= ShaderFileManager::the()->update(mFilename + ".fsh");
#ifndef ACGL_OPENGL_ES
if (OpenGL::doesSupportGeometryShader()) {
update |= ShaderFileManager::the()->update(mFilename + ".gsh");
}
if (OpenGL::doesSupportTessellationShader()) {
update |= ShaderFileManager::the()->update(mFilename + ".tcsh");
update |= ShaderFileManager::the()->update(mFilename + ".tesh");
}
#endif
if(update)
return shaderProgram->link();
return false;
......
......@@ -77,6 +77,32 @@ uint32_t getOpenGLVersionNumber()
return privateGetOpenGLVersion( 2 );
}
bool doesSupportGeometryShader()
{
#ifdef ACGL_OPENGL_ES
return false;
#else
# if defined(ACGL_USE_GLEW)
return (GLEW_EXT_geometry_shader4 || GLEW_ARB_geometry_shader4 || (getOpenGLVersionNumber() >= 32));
# else
return (getOpenGLVersionNumber() >= 32);
# endif
#endif
}
bool doesSupportTessellationShader()
{
#ifdef ACGL_OPENGL_ES
return false;
#else
# if defined(ACGL_USE_GLEW)
return ( GLEW_ARB_tessellation_shader || (getOpenGLVersionNumber() >= 40));
# else
return (getOpenGLVersionNumber() >= 40);
# endif
#endif
}
const GLubyte* acglErrorString( GLenum _errorCode )
{
#ifndef ACGL_USE_GLEW
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment