0

画面にテクスチャ付きの正方形を描画しようとしていますが、使用しようとすると常に と が表示さglGetAttribLocationruntimeExceptionますglError 1280。Samsung Galaxy S 3 などの新しいエンド デバイスでテストしたときに、エラーが見つからなかった理由がわかりません。しかし、私のテストデバイスの残りの部分では、このエラーが表示され続けました。

ここに私の頂点シェーダーがあります:

uniform mat4 uMVPMatrix;
attribute vec4 aPosition;     
attribute vec2 aTextureCoord;
varying vec2 vTextureCoord;
void main() {

gl_Position = uMVPMatrix * aPosition;
vTextureCoord = aTextureCoord;

}

そして私のフラグメントシェーダー:

precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D sTexture;
void main() {

 gl_FragColor = texture2D(sTexture, vTextureCoord);

}

そして、これがエラーが発生する場所です:

    private void initProgram() {
    mProgram = createProgram(mVertexShader, mFragmentShader);
    if (mProgram == 0) {
        return;
    }
    maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
    checkGlError("glGetAttribLocation aPosition");
    if (maPositionHandle == -1) {
        throw new RuntimeException(
                "Could not get attrib location for aPosition");
    }
    maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
    checkGlError("glGetAttribLocation aTextureCoord");
    if (maTextureHandle == -1) {
        throw new RuntimeException(
                "Could not get attrib location for aTextureCoord");
    }

    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    checkGlError("glGetUniformLocation uMVPMatrix");
    if (muMVPMatrixHandle == -1) {
        throw new RuntimeException(
                "Could not get attrib location for uMVPMatrix");
    }

}

GLError をチェックすると、次の例外が発生します。

12-31 21:07:56.836: E/ChizEngine(27809): glGetAttribLocation aPosition: glError 1280
12-31 21:07:56.856: W/dalvikvm(27809): threadid=9: thread exiting with uncaught exception (group=0x4001d560)
12-31 21:07:56.856: E/AndroidRuntime(27809): FATAL EXCEPTION: GLThread 10
12-31 21:07:56.856: E/AndroidRuntime(27809): java.lang.RuntimeException: glGetAttribLocation aPosition: glError 1280
12-31 21:07:56.856: E/AndroidRuntime(27809):    at test.projects.ogc.util.GLHelper.checkGlError(GLHelper.java:13)
12-31 21:07:56.856: E/AndroidRuntime(27809):    at test.projects.ogc.objects.GameObject.initProgram(GameObject.java:168)
12-31 21:07:56.856: E/AndroidRuntime(27809):    at test.projects.ogc.objects.GameObject.Draw(GameObject.java:206)
12-31 21:07:56.856: E/AndroidRuntime(27809):    at test.projects.ogc.util.ChizRenderer.drawObjects(ChizRenderer.java:110)
12-31 21:07:56.856: E/AndroidRuntime(27809):    at test.projects.ogc.util.ChizRenderer.onDrawFrame(ChizRenderer.java:42)
12-31 21:07:56.856: E/AndroidRuntime(27809):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
12-31 21:07:56.856: E/AndroidRuntime(27809):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

を呼び出すと表示されますがglGetAttribLocation、理由はありますか?

さらに情報が必要な場合は、私に教えてください、私は数時間それを理解しようとしています.

ところで、レンダラーinitProgramの関数で関数を呼び出します。onSurfaceCreated

どうやらエラーはcheckGLErrorそれ自体 (以下のコード) でした。アプリから関数のすべての呼び出しを削除した後、チェックしたすべてのデバイスで想定どおりに機能しました。

checkGLError関数:

    public static void checkGlError(String op) {
    int error;
    while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        Log.e(TAG, op + ": glError " + error);
        throw new RuntimeException(op + ": glError " + error);
    }
}

私の仮説は、関数内の何かが、アプリがチェックされた2.3 Androidデバイスではサポートされていないより高いAPI用に作成されているため、4.1.3 Androidデバイスで正常に機能したということです。

アプリから関数を完全に除外する必要がありますか?

4

1 に答える 1

0

仕様を確認すると、はエラー (1280) をglGetAttribLocation生成しませんINVALID_ENUM。これは、おそらく問題が別の場所にあることを意味します。

  • checkGlErrorプログラムの作成中および作成後に配置します。
  • checkGlErrorglGetError へのループ呼び出しが含まれていることを確認してください
于 2013-05-17T06:23:36.287 に答える