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 by specifying a draws command buffer. This allows for the drawing of instanced geometry to be orchestrated by a compute shader that writes to the draws buffer. The draws buffer contains one or more commands that define how to draw instances. The stride determines the number of bytes between each draw command. By default the draws are assumed to be tightly packed, with 20 bytes between indexed draws and 16 bytes for non-indexed draws.

The draws buffer should use one of these formats:

{ -- drawing with vertices and indices
  { name = 'indexCount', type = 'u32' },
  { name = 'instanceCount', type = 'u32' },
  { name = 'firstIndex', type = 'u32' },
  { name = 'vertexOffset', type = 'i32' },
  { name = 'firstInstance', type = 'u32' }
}

{ -- drawing with vertices; indices = nil
  { name = 'vertexCount', type = 'u32' },
  { name = 'instanceCount', type = 'u32' },
  { name = 'firstVertex', type = 'u32' },
  { name = 'firstInstance', type = 'u32' }
}

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.
drawcountnumber1 The number of indirect draws to draw.
offsetnumber0 A byte offset into the draw buffer.
stridenumber0 The number of bytes between consecutive elements in the draw buffer. When zero or nil, the stride is autodetected, and will be 20 bytes when an index buffer is provided and 16 bytes otherwise.

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 DrawMode controls whether the vertices are drawn as points, lines, or triangles.

The active Material is applied to the mesh.

Example

function lovr.load()
  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 = {
    { name = 'VertexPosition', type = 'vec3' },
    { name = 'VertexColor', type = 'vec4' }
  }

  triangle = lovr.graphics.newBuffer(format, vertices)
end

function lovr.draw(pass)
  pass:mesh(triangle, 0, 1.7, -1)
end

See also