VertexArray

new Cesium.VertexArray(options)VertexArray

Creates a vertex array, which defines the attributes making up a vertex, and contains an optional index buffer to select vertices for rendering. Attributes are defined using object literals as shown in Example 1 below.
Name Type Description
options Object Object with the following properties:
Name Type Description
context Context The context in which the VertexArray gets created.
attributes Array.<Object> An array of attributes.
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.
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:
  • Buffer#createVertexBuffer
  • Buffer#createIndexBuffer
  • Context#draw

Methods

staticCesium.VertexArray.fromGeometry(options)

Creates a vertex array from a geometry. A geometry contains vertex attributes and optional index data in system memory, whereas a vertex array contains vertex buffers and an optional index buffer in WebGL memory for use with rendering.

The geometry argument should use the standard layout like the geometry returned by BoxGeometry.

options can have four properties:
  • geometry: The source geometry containing data used to create the vertex array.
  • attributeLocations: An object that maps geometry attribute names to vertex shader attribute locations.
  • bufferUsage: The expected usage pattern of the vertex array's buffers. On some WebGL implementations, this can significantly affect performance. See BufferUsage. Default: BufferUsage.DYNAMIC_DRAW.
  • interleave: Determines if all attributes are interleaved in a single vertex buffer or if each attribute is stored in a separate vertex buffer. Default: false.

If options is not specified or the geometry contains no data, the returned vertex array is empty.
Name Type Description
options Object An object defining the geometry, attribute indices, buffer usage, and vertex layout used to create the vertex array.
Throws:
  • RuntimeError : Each attribute list must have the same number of vertices.
  • DeveloperError : The geometry must have zero or one index lists.
  • DeveloperError : Index n is used by more than one attribute.
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:

getAttribute()

index is the location in the array of attributes, not the index property of an attribute.