6

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.

Mike Weir
  • 3,094
  • 1
  • 30
  • 46

2 Answers2

3

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;
  }
}
user1095108
  • 14,119
  • 9
  • 58
  • 116
2

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).

Arttu Peltonen
  • 1,250
  • 14
  • 18
  • I don't think there's anything similar to GLU library for EGL afaik, you'll probably have to do that manually anyway. But again, there's only a few errors to handle. – Arttu Peltonen Aug 25 '13 at 16:39
  • I suppose so. And yeah, I have to do Android manually too, because gluGetError() isn't exposed. I did end up finding this though: https://code.google.com/p/glues/ – Mike Weir Aug 25 '13 at 17:22
  • Note that iOS link is broken. – Alexis Wilke Sep 21 '20 at 06:19