模型法线(或其他东西)的 GLES 2.0 错误
GLES 2.0 error with model normals (or something else)
这是我修改 Google CardBoard 示例的项目:
https://github.com/MrCsabaToth/cardboard-java
(我基本上砍掉了一堆东西:我不需要 3D 音频反馈,我不生成立方体。我的 3D 模型中没有 "floor"(大表面下面呈现为网格),但我前面有一个表面(我称之为屏幕),我将 png 图像渲染为纹理。因此着色器(片段和顶点)也非常简单。)
不幸的是我在修改过程中做错了什么,我无法弄清楚它是什么。
如果我取消注释 MainActivity (https://github.com/MrCsabaToth/cardboard-java/blob/master/CardboardSample/src/main/java/com/google/vrtoolkit/cardboard/samples/treasurehunt/MainActivity.java#L289) 中的第 289 行 (GLES20.glEnableVertexAttribArray(screenNormalParam);
),应用程序会在启动后崩溃:
01-16 20:17:40.325 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt I/OpenGLRenderer: Initialized EGL, version 1.4
01-16 20:17:40.355 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt I/OpenGLRenderer: HWUI protection enabled for context , &this =0xaf440088 ,&mEglDisplay = 1 , &mEglConfig = 8
01-16 20:17:40.355 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt D/OpenGLRenderer: Enabling debug mode 0
01-16 20:17:40.485 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt I/MainActivity: onSurfaceCreated
01-16 20:17:40.515 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt V/RenderScript: Application requested CPU execution
01-16 20:17:40.525 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt W/Adreno-ES20: <core_glEnableVertexAttribArray:193>: GL_INVALID_VALUE
01-16 20:17:40.525 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt E/MainActivity: Screen program params: glError 1281
01-16 20:17:40.535 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt V/RenderScript: 0xa126c400 Launching thread(s), CPUs 4
01-16 20:17:40.545 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt E/AndroidRuntime: FATAL EXCEPTION: GLThread 231450
Process: com.google.vrtoolkit.cardboard.samples.treasurehunt, PID: 9167
java.lang.RuntimeException: Screen program params: glError 1281
at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.checkGLError(MainActivity.java:177)
at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.onSurfaceCreated(MainActivity.java:292)
at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl$RendererHelper.callOnSurfaceCreated(CardboardViewNativeImpl.java:811)
at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl$RendererHelper.onSurfaceCreated(CardboardViewNativeImpl.java:832)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
我的主要问题是我并没有真正得到任何关于错误的更详细信息,glError 1281
非常广泛。通过反复试验,我发现在评论第 289 行(上面提到的)之后,应用程序开始运行并且看起来像在运行,但它充斥着 LogCat 这个(不好):
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/Adreno-ES20: <core_glVertexAttribPointer:533>: GL_INVALID_VALUE
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt E/MainActivity: drawing screen: glError 1281
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: java.lang.RuntimeException: drawing screen: glError 1281
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.checkGLError(MainActivity.java:177)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.drawScreen(MainActivity.java:406)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.onDrawEye(MainActivity.java:368)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl.nativeOnDrawFrame(Native Method)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl.access00(CardboardViewNativeImpl.java:52)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl$RendererHelper.onDrawFrame(CardboardViewNativeImpl.java:741)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
调用堆栈将我引向 checkGLError
,这将我引向通用 glError 1281
。我是 OpenGL 调试的新手,感谢任何帮助。
在我的简单着色器中,我实际上并没有使用法线进行计算。我注意到 screenNormalParam
整数的值为 -1。我修改了顶点着色器并添加了一个 varying vec3 v_Normal
变量。我仍然没有将这个变量用于任何计算,因为闪电对我的应用程序无关紧要,但我只是做了一个虚拟赋值 v_Normal = a_Normal
:
uniform mat4 u_Model;
uniform mat4 u_MVMatrix;
uniform mat4 u_MVP;
attribute vec4 a_Position;
attribute vec3 a_Normal;
attribute vec2 a_TexCoordinate;
varying vec2 v_TexCoordinate;
varying vec3 v_Normal;
void main() {
v_TexCoordinate = a_TexCoordinate;
v_Normal = a_Normal;
gl_Position = u_MVP * a_Position;
}
screenModelParam
(u_Model
)和screenModelViewParam
(u_MVMatrix
)仍然是-1,但它们不像u_MVP
那样使用,我不'对他们打电话 GLES20.glEnableVertexAttribArray
。到目前为止,我现在没有看到错误消息,但我不明白为什么需要虚拟变量,我想我需要了解更多有关着色器的知识。
这是我修改 Google CardBoard 示例的项目: https://github.com/MrCsabaToth/cardboard-java
(我基本上砍掉了一堆东西:我不需要 3D 音频反馈,我不生成立方体。我的 3D 模型中没有 "floor"(大表面下面呈现为网格),但我前面有一个表面(我称之为屏幕),我将 png 图像渲染为纹理。因此着色器(片段和顶点)也非常简单。)
不幸的是我在修改过程中做错了什么,我无法弄清楚它是什么。
如果我取消注释 MainActivity (https://github.com/MrCsabaToth/cardboard-java/blob/master/CardboardSample/src/main/java/com/google/vrtoolkit/cardboard/samples/treasurehunt/MainActivity.java#L289) 中的第 289 行 (GLES20.glEnableVertexAttribArray(screenNormalParam);
),应用程序会在启动后崩溃:
01-16 20:17:40.325 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt I/OpenGLRenderer: Initialized EGL, version 1.4
01-16 20:17:40.355 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt I/OpenGLRenderer: HWUI protection enabled for context , &this =0xaf440088 ,&mEglDisplay = 1 , &mEglConfig = 8
01-16 20:17:40.355 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt D/OpenGLRenderer: Enabling debug mode 0
01-16 20:17:40.485 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt I/MainActivity: onSurfaceCreated
01-16 20:17:40.515 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt V/RenderScript: Application requested CPU execution
01-16 20:17:40.525 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt W/Adreno-ES20: <core_glEnableVertexAttribArray:193>: GL_INVALID_VALUE
01-16 20:17:40.525 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt E/MainActivity: Screen program params: glError 1281
01-16 20:17:40.535 9167-9305/com.google.vrtoolkit.cardboard.samples.treasurehunt V/RenderScript: 0xa126c400 Launching thread(s), CPUs 4
01-16 20:17:40.545 9167-9302/com.google.vrtoolkit.cardboard.samples.treasurehunt E/AndroidRuntime: FATAL EXCEPTION: GLThread 231450
Process: com.google.vrtoolkit.cardboard.samples.treasurehunt, PID: 9167
java.lang.RuntimeException: Screen program params: glError 1281
at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.checkGLError(MainActivity.java:177)
at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.onSurfaceCreated(MainActivity.java:292)
at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl$RendererHelper.callOnSurfaceCreated(CardboardViewNativeImpl.java:811)
at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl$RendererHelper.onSurfaceCreated(CardboardViewNativeImpl.java:832)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
我的主要问题是我并没有真正得到任何关于错误的更详细信息,glError 1281
非常广泛。通过反复试验,我发现在评论第 289 行(上面提到的)之后,应用程序开始运行并且看起来像在运行,但它充斥着 LogCat 这个(不好):
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/Adreno-ES20: <core_glVertexAttribPointer:533>: GL_INVALID_VALUE
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt E/MainActivity: drawing screen: glError 1281
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: java.lang.RuntimeException: drawing screen: glError 1281
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.checkGLError(MainActivity.java:177)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.drawScreen(MainActivity.java:406)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.onDrawEye(MainActivity.java:368)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl.nativeOnDrawFrame(Native Method)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl.access00(CardboardViewNativeImpl.java:52)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at com.google.vrtoolkit.cardboard.CardboardViewNativeImpl$RendererHelper.onDrawFrame(CardboardViewNativeImpl.java:741)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
01-16 16:38:57.984 30664-30723/com.google.vrtoolkit.cardboard.samples.treasurehunt W/System.err: at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
调用堆栈将我引向 checkGLError
,这将我引向通用 glError 1281
。我是 OpenGL 调试的新手,感谢任何帮助。
在我的简单着色器中,我实际上并没有使用法线进行计算。我注意到 screenNormalParam
整数的值为 -1。我修改了顶点着色器并添加了一个 varying vec3 v_Normal
变量。我仍然没有将这个变量用于任何计算,因为闪电对我的应用程序无关紧要,但我只是做了一个虚拟赋值 v_Normal = a_Normal
:
uniform mat4 u_Model;
uniform mat4 u_MVMatrix;
uniform mat4 u_MVP;
attribute vec4 a_Position;
attribute vec3 a_Normal;
attribute vec2 a_TexCoordinate;
varying vec2 v_TexCoordinate;
varying vec3 v_Normal;
void main() {
v_TexCoordinate = a_TexCoordinate;
v_Normal = a_Normal;
gl_Position = u_MVP * a_Position;
}
screenModelParam
(u_Model
)和screenModelViewParam
(u_MVMatrix
)仍然是-1,但它们不像u_MVP
那样使用,我不'对他们打电话 GLES20.glEnableVertexAttribArray
。到目前为止,我现在没有看到错误消息,但我不明白为什么需要虚拟变量,我想我需要了解更多有关着色器的知识。