DataArrayTexture.html 5.1 KB

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