gpt4 book ai didi

android - glGetString(GL_VERSION) 返回 "OpenGL ES-CM 1.1"但我的手机支持 OpenGL 2

转载 作者:太空狗 更新时间:2023-10-29 16:16:23 28 4
gpt4 key购买 nike

我正在尝试制作一个基于 NDK 的 OpenGL 应用程序。在我的代码中的某个时刻,我想检查设备上可用的 OpenGL 版本。

我正在使用以下代码:

const char *version = (const char *) glGetString(GL_VERSION);
if (strstr(version, "OpenGL ES 2.")) {
// do something
} else {
__android_log_print(ANDROID_LOG_ERROR, "NativeGL", "Open GL 2 not available (%s)", version=;
}

问题是版本字符串总是等于 "OpenGL ES-CM 1.1"

我正在 Moto G (Android 4.4.4) 和 Samsung Galaxy Nexus (Android 4.3) 上进行测试,两者都兼容 OpenGL ES 2.0(moto G 也兼容 OpenGL ES 3.0)。

我在初始化显示时尝试强制使用 EGL_CONTEXT_CLIENT_VERSION,但随后 eglChooseConfig 返回 0 个配置。当我在默认配置中测试上下文客户端版本值时,它始终为 0 :

const EGLint attrib_list[] = {
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};

// get the number of configs matching the attrib_list
EGLint num_configs;
eglChooseConfig(display, attrib_list, NULL, 0, &num_configs);
LOG_D(TAG, " • %d EGL configurations found", num_configs);

// find matching configurations
EGLConfig configs[num_configs];
EGLint client_version = 0, depth_size = 0, stencil_size = 0, surface_type = 0;
eglChooseConfig(display, requirements, configs, num_configs, &num_configs);
for(int i = 0; i < num_configs; ++i){

eglGetConfigAttrib(display, configs[i], EGL_CONTEXT_CLIENT_VERSION, &client_version);


LOG_D(TAG, " client version %d = 0x%08x", i, client_version);

}

// Update the window format from the configuration
EGLint format;
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(window, 0, 0, format);

// create the surface and context
EGLSurface surface = eglCreateWindowSurface(display, config, window, NULL);
EGLContext context = eglCreateContext(display, config, NULL, NULL);

我正在链接 Open GL ES 2.0 库:这是我的 Android.mk

的摘录
LOCAL_LDLIBS    := -landroid -llog -lEGL -lGLESv2

最佳答案

感谢 mstorsjo 提供的提示,我设法获得了正确的初始化代码,如果其他人对此有困难,我会在此处显示。

const EGLint attrib_list[] = {
// this specifically requests an Open GL ES 2 renderer
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
// (ommiting other configs regarding the color channels etc...
EGL_NONE
};

EGLConfig config;
EGLint num_configs;
eglChooseConfig(display, attrib_list, &config, 1, &num_configs);

// ommiting other codes

const EGLint context_attrib_list[] = {
// request a context using Open GL ES 2.0
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLContext context = eglCreateContext(display, config, NULL, context_attrib_list);

关于android - glGetString(GL_VERSION) 返回 "OpenGL ES-CM 1.1"但我的手机支持 OpenGL 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25843368/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com