2
0

DataArrayTexture.html 5.1 KB

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