newComputeShader.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. return {
  2. tag = 'graphicsObjects',
  3. summary = 'Create a new compute Shader.',
  4. description = [[
  5. Creates a new compute Shader, used for running generic compute operations on the GPU.
  6. ]],
  7. arguments = {
  8. {
  9. name = 'source',
  10. type = 'string',
  11. description = 'The code or filename of the compute shader.'
  12. },
  13. {
  14. name = 'options',
  15. type = 'table',
  16. default = '{}',
  17. description = 'Optional settings for the Shader.',
  18. table = {
  19. {
  20. name = 'flags',
  21. type = 'table',
  22. default = '{}',
  23. description = 'A table of key-value options passed to the Shader.'
  24. }
  25. }
  26. }
  27. },
  28. returns = {
  29. {
  30. name = 'shader',
  31. type = 'Shader',
  32. description = 'The new compute Shader.'
  33. }
  34. },
  35. notes = [[
  36. Compute shaders are not supported on all hardware, use `lovr.graphics.getFeatures` to check if
  37. they're available on the current system.
  38. The source code for a compute shader needs to implement the `void compute();` GLSL function.
  39. This function doesn't return anything, but the compute shader is able to write data out to
  40. `Texture`s or `ShaderBlock`s.
  41. The GLSL version used for compute shaders is GLSL 430.
  42. Currently, up to 32 shader flags are supported.
  43. ]],
  44. example = [=[
  45. function lovr.load()
  46. computer = lovr.graphics.newComputeShader([[
  47. layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
  48. void compute() {
  49. // compute things!?
  50. }
  51. ]])
  52. -- Run the shader 4 times
  53. local width, height, depth = 4, 1, 1
  54. -- Dispatch the compute operation
  55. lovr.graphics.compute(computer, width, height, depth)
  56. end
  57. ]=],
  58. related = {
  59. 'lovr.graphics.compute',
  60. 'lovr.graphics.newShader',
  61. 'lovr.graphics.setShader',
  62. 'lovr.graphics.getShader'
  63. }
  64. }