getBuffer.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. return {
  2. deprecated = true,
  3. tag = 'graphics-objects',
  4. summary = 'Get a temporary Buffer.',
  5. description = 'Returns a temporary Buffer.',
  6. arguments = {
  7. size = {
  8. type = 'number',
  9. description = 'The size of the Buffer, in bytes.'
  10. },
  11. length = {
  12. type = 'number',
  13. default = '1',
  14. description = 'The length of the Buffer.'
  15. },
  16. data = {
  17. type = 'table',
  18. description = [[
  19. The initial data to put into the Buffer. The length of the Buffer will be determined by the
  20. contents of the table. The contents can be a mix of tables, numbers, and vectors, but the
  21. length calculation requires each field to consistently use one type of data.
  22. ]]
  23. },
  24. blob = {
  25. type = 'Blob',
  26. description = [[
  27. A Blob with the initial contents of the Buffer. The size of the Blob will be used to
  28. determine the length of the Buffer.
  29. ]]
  30. },
  31. type = {
  32. type = 'DataType',
  33. description = 'The type of each item in the Buffer.'
  34. },
  35. format = {
  36. type = 'table',
  37. description = 'A list of fields in the Buffer.',
  38. table = {
  39. {
  40. name = 'layout',
  41. type = 'DataLayout',
  42. default = 'packed',
  43. description = 'How to lay out the Buffer fields in memory.'
  44. },
  45. {
  46. name = 'stride',
  47. type = 'number',
  48. description = [[
  49. The stride of the Buffer, in bytes. When `nil`, the stride will be automatically
  50. computed based on the fields. The stride can not be zero or smaller than the max byte
  51. occupied by one of the fields. The layout of the Buffer may adjust the stride.
  52. ]]
  53. }
  54. }
  55. }
  56. },
  57. returns = {
  58. buffer = {
  59. type = 'Buffer',
  60. description = 'The new Buffer.'
  61. }
  62. },
  63. variants = {
  64. {
  65. arguments = { 'size' },
  66. returns = { 'buffer' }
  67. },
  68. {
  69. arguments = { 'blob' },
  70. returns = { 'buffer' }
  71. },
  72. {
  73. arguments = { 'format', 'length' },
  74. returns = { 'buffer' }
  75. },
  76. {
  77. arguments = { 'format', 'data' },
  78. returns = { 'buffer' }
  79. },
  80. {
  81. arguments = { 'format', 'blob' },
  82. returns = { 'buffer' }
  83. },
  84. {
  85. arguments = { 'type', 'length' },
  86. returns = { 'buffer' }
  87. },
  88. {
  89. arguments = { 'type', 'data' },
  90. returns = { 'buffer' }
  91. },
  92. {
  93. arguments = { 'type', 'blob' },
  94. returns = { 'buffer' }
  95. },
  96. {
  97. deprecated = true,
  98. arguments = { 'length', 'type' },
  99. returns = { 'buffer' }
  100. },
  101. {
  102. deprecated = true,
  103. arguments = { 'data', 'type' },
  104. returns = { 'buffer' }
  105. },
  106. {
  107. deprecated = true,
  108. arguments = { 'length', 'format' },
  109. returns = { 'buffer' }
  110. },
  111. {
  112. deprecated = true,
  113. arguments = { 'data', 'format' },
  114. returns = { 'buffer' }
  115. },
  116. {
  117. deprecated = true,
  118. arguments = { 'blob', 'type' },
  119. returns = { 'buffer' }
  120. },
  121. {
  122. deprecated = true,
  123. arguments = { 'blob', 'format' },
  124. returns = { 'buffer' }
  125. }
  126. },
  127. notes = [[
  128. The format table can contain a list of `DataType`s or a list of tables to provide extra
  129. information about each field. Each inner table has the following keys:
  130. - `type` is the `DataType` of the field and is required.
  131. - `name` is the name of the field, used to match table keys and vertex attribute names.
  132. - `offset` is the byte offset of the field. Any fields with a `nil` offset will be placed next
  133. to each other sequentially in memory, subject to any padding required by the Buffer's layout.
  134. In practice this means that you probably want to provide an `offset` for either all of the
  135. fields or none of them.
  136. - `length` is the array size of the field.
  137. As a shorthand, the name, type, and optionally the length of a field can be provided as a list
  138. instead of using keys.
  139. If no table or Blob is used to define the initial Buffer contents, its data will be undefined.
  140. ]],
  141. example = {
  142. description = 'Examples of different buffer formats.',
  143. code = [[
  144. -- 2 matrices
  145. lovr.graphics.getBuffer('mat4', 2)
  146. -- 3 integers, with initial data
  147. lovr.graphics.getBuffer('int', { 1, 2, 3 })
  148. -- a simple mesh:
  149. lovr.graphics.getBuffer({
  150. { name = 'VertexPosition', type = 'vec3' },
  151. { name = 'VertexColor', type = 'color' }
  152. }, 4)
  153. -- a uniform buffer with vec3's, using the std140 packing
  154. lovr.graphics.getBuffer({ 'vec3', layout = 'std140' }, data)
  155. -- a uniform buffer with key-value fields
  156. lovr.graphics.getBuffer({
  157. { 'AmbientColor', 'vec3' },
  158. { 'LightPosition', 'vec3' },
  159. { 'LightType', 'u32' },
  160. { 'LightColor', 'vec4' },
  161. layout = 'std140'
  162. })
  163. -- a buffer with nested structure and array types
  164. lovr.graphics.getBuffer({
  165. { 'globals', {
  166. { 'ObjectCount', 'int' },
  167. { 'WorldSize', 'vec2' },
  168. { 'Scale', 'float' }
  169. }},
  170. { 'materials', {
  171. { 'Color', 'vec4' },
  172. { 'Glow', 'vec3' },
  173. { 'Roughness', 'float' }
  174. }, length = 32 },
  175. layout = 'std430'
  176. })
  177. -- a buffer using a variable from a shader:
  178. lovr.graphics.getBuffer(shader:getBufferFormat('transforms'))
  179. ]]
  180. }
  181. }