Pass:mesh
EditDraws a mesh.
Draw a range of vertices from a Buffer, using numbers for the transform.
Arguments
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
x | number | 0 | The x coordinate of the position to draw the mesh at. |
y | number | 0 | The y coordinate of the position to draw the mesh at. |
z | number | 0 | The z coordinate of the position to draw the mesh at. |
scale | number | 1 | The scale of the mesh. |
angle | number | 0 | The number of radians the mesh is rotated around its rotational axis. |
ax | number | 0 | The x component of the axis of rotation. |
ay | number | 1 | The y component of the axis of rotation. |
az | number | 0 | The z component of the axis of rotation. |
start | number | 1 | The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer). |
count | number | nil |
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 ).
|
instances | number | 1 | 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
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
position | Vec3 | The position to draw the mesh at. | |
scales | Vec3 | The scale of the mesh. | |
orientation | Quat | The orientation of the mesh. | |
start | number | 1 | The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer). |
count | number | nil |
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 ).
|
instances | number | 1 | 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
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
transform | Mat4 | The transform to apply to the mesh. | |
start | number | 1 | The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer). |
count | number | nil |
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 ).
|
instances | number | 1 | 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
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
indices | Buffer | The buffer containing the vertex indices to draw. | |
x | number | 0 | The x coordinate of the position to draw the mesh at. |
y | number | 0 | The y coordinate of the position to draw the mesh at. |
z | number | 0 | The z coordinate of the position to draw the mesh at. |
scale | number | 1 | The scale of the mesh. |
angle | number | 0 | The number of radians the mesh is rotated around its rotational axis. |
ax | number | 0 | The x component of the axis of rotation. |
ay | number | 1 | The y component of the axis of rotation. |
az | number | 0 | The z component of the axis of rotation. |
start | number | 1 | The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer). |
count | number | nil |
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 ).
|
instances | number | 1 | The number of copies of the mesh to render. |
base | number | 0 | 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
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
indices | Buffer | The buffer containing the vertex indices to draw. | |
position | Vec3 | The position to draw the mesh at. | |
scales | Vec3 | The scale of the mesh. | |
orientation | Quat | The orientation of the mesh. | |
start | number | 1 | The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer). |
count | number | nil |
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 ).
|
instances | number | 1 | The number of copies of the mesh to render. |
base | number | 0 | 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
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
indices | Buffer | The buffer containing the vertex indices to draw. | |
transform | Mat4 | The transform to apply to the mesh. | |
start | number | 1 | The 1-based index of the first vertex to render from the vertex buffer (or the first index, when using an index buffer). |
count | number | nil |
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 ).
|
instances | number | 1 | The number of copies of the mesh to render. |
base | number | 0 | 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
Name | Type | Default | Description |
vertices | Buffer | nil | The buffer containing the vertices to draw. |
indices | Buffer | The buffer containing the vertex indices to draw. | |
draws | Buffer | The buffer containing indirect draw commands. | |
drawcount | number | 1 | The number of indirect draws to draw. |
offset | number | 0 | A byte offset into the draw buffer. |
stride | number | 0 | 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