且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-08 10:22:04

NDK 中包含的 GLES2 库可能仅包含标准的 OpenGL ES 2.0 调用,而没有任何特定设备可能支持或不支持的扩展/制造商/司机...

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...

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

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).

我不得不求助于使用此代码从 dylib 中获取函数指针:

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.

希望这会有所帮助.