简体   繁体   English

Android OpenGL ES 2.0是否支持使用扩展的顶点数组对象?

[英]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. 我正在尝试使用Android NDK编写一些在C ++中使用VAO的代码。 I expect to be able to use glDeleteVertexArraysOES , glGenVertexArraysOES , and glBindVertexArrayOES . 我希望能够使用glDeleteVertexArraysOESglGenVertexArraysOESglBindVertexArrayOES

I am including the headers for OpenGL ES 2 and the extensions in my header. 我包括OpenGL ES 2的标题和我标题中的扩展名。

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

I'm also linking to OpenGL ES 2 in Android.mk . 我也在Android.mk链接到OpenGL ES 2。

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 ? 链接器不包括GLES2/gl2ext.h吗?

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... NDK附带的GLES2库可能只包含标准的OpenGL ES 2.0调用,没有任何扩展,每个特定设备/制造商/驱动程序可能支持也可能不支持...

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). 虽然大多数新设备支持VAO,但您可能必须自己获取指向函数的指针,或者获取不同的二进制库(您可以从设备或某些ROM中提取它)。

I had to resort to using this code to get the function pointers from the dylib: 我不得不求助于使用此代码从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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM