博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
glGetString(GL_VERSION) returns “OpenGL ES-CM 1.1” but my phone supports OpenGL 2
阅读量:6262 次
发布时间:2019-06-22

本文共 3084 字,大约阅读时间需要 10 分钟。

 

【问】

I'm trying to make an NDK based OpenGL application. At some point in my code, I want to check the OpenGL version available on the device.

I'm using the following code :

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=;

}

THe problem is that the version string is always equals to "OpenGL ES-CM 1.1".

I'm testing on both a Moto G (Android 4.4.4) and Samsung Galaxy Nexus (Android 4.3), both of which are OpenGL ES 2.0 compliant (the moto G is also OpenGL ES 3.0 compliant).

I tried to force the EGL_CONTEXT_CLIENT_VERSION when I initialise my display, but then eglChooseConfig returns 0 configurations. And when I test the context client version value in the default configuration, it's always 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);

I'm linking against the Open GL ES 2.0 library : here's the excerpt from my Android.mk

LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2

 

【答】

What version you get from glGetString(GL_VERSION) depends on which library you've linked the code against, either libGLESv1_CM.so or libGLESv2.so. Similarly for all the other common GL functions. This means that in practice, you need to build two separate .so files for your GL ES 1 and 2 versions of your rendering, and only load the right one once you know which one of them you can use (or load the function pointers dynamically). (This apparently is different when having compatibility between GL ES 2 and 3, where you can check using glGetString(GL_VERSION).)

You didn't say where you tried using EGL_CONTEXT_CLIENT_VERSION - it should be used in the parameter array to eglCreateContext (which you only call once you actually have chosen a config). The attribute array given to eglChooseConfig should have the pair EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT to get a suitable config.

 

 

来自:https://stackoverflow.com/questions/25843368/glgetstringgl-version-returns-opengl-es-cm-1-1-but-my-phone-supports-opengl

转载地址:http://tpzpa.baihongyu.com/

你可能感兴趣的文章
浅谈尾递归
查看>>
追踪解析 Disruptor 源码
查看>>
CSS-伪类选择器(未完待续。。。)
查看>>
Markdown常用标记使用
查看>>
使用 Docker 部署 Spring Boot项目
查看>>
高清的GIF表情包如何制作
查看>>
mysql-存储过程
查看>>
flac格式转换mp3格式要用什么软件
查看>>
黑客图标
查看>>
JavaScript数据结构与算法——集合
查看>>
DevOps自动化工具集合
查看>>
公共DNS服务器整理
查看>>
Linux快速配置 VIM 实现语法高亮 补全 缩进等功能
查看>>
Alain 菜单权限控制
查看>>
共享本地项目
查看>>
聊聊flink的BlobStoreService
查看>>
275. H-Index II
查看>>
【Leetcode】103. 二叉树的锯齿形层次遍历
查看>>
关于 synchronizeOnSession
查看>>
git status将文件状态标为renamed问题探究
查看>>