VertexFormat
A vertex format is a descriptor that defines the layout of vertex data inside a VertexBuffer.
// Specify 3-component positions (x, y, z)
const vertexFormat = new pc.VertexFormat(graphicsDevice, [
{ semantic: pc.SEMANTIC_POSITION, components: 3, type: pc.TYPE_FLOAT32 }
]);
// 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 }
]);
Summary
Static Methods
getDefaultInstancingFormat | The VertexFormat used to store matrices of type Mat4 for hardware instancing. |
Properties
elements | The vertex attribute elements. |
elements[].dataType | The data type of the attribute. |
elements[].name | The meaning of the vertex element. |
elements[].normalize | If true, vertex attribute data will be mapped from a 0 to 255 range down to 0 to 1 when fed to a shader. |
elements[].numComponents | The number of components of the vertex attribute. |
elements[].offset | The number of initial bytes at the start of a vertex that are not relevant to this attribute. |
elements[].size | The size of the attribute in bytes. |
elements[].stride | The number of total bytes that are between the start of one vertex, and the start of the next. |
Details
Static Methods
getDefaultInstancingFormat(graphicsDevice)
The VertexFormat used to store matrices of type Mat4 for hardware instancing.
Parameters
graphicsDevice | GraphicsDevice | The graphics device used to create this vertex format. |
Returns
VertexFormatThe default instancing vertex format.
Constructor
VertexFormat(graphicsDevice, description, [vertexCount])
Create a new VertexFormat instance.
// Specify 3-component positions (x, y, z)
const vertexFormat = new pc.VertexFormat(graphicsDevice, [
{ semantic: pc.SEMANTIC_POSITION, components: 3, type: pc.TYPE_FLOAT32 }
]);
// 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 }
]);
Parameters
graphicsDevice | GraphicsDevice | The graphics device used to manage this vertex format. |
description | object[] | An array of vertex attribute descriptions. |
description[].semantic | string | The meaning of the vertex element. This is used to link the vertex data to a shader input. Can be:
If vertex data has a meaning other that one of those listed above, use the user-defined semantics: SEMANTIC_ATTR0 to SEMANTIC_ATTR15. |
description[].components | number | The number of components of the vertex attribute. Can be 1, 2, 3 or 4. |
description[].type | number | The data type of the attribute. Can be: |
description[].normalize | boolean | If true, vertex attribute data will be mapped from a 0 to 255 range down to 0 to 1 when fed to a shader. If false, vertex attribute data is left unchanged. If this property is unspecified, false is assumed. |
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). |
Properties
The meaning of the vertex element. This is used to link the vertex data to a shader input. Can be:
- SEMANTIC_POSITION
- SEMANTIC_NORMAL
- SEMANTIC_TANGENT
- SEMANTIC_BLENDWEIGHT
- SEMANTIC_BLENDINDICES
- SEMANTIC_COLOR
- SEMANTIC_TEXCOORD0
- SEMANTIC_TEXCOORD1
- SEMANTIC_TEXCOORD2
- SEMANTIC_TEXCOORD3
- SEMANTIC_TEXCOORD4
- SEMANTIC_TEXCOORD5
- SEMANTIC_TEXCOORD6
- SEMANTIC_TEXCOORD7
If vertex data has a meaning other that one of those listed above, use the user-defined semantics: SEMANTIC_ATTR0 to SEMANTIC_ATTR15.
If true, vertex attribute data will be mapped from a 0 to 255 range down to 0 to 1 when fed to a shader. If false, vertex attribute data is left unchanged. If this property is unspecified, false is assumed.
The number of components of the vertex attribute. Can be 1, 2, 3 or 4.