Mesh:setIndexBuffer
EditSets a Buffer
object the Mesh will use for vertex indices.
This can only be used if the Mesh uses the gpu
storage mode.
The Buffer must have a single field with the u16
, u32
, index16
, or index32
type.
Mesh:setIndexBuffer(buffer)
Notes
The index buffer stores a list of numbers where each number is the index of a vertex in the Mesh. When drawing the Mesh, the data from the vertex corresponding to the index is used. This can be used to reorder or reuse vertices, which uses less data than repeating a vertex multiple times in the Mesh.
Example
Use an index buffer to draw a plane.
function lovr.load()
mesh = lovr.graphics.newMesh({
{ -1, 1, 0 }, -- upper left
{ 1, 1, 0 }, -- upper right
{ -1, -1, 0 }, -- lower left
{ 1, -1, 0 }, -- lower right
}, 'gpu')
-- 2 triangles
local indices = { 1,3,2, 2,3,4 }
local indexBuffer = lovr.graphics.newBuffer('index16', indices)
mesh:setIndexBuffer(indexBuffer)
end
function lovr.draw(pass)
pass:draw(mesh, 0, 1.7, -2)
end