本文介绍了glGetString(GL_VERSION)的回报"的OpenGL ES-CM 1.1"但我的手机支持OpenGL 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个基于NDK OpenGL应用程序。在我的code某一点上,我要检查的设备上可用的OpenGL的版本。

我用下面的code:

 为const char *版本=(为const char *)glGetString(GL_VERSION);
如果(的strstr(版本的OpenGL ES 2)){
    // 做一点事
}其他{
    __android_log_print(ANDROID_LOG_ERRORNativeGL,Open GL的2不可用(%S),版本=;
}

问题是该版本字符串始终等于的OpenGL ES-CM 1.1

我测试上都有了摩托G(Android版4.4.4)和三星GALAXY Nexus(Android 4.3的),这两者都是OpenGL ES 2.0的兼容(moto的G是同样的OpenGL ES 3.0标准)。

我试图强迫 EGL_CONTEXT_CLIENT_VERSION 当我初始化我的显示器,但随后eglChooseConfig返回0配置。而当我测试在默认配置情况下客户端版本的价值,它总是0:

 常量EGLint attrib_list [] = {
        EGL_BLUE_SIZE,8,
        EGL_GREEN_SIZE,8,
        EGL_RED_SIZE,8,
        EGL_NONE
};//获取CONFIGS的匹配attrib_list数
EGLint num_configs;
eglChooseConfig(显示,attrib_list,NULL,0,&安培; num_configs);
LOG_D(TAG,发现•%d个EGL配置,num_configs);//查找匹配的配置
EGLConfig CONFIGS [num_configs]
EGLint client_version = 0,depth_size = 0,stencil_size = 0,surface_type = 0;
eglChooseConfig(显示器,要求,CONFIGS,num_configs,&安培; num_configs);
的for(int i = 0; I< num_configs ++我){    eglGetConfigAttrib(显示,CONFIGS [I],EGL_CONTEXT_CLIENT_VERSION,&安培; client_version);
    LOG_D(TAG,客户端版本%D =为0x%08X,我,client_version);}//更新从配置窗口格式
EGLint格式;
eglGetConfigAttrib(显示器,配置,EGL_NATIVE_VISUAL_ID,&安培;格式);
ANativeWindow_setBuffersGeometry(窗口,0,0,格式);//创建面和上下文
EGLSurface表面= eglCreateWindowSurface(显示器,配置,窗,NULL);
EGLContext上下文= eglCreateContext(显示器,配置,NULL,NULL);

我对链接的的Open GL ES 2.0库:这里是从我的节选 Android.mk

  LOCAL_LDLIBS:= -landroid -llog -lEGL -lGLESv2


解决方案

您从 glGetString得到什么版本(GL_VERSION)取决于您链接的$ C哪个库针对$ C,无论是 libGLESv1_CM.so libGLESv2.so 。同样,对于所有的其他常见总帐的功能。这意味着,在实践中,你需要建立你的GL ES 1两个独立的.so文件和2个版本的渲染,只有一次,你知道你可以使用其中的一个加载正确的(或动态加载函数指针)。 (这个有GL ES 2和3,在这里你可以查看使用之间的兼容性时,显然是不同的 glGetString(GL_VERSION)

您没有说,你尝试使用 EGL_CONTEXT_CLIENT_VERSION - 它应该参数数组中使用 eglCreateContext (一旦你真正选择了配置,你只调用)。考虑到 eglChooseConfig 属性数组应具有对 EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT 来获得一个合适的配置。

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.

这篇关于glGetString(GL_VERSION)的回报&QUOT;的OpenGL ES-CM 1.1&QUOT;但我的手机支持OpenGL 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:36