Choosing an EGL Configuration#

The following two-step process will demonstrate how to select an EGL configuration which matches the requirements of the application.

Note

An EGL “configuration” describes the capabilities an application requires and the type of surfaces that can be used for drawing.

Each implementation exposes a number of different configurations, and an application needs to describe to EGL what capabilities it requires so that an appropriate one can be chosen.

The first step involves specifying the required configuration attributes by creating an attribute list. This is an array of key/value pairs which describe the particular capabilities requested. In this application nothing special is required, so a minimum set of attributes can be queried. These attributes are: needing the application to be able to render to a window and being OpenGL ES 2.0 capable. The final element here, EGL_NONE, specifies the end of the list.

const EGLint configurationAttributes[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE };

The next and final step simply involves selecting a suitable configuration.

eglChooseConfig is provided by EGL as an easy way to select an appropriate configuration. It takes in the capabilities specified in the attribute list and returns a list of available configurations that match or exceed the capabilities requested.

Details of all the possible attributes and how they are selected for by this function are available in the EGL reference pages here:

http://www.khronos.org/registry/egl/sdk/docs/man/xhtml/eglChooseConfig.html.

It is also possible to get the entire list of configurations and use a custom algorithm to choose a suitable one. Many advanced applications choose to do this. The first EGLConfig that the function returns is well-suited for use in this application. Therefore, the function is limited to returning a single EGLConfig.

EGLint configsReturned;
if ((eglChooseConfig(_eglDisplay, configurationAttributes, &config, 1, &configsReturned) || (configsReturned != 1))
{
    Log(true, "eglChooseConfig() failed.");
    return false;
}
return true;

See also

External: