模型法线(或其他)的GLES 2.0错误

时间:2016-01-17 04:45:37

标签: java android opengl-es opengl-es-2.0 google-cardboard

这是我修改Google CardBoard示例的项目: https://github.com/MrCsabaToth/cardboard-java

(我基本上切断了一堆东西:我不需要3D音频反馈,我不会生成立方体。我没有#34;地板" in我的3D模型(下面渲染为网格的大表面),但我在我前面有一个表面(我称之为屏幕),在那里我将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.access$3200(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调试的新手,感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

在我的简单着色器中,我并没有用法线计算。我注意到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;
}

screenModelParamu_Model)和screenModelViewParamu_MVMatrix)仍然是-1,但它们不像u_MVP那样使用,我不会&#39 ; t对他们打电话GLES20.glEnableVertexAttribArray。到目前为止,我现在还没有看到错误消息,但我不明白为什么需要虚拟变量,我想我需要了解有关着色器的更多信息。