p3/regal — pull request #34 by adhoc-bobcat (2012-12-19 21:43:11+00:00)
Title: Implement a Texture Conversion Emulation recipe

A patch for issue #31.

Under an GLES2 API (and specifically Pepper implementation of GLES2),
calls to glTexSubImage2D may be required to use a type and format for
the new data that matches the underlying texture type/format, so that
the GLES2 implementation is a simple, straight copy of the data.

This means that in order for Regal to emulate the less strict OpenGL
interface, it must perform texture format conversions when calling a
GLES2 backend.

This patch adds such an emulation recipe, that:

1. Shadows the state of textures, so that Regal knows the underlying
formats, and
2. On a call to glTexSubImage2D, if the caller is passing something that
doesn't match the underlying texture format, Regal will handle the
conversion.

This patch makes a few assumptions that may need to be relaxed with
further changes:

* Only OpenGLES 2.0 compatible texture types and formats are supported.
GL_BGRA and GL_UNSIGNED_BYTE_3_2_2 for example, while easy to add, are
not. Other more general OpenGL formats could be added to, with a bit
more work.
* As per the GLES2.x spec, only GL_UNPACK_ALIGNMENT is assumed to be
relevant.
* To avoid a combinatorial explosion, all texture conversions are too
and from a simple GL_RGBA, GL_UNSIGNED_BYTE intermedate format.