70 likes | 234 Views
What is EGL?. EGL is the Khronos -supplied API layer that provides a cross-platform interface that handles interactions between OpenGL and the native windowing system. EGL handles: provides available surface specifications context management surface binding render surface synchronization.
E N D
What is EGL? EGL is the Khronos-supplied API layer that provides a cross-platform interface that handles interactions between OpenGL and the native windowing system. • EGL handles: • provides available surface specifications • context management • surface binding • render surface synchronization
What is EGL? • EGL is an alternative to the OS’s implementation • Windows: wgl • Linux: glx • Mac: egl/agl • You can pretty much ignore EGL if you want, but you’ll need to work with it if you’ll be: • Querying and iterating through all configurations • Querying/selecting buffer formats • Creating additional render targets • Querying for extensions • Using synchronization primitives • The default behavior is not good enough…
Special note on eglChooseConfig() • Since this is in nearly every example on the Internet, you should be aware of what’s going on. • “By default GLSurfaceView chooses a EGLConfig that has an RGB_888 pixel format, with at least a 16-bit depth buffer and no stencil.” • Most code samples just choose the first configuration from the array of configurations. • EGL’s method of sorting configurations returned from queries is often counter-intuitive. Applications using eglChooseConfig must not simply select the first returned configuration, nor should they request only one configuration. An example of a common and confusing case is requesting a 565 RGB configuration. Owing to section 3.4 of the EGL spec, eglChooseConfig must return the deepest color buffer first, even if it is deeper than the requested format, and even if the requested format could have been matched exactly. In other words, an implementation that supports 565 and 8888 must return 8888 earlier in the list than 565, even if 565 is requested. The EGL spec notes the following in a footnote to 3.4: • “This rule places configs with deeper color buffers first in the list returned by eglChooseConfig. Applications may find this counterintuitive, and need to perform additional processing on the list of configs to find one best matching their requirements. For example, specifying RGBA depths of 5651 could return a list whose first config has a depth of 8888.” • Applications should always request an array of multiple configurations, and should query important attributes such as red, green and blue depths of each, performing their own manual sorting and filtering of the resulting array. EGL’s behavior is defined by the spec.
Extensions • like most other programming languages, it’s possible for vendors to put in customizations for their particular platform. • In OpenGL these are called “extensions”, and they are features that extend beyond the current API specification. • They can be from an IHV, from the ARB, an experimental feature, or a modification/clarification to an existing feature. • They are discovered through the glGetString or glGetStringi function calls.
Extensions • Old School (OpenGL-ES 2.0)* • constGLubyte* extensions = glGetString(GL_EXTENSIONS); • This returns a space-separated list of extensions that ends in a null char. Parse however you like. • New School (OpenGL-ES 3.0)* • intmaxExt = 0;glGetIntegerv(GL_NUM_EXTENSIONS, &maxExt);std::vector<std::string> extensions; for (inti = 0; i < maxExt; ++i){extensions.push_back(std::string(glGetStringi(GL_EXTENSIONS, i) )); } * You can’t make OpenGL calls (or query OpenGL indirectly) before you have a context.
Extensions • You then use either the local interface code (e.g. wgl for Windows) or the generic EGL interface. • set up function declaration typedef and create a function pointer variabletypedefvoid (GL_APIENTRYP PFNGLCUR_PAL_MATRIX)(GLuint);PFNGLCUR_PAL_MATRIX fp_glCurrentPaletteMatrixOES; • Get the function pointer using the eglGetProcAddress() method:* • fp_glCurrentPaletteMatrixOES = (PFNGLCUR_PAL_MATRIX)eglGetProcAddress("glCurrentPaletteMatrixOES"); • // Ok to call this method if function pointer is not nullfp_glCurrentPaletteMatrixOES( index ); // Gluint argument * You can’t make OpenGL calls (or query OpenGL indirectly) before you have a context.