setIndexBuffer.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. return {
  2. summary = 'Set a Buffer for the Mesh to use for vertex indices.',
  3. description = [[
  4. Sets a `Buffer` object the Mesh will use for vertex indices.
  5. This can only be used if the Mesh uses the `gpu` storage mode.
  6. The Buffer must have a single field with the `u16`, `u32`, `index16`, or `index32` type.
  7. ]],
  8. arguments = {},
  9. returns = {
  10. buffer = {
  11. type = 'Buffer',
  12. description = 'The index buffer.'
  13. }
  14. },
  15. variants = {
  16. {
  17. arguments = {},
  18. returns = { 'buffer' }
  19. }
  20. },
  21. notes = [[
  22. The index buffer stores a list of numbers where each number is the index of a vertex in the
  23. Mesh. When drawing the Mesh, the data from the vertex corresponding to the index is used. This
  24. can be used to reorder or reuse vertices, which uses less data than repeating a vertex multiple
  25. times in the Mesh.
  26. ]],
  27. example = {
  28. description = 'Use an index buffer to draw a plane.',
  29. code = [[
  30. function lovr.load()
  31. mesh = lovr.graphics.newMesh({
  32. { -1, 1, 0 }, -- upper left
  33. { 1, 1, 0 }, -- upper right
  34. { -1, -1, 0 }, -- lower left
  35. { 1, -1, 0 }, -- lower right
  36. }, 'gpu')
  37. -- 2 triangles
  38. local indices = { 1,3,2, 2,3,4 }
  39. local indexBuffer = lovr.graphics.newBuffer('index16', indices)
  40. mesh:setIndexBuffer(indexBuffer)
  41. end
  42. function lovr.draw(pass)
  43. pass:draw(mesh, 0, 1.7, -2)
  44. end
  45. ]]
  46. },
  47. related = {
  48. 'Mesh:getIndices',
  49. 'Mesh:setIndices',
  50. 'Mesh:getVertexBuffer'
  51. }
  52. }