无法在 nexus 6(和类似设备)上编译 gles 30

can't compile gles 30 on nexus 6 (and similar devices)

我 运行 遇到了一个对我来说意义不大的问题。我正在 HTC 的 Nexus 6 设备上测试一些简单的 GLES30 代码。我将代码设置为 API 23 和 OS lollipop 5.0。根据 wiki,它使用支持完整 gles 3.1 配置文件的 Adreno 420

https://en.wikipedia.org/wiki/Nexus_6

然而,一个简单的着色器编译失败如下:

着色器代码:

#version 300 es

layout(location = 4) in vec4 a_position;
layout(location = 5) in vec4 a_color;

uniform mat4    u_mvpMatrix;
out     vec4    v_color;

void main()
{
    v_color = a_color;
    gl_Position = u_mvpMatrix * a_position;
}

日志:

Vertex shader failed to compile with the following errors:
ERROR: 0:2: error(#308) Profile " " is not available in shader version 1777753240
ERROR: 0:1: error(#132) Syntax error: "es" parse error
ERROR: error(#273) 2 compilation errors.  No code generated

我将上下文设置为 3.0,如下所示。

const EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION,
                            3,  // Request opengl ES3.0
                            EGL_NONE};
context_ = eglCreateContext(display_, config_, NULL, context_attribs);

仍然没有编译。

我是不是漏掉了什么?

谢谢!

通常这意味着您的设备不支持您需要的 GLSL 版本。尝试运行以下代码以确认 GLSL 版本支持 GLSL 3。

glGetString(GL_SHADING_LANGUAGE_VERSION);

here你可以决定如何阅读这个格式。

The GL_VERSION and GL_SHADING_LANGUAGE_VERSION strings begin with a version number. The version number uses one of these forms: major_number.minor_number major_number.minor_number.release_number Vendor-specific information may follow the version number. Its format depends on the implementation, but a space always separates the version number and the vendor-specific information.

这是我目前使用的配置。

#define EGL_OPENGL_ES3_BIT_KHR 0x0040
const EGLint attribs[] = {
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_BLUE_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_RED_SIZE, 8,
    EGL_ALPHA_SIZE, 8,
    EGL_DEPTH_SIZE, 8,
    EGL_STENCIL_SIZE, 8,
    EGL_NONE
};
...
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
...
EGLint openGLVersionRequested = 3; 
EGLint contextAttribs[] = {
    EGL_CONTEXT_CLIENT_VERSION,
    openGLVersionRequested,      // selects OpenGL ES 3.0, set to 2 to select OpenGL ES 2.0
    EGL_NONE
};
context = eglCreateContext(display, config, NULL, contextAttribs);
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
    LOGW("Unable to eglMakeCurrent");
    return -1;
}