8

According to the Khronos OpenGL ES Registry, the extension header for GLES 3.0 is actually <GLES2/gl2ext.h>. gl3ext.h should be empty and provided only for legacy compatibility. Thus, if you want to include GLES 3.0 headers, you should do:

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

However, compiling with the Android NDK, it appears that that version of the gl2ext.h internally does #include <GLES2/gl2.h>, giving the following error *(I am compiling with 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);

This is because the prototype of glShaderSource changed from GLES 2.0 to GLES 3.0 core. Is this an error in the Android NDK version of the glext headers, or am I not doing something properly?

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • 3
    Could you use the GLES headers from a later platform? The gl2.h header from android-21 appears to have been changed in such a way that its prototypes won't be included if you've included gl3.h before gl2.h gets included. – Michael Jun 23 '15 at 15:28
  • @Michael Yes, this appears 'fixed' in API-21... unfortunately, this is for a library that could be recompiled. I don't necessarily know the API level ahead of time (and it could be 19). – MuertoExcobito Jun 23 '15 at 15:37
  • 1
    Well, you could place the same kind of guards in your older headers. Unless it's a requirement that you use a "clean" set of NDK headers. – Michael Jun 23 '15 at 15:38
  • 1
    What is the gl2ext.h, why is it needed? – Viktor Sehr Aug 27 '15 at 17:54

1 Answers1

10

Based on Michael's comments, I've found that this is fixed in API-21. However, if you still need to use API-18 or API-19, there is a work-around. You can simply:

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

When gl2ext.h includes gl2.h, the defined include guard will cause the contents of gl2.h to be skipped.

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78