DataArrayTexture.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Texture] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. Creates an array of textures directly from raw data, width and height and
  14. depth.
  15. </p>
  16. <h2>Constructor</h2>
  17. <h3>[name]( data, width, height, depth )</h3>
  18. <p>
  19. The data argument must be an
  20. [link:https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView].
  21. The properties inherited from [page:Texture] are the
  22. default, except magFilter and minFilter default to THREE.NearestFilter.
  23. The properties flipY and generateMipmaps are initially set to false.
  24. </p>
  25. <p>
  26. The interpretation of the data depends on type and format: If the type is
  27. THREE.UnsignedByteType, a Uint8Array will be useful for addressing the
  28. texel data. If the format is THREE.RGBAFormat, data needs four values for
  29. one texel; Red, Green, Blue and Alpha (typically the opacity).<br />
  30. For the packed types, THREE.UnsignedShort4444Type and
  31. THREE.UnsignedShort5551Type all color components of one texel can be
  32. addressed as bitfields within an integer element of a Uint16Array.<br />
  33. In order to use the types THREE.FloatType and THREE.HalfFloatType, the
  34. WebGL implementation must support the respective extensions
  35. OES_texture_float and OES_texture_half_float. In order to use
  36. THREE.LinearFilter for component-wise, bilinear interpolation of the
  37. texels based on these types, the WebGL extensions OES_texture_float_linear
  38. or OES_texture_half_float_linear must also be present.
  39. </p>
  40. <h2>Code Example</h2>
  41. <p>This creates a [name] where each texture has a different color.</p>
  42. <code>
  43. // create a buffer with color data
  44. const width = 512;
  45. const height = 512;
  46. const depth = 100;
  47. const size = width * height;
  48. const data = new Uint8Array( 4 * size * depth );
  49. for ( let i = 0; i < depth; i ++ ) {
  50. const color = new THREE.Color( Math.random(), Math.random(), Math.random() );
  51. const r = Math.floor( color.r * 255 );
  52. const g = Math.floor( color.g * 255 );
  53. const b = Math.floor( color.b * 255 );
  54. for ( let j = 0; j < size; j ++ ) {
  55. const stride = ( i * size + j ) * 4;
  56. data[ stride ] = r;
  57. data[ stride + 1 ] = g;
  58. data[ stride + 2 ] = b;
  59. data[ stride + 3 ] = 255;
  60. }
  61. }
  62. // used the buffer to create a [name]
  63. const texture = new THREE.DataArrayTexture( data, width, height, depth );
  64. texture.needsUpdate = true;
  65. </code>
  66. <h2>Examples</h2>
  67. <p>
  68. [example:webgl_texture2darray WebGL / texture2darray]<br />
  69. [example:webgl_rendertarget_texture2darray WebGL / rendertarget / texture2darray]
  70. </p>
  71. <h2>Properties</h2>
  72. <p>See the base [page:Texture Texture] class for common properties.</p>
  73. <h3>[property:Boolean flipY]</h3>
  74. <p>
  75. Whether the texture is flipped along the Y axis when uploaded to the GPU.
  76. Default is `false`.
  77. </p>
  78. <h3>[property:Boolean generateMipmaps]</h3>
  79. <p>
  80. Whether to generate mipmaps (if possible) for the texture. Default is
  81. `false`.
  82. </p>
  83. <h3>[property:Object image]</h3>
  84. <p>Overridden with a object holding data, width, height, and depth.</p>
  85. <h3>[property:Boolean isDataArrayTexture]</h3>
  86. <p>Read-only flag to check if a given object is of type [name].</p>
  87. <h3>[property:number magFilter]</h3>
  88. <p>
  89. How the texture is sampled when a texel covers more than one pixel. The
  90. default is [page:Textures THREE.NearestFilter], which uses the value of
  91. the closest texel.<br /><br />
  92. See the [page:Textures texture constants] page for details.
  93. </p>
  94. <h3>[property:number minFilter]</h3>
  95. <p>
  96. How the texture is sampled when a texel covers less than one pixel. The
  97. default is [page:Textures THREE.NearestFilter], which uses the value of
  98. the closest texel.<br /><br />
  99. See the [page:Textures texture constants] page for details.
  100. </p>
  101. <h3>[property:number unpackAlignment]</h3>
  102. <p>
  103. `1` by default. Specifies the alignment requirements for the start of each
  104. pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows
  105. aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on
  106. double-word boundaries). See
  107. [link:https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glPixelStorei.xhtml glPixelStorei] for more information.
  108. </p>
  109. <h3>[property:number wrapR]</h3>
  110. <p>
  111. This defines how the texture is wrapped in the depth direction.<br />
  112. The default is [page:Textures THREE.ClampToEdgeWrapping], where the edge
  113. is clamped to the outer edge texels. The other two choices are
  114. [page:Textures THREE.RepeatWrapping] and [page:Textures THREE.MirroredRepeatWrapping].
  115. See the [page:Textures texture constants]
  116. page for details.
  117. </p>
  118. <h3>[property:Set layerUpdates]</h3>
  119. <p>
  120. A set of all layers which need to be updated in the texture. See
  121. [Page:DataArrayTexture.addLayerUpdate addLayerUpdate].
  122. </p>
  123. <h2>Methods</h2>
  124. <h3>[method:addLayerUpdate addLayerUpdate]( layerIndex )</h3>
  125. <p>
  126. Describes that a specific layer of the texture needs to be updated.
  127. Normally when [page:Texture.needsUpdate needsUpdate] is set to true, the
  128. entire compressed texture array is sent to the GPU. Marking specific
  129. layers will only transmit subsets of all mipmaps associated with a
  130. specific depth in the array which is often much more performant.
  131. </p>
  132. <h3>[method:clearLayerUpdates clearLayerUpdates]()</h3>
  133. <p>
  134. Resets the layer updates registry. See
  135. [Page:DataArrayTexture.addLayerUpdate addLayerUpdate].
  136. </p>
  137. <p>See the base [page:Texture Texture] class for common methods.</p>
  138. <h2>Source</h2>
  139. <p>
  140. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  141. </p>
  142. </body>
  143. </html>