new SuperMap3D.VertexArray(options具有以下属性的对象:) → VertexArray
创建顶点数组,该数组定义了构成顶点的属性,并包含一个可选的索引缓冲区,用于选择要渲染的顶点。 属性是使用对象文字定义的,如下例 1 所示。
Name | Type | Description |
---|---|---|
options具有以下属性的对象: |
Object | |
options.context |
Context | The context in which the VertexArray gets created. |
options.attributes |
Array.<Object> | An array of attributes. |
options.indexBuffer |
IndexBuffer | optional An optional index buffer. |
Returns:
The vertex array, ready for use with drawing.
Throws:
-
DeveloperError : Attribute must have a
vertexBuffer
. -
DeveloperError : Attribute must have a
componentsPerAttribute
. -
DeveloperError : Attribute must have a valid
componentDatatype
or not specify it. -
DeveloperError : Attribute must have a
strideInBytes
less than or equal to 255 or not specify it. -
DeveloperError : Index n is used by more than one attribute.
- Buffer#createVertexBuffer
- Buffer#createIndexBuffer
- Context#draw
Examples:
// Example 1. Create a vertex array with vertices made up of three floating point
// values, e.g., a position, from a single vertex buffer. No index buffer is used.
var positionBuffer = Buffer.createVertexBuffer({
context : context,
sizeInBytes : 12,
usage : BufferUsage.STATIC_DRAW
});
var attributes = [
{
index : 0,
enabled : true,
vertexBuffer : positionBuffer,
componentsPerAttribute : 3,
componentDatatype : ComponentDatatype.FLOAT,
normalize : false,
offsetInBytes : 0,
strideInBytes : 0 // tightly packed
instanceDivisor : 0 // not instanced
}
];
var va = new VertexArray({
context : context,
attributes : attributes
});
// Example 2. Create a vertex array with vertices from two different vertex buffers.
// Each vertex has a three-component position and three-component normal.
var positionBuffer = Buffer.createVertexBuffer({
context : context,
sizeInBytes : 12,
usage : BufferUsage.STATIC_DRAW
});
var normalBuffer = Buffer.createVertexBuffer({
context : context,
sizeInBytes : 12,
usage : BufferUsage.STATIC_DRAW
});
var attributes = [
{
index : 0,
vertexBuffer : positionBuffer,
componentsPerAttribute : 3,
componentDatatype : ComponentDatatype.FLOAT
},
{
index : 1,
vertexBuffer : normalBuffer,
componentsPerAttribute : 3,
componentDatatype : ComponentDatatype.FLOAT
}
];
var va = new VertexArray({
context : context,
attributes : attributes
});
// Example 3. Creates the same vertex layout as Example 2 using a single
// vertex buffer, instead of two.
var buffer = Buffer.createVertexBuffer({
context : context,
sizeInBytes : 24,
usage : BufferUsage.STATIC_DRAW
});
var attributes = [
{
vertexBuffer : buffer,
componentsPerAttribute : 3,
componentDatatype : ComponentDatatype.FLOAT,
offsetInBytes : 0,
strideInBytes : 24
},
{
vertexBuffer : buffer,
componentsPerAttribute : 3,
componentDatatype : ComponentDatatype.FLOAT,
normalize : true,
offsetInBytes : 12,
strideInBytes : 24
}
];
var va = new VertexArray({
context : context,
attributes : attributes
});
See:
Methods
-
从几何体创建一个顶点数组。几何体包含系统内存中的顶点属性和可选的索引数据,而顶点数组包含WebGL内存中的顶点缓冲区和可选的索引缓冲区,用于渲染。
geometry
参数应该使用标准布局,如由BoxGeometry
返回的几何体。
options
有以下四个属性:geometry
: 包含用于创建顶点阵列的数据的源几何体。attributeLocations
: 将几何属性名称映射到顶点着色器属性位置的对象。bufferUsage
: 顶点数组buffers的预期使用模式。在某些WebGL实现中,这可能会严重影响性能。参见BufferUsage
。默认值:BufferUsage。DYNAMIC_DRAWinterleave
: 确定所有属性是否在单个顶点buffer中交错,还是每个属性都存储在单独的顶点buffer中。默认值:false。
如果没有指定选项
或者几何
不包含数据,则返回的顶点数组为空。Name Type Description options
Object 对象,定义用于创建顶点数组的几何形状、属性索引、缓冲区使用和顶点布局。 Throws:
-
RuntimeError : 每个属性列表必须具有相同数量的顶点。
-
DeveloperError : 几何图形必须有零个或一个索引列表。
-
DeveloperError : 索引n由多个属性使用。
- Buffer#createVertexBuffer
- Buffer#createIndexBuffer
- GeometryPipeline.createAttributeLocations
- ShaderProgram
Examples:
// Example 1. Creates a vertex array for rendering a box. The default dynamic draw // usage is used for the created vertex and index buffer. The attributes are not // interleaved by default. var geometry = new BoxGeometry(); var va = VertexArray.fromGeometry({ context : context, geometry : geometry, attributeLocations : GeometryPipeline.createAttributeLocations(geometry), });
// Example 2. Creates a vertex array with interleaved attributes in a // single vertex buffer. The vertex and index buffer have static draw usage. var va = VertexArray.fromGeometry({ context : context, geometry : geometry, attributeLocations : GeometryPipeline.createAttributeLocations(geometry), bufferUsage : BufferUsage.STATIC_DRAW, interleave : true });
// Example 3. When the caller destroys the vertex array, it also destroys the // attached vertex buffer(s) and index buffer. va = va.destroy();
See:
-
Index是属性数组中的位置,而不是属性的索引属性。