GLES20.glGetAttribLocationが-1を返す?

213 views
Skip to first unread message

たけし

unread,
Apr 26, 2014, 2:23:47 PM4/26/14
to android-g...@googlegroups.com
OpenGL ES 2でGLES20.glGetAttribLocationが-1を返すのですが、どういう原因が考えられるのでしょうか?

「4.0.3」「4.3」で試しました。

たけし

unread,
Apr 26, 2014, 2:37:42 PM4/26/14
to android-g...@googlegroups.com
補足です。

       "attribute vec4 a_Position;\n" +
       "attribute vec4 a_Normal;\n" +
       "attribute vec2 a_TextureCoord;\n" +
       "attribute float a_Bone;\n" +

     _aPositionHandle = GLES20.glGetAttribLocation(_program, "a_Position");
    if (_aPositionHandle == -1)
    {
    throw new RuntimeException("Could not get attrib location for a_Position");
    }

    _aNormalHandle = GLES20.glGetAttribLocation(_program, "a_Normal");
    if (_aNormalHandle == -1)
    {
    throw new RuntimeException("Could not get attrib location for a_Normal");
    }
    _aBoneHandle = GLES20.glGetAttribLocation(_program, "a_Bone");
    if (_aBoneHandle == -1)
    {
    throw new RuntimeException("Could not get attrib location for a_Bone");
    }
    _aTextureHandle = GLES20.glGetAttribLocation(_program, "a_TextureCoord");
    if (_aTextureHandle == -1)
    {
    throw new RuntimeException("Could not get attrib location for a_TextureCoord");
    }

この「a_Normal」と「a_TextureCoord」で「-1」が返ります。

Makoto Yamazaki

unread,
Apr 26, 2014, 2:46:19 PM4/26/14
to android-g...@googlegroups.com
zaki です。

コンパイラに未使用変数と判断されて最適化で削除されているのではないでしょうか。


--
このメールは Google グループのグループ「日本Androidの会」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには android-group-j...@googlegroups.com にメールを送信してください。
このグループに投稿するには android-g...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/android-group-japan からこのグループにアクセスしてください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。



--
YAMAZAKI Makoto

たけし

unread,
May 3, 2014, 6:41:56 PM5/3/14
to android-g...@googlegroups.com
YAMAZAKI Makotoさん、ありがとうございます。

同じ書き方で別の変数は未使用と判断されてないみたいです。

Makoto Yamazaki

unread,
May 4, 2014, 3:04:51 AM5/4/14
to android-g...@googlegroups.com
zaki です。

本当にまったく同じなら結果が異なることは考えにくいので、わたしは「同じ書き方」では
ないのではないかと思います。
未使用かどうかは宣言の部分ではなく、変数の使い方で決まります。


2014-05-04 7:41 GMT+09:00 たけし <vixa...@gmail.com>:
YAMAZAKI Makotoさん、ありがとうございます。

同じ書き方で別の変数は未使用と判断されてないみたいです。

--
このメールは Google グループのグループ「日本Androidの会」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには android-group-j...@googlegroups.com にメールを送信してください。
このグループに投稿するには android-g...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/android-group-japan からこのグループにアクセスしてください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。



--
YAMAZAKI Makoto

たけし

unread,
May 4, 2014, 11:56:56 AM5/4/14
to android-g...@googlegroups.com
zakiさん、ありがとうございます。

     _aPositionHandle = 0;
    GLES20.glBindAttribLocation(_program, _aPositionHandle, "a_Position");
    _aNormalHandle = 1;
    GLES20.glBindAttribLocation(_program, _aNormalHandle, "a_Normal");
    _aTextureHandle = 2;
    GLES20.glBindAttribLocation(_program, _aTextureHandle, "a_TextureCoord");
    _aBoneHandle = 3;
    GLES20.glBindAttribLocation(_program, _aBoneHandle, "a_Bone");

という風に明示的に変数の値を指定したらうまくいきました。
Reply all
Reply to author
Forward
0 new messages