Game Development Reference
In-Depth Information
4. On Android, we deine a thunk function:
void Emulate_glClearDepth( double Depth )
{
glClearDepthf( static_cast<float>( Depth ) );
}
5.
This function emulates the
glClearDepth()
call of OpenGL 3 using the
glClearDepthf()
call of OpenGL ES 3. Now things are simple again. There
are some GL3 functions that cannot be trivially emulated on GLES3. We can
now easily implement empty stubs for them, for example:
void Emulate_glPolygonMode( GLenum, GLenum )
{
// not supported
}
Unimplemented features in this case will disable some rendering capabilities; but the
application will run ine, while gracefully degrading on GLES2. Some more complicated
aspects, such as multiple render targets using
glBindFragDataLocation()
, will still
require us to select different shader programs and code paths for OpenGL 3 and OpenGL
ES 2. However, this is now doable.
How it works…
The
sLGLAPI
binding code is implemented in the
GetAPI()
function. The Windows version
that was described in previous recipes was simple
.DLL
loading code. The Android version
is even simpler. Since our application is linked statically with the OpenGL ES 2 library, we just
assign function pointers to the ields of
sLGLAPI
, except the calls that are not present in
OpenGL ES 2:
void GetAPI( sLGLAPI* API ) const
{
API->glActiveTexture = &glActiveTexture;
API->glAttachShader = &glAttachShader;
API->glBindAttribLocation = &glBindAttribLocation;
…
Instead, we use stubs for them, as described previously:
API->glClearDepth = &Emulate_glClearDepth;
API->glBindFragDataLocation = &Emulate_glBindFragDataLocation;
…