public function setVertexBufferAt(index:int, buffer:VertexBuffer3D, bufferOffset:int = 0, format:String = "float4"):void
使用 setVertexBufferAt 方法来标识 VertexBuffer3D 缓冲区中每个顶点定义的哪些数据组件属于顶点程序的哪些输入。顶点程序的开发人员会确定每个顶点需要的数据量。该数据从 1 个或多个 VertexBuffer3D 流映射到顶点着色器程序的属性寄存器中。
顶点着色器所使用数据的最小单位为 32 位数据。距顶点流的偏移量以 32 位的倍数指定。
举例来说,编程人员可以使用以下数据定义每个顶点:
position: x float32
y float32
z float32
color: r unsigned byte
g unsigned byte
b unsigned byte
a unsigned byte
假定在 VertexBuffer3D 对象中定义了名为 buffer 的对象,则可使用以下代码将其分配给顶点着色器:
setVertexBufferAt( 0, buffer, 0, Context3DVertexBufferFormat.FLOAT_3 ); // attribute #0 will contain the position information
setVertexBufferAt( 1, buffer, 3, Context3DVertexBufferFormat.BYTES_4 ); // attribute #1 will contain the color information
index:int — 顶点着色器中的属性寄存器的索引(0 到 7)。
buffer:VertexBuffer3D — 包含要馈送到顶点着色器中的源顶点数据的缓冲区。
bufferOffset:int (default = 0) — 单个顶点的起始数据偏移量,从此处开始读取此属性。在上例中,位置数据的偏移量为 0,因为它是第一个属性;颜色的偏移量为 3,因为颜色属性跟在 3 个 32 位位置值之后。以 32 位为单位指定偏移量。
format:String (default = "float4") — 来自 Context3DVertexBufferFormat 类的值,指定此属性的数据类型。
引发
Error — 无效的枚举:当格式不是 Context3DVertexBufferFormat 类中定义的值之一时。
RangeError — 属性寄存器超出边界:当 index 参数超出 0 到 7 的范围时。(着色器最多可使用 8 个顶点属性寄存器。)