GLES 3.0 包括 gl2ext.h

GLES 3.0 including gl2ext.h

根据 Khronos OpenGL ES Registry,GLES 3.0 的扩展 header 实际上是 <GLES2/gl2ext.h>gl3ext.h 应为空,仅为了兼容旧版而提供。因此,如果你想包含 GLES 3.0 headers,你应该这样做:

#include <GLES3/gl3.h>
#include <GLES2/gl2ext.h>

但是,使用 Android NDK 进行编译时,似乎 gl2ext.h 的那个版本在内部执行 #include <GLES2/gl2.h>,给出以下错误 *(我正在使用 API-19):

C:\android-ndk-r10e\platforms\android-19\arch-arm\usr\include\GLES2\gl2ext.h(6): includes this header: 
C:\android-ndk-r10e\platforms\android-19\arch-arm\usr\include\GLES2\gl2.h(572,37): error : conflicting types for 'glShaderSource'
GL_APICALL void         GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar** string, const GLint* length);
                                    ^
C:\android-ndk-r10e\platforms\android-19\arch-arm\usr\include\GLES3\gl3.h(905,39):  note: previous declaration is here
GL_APICALL void           GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length);

这是因为glShaderSource的原型从GLES 2.0变成了GLES 3.0核心。这是 glext headers 的 Android NDK 版本中的错误,还是我没有正确执行某些操作?

根据 Michael 的评论,我发现此问题已在 API-21 中修复。但是,如果您仍然需要使用 API-18 或 API-19,则有一个解决方法。您可以简单地:

#define __gl2_h_
#include <GLES2/gl2ext.h>

当gl2ext.h包含gl2.h时,定义的include guard会导致跳过gl2.h的内容。