libgdx中VertexAttribute构造函数的整数参数是什么?

P.T*_*.T. 1 java libgdx

在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"));
Run Code Online (Sandbox Code Playgroud)

VertexAttribute构造函数中,整数参数是什么?该文档说明了编码信息所需的"组件数量".

我把它读作每个条目使用的'vertex'数组(一个浮点数组)中的条目数.所以,对于第一个VertexAttribute是3,这是有意义的(x,y和z各一个).但是,ColorPacked属性有4但是由于颜色数据被编码为单个浮点数,这不应该是1吗?最后添加纹理坐标(得到2,它匹配每个顶点所需的两个浮点u,v坐标).

VertexAttribute构造函数javadoc说这个参数是:

numComponents - the number of components of this attribute, must be between 1 and 4.
Run Code Online (Sandbox Code Playgroud)

注意一个较旧的问题, 在libgdx中用于VertexAttribute()的第三个参数是什么?,涵盖了这个构造函数的第三个参数,所以我们只需要一个SO问题来覆盖第一个.:)

Dor*_*ran 6

VertextAttribute构造函数的numComponents整数参数是gl*Pointer的"size"参数

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

使用ColorPacked属性将glColorPointer调用的"type"参数从GL10.GL_FLOAT更改为GL11.GL_UNSIGNED_BYTE.颜色需要4个字节,因此您需要将"numComponents"参数设置为4.

来源:VertexArray.bind()glColorPointer