getData.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. return {
  2. tag = 'buffer-transfer',
  3. summary = 'Get the data in the Buffer.',
  4. description = [[
  5. Downloads the Buffer's data from VRAM and returns it as a table. This function is very very
  6. slow because it stalls the CPU until the data is finished downloading, so it should only be used
  7. for debugging or non-interactive scripts. `Buffer:newReadback` is an alternative that returns a
  8. `Readback` object, which will not block the CPU.
  9. ]],
  10. arguments = {
  11. index = {
  12. type = 'number',
  13. default = '1',
  14. description = 'The index of the first item to read.'
  15. },
  16. count = {
  17. type = 'number',
  18. default = 'nil',
  19. description = 'The number of items to read. If nil, reads the remainder of the buffer.'
  20. }
  21. },
  22. returns = {
  23. t = {
  24. type = 'table',
  25. description = 'The table with the Buffer\'s data.'
  26. }
  27. },
  28. variants = {
  29. {
  30. arguments = { 'index', 'count' },
  31. returns = { 't' }
  32. }
  33. },
  34. notes = [[
  35. The length of the table will equal the number of items read. Here are some examples of how the
  36. table is formatted:
  37. buffer = lovr.graphics.newBuffer('int', { 7 })
  38. buffer:getData() --> returns { 7 }
  39. buffer = lovr.graphics.newBuffer('vec3', { 7, 8, 9 })
  40. buffer:getData() --> returns {{ 7, 8, 9 }}
  41. buffer = lovr.graphics.newBuffer('int', { 1, 2, 3 })
  42. buffer:getData() --> returns { 1, 2, 3 }
  43. buffer = lovr.graphics.newBuffer({ 'vec2', 'vec2' }, {
  44. vec2(1,2), vec2(3,4),
  45. vec2(5,6), vec2(7,8)
  46. })
  47. buffer:getData() --> returns { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } }
  48. buffer = lovr.graphics.newBuffer({
  49. { 'a', 'float' },
  50. { 'b', 'float' }
  51. }, { a = 1, b = 2 })
  52. buffer:getData() --> returns { { 1, 2 } }
  53. buffer = lovr.graphics.newBuffer({
  54. { 'x', 'int', 3 }
  55. }, { x = { 1, 2, 3 } })
  56. buffer:getData() --> returns { { x = { 1, 2, 3 } } }
  57. buffer = lovr.graphics.newBuffer({
  58. { 'lights', {
  59. { 'pos', 'vec3' },
  60. { 'size', 'float' },
  61. }, 10}
  62. }, data)
  63. buffer:getData() --> returns { { lights = { { pos = ..., size = ... }, ... } } }
  64. In summary, each individual item is wrapped in a table, except if the format is a single number.
  65. If the format has nested types or arrays then the tables will be key-value, otherwise they will
  66. use numeric keys.
  67. ]],
  68. related = {
  69. 'Buffer:newReadback',
  70. 'Buffer:mapData',
  71. 'Readback:getData'
  72. }
  73. }