A vertex format is a descriptor that defines the layout of vertex data inside a VertexBuffer.

Constructors

  • Create a new VertexFormat instance.

    Parameters

    • graphicsDevice: GraphicsDevice

      The graphics device used to manage this vertex format.

    • description: AttributeDescription[]

      An array of vertex attribute descriptions.

    • Optional vertexCount: number

      When specified, vertex format will be set up for non-interleaved format with a specified number of vertices. (example: PPPPNNNNCCCC), where arrays of individual attributes will be stored one right after the other (subject to alignment requirements). Note that in this case, the format depends on the number of vertices, and needs to change when the number of vertices changes. When not specified, vertex format will be interleaved. (example: PNCPNCPNCPNC).

    Returns VertexFormat

    Example

    // Specify 3-component positions (x, y, z)
    const vertexFormat = new pc.VertexFormat(graphicsDevice, [
    { semantic: pc.SEMANTIC_POSITION, components: 3, type: pc.TYPE_FLOAT32 }
    ]);

    Example

    // Specify 2-component positions (x, y), a texture coordinate (u, v) and a vertex color (r, g, b, a)
    const vertexFormat = new pc.VertexFormat(graphicsDevice, [
    { semantic: pc.SEMANTIC_POSITION, components: 2, type: pc.TYPE_FLOAT32 },
    { semantic: pc.SEMANTIC_TEXCOORD0, components: 2, type: pc.TYPE_FLOAT32 },
    { semantic: pc.SEMANTIC_COLOR, components: 4, type: pc.TYPE_UINT8, normalize: true }
    ]);

Accessors

  • get elements(): {
        asInt: boolean;
        dataType: number;
        name: string;
        normalize: boolean;
        numComponents: number;
        offset: any;
        size: number;
        stride: any;
    }[]
  • The vertex attribute elements.

    Returns {
        asInt: boolean;
        dataType: number;
        name: string;
        normalize: boolean;
        numComponents: number;
        offset: any;
        size: number;
        stride: any;
    }[]

Methods