Pass:mesh

Edit

Draws a mesh.








Draw a range of vertices from a Buffer, using numbers for the transform.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
xnumber0 The x coordinate of the position to draw the mesh at.
ynumber0 The y coordinate of the position to draw the mesh at.
znumber0 The z coordinate of the position to draw the mesh at.
scalenumber1 The scale of the mesh.
anglenumber0 The number of radians the mesh is rotated around its rotational axis.
axnumber0 The x component of the axis of rotation.
aynumber1 The y component of the axis of rotation.
aznumber0 The z component of the axis of rotation.
startnumber1 The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer).
countnumbernil The number of vertices to render (or the number of indices, when using an index buffer). When nil, as many vertices or indices as possible will be drawn (based on the length of the Buffers and start).
instancesnumber1 The number of copies of the mesh to render.

Returns

Nothing

Draw a range of vertices from a Buffer, using vector types for the transform.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
positionVec3 The position to draw the mesh at.
scalesVec3 The scale of the mesh.
orientationQuat The orientation of the mesh.
startnumber1 The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer).
countnumbernil The number of vertices to render (or the number of indices, when using an index buffer). When nil, as many vertices or indices as possible will be drawn (based on the length of the Buffers and start).
instancesnumber1 The number of copies of the mesh to render.

Returns

Nothing

Draw a range of vertices from a Buffer, using a matrix for the transform.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
transformMat4 The transform to apply to the mesh.
startnumber1 The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer).
countnumbernil The number of vertices to render (or the number of indices, when using an index buffer). When nil, as many vertices or indices as possible will be drawn (based on the length of the Buffers and start).
instancesnumber1 The number of copies of the mesh to render.

Returns

Nothing

Draw a mesh using a vertex buffer and an index buffer, using numbers for the transform.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
indicesBuffer The buffer containing the vertex indices to draw.
xnumber0 The x coordinate of the position to draw the mesh at.
ynumber0 The y coordinate of the position to draw the mesh at.
znumber0 The z coordinate of the position to draw the mesh at.
scalenumber1 The scale of the mesh.
anglenumber0 The number of radians the mesh is rotated around its rotational axis.
axnumber0 The x component of the axis of rotation.
aynumber1 The y component of the axis of rotation.
aznumber0 The z component of the axis of rotation.
startnumber1 The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer).
countnumbernil The number of vertices to render (or the number of indices, when using an index buffer). When nil, as many vertices or indices as possible will be drawn (based on the length of the Buffers and start).
instancesnumber1 The number of copies of the mesh to render.
basenumber0 A base offset to apply to vertex indices.

Returns

Nothing

Draw a mesh using a vertex buffer and an index buffer, using vector types for the transform.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
indicesBuffer The buffer containing the vertex indices to draw.
positionVec3 The position to draw the mesh at.
scalesVec3 The scale of the mesh.
orientationQuat The orientation of the mesh.
startnumber1 The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer).
countnumbernil The number of vertices to render (or the number of indices, when using an index buffer). When nil, as many vertices or indices as possible will be drawn (based on the length of the Buffers and start).
instancesnumber1 The number of copies of the mesh to render.
basenumber0 A base offset to apply to vertex indices.

Returns

Nothing

Draw a mesh using a vertex buffer and an index buffer, using a matrix for the transform.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
indicesBuffer The buffer containing the vertex indices to draw.
transformMat4 The transform to apply to the mesh.
startnumber1 The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer).
countnumbernil The number of vertices to render (or the number of indices, when using an index buffer). When nil, as many vertices or indices as possible will be drawn (based on the length of the Buffers and start).
instancesnumber1 The number of copies of the mesh to render.
basenumber0 A base offset to apply to vertex indices.

Returns

Nothing

Perform indirect draws. drawcount meshes from the vertex and index buffer will be drawn, using parameters starting from offset bytes in the draws buffer.

Arguments

NameTypeDefaultDescription
verticesBuffernil The buffer containing the vertices to draw.
indicesBuffer The buffer containing the vertex indices to draw.
drawsBuffer The buffer containing indirect draw commands.
drawcountnumber The number of indirect draws to draw.
offsetnumber A byte offset into the draw buffer.
stridenumber The number of bytes between consecutive elements in the draw buffer.

Returns

Nothing

Notes

The index buffer defines the order the vertices are drawn in. It can be used to reorder, reuse, or omit vertices from the mesh.

When drawing without a vertex buffer, the VertexIndex variable can be used in shaders to compute the position of each vertex, possibly by reading data from other Buffer or Texture resources.

The active MeshMode controls whether the vertices are drawn as points, lines, or triangles.

The active Material is applied to the mesh.

Example

function lovr.draw(pass)
  local vertices = {
    vec3(  0,  .4, 0), vec4(1, 0, 0, 1),
    vec3(-.5, -.4, 0), vec4(0, 1, 0, 1),
    vec3( .5, -.4, 0), vec4(0, 0, 1, 1)
  }

  local format = {
    { type = 'vec3', location = 'VertexPosition' },
    { type = 'vec4', location = 'VertexColor' }
  }

  local triangle = lovr.graphics.getBuffer(vertices, format)

  pass:mesh(triangle, 0, 1.7, -1)
end

See also