getShaderCode.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. return {
  2. summary = 'Get a GLSL string that defines the ShaderBlock in a Shader.',
  3. description = [[
  4. Before a ShaderBlock can be used in a Shader, the Shader has to have the block's variables
  5. defined in its source code. This can be a tedious process, so you can call this function to
  6. return a GLSL string that contains this definition. Roughly, it will look something like this:
  7. layout(std140) uniform <label> {
  8. <type> <name>[<count>];
  9. } <namespace>;
  10. ]],
  11. arguments = {
  12. {
  13. name = 'label',
  14. type = 'string',
  15. description = [[
  16. The label of the block in the shader code. This will be used to identify it when using
  17. `Shader:sendBlock`.
  18. ]]
  19. },
  20. {
  21. name = 'namespace',
  22. type = 'string',
  23. default = 'nil',
  24. description = [[
  25. The namespace to use when accessing the block's variables in the shader code. This can be
  26. used to prevent naming conflicts if two blocks have variables with the same name. If the
  27. namespace is nil, the block's variables will be available in the global scope.
  28. ]]
  29. }
  30. },
  31. returns = {
  32. {
  33. name = 'code',
  34. type = 'string',
  35. description = 'The code that can be prepended to `Shader` code.'
  36. }
  37. },
  38. example = [=[
  39. block = lovr.graphics.newShaderBlock('uniform', {
  40. sizes = { 'float', 10 }
  41. })
  42. code = [[
  43. #ifdef VERTEX
  44. ]] .. block:getShaderCode('MyBlock', 'sizeBlock') .. [[
  45. // vertex shader goes here,
  46. // it can access sizeBlock.sizes
  47. #endif
  48. #ifdef PIXEL
  49. // fragment shader goes here
  50. #endif
  51. ]]
  52. shader = lovr.graphics.newShader(code, code)
  53. shader:sendBlock('MyBlock', block)
  54. ]=],
  55. related = {
  56. 'lovr.graphics.newShader',
  57. 'lovr.graphics.newComputeShader'
  58. }
  59. }