Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES Error to String

Is there a standard for getting an error string from glGetError() (Android and iOS) and eglGetError() (Android) in OpenGL ES 1.1 or 2.0?

I'm using something like this:

#define AssertGL(x) { x; GLenum __gle = glGetError(); Assert(__gle == GL_NO_ERROR); }

Would be nice to enhance this to provide text to the debugger rather than having to look up the GLenum manually of the returned value stored in __gle.

like image 611
Mike Weir Avatar asked Aug 19 '13 17:08

Mike Weir


2 Answers

Just follow the specs, GL is cross-platform:

char const* gl_error_string(GLenum const err) noexcept
{
  switch (err)
  {
    // opengl 2 errors (8)
    case GL_NO_ERROR:
      return "GL_NO_ERROR";

    case GL_INVALID_ENUM:
      return "GL_INVALID_ENUM";

    case GL_INVALID_VALUE:
      return "GL_INVALID_VALUE";

    case GL_INVALID_OPERATION:
      return "GL_INVALID_OPERATION";

    case GL_STACK_OVERFLOW:
      return "GL_STACK_OVERFLOW";

    case GL_STACK_UNDERFLOW:
      return "GL_STACK_UNDERFLOW";

    case GL_OUT_OF_MEMORY:
      return "GL_OUT_OF_MEMORY";

    case GL_TABLE_TOO_LARGE:
      return "GL_TABLE_TOO_LARGE";

    // opengl 3 errors (1)
    case GL_INVALID_FRAMEBUFFER_OPERATION:
      return "GL_INVALID_FRAMEBUFFER_OPERATION";

    // gles 2, 3 and gl 4 error are handled by the switch above
    default:
      assert(!"unknown error");
      return nullptr;
  }
}
like image 130
user1095108 Avatar answered Sep 19 '22 16:09

user1095108


Try this on Android: http://developer.android.com/reference/android/opengl/GLU.html#gluErrorString(int) and this on iOS: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/gluErrorString.3.html

If those don't work for you, you can always create your own mapping from the integer error value to a corresponding string - it should be easy since there's only a handful of error values. Just look up the error values from the gl2.h and gl.h headers (they start with 0x05).

like image 42
Arttu Peltonen Avatar answered Sep 18 '22 16:09

Arttu Peltonen