# Class VertexFormat

java.lang.Object
com.codename1.gpu.VertexFormat

public final class VertexFormat extends Object
An ordered, interleaved layout of `VertexAttribute`s describing how the floats of a `VertexBuffer` are grouped into vertices. All attributes are tightly packed in declaration order; the stride is the sum of the component counts. A handful of common formats are provided as constants.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final VertexFormat`
  `POSITION`
  Position only (3 floats).
  `static final VertexFormat`
  `POSITION_NORMAL`
  Position and normal (3 + 3 floats).
  `static final VertexFormat`
  `POSITION_NORMAL_TEXCOORD`
  Position, normal and texture coordinate (3 + 3 + 2 floats).
  `static final VertexFormat`
  `POSITION_TEXCOORD`
  Position and texture coordinate (3 + 2 floats).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `VertexFormat(VertexAttribute[] attributes)`
  Creates a vertex format from the supplied attributes in interleaved order.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `VertexAttribute`
  `findByUsage(VertexAttribute.Usage usage)`
  Returns the first attribute matching the supplied usage, or null when the format does not contain it.
  `VertexAttribute`
  `getAttribute(int index)`
  Returns the attribute at the supplied index in declaration order.
  `int`
  `getAttributeCount()`
  Returns the number of attributes in this format.
  `int`
  `getAttributeOffset(int index)`
  Returns the float offset of the attribute at the supplied index within a vertex.
  `int`
  `getFloatsPerVertex()`
  Returns the number of floats that make up a single vertex (the stride measured in floats).
  `int`
  `getStrideBytes()`
  Returns the stride of a vertex in bytes.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### POSITION

    public static final VertexFormat POSITION
    Position only (3 floats).

  - ### POSITION_TEXCOORD

    public static final VertexFormat POSITION_TEXCOORD
    Position and texture coordinate (3 + 2 floats).

  - ### POSITION_NORMAL

    public static final VertexFormat POSITION_NORMAL
    Position and normal (3 + 3 floats).

  - ### POSITION_NORMAL_TEXCOORD

    public static final VertexFormat POSITION_NORMAL_TEXCOORD
    Position, normal and texture coordinate (3 + 3 + 2 floats). The common format for lit, textured meshes.

- ## Constructor Details

  - ### VertexFormat

    public VertexFormat(VertexAttribute[] attributes)

    Creates a vertex format from the supplied attributes in interleaved order.

    ###### Parameters

    - `attributes`: the attributes that make up a single vertex

- ## Method Details

  - ### getAttributeCount

    public int getAttributeCount()
    Returns the number of attributes in this format.

  - ### getAttribute

    public VertexAttribute getAttribute(int index)
    Returns the attribute at the supplied index in declaration order.

  - ### getAttributeOffset

    public int getAttributeOffset(int index)
    Returns the float offset of the attribute at the supplied index within a vertex.

  - ### findByUsage

    public VertexAttribute findByUsage(VertexAttribute.Usage usage)
    Returns the first attribute matching the supplied usage, or null when the format does not contain it.

  - ### getFloatsPerVertex

    public int getFloatsPerVertex()
    Returns the number of floats that make up a single vertex (the stride measured in floats).

  - ### getStrideBytes

    public int getStrideBytes()
    Returns the stride of a vertex in bytes.