用于OpenGL ES 3.0的GLSL,无法编译着色器:不支持的着色器版本

时间:2017-02-14 06:40:26

标签: opengl-es shader

我正在尝试创建一个使用NDK加载和显示图像的应用程序,JNI来调用C ++代码。但是,我遇到了一些错误,我的着色器出了问题(我正在使用GLES for OpenGL ES 3.0)并且它无法编译,我不知道如何修复它。这是日志:

02-14 15:53:37.523 6379-6379/? I/art: Not late-enabling -Xcheck:jni (already on)
02-14 15:53:37.523 6379-6379/? W/art: Unexpected CPU variant for X86 using defaults: x86
02-14 15:53:37.990 6379-6398/com.android.gl2jni I/OpenGLRenderer: Initialized EGL, version 1.4
02-14 15:53:37.990 6379-6398/com.android.gl2jni D/OpenGLRenderer: Swap behavior 1
02-14 15:53:38.119 6379-6398/com.android.gl2jni E/EGL_emulation: tid 6398: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
02-14 15:53:38.119 6379-6398/com.android.gl2jni W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9b67fa80, error=EGL_BAD_MATCH
02-14 15:53:38.166 6379-6397/com.android.gl2jni E/libc: Access denied finding property "ro.opengles.version"
02-14 15:53:38.172 6379-6397/com.android.gl2jni I/libgl2jni: GL Version = OpenGL ES 2.0 (4.3.0 - Build 10.18.14.4414)
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: GL Vendor = Google (Intel)
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: GL Renderer = Android Emulator OpenGL ES Translator (Intel(R) HD Graphics 4400)
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: GL Extensions = GL_EXT_debug_marker GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8 ANDROID_EMU_CHECKSUM_HELPER_v1 
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: setupGraphics(1080, 1776)
02-14 15:53:38.179 6379-6397/com.android.gl2jni E/libgl2jni: Could not compile shader 35633:
                                                             ERROR: unsupported shader version
02-14 15:53:38.179 6379-6397/com.android.gl2jni E/libgl2jni: Could not create program.
02-14 15:53:38.183 6379-6397/com.android.gl2jni I/libgl2jni: after glClearColor() glError (0x502)
02-14 15:53:38.184 6379-6397/com.android.gl2jni I/libgl2jni: after glClearColor() glError (0x501)

CPP文件中的我的顶点着色器:

auto gVertexShader =
"#version 300 es\n"
"layout (location = 0) in vec3 position;\n"
"layout (location = 1) in vec3 color;\n"
"layout (location = 2) in vec2 texCoord;\n"

"out vec3 ourColor;\n"
"out vec2 TexCoord;\n"

"void main()\n"
"{\n"
    "gl_Position = vec4(position,1.0f); // Add the xOffset to the x position of the vertex position\n"
    "ourColor = color;\n"
    "TexCoord= vec2(texCoord.x,1.0f-texCoord.y);\n"
"}";

我在CPP文件中的片段着色器:

auto gFragmentShader =

"#version 300 es\n"
"in vec3 ourColor;\n"
"in vec2 TexCoord;\n"

"out vec4 color;\n"

"uniform sampler2D ourTexture;\n"


"void main()\n"
"{\n"
    "color = texture2D(ourTexture , TexCoord);\n"
"}\n";

1 个答案:

答案 0 :(得分:0)

版本330不是OpenGLES 2.0上下文的有效GLSL版本号。

讨论了here的GLSL版本。对于OpenGLES 2.0上下文,您需要使用#version 100,它类似于桌面版本120,您的着色器代码在它可以工作之前需要进行一些更改。或者你可以创建一个OpenGLES 3.0上下文并使用" #version 330 es"但是你将无法访问大约40%的Android设备(source