I’m trying to use the
GL_EXT_color_buffer_half_float OpenGL ES 2.0 extension with a native Android NDK application. OpenGL ES 2.0 extensions are defined in the
<GLES2/gl2ext.h> header. The problem is that the
GL_EXT_color_buffer_half_float extension isn’t defined in the
<GLES2/gl2ext.h> header until Android API level 21**, which corresponds to Android 5.0 “Lollipop”. Previous versions of the header don’t define the
GL_EXT_color_buffer_half_float extension so when I try to compile against an earlier API level (like 10 or 14) I get an undeclared identifier error:
error: use of undeclared identifier 'GL_RGBA16F_EXT'
If I go to the
<GLES2/gl2ext.h> header from API level 21 and copy out the
GL_EXT_color_buffer_half_float extension and put it in my own header:
#ifndef GL_EXT_color_buffer_half_float #define GL_EXT_color_buffer_half_float 1 #define GL_RGBA16F_EXT 0x881A #define GL_RGB16F_EXT 0x881B #define GL_RG16F_EXT 0x822F #define GL_R16F_EXT 0x822D #define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT 0x8211 #define GL_UNSIGNED_NORMALIZED_EXT 0x8C17 #endif /* GL_EXT_color_buffer_half_float */
Then everything appears to be working correctly. We do check to make sure that the
GL_EXT_color_buffer_half_float is actually available on a device before using it so we shouldn’t ever run code that uses it on a device that doesn’t support the extension. However, this seems like a horrible, ugly hack.
Is there a better way to do this? What’s the “correct” way to use an OpenGL extension that isn’t included in the
<GLES2/gl2ext.h> header but is supported by the OS/device?
**Note: I tried compiling our app using API level 21, however when I do this the app doesn’t run on older devices (Android 4.4, API level 20). It only runs on Android 5.0 devices. I’m not sure yet if this is a problem with our app or if this just isn’t even possible. Does anyone know if it’s even possible for an app compiled using the NDK API level 21 to run on older API versions?