2

libgdxメッシュ、色、テクスチャ チュートリアルでは、各頂点の色とテクスチャ情報を持つ単純な三角形を表すメッシュが次のように作成されます。

mesh = new Mesh(true, 3, 3, 
                new VertexAttribute(Usage.Position, 3, "a_position"),
                new VertexAttribute(Usage.ColorPacked, 4, "a_color"),
                new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));

コンストラクターのVertexAttribute整数引数は何ですか? ドキュメントには、情報をエンコードするために必要な「コンポーネントの数」と書かれています。

I read that as the number of entries in the 'vertex' array (an array of floats) that each entry uses. So, for the first VertexAttribute that is 3, which makes sense (one each for x, for y, and for z). However, the ColorPacked attribute has 4 but but since the color data gets encoded into a single float, shouldn't this be 1? Finally the texture coordinates are added (that gets 2, which matches the two float u,v coordinates needed for each vertex).

The javadoc for the VertexAttribute constructor says this parameter is:

numComponents - the number of components of this attribute, must be between 1 and 4.

Note an older question, Whats the 3rd argument in VertexAttribute() used for in libgdx?, covers the 3rd argument to this constructor, so we just need one more SO question to cover the first. :)

4

2 に答える 2

7

VertextAttribute コンストラクターへの numComponents 整数パラメーターは、gl*Pointer への「サイズ」引数です。

  • Usage.Position -> glVertexPointer
  • Usage.Color -> glColorPointer
  • Usage.ColorPacked -> glColorPointer
  • Usage.TextureCoordinates -> glTexCoordPointer
  • Usage.Normal -> glNormalPointer

ColorPacked 属性を使用すると、glColorPointer への呼び出しの「タイプ」引数が GL10.GL_FLOAT から GL11.GL_UNSIGNED_BYTE に変更されます。色には 4 バイトが必要なので、"numComponents" 引数を 4 に設定する必要があります。

ソース: VertexArray.bind()およびglColorPointer

于 2011-10-27T14:15:55.780 に答える
0

これは、CPU 側の計算ではなく、シェーダー内のコンポーネントの数です。position-vector をシェーダーに渡すと、4 は、ベクターがシェーダーの vec4 にエンコードされることを示します。

色についても同様です。パックされた単一の float 値をシェーダーに渡すことはできますが、シェーダーでは vec4 カラー ベクトルを使用することになります。

于 2013-11-10T14:15:56.863 に答える