Commit d25b9f6a authored by Robert Menzel's avatar Robert Menzel

cleanups and documentation

parent fb78c669
...@@ -137,14 +137,18 @@ namespace ACGL ...@@ -137,14 +137,18 @@ namespace ACGL
/* /*
* This should get called as soon as a valid OpenGL context exists, * This should get called as soon as a valid OpenGL context exists,
* it will init glew (if used). * it will init glew (if used) or the internal GL function loader.
* Call this before calling any OpenGL functions or OpenGL related * Call this before calling any OpenGL functions or OpenGL related
* ACGL stuff. * ACGL stuff.
* *
* Returns false if a critical error occured, in that case the ACGL behavior is * Returns false if a critical error occured, in that case the ACGL behavior is
* not defined. * not defined.
*
* parameter forDebugging: if true, register a debug callback for OpenGL and simulate
* a debug context (slow) in case the application is not running in a native debug
* context.
*/ */
bool init(); bool init( bool forceDebuggingContext = true );
} }
......
...@@ -22,6 +22,7 @@ const char *debugTypeName( GLenum _type ); ...@@ -22,6 +22,7 @@ const char *debugTypeName( GLenum _type );
const char *debugSeverityName( GLenum _type ); const char *debugSeverityName( GLenum _type );
//! tries to register the default debug callback: //! tries to register the default debug callback:
//! applications can register alternative callbacks with glDebugMessageCallback !
void ACGLRegisterDefaultDebugCallback(); void ACGLRegisterDefaultDebugCallback();
//! default debug callback //! default debug callback
......
...@@ -198,15 +198,8 @@ private: ...@@ -198,15 +198,8 @@ private:
// ===================================================================================================== \/ // ===================================================================================================== \/
public: public:
//! Bind this VAO //! Bind this VAO
//! If error checking is set to common or higher, some consistancy checks are made //! some consistancy checks are made
#ifdef ACGL_CHECK_COMMON_GL_ERRORS
void bind() const; void bind() const;
#else
inline void bind() const
{
glBindVertexArray( mObjectName );
}
#endif
//! Nothing has to be prepared for a render call //! Nothing has to be prepared for a render call
inline void render (void) inline void render (void)
......
...@@ -161,6 +161,11 @@ const GLubyte* acglErrorString( GLenum _errorCode ); ...@@ -161,6 +161,11 @@ const GLubyte* acglErrorString( GLenum _errorCode );
GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber ); GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber );
/* /*
* NOTE: Explicit error checks are not needed anymore on desktop systems! Use KHR_debug
* callback instead (ACGL registers a default callback automatically).
*
*
*
* Inside of ACGL we distinguish between rare, common and critical errors. Each kind can be * Inside of ACGL we distinguish between rare, common and critical errors. Each kind can be
* switched off which turns the function into nothing after compiler optimization. If an * switched off which turns the function into nothing after compiler optimization. If an
* error check is turned off it will always behave as if there was no error, even if there * error check is turned off it will always behave as if there was no error, even if there
......
...@@ -13,27 +13,12 @@ ...@@ -13,27 +13,12 @@
namespace ACGL namespace ACGL
{ {
bool init() bool init( bool forceDebuggingContext )
{ {
Utils::debug() << "ACGL was compiled for "
#ifdef ACGL_DEBUG #ifdef ACGL_DEBUG
<< "debug" << std::endl; Utils::debug() << "ACGL was compiled for debug" << std::endl;
#else
<< "release" << std::endl;
#endif #endif
Utils::debug() << "OpenGL error checking is set to "
#if defined( ACGL_CHECK_NO_GL_ERRORS )
<< "NO checks" << std::endl;
#elif defined( ACGL_CHECK_RARE_GL_ERRORS )
<< "check a lot (for debugging)" << std::endl;
#elif defined( ACGL_CHECK_COMMON_GL_ERRORS )
<< "normal" << std::endl;
#elif defined( ACGL_CHECK_CRITICAL_GL_ERRORS )
<< "only most critical checks" << std::endl;
#endif
// //
// init GLEW or own extension loader, do nothing on ES // init GLEW or own extension loader, do nothing on ES
// //
...@@ -42,15 +27,15 @@ bool init() ...@@ -42,15 +27,15 @@ bool init()
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
# endif # endif
GLenum errorCode = glewInit(); GLenum errorCode = glewInit();
if ((errorCode != GLEW_OK) || (openGLCriticalErrorOccured())) { if ((errorCode != GLEW_OK) || (openGLErrorOccured())) {
Utils::error() << "could not init GLEW!" << std::endl; Utils::error() << "could not init GLEW!" << std::endl;
#ifdef ACGL_OPENGL_PROFILE_CORE #ifdef ACGL_OPENGL_PROFILE_CORE
Utils::error() << "Make sure your version of GLEW is compatible with core contexts" << std::endl; Utils::error() << "Make sure your version of GLEW is compatible with core contexts!" << std::endl;
#endif #endif
return false; return false;
} }
#elif defined( ACGL_EXTENSION_LOADER_GLLOADGEN ) #elif defined( ACGL_EXTENSION_LOADER_GLLOADGEN )
int loaded = ogl_LoadFunctionsForDebug( GL_TRUE, GL_TRUE ); int loaded = ogl_LoadFunctionsForDebug( GL_TRUE, forceDebuggingContext );
if (loaded == ogl_LOAD_FAILED) if (loaded == ogl_LOAD_FAILED)
{ {
Utils::error() << "could not load OpenGL functions!" << std::endl; Utils::error() << "could not load OpenGL functions!" << std::endl;
......
...@@ -56,7 +56,6 @@ SharedShaderProgram ShaderProgramCreator::create() ...@@ -56,7 +56,6 @@ SharedShaderProgram ShaderProgramCreator::create()
} }
for (std::vector<std::string>::size_type i = 0; i < numberOfFiles; ++i) { for (std::vector<std::string>::size_type i = 0; i < numberOfFiles; ++i) {
# ifdef ACGL_CHECK_CRITICAL_GL_ERRORS
// check for problems: // check for problems:
if ( mShaderType[i] == GL_INVALID_VALUE ) { if ( mShaderType[i] == GL_INVALID_VALUE ) {
...@@ -79,7 +78,6 @@ SharedShaderProgram ShaderProgramCreator::create() ...@@ -79,7 +78,6 @@ SharedShaderProgram ShaderProgramCreator::create()
Utils::error() << "file " << mFileNames[i] << " ignored, hardware does not support tessellation shader" << std::endl; Utils::error() << "file " << mFileNames[i] << " ignored, hardware does not support tessellation shader" << std::endl;
mShaderType[i] = GL_INVALID_VALUE; mShaderType[i] = GL_INVALID_VALUE;
} }
# endif // critical checks
// attach shader // attach shader
if ( mShaderType[i] != GL_INVALID_VALUE ) { if ( mShaderType[i] != GL_INVALID_VALUE ) {
...@@ -87,9 +85,7 @@ SharedShaderProgram ShaderProgramCreator::create() ...@@ -87,9 +85,7 @@ SharedShaderProgram ShaderProgramCreator::create()
if ( shader ) { if ( shader ) {
shaderProgram->attachShader( shader ); shaderProgram->attachShader( shader );
} else { } else {
# ifdef ACGL_CHECK_CRITICAL_GL_ERRORS
Utils::error() << "could not attach shader " << mFileNames[i] << std::endl; Utils::error() << "could not attach shader " << mFileNames[i] << std::endl;
# endif // critical checks
} }
} }
} }
......
...@@ -55,7 +55,7 @@ void ACGLRegisterDefaultDebugCallback() ...@@ -55,7 +55,7 @@ void ACGLRegisterDefaultDebugCallback()
GLint v; GLint v;
glGetIntegerv( GL_CONTEXT_FLAGS, &v ); glGetIntegerv( GL_CONTEXT_FLAGS, &v );
if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) { if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) {
debug() << "context was created with KHR_debug flag" << endl; debug() << "context was created with KHR_debug flag, register callback" << endl;
} else { } else {
debug() << "context was created WITHOUT KHR_debug flag - registering a debug callback is possible but might not result in getting called even if errors occur!" << endl; debug() << "context was created WITHOUT KHR_debug flag - registering a debug callback is possible but might not result in getting called even if errors occur!" << endl;
} }
......
...@@ -17,7 +17,6 @@ bool ShaderProgram::link() const ...@@ -17,7 +17,6 @@ bool ShaderProgram::link() const
{ {
glLinkProgram(mObjectName); glLinkProgram(mObjectName);
#ifdef ACGL_CHECK_CRITICAL_GL_ERRORS
// check for program link errors: // check for program link errors:
GLint programError; GLint programError;
glGetProgramiv(mObjectName, GL_LINK_STATUS, &programError); glGetProgramiv(mObjectName, GL_LINK_STATUS, &programError);
...@@ -39,7 +38,6 @@ bool ShaderProgram::link() const ...@@ -39,7 +38,6 @@ bool ShaderProgram::link() const
delete[] pInfo; delete[] pInfo;
return (programError == GL_TRUE); // if the log contains only warnings we return true return (programError == GL_TRUE); // if the log contains only warnings we return true
} }
#endif
return true; return true;
} }
......
...@@ -24,7 +24,6 @@ VertexArrayObject::VertexArrayObject( GLenum _mode ) : ...@@ -24,7 +24,6 @@ VertexArrayObject::VertexArrayObject( GLenum _mode ) :
mAttributes.resize( maxAttributes ); // reserve probably 16 slots, the size() can now be used to query the MAX_VERTEX_ATTRIBS mAttributes.resize( maxAttributes ); // reserve probably 16 slots, the size() can now be used to query the MAX_VERTEX_ATTRIBS
} }
#ifdef ACGL_CHECK_COMMON_GL_ERRORS
void VertexArrayObject::bind() const void VertexArrayObject::bind() const
{ {
glBindVertexArray( mObjectName ); glBindVertexArray( mObjectName );
...@@ -45,7 +44,6 @@ void VertexArrayObject::bind() const ...@@ -45,7 +44,6 @@ void VertexArrayObject::bind() const
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, myEAB); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, myEAB);
} }
} }
#endif
void VertexArrayObject::attachElementArrayBuffer( const ConstSharedElementArrayBuffer& _elementArrayBuffer ) void VertexArrayObject::attachElementArrayBuffer( const ConstSharedElementArrayBuffer& _elementArrayBuffer )
{ {
......
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