Commit f5f024a0 authored by Robert Menzel's avatar Robert Menzel
Browse files
parents c477eacc 09129e4e
...@@ -61,6 +61,11 @@ namespace FileHelpers ...@@ -61,6 +61,11 @@ namespace FileHelpers
* Will return the modification time of the file. * Will return the modification time of the file.
*/ */
FileModificationTime getFileModificationTime( const std::string &fileName ) ; FileModificationTime getFileModificationTime( const std::string &fileName ) ;
/*
* Checks whether a file with the given filename exists and is readable.
*/
bool fileExists( const std::string &fileName );
} }
} // Base } // Base
......
...@@ -39,6 +39,9 @@ uint32_t getOpenGLMajorVersionNumber(); ...@@ -39,6 +39,9 @@ uint32_t getOpenGLMajorVersionNumber();
// returns the combined version number as 10*major + minor for easy comparing // returns the combined version number as 10*major + minor for easy comparing
uint32_t getOpenGLVersionNumber(); uint32_t getOpenGLVersionNumber();
bool doesSupportGeometryShader();
bool doesSupportTessellationShader();
// for every OpenGL error enum this will return a human readable version of it // 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 // similar to gluErrorString, but that function is not available on all plattforms
// (read: iOS) // (read: iOS)
......
...@@ -103,6 +103,12 @@ namespace FileHelpers ...@@ -103,6 +103,12 @@ namespace FileHelpers
stat(fileName.c_str(), &fileStats); stat(fileName.c_str(), &fileStats);
return fileStats.st_mtime; return fileStats.st_mtime;
} }
bool fileExists(const std::string &fileName)
{
std::ifstream file( fileName.c_str() );
return file.good();
}
} }
} // Base } // Base
......
...@@ -22,6 +22,10 @@ SharedShader ShaderControlFile::create(void) ...@@ -22,6 +22,10 @@ SharedShader ShaderControlFile::create(void)
if(extension == "vsh") if(extension == "vsh")
mType = GL_VERTEX_SHADER; mType = GL_VERTEX_SHADER;
else if(extension == "tcsh")
mType = GL_TESS_CONTROL_SHADER;
else if(extension == "tesh")
mType = GL_TESS_EVALUATION_SHADER;
else if(extension == "gsh") else if(extension == "gsh")
mType = GL_GEOMETRY_SHADER; mType = GL_GEOMETRY_SHADER;
else if(extension == "fsh") else if(extension == "fsh")
......
...@@ -8,18 +8,51 @@ ...@@ -8,18 +8,51 @@
#include <ACGL/Resource/FileManager.hh> #include <ACGL/Resource/FileManager.hh>
#include <ACGL/OpenGL/Managers.hh> #include <ACGL/OpenGL/Managers.hh>
#include <ACGL/Base/Settings.hh> #include <ACGL/Base/Settings.hh>
#include <ACGL/Base/FileHelpers.hh>
using namespace ACGL::Base; using namespace ACGL::Base;
using namespace ACGL::OpenGL; using namespace ACGL::OpenGL;
//using namespace ACGL::Resource;
SharedShaderProgram ShaderProgramControlAutoFiles::create(void) SharedShaderProgram ShaderProgramControlAutoFiles::create(void)
{ {
SharedShaderProgram shaderProgram(new ShaderProgram()); SharedShaderProgram shaderProgram(new ShaderProgram());
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".vsh").type(GL_VERTEX_SHADER))) if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".vsh").type(GL_VERTEX_SHADER)))
shaderProgram->attachShader(shader); shaderProgram->attachShader(shader);
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".gsh").type(GL_GEOMETRY_SHADER)))
shaderProgram->attachShader(shader); #ifndef ACGL_OPENGL_ES
// this shader types are not defined for ES
bool tessellationControlShaderPresent = FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".tcsh");
bool tessellationEvaluationShaderPresent = FileHelpers::fileExists(Base::Settings::the()->getFullShaderPath() + mFilename + ".tesh");
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))) if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".fsh").type(GL_FRAGMENT_SHADER)))
shaderProgram->attachShader(shader); shaderProgram->attachShader(shader);
...@@ -30,6 +63,7 @@ SharedShaderProgram ShaderProgramControlAutoFiles::create(void) ...@@ -30,6 +63,7 @@ SharedShaderProgram ShaderProgramControlAutoFiles::create(void)
if(shaderProgram->link()) if(shaderProgram->link())
return shaderProgram; return shaderProgram;
return SharedShaderProgram(); return SharedShaderProgram();
} }
...@@ -37,8 +71,17 @@ bool ShaderProgramControlAutoFiles::update(SharedShaderProgram& shaderProgram) ...@@ -37,8 +71,17 @@ bool ShaderProgramControlAutoFiles::update(SharedShaderProgram& shaderProgram)
{ {
bool update = false; bool update = false;
update |= ShaderFileManager::the()->update(mFilename + ".vsh"); update |= ShaderFileManager::the()->update(mFilename + ".vsh");
update |= ShaderFileManager::the()->update(mFilename + ".gsh");
update |= ShaderFileManager::the()->update(mFilename + ".fsh"); 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) if(update)
return shaderProgram->link(); return shaderProgram->link();
return false; return false;
......
...@@ -77,6 +77,32 @@ uint32_t getOpenGLVersionNumber() ...@@ -77,6 +77,32 @@ uint32_t getOpenGLVersionNumber()
return privateGetOpenGLVersion( 2 ); 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 ) const GLubyte* acglErrorString( GLenum _errorCode )
{ {
#ifndef ACGL_USE_GLEW #ifndef ACGL_USE_GLEW
......
Supports Markdown
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