5

I'm trying to write some code that uses VAOs in C++ using the Android NDK to compile. I expect to be able to use glDeleteVertexArraysOES, glGenVertexArraysOES, and glBindVertexArrayOES.

I am including the headers for OpenGL ES 2 and the extensions in my header.

#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

I'm also linking to OpenGL ES 2 in Android.mk.

LOCAL_LDLIBS += -lGLESv2

But for some reason when the code is being linked, it fails.

undefined reference to 'glDeleteVertexArraysOES'
undefined reference to 'glGenVertexArraysOES'
undefined reference to 'glBindVertexArrayOES'

Is the linker not including GLES2/gl2ext.h?

Cypress Frankenfeld
  • 2,317
  • 2
  • 28
  • 40
  • I checked in the NDK libraries, and the only library I found those calls in (using the `nm` command on Linux) was the GLESv3 library. It obviously has the calls without the `OES` in the name because this is core functionality in ES 3.0. But the form with `OES` is in the same library. I find that somewhat puzzling. I guess you could try adding `-lGLESv3` at the end of `LOCAL_LDLIBS`, and see if something horrible happens. It definitely wouldn't look like a good idea in general. – Reto Koradi Jul 22 '14 at 05:11
  • The funny thing is, -lGLESv3 actually works. My problem: I want to run it on the emulator, which doesn't support OpenGL ES 3. – Cypress Frankenfeld Jul 22 '14 at 15:04

1 Answers1

8

The GLES2 library that gets included with NDK may only include the standard OpenGL ES 2.0 calls, without any extensions that may or may not be supported by each particular device/manufacturer/driver...

While most new devices support VAO, you may have to get the pointers to the functions yourself, or get a different binary library (you can extract it from your device, or from some ROM).

I had to resort to using this code to get the function pointers from the dylib:

//these ugly typenames are defined in GLES2/gl2ext.h
PFNGLBINDVERTEXARRAYOESPROC bindVertexArrayOES;
PFNGLDELETEVERTEXARRAYSOESPROC deleteVertexArraysOES;
PFNGLGENVERTEXARRAYSOESPROC genVertexArraysOES;
PFNGLISVERTEXARRAYOESPROC isVertexArrayOES;

void initialiseFunctions () {

//[check here that VAOs are actually supported]

void *libhandle = dlopen("libGLESv2.so", RTLD_LAZY);

bindVertexArrayOES = (PFNGLBINDVERTEXARRAYOESPROC) dlsym(libhandle,
                                                         "glBindVertexArrayOES");
deleteVertexArraysOES = (PFNGLDELETEVERTEXARRAYSOESPROC) dlsym(libhandle,
                                                               "glDeleteVertexArraysOES");
genVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)dlsym(libhandle,
                                                        "glGenVertexArraysOES");
isVertexArrayOES = (PFNGLISVERTEXARRAYOESPROC)dlsym(libhandle,
                                                    "glIsVertexArrayOES");

[...]
}

I define these function pointers inside a static object. There may be better ways of doing it, but this has worked for me so far.

Hope this helps.

user1906
  • 2,310
  • 2
  • 20
  • 37