mesh.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. return {
  2. tag = 'drawing',
  3. summary = 'Draw a mesh.',
  4. description = 'Draws a mesh.',
  5. arguments = {
  6. vertices = {
  7. type = 'Buffer',
  8. default = 'nil',
  9. description = 'The buffer containing the vertices to draw.'
  10. },
  11. indices = {
  12. type = 'Buffer',
  13. description = 'The buffer containing the vertex indices to draw.'
  14. },
  15. draws = {
  16. type = 'Buffer',
  17. description = 'The buffer containing indirect draw commands.'
  18. },
  19. drawcount = {
  20. type = 'number',
  21. description = 'The number of indirect draws to draw.'
  22. },
  23. offset = {
  24. type = 'number',
  25. description = 'A byte offset into the draw buffer.'
  26. },
  27. stride = {
  28. type = 'number',
  29. description = 'The number of bytes between consecutive elements in the draw buffer.'
  30. },
  31. transform = {
  32. type = 'Mat4',
  33. description = [[
  34. The transform to apply to the mesh. Can also be provided as a position, 1-component scale,
  35. and rotation using a combination of `Vectors` and numbers.
  36. ]]
  37. },
  38. start = {
  39. type = 'number',
  40. default = '1',
  41. description = [[
  42. The 1-based index of the first vertex to render from the vertex buffer (or the first index,
  43. when using an index buffer).
  44. ]]
  45. },
  46. count = {
  47. type = 'number',
  48. default = 'nil',
  49. description = [[
  50. The number of vertices to render (or the number of indices, when using an index buffer).
  51. When `nil`, as many vertices or indices as possible will be drawn (based on the length of
  52. the Buffers and `start`).
  53. ]]
  54. },
  55. vertexcount = {
  56. type = 'number',
  57. description = 'The number of vertices or indices to draw.'
  58. },
  59. instances = {
  60. type = 'number',
  61. default = '1',
  62. description = 'The number of copies of the mesh to render.'
  63. },
  64. base = {
  65. type = 'number',
  66. default = '0',
  67. description = 'A base offset to apply to vertex indices.'
  68. }
  69. },
  70. returns = {},
  71. variants = {
  72. {
  73. arguments = { 'vertices', 'transform', 'start', 'count', 'instances', 'base' },
  74. returns = {}
  75. },
  76. {
  77. arguments = { 'vertices', 'indices', 'transform', 'start', 'count', 'instances', 'base' },
  78. returns = {}
  79. },
  80. {
  81. arguments = { 'vertices', 'indices', 'draws', 'drawcount', 'offset', 'stride' },
  82. returns = {}
  83. },
  84. {
  85. arguments = { 'vertexcount', 'transform' },
  86. returns = {}
  87. },
  88. {
  89. arguments = { 'vertexcount', 'indices', 'transform' },
  90. returns = {}
  91. }
  92. },
  93. notes = [[
  94. The index buffer defines the order the vertices are drawn in. It can be used to reorder, reuse,
  95. or omit vertices from the mesh.
  96. The active `MeshMode` controls whether the vertices are drawn as points, lines, or triangles.
  97. The active `Material` is applied to the mesh.
  98. ]],
  99. example = [[
  100. function lovr.draw(pass)
  101. local vertices = {
  102. vec3( 0, .4, 0), vec4(1, 0, 0, 1),
  103. vec3(-.5, -.4, 0), vec4(0, 1, 0, 1),
  104. vec3( .5, -.4, 0), vec4(0, 0, 1, 1)
  105. }
  106. local format = {
  107. { type = 'vec3', location = 'VertexPosition' },
  108. { type = 'vec4', location = 'VertexColor' }
  109. }
  110. local triangle = lovr.graphics.getBuffer(vertices, format)
  111. pass:mesh(triangle, 0, 1.7, -1)
  112. end
  113. ]]
  114. }