newTexture.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. return {
  2. tag = 'graphics-objects',
  3. summary = 'Create a new Texture.',
  4. description = [[
  5. Creates a new Texture. Image filenames or `Image` objects can be used to provide the initial
  6. pixel data and the dimensions, format, and type. Alternatively, dimensions can be provided,
  7. which will create an empty texture.
  8. ]],
  9. arguments = {
  10. filename = {
  11. type = 'string',
  12. description = 'The filename of an image to load.'
  13. },
  14. image = {
  15. type = 'string',
  16. description = 'An Image object holding pixel data to load into the Texture.'
  17. },
  18. blob = {
  19. type = 'Blob',
  20. description = 'A Blob object holding pixel data to load into the Texture.'
  21. },
  22. width = {
  23. type = 'number',
  24. description = 'The width of the Texture, in pixels.'
  25. },
  26. height = {
  27. type = 'number',
  28. description = 'The height of the Texture, in pixels.'
  29. },
  30. layers = {
  31. type = 'number',
  32. description = 'The number of layers in the Texture.'
  33. },
  34. images = {
  35. type = 'table',
  36. description = 'A table of filenames or Images to load into the Texture.'
  37. },
  38. options = {
  39. type = 'table',
  40. description = 'Texture options.',
  41. table = {
  42. {
  43. name = 'type',
  44. type = 'TextureType',
  45. description = 'The type of the texture.'
  46. },
  47. {
  48. name = 'format',
  49. type = 'TextureFormat',
  50. default = [['rgba8']],
  51. description = 'The format of the texture (ignored when images are provided).'
  52. },
  53. {
  54. name = 'linear',
  55. type = 'boolean',
  56. default = 'false',
  57. description = [[
  58. Whether the texture is in linear color space instead of sRGB. Linear textures should be
  59. used for non-color data, like normal maps.
  60. ]]
  61. },
  62. {
  63. name = 'samples',
  64. type = 'number',
  65. default = '1',
  66. description = [[
  67. The number of samples in the texture, used for multisample antialiasing. Currently must be 1 or 4. Ignored when images are provided.
  68. ]]
  69. },
  70. {
  71. name = 'mipmaps',
  72. type = '*',
  73. default = 'true',
  74. description = [[
  75. The number of mipmap levels in the texture, or a boolean. If true, a full mipmap chain
  76. will be created. If false, the texture will only have a single mipmap.
  77. ]]
  78. },
  79. {
  80. name = 'usage',
  81. type = 'table',
  82. description = 'A list of `TextureUsage` indicating how the texture will be used.'
  83. },
  84. {
  85. name = 'label',
  86. type = 'string',
  87. description = 'A label for the Texture that will show up in debugging tools.'
  88. }
  89. }
  90. }
  91. },
  92. returns = {
  93. texture = {
  94. type = 'Texture',
  95. description = 'The new Texture.'
  96. }
  97. },
  98. variants = {
  99. {
  100. arguments = { 'filename', 'options' },
  101. returns = { 'texture' }
  102. },
  103. {
  104. arguments = { 'width', 'height', 'options' },
  105. returns = { 'texture' }
  106. },
  107. {
  108. arguments = { 'width', 'height', 'layers', 'options' },
  109. returns = { 'texture' }
  110. },
  111. {
  112. arguments = { 'image', 'options' },
  113. returns = { 'texture' }
  114. },
  115. {
  116. arguments = { 'images', 'options' },
  117. returns = { 'texture' }
  118. },
  119. {
  120. arguments = { 'blob', 'options' },
  121. returns = { 'texture' }
  122. }
  123. },
  124. notes = [[
  125. If no `type` is provided in the options table, LÖVR will guess the `TextureType` of the Texture
  126. based on the number of layers:
  127. - If there's only 1 layer, the type will be `2d`.
  128. - If there are 6 images provided, the type will be `cube`.
  129. - Otherwise, the type will be `array`.
  130. Note that an Image can contain multiple layers and mipmaps. When a single Image is provided,
  131. its layer count will be used as the Texture's layer count.
  132. If multiple Images are used to initialize the Texture, they must all have a single layer, and
  133. their dimensions, format, and mipmap counts must match.
  134. When providing cubemap images in a table, they can be in one of the following forms:
  135. { 'px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png' }
  136. { right = 'px.png', left = 'nx.png', top = 'py.png', bottom = 'ny.png', back = 'pz.png', front = 'nz.png' }
  137. { px = 'px.png', nx = 'nx.png', py = 'py.png', ny = 'ny.png', pz = 'pz.png', nz = 'nz.png' }
  138. (Where 'p' stands for positive and 'n' stands for negative).
  139. If no `usage` is provided in the options table, LÖVR will guess the `TextureUsage` of the
  140. Texture. The `sample` usage is always included, but if the texture was created without any
  141. images then the texture will have the `render` usage as well.
  142. The supported image formats are png, jpg, hdr, dds, ktx1, ktx2, and astc.
  143. If image data is provided, mipmaps will be generated for any missing mipmap levels.
  144. ]],
  145. related = {
  146. 'Texture:newView'
  147. }
  148. }