0
我試圖使一個應用程序,負載和使用NDK,JNI調用C++代碼顯示圖像。然而,我遇到了一些錯誤,我的着色器出錯了(我使用GLES for OpenGL ES 3.0),它無法編譯,我不知道如何解決它。下面是日誌:GLSL的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";
科倫坡您好,感謝您的回答中約40%的訪問。經過考慮,我想創建一個OpenGLES 3.0上下文並使用#version 330 es。但是,我是OpenGL ES中的新手,所以請你指導我如何創建OpenGLES 3.0上下文?我使用這個例子:https://github.com/googlesamples/android-ndk/tree/master/hello-gl2。 –
看看GL2JNIView.java,createContext,你需要改變那裏的選項。 – Columbo
我將它設置爲 setEGLContextClientVersion(3); 和編輯 我Manifest.xml文件<採用特徵的android:glEsVersion = 「0x00030000」 機器人:要求= 「真」/> 但在啓動應用程序崩潰,任何想法,爲什麼? –