# OpenGL ES State Trackers

The current version of the OpenGL ES state trackers implement OpenGL ES 1.1 and OpenGL ES 2.0. More informations about OpenGL ES can be found at http://www.khronos.org/opengles/.

The OpenGL ES state trackers depends on the Gallium architecture and a working EGL implementation. Please refer to Mesa EGL for more information about EGL.

## Build the Libraries

1. Run `configure` with `--with-state-trackers=egl,es` and enable the Gallium driver for your hardware.
2. Build and install Mesa as usual.

It will install libGLESv1_CM, libGLESv2, libEGL, and one or more EGL drivers for your hardware.

## Run the Demos

There are some demos in `progs/es1/` and `progs/es2/`. You can use them to test your build. For example,

      $ cd progs/es1/xegl
      $ make
      $ ./torus

## Developers

The core of OpenGL ES state trackers is the ES overlay. It is located in `src/mesa/es/`.

### Structure

The ES overlay uses as much code as possible from Mesa. It has its own glapi XMLs to describe the APIs of OpenGL ES. The ES overlay can be built parallelly with Mesa, and they will give

Library Name | Usage | Source
libmesagallium.a | OpenGL state tracker | Mesa
libes1gallium.a | OpenGL ES 1.x state tracker | ES overlay
libes2gallium.a | OpenGL ES 2.x state tracker | ES overlay
libglapi.a | OpenGL API | Mesa
libes1api.a | OpenGL ES 1.x API | ES overlay
libes2api.a | OpenGL ES 2.x API | ES overlay

The OpenGL ES state trackers and APIs are then used by `src/gallium/state_trackers/es/` to create the final libraries.

### Dispatch Table

The ES overlay uses an additional indirection when dispatching fucntions

      Mesa:       glFoo() --> _mesa_Foo()
      ES overlay: glFoo() --> _es_Foo() --> _mesa_Foo()

The indirection serves several purposes

- When a function is in Mesa and the type matches, it checks the arguments and calls the Mesa function.
- When a function is in Mesa but the type mismatches, it checks and converts the arguments before calling the Mesa function.
- When a function is not available in Mesa, or accepts arguments that are not available in OpenGL, it provides its own implementation.

Other than the last case, the ES overlay uses `APIspec.xml` to generate functions to check and/or converts the arguments.