Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualJuliean

Posted 31 March 2014 - 11:43 AM

Since the glDebugMessageCallback​-stuff is rather new and probably not widely supported (I see core in 4.3 when you are using 3.3) it might be well advised to wrap all your opengl-calls with a simple macro:

void CheckOpenGLError(const char* stmt, const char* fname, int line)
{
	GLenum err = glGetError();
	if(err != GL_NO_ERROR)
	{
              // handle error here
	}
}

#ifdef _DEBUG
#define GL_CHECK(stmt) { \
	stmt; \
	CheckOpenGLError(#stmt, __FILE__, __LINE__); \
		}
#else
#define GL_CHECK(stmt) stmt
#endif

Which you can then use:

GL_CHECK(glEnableVertexAttribArray( 0 ));

and it will tell you if something is wrong in debug (compile) mode. You do need to wrap it around EVERY function that you have, or else uncaught error codes will leak to other parts of the program and cause another function to report the error instead. To end with a generic OpenGL-rant: Thats why OpenGLs global error handling and/or global state b... stuff sucks. glDebugMessageCallback is a nice step in the right direction, but for now I would recommend to use both of those side by side.

 

EDIT: Just rechecked, you might want to keep the macro around for even faster debuggin anyway, since at least on my two PCs there is no way to get the exact line of error from the glDebugMessageCallback, e.g. throwing a exception thrown is kept inside the GPU-driver dlls. With the macro you can assert, throw an exception, set a breakpoint etc.. and be fine. Repeated, use both of them side by side, as its supported in 4.2 I assume it could also work for 3.3, even though the specification tells otherwise.


#2Juliean

Posted 31 March 2014 - 11:16 AM

Since the glDebugMessageCallback​-stuff is rather new and probably not widely supported (I see core in 4.3 when you are using 3.3) it might be well advised to wrap all your opengl-calls with a simple macro:

void CheckOpenGLError(const char* stmt, const char* fname, int line)
{
	GLenum err = glGetError();
	if(err != GL_NO_ERROR)
	{
              // handle error here
	}
}

#ifdef _DEBUG
#define GL_CHECK(stmt) { \
	stmt; \
	CheckOpenGLError(#stmt, __FILE__, __LINE__); \
		}
#else
#define GL_CHECK(stmt) stmt
#endif

Which you can then use:

GL_CHECK(glEnableVertexAttribArray( 0 ));

and it will tell you if something is wrong in debug (compile) mode. You do need to wrap it around EVERY function that you have, or else uncaught error codes will leak to other parts of the program and cause another function to report the error instead. To end with a generic OpenGL-rant: Thats why OpenGLs global error handling and/or global state b... stuff sucks. glDebugMessageCallback is a nice step in the right direction, but for now I would recommend to use both of those side by side.


#1Juliean

Posted 31 March 2014 - 11:16 AM

Since the glDebugMessageCallback​-stuff is rather new and probably not widely supported (I see core in 4.3 when you are using 4.4) it might be well advised to wrap all your opengl-calls with a simple macro:

void CheckOpenGLError(const char* stmt, const char* fname, int line)
{
	GLenum err = glGetError();
	if(err != GL_NO_ERROR)
	{
              // handle error here
	}
}

#ifdef _DEBUG
#define GL_CHECK(stmt) { \
	stmt; \
	CheckOpenGLError(#stmt, __FILE__, __LINE__); \
		}
#else
#define GL_CHECK(stmt) stmt
#endif

Which you can then use:

GL_CHECK(glEnableVertexAttribArray( 0 ));

and it will tell you if something is wrong in debug (compile) mode. You do need to wrap it around EVERY function that you have, or else uncaught error codes will leak to other parts of the program and cause another function to report the error instead. To end with a generic OpenGL-rant: Thats why OpenGLs global error handling and/or global state b... stuff sucks. glDebugMessageCallback is a nice step in the right direction, but for now I would recommend to use both of those side by side.


PARTNERS