使用扩展的 Android OpenGL ES 2.0 是否支持顶点数组对象? [英] Are Vertex Array Objects supported in Android OpenGL ES 2.0 using extensions?

查看:38
本文介绍了使用扩展的 Android OpenGL ES 2.0 是否支持顶点数组对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Android NDK 编写一些使用 C++ 中的 VAO 进行编译的代码.我希望能够使用 glDeleteVertexArraysOESglGenVertexArraysOESglBindVertexArrayOES.

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.

我在我的标题中包含了 OpenGL ES 2 的头文件和扩展.

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>

我还在 Android.mk 中链接到 OpenGL ES 2.

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'

链接器不包括GLES2/gl2ext.h吗?

推荐答案

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.

希望这会有所帮助.

这篇关于使用扩展的 Android OpenGL ES 2.0 是否支持顶点数组对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆