Is there a standard way to query EGL error string?

Definitely not as part of EGL itself. And I don't think it should be there. EGL is a low level window system interface. Producing user readable strings is really not its job.

You may think that having a function that produces a few strings is trivial and harmless. But since this would be user readable strings, you would almost have to think about internationalization. Meaning that you could get the strings in various languages, including ones that use different character sets. So what looked simple suddenly becomes much more complex. And at least in my opinion, supporting only English strings would be very arbitrary.

Even more importantly, translating error codes to strings is not conceptually part of an API that provides an interface to a window system. IMHO, these kinds of APIs should be minimal. In this case, it should provide exactly the functionality needed to interface with the window system, and nothing more.

Of course nobody stops you (or anybody else) from implementing a higher level library that provides this kind of functionality. That's exactly what GLU (which is where gluErrorString() came from) was for OpenGL. It provided some commonly used functionality layered on top of OpenGL.

The use of past tense when talking about GLU in the previous paragraph was deliberate. It's built on top of OpenGL functionality from a previous millennium.


Macro stringification can save you some typing:

#define CASE_STR( value ) case value: return #value; 
const char* eglGetErrorString( EGLint error )
{
    switch( error )
    {
    CASE_STR( EGL_SUCCESS             )
    CASE_STR( EGL_NOT_INITIALIZED     )
    CASE_STR( EGL_BAD_ACCESS          )
    CASE_STR( EGL_BAD_ALLOC           )
    CASE_STR( EGL_BAD_ATTRIBUTE       )
    CASE_STR( EGL_BAD_CONTEXT         )
    CASE_STR( EGL_BAD_CONFIG          )
    CASE_STR( EGL_BAD_CURRENT_SURFACE )
    CASE_STR( EGL_BAD_DISPLAY         )
    CASE_STR( EGL_BAD_SURFACE         )
    CASE_STR( EGL_BAD_MATCH           )
    CASE_STR( EGL_BAD_PARAMETER       )
    CASE_STR( EGL_BAD_NATIVE_PIXMAP   )
    CASE_STR( EGL_BAD_NATIVE_WINDOW   )
    CASE_STR( EGL_CONTEXT_LOST        )
    default: return "Unknown";
    }
}
#undef CASE_STR

Tags:

C++

Egl