init.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. return {
  2. summary = 'A block of memory on the GPU.',
  3. description = [[
  4. A Buffer is a block of memory on the GPU. It's like a GPU version of a `Blob`. Lua code can
  5. write data to the buffer which uploads to VRAM, and shaders read buffer data during rendering.
  6. Compute shaders can also write to buffers.
  7. The **size** of a Buffer is the number of bytes of VRAM it occupies. It's set when the Buffer
  8. is created and can't be changed afterwards.
  9. Buffers can optionally have a **format**, which defines the type of data stored in the buffer.
  10. The format determines how Lua values are converted into binary. Like the size, it can't change
  11. after the buffer is created. `Shader:getBufferFormat` returns the format of a variable in a
  12. `Shader`.
  13. When a Buffer has a format, it also has a **length**, which is the number of items it holds, and
  14. a **stride**, which is the number of bytes between each item.
  15. `Buffer:setData` is used to upload data to the Buffer. `Buffer:clear` can also be used to
  16. efficiently zero out a Buffer.
  17. `Buffer:getData` can be used to download data from the Buffer, but be aware that it stalls the
  18. GPU until the download is complete, which is very slow! `Buffer:newReadback` will instead
  19. download the data in the background, which avoids costly stalls.
  20. Buffers are often used for mesh data. Vertices stored in buffers can be drawn using
  21. `Pass:mesh`. `Mesh` objects can also be used, which wrap Buffers along with some extra
  22. metadata.
  23. Buffers can be "bound" to a variable in a Shader using `Pass:send`. That means that the next
  24. time the shader runs, the data from the Buffer will be used for the stuff in the variable.
  25. It's important to understand that data from a Buffer will only be used at the point when
  26. graphics commands are actually submitted. This example records 2 draws, changing the buffer
  27. data between each one:
  28. buffer:setData(data1)
  29. pass:mesh(buffer)
  30. buffer:setData(data2)
  31. pass:mesh(buffer)
  32. lovr.graphics.submit(pass)
  33. **Both** draws will use `data2` here! That's because `lovr.graphics.submit` is where the draws
  34. actually get processed, so they both see the "final" state of the buffer. The data in a Buffer
  35. can't be 2 things at once! If you need multiple versions of data, it's best to use a bigger
  36. buffer with offsets (or multiple buffers).
  37. ]],
  38. constructors = {
  39. 'lovr.graphics.newBuffer',
  40. 'lovr.graphics.getBuffer'
  41. },
  42. sections = {
  43. {
  44. name = 'Metadata',
  45. tag = 'buffer-metadata'
  46. },
  47. {
  48. name = 'Transfers',
  49. tag = 'buffer-transfer'
  50. }
  51. }
  52. }