Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Vertex Array Objects supported in Android OpenGL ES 2.0 using extensions?

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?

like image 874
Cypress Frankenfeld Avatar asked Jul 21 '14 21:07

Cypress Frankenfeld


1 Answers

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.

like image 63
user1906 Avatar answered Oct 13 '22 03:10

user1906