VAO(Vertext Array Object),中文是顶点数组对象。之前在《Buffer》一文中,我们介绍了Cesium如何创建VBO的过程,而VAO可以简单的认为是基于VBO的一个封装,为顶点属性数组和VBO中的顶点数据之间建立了关联。我们来看一下使用示例:
var indexBuffer = Buffer.createIndexBuffer({
context : context,
typedArray : indices,
usage : BufferUsage.STATIC_DRAW,
indexDatatype : indexDatatype
});var buffer = Buffer.createVertexBuffer({
context : context,
typedArray : typedArray,
usage : BufferUsage.STATIC_DRAW
});// 属性数组,当前是顶点数据z// 因此,该属性有3个分量XYZ// 值类型为float,4个字节// 因此总共占3 *4= 12字节attributes.push({
index : 0,
vertexBuffer : buffer,
componentsPerAttribute : 3,
componentDatatype : ComponentDatatype.FLOAT,
offsetInBytes : 0,
strideInBytes : 3 * 4,
normalize : false});// 根据属性数组和顶点索引构建VAOvar va = new VertexArray({
context : context,
attributes : attributes,
indexBuffer : indexBuffer
});如同,创建顶点数据和顶点索引的部分之前已经讲过,然后将顶点数据添加到属性数组中,并最终构建成VAO,使用方式很简单。
延伸阅读
学习是年轻人改变自己的最好方式
