Commit fd29e9c3 authored by Robert Menzel's avatar Robert Menzel
Browse files

OpenGL Error check bugfixes & OpenGL header fixes & OpenGL version checking

* OpenGL error checking level can now be set via cmake
* OpenGL header configuration works better with external defines via cmake
* OpenGL version gets checked at runtime in the ACGL::init function and complains it the version it was compiled for is not present
parent fae8d4a9
...@@ -28,8 +28,11 @@ namespace ACGL ...@@ -28,8 +28,11 @@ namespace ACGL
* it will init glew (if used). * it will init glew (if used).
* 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
* not defined.
*/ */
void init(void); bool init(void);
}; };
......
...@@ -13,17 +13,17 @@ ...@@ -13,17 +13,17 @@
* and critical&common in debug build. * and critical&common in debug build.
* *
* This can get overwritten with a compile flag define: * This can get overwritten with a compile flag define:
* -DACGL_CHECK_NO_GL_ERRORS * -DACGL_ERROR_LEVEL_EC0
* No error checking at all * No error checking at all
* -DACGL_CHECK_CRITICAL_GL_ERRORS * -DACGL_ERROR_LEVEL_EC1
* Places will get checked where errors like out of memory can occur. * Places will get checked where errors like out of memory can occur.
* This will detect runtime errors which can happen even if the program * This will detect runtime errors which can happen even if the program
* is bug free. * is bug free.
* Switching this on shouldn't be a performance hit. * Switching this on shouldn't be a performance hit.
* -DACGL_CHECK_COMMON_GL_ERRORS * -DACGL_ERROR_LEVEL_EC2
* Problems that happen more often while developing like typos in uniform * Problems that happen more often while developing like typos in uniform
* names. All placed where strings are used to call OpenGL objects etc. * names. All placed where strings are used to call OpenGL objects etc.
* -DACGL_CHECK_RARE_GL_ERRORS * -DACGL_ERROR_LEVEL_EC3
* Most likely bugs in ACGL itself or wrong usage. If there are strange errors * Most likely bugs in ACGL itself or wrong usage. If there are strange errors
* switch this on to find the reason more quickly. Even normal development * switch this on to find the reason more quickly. Even normal development
* should work without this. Results in a lot of glGetError! * should work without this. Results in a lot of glGetError!
...@@ -31,6 +31,22 @@ ...@@ -31,6 +31,22 @@
* Note that all error levels also include the higher ones (COMMON also adds CRITICAL). * Note that all error levels also include the higher ones (COMMON also adds CRITICAL).
*/ */
/*
* Map CMake generated error-level defines to internally used, more readable defines
*/
#ifdef ACGL_ERROR_LEVEL_EC0
# define ACGL_CHECK_NO_GL_ERRORS
#endif
#ifdef ACGL_ERROR_LEVEL_EC1
# define ACGL_CHECK_CRITICAL_GL_ERRORS
#endif
#ifdef ACGL_ERROR_LEVEL_EC2
# define ACGL_CHECK_COMMON_GL_ERRORS
#endif
#ifdef ACGL_ERROR_LEVEL_EC3
# define ACGL_CHECK_RARE_GL_ERRORS
#endif
#ifndef ACGL_CHECK_NO_GL_ERRORS #ifndef ACGL_CHECK_NO_GL_ERRORS
# ifndef ACGL_CHECK_CRITICAL_GL_ERRORS # ifndef ACGL_CHECK_CRITICAL_GL_ERRORS
......
...@@ -13,25 +13,67 @@ ...@@ -13,25 +13,67 @@
* While these includes are located in a subdirectory of GL/ on most systems, * While these includes are located in a subdirectory of GL/ on most systems,
* Apple hides them on different locations. * Apple hides them on different locations.
* *
* This header can get configured via compile-time defines:
* *
* -DCOMPILE_WITH_QT : If using ACGL with QT this will also include the qgl.h * This wrapper can get configured with external defines:
* -DCOMPILED_FOR_OGL : 20 21 30 31 32 33 40 41 * QT_OPENGL_LIB : include also the QT OpenGL headers and maybe use QT for other
* -DCOMPILED_FOR_OGL_PROFILE_FULL : full OpenGL profile (>= 2.1) * graphics related stuff, like image loading for textures.
* -DCOMPILED_FOR_OGL_PROFILE_CORE : core OpenGL profile (>= 3.2) * ACGL_OPENGL_SUPPORT_CORE_41 : (or other versions): basicly ACGL_OPENGL_PROFILE_* and ACGL_OPENGL_VERSION_*
* -DCOMPILED_FOR_OGL_PROFILE_ES : embedded profile (OpenGL ES 2.0) * combined!
* -DSIMULATE_OGL_ES : Simulate ES feature set with desktop OGL * ACGL_OPENGL_PROFILE_CORE : CORE: only support for CORE functions, demands a CORE OpenGL context
* * FULL: support for CORE and deprecated functions
* Not all combinations are valid! * ACGL_OPENGL_VERSION_41 : (or other versions): minimal OpenGL version that can be assumed to be present.
* The app can't run on older contexts and will probably terminate at startup.
* Set this to a low version and it will run on lost machines
* Set this to a high version and less run-time checks have to be performed to
* work around missing features (like querying extensions etc).
* ACGL_PLATFORM_DESKTOP : DESKTOP vs. MOBILE plattform = GL vs. GL ES
*/ */
// TODO: remove and move to cmake: // If there is a demand for a core context, we should include the new core headers as well,
#define COMPILE_WITH_QT // sadly, these are not very good supported yet, so this stays commented out for a while :-(
#ifdef ACGL_OPENGL_PROFILE_CORE
//# define ACGL_OPENGL_PROFILE_CORE_HEADER
#endif
// To compare the OpenGL version number we define a new ACGL_OPENGL_VERSION XY define here
// analog to ACGL_OPENGL_VERSION_XY
#ifdef ACGL_OPENGL_VERSION_21
# define ACGL_OPENGL_VERSION 21
#else
# ifdef ACGL_OPENGL_VERSION_30
# define ACGL_OPENGL_VERSION 30
# else
# ifdef ACGL_OPENGL_VERSION_31
# define ACGL_OPENGL_VERSION 31
# else
# ifdef ACGL_OPENGL_VERSION_32
# define ACGL_OPENGL_VERSION 32
# else
# ifdef ACGL_OPENGL_VERSION_33
# define ACGL_OPENGL_VERSION 33
# else
# ifdef ACGL_OPENGL_VERSION_40
# define ACGL_OPENGL_VERSION 40
# else
# ifdef ACGL_OPENGL_VERSION_41
# define ACGL_OPENGL_VERSION 41
# else
# ifdef ACGL_OPENGL_VERSION_42
# define ACGL_OPENGL_VERSION 42
# else
// failback:
# define ACGL_OPENGL_VERSION_32
# define ACGL_OPENGL_VERSION 32
# endif
# endif
# endif
# endif
# endif
# endif
# endif
#endif
// We can try to build against OpenGL core profile or compatibility (core means automatically
// 3.2 or higher). On MacOS X 10.7 Lion we can choose between 2.1 or 3.2 core, but 3.2
// compatibility is not an option.
//#define USE_OPENGL_CORE_PROFILE
// If we're compiling for an Apple system we need this to distinquish between Mac and iOS: // If we're compiling for an Apple system we need this to distinquish between Mac and iOS:
#ifdef __APPLE__ #ifdef __APPLE__
...@@ -42,11 +84,20 @@ ...@@ -42,11 +84,20 @@
#define USE_GLEW #define USE_GLEW
#if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)) #if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
#if (TARGET_OS_IPHONE == 1) # if (TARGET_OS_IPHONE == 1)
#define PLATFORM_IOS # define PLATFORM_IOS
#define OPENGL_ES # define OPENGL_ES
#undef USE_GLEW // no glew support on iOS # undef USE_GLEW // no glew support on iOS
#endif # endif
#else
// no iOS device...
# ifdef ACGL_PLATFORM_MOBILE
// ...but mobile:
// maybe maemo or android: first one to program for these plattforms should add
// the correct includes here!
# error UNKNOWN mobile plattform! Dont know what to include!
# define OPENGL_ES
# endif
#endif #endif
// we have allways to include glew first! // we have allways to include glew first!
...@@ -71,22 +122,23 @@ ...@@ -71,22 +122,23 @@
#import <OpenGLES/ES2/glext.h> #import <OpenGLES/ES2/glext.h>
#else #else
// Desktop MacOS X: // Desktop MacOS X:
#ifdef USE_OPENGL_CORE_PROFILE #ifdef ACGL_OPENGL_PROFILE_CORE
// On MacOS X, all OpenGL versions >=3.2 are core and have to use the new headers:
#include <GL3/gl3.h> #include <GL3/gl3.h>
#else #else
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
#endif #endif
#endif #endif
#else #else
#ifdef USE_OPENGL_CORE_PROFILE #ifdef ACGL_OPENGL_PROFILE_CORE_HEADER
#include <GL3/gl3.h> #include <GL3/gl3.h>
#else #else
#include <GL/gl.h> #include <GL/gl.h>
#endif #endif
#endif #endif
#ifdef COMPILE_WITH_QT #ifdef QT_OPENGL_LIB
#include <QtOpenGL/qgl.h> # include <QtOpenGL/qgl.h>
#endif // USE_QT #endif // USE_QT
#endif // ACGL_OPENGL_GL_HH #endif // ACGL_OPENGL_GL_HH
...@@ -6,13 +6,59 @@ ...@@ -6,13 +6,59 @@
#include <ACGL/ACGL.hh> #include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/GL.hh> #include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <stdlib.h>
namespace ACGL namespace ACGL
{ {
void init(void) bool init(void)
{ {
//
// init GLEW
//
#ifdef USE_GLEW
glewInit(); glewInit();
if (openGLCriticalErrorOccured()) {
ACGL::Utils::error() << "could not init GLEW!" << std::endl;
return false;
}
#endif
//
// check OpenGL version
//
float openGLVersionF = atof( (const char*) glGetString(GL_VERSION) );
GLint openGLmajorVersion;
GLint openGLminorVersion;
if (openGLVersionF < 3.0) {
if (openGLVersionF >= 2.1) {
openGLmajorVersion = 2;
openGLminorVersion = 1;
} else {
ACGL::Utils::error() << "OpenGL version " << openGLVersionF << " not supported!" << std::endl;
return false;
}
} else {
// OpenGL 3.0 is needed for this (saves us float/ascii to int conversion)
glGetIntegerv(GL_MAJOR_VERSION, &openGLmajorVersion);
glGetIntegerv(GL_MINOR_VERSION, &openGLminorVersion);
}
if (openGLRareErrorOccured()) {
ACGL::Utils::error() << "could not query OpenGL version!" << std::endl;
return false;
}
ACGL::Utils::debug() << "OpenGL Version: " << openGLmajorVersion << "." << openGLminorVersion << std::endl;
uint32_t openGLVersion = (openGLmajorVersion*10 + openGLminorVersion);
if (openGLVersion < ACGL_OPENGL_VERSION) {
ACGL::Utils::error() << "At compile time an OpenGL context of version " << ACGL_OPENGL_VERSION
<< " was requested, but the current context only supports " << openGLVersion << std::endl;
return false;
}
} }
}; };
......
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