DataTexture.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Texture } from './Texture.js';
  2. import { NearestFilter } from '../constants.js';
  3. /**
  4. * Creates a texture directly from raw buffer data.
  5. *
  6. * The interpretation of the data depends on type and format: If the type is
  7. * `UnsignedByteType`, a `Uint8Array` will be useful for addressing the
  8. * texel data. If the format is `RGBAFormat`, data needs four values for
  9. * one texel; Red, Green, Blue and Alpha (typically the opacity).
  10. *
  11. * @augments Texture
  12. */
  13. class DataTexture extends Texture {
  14. /**
  15. * Constructs a new data texture.
  16. *
  17. * @param {?TypedArray} [data=null] - The buffer data.
  18. * @param {number} [width=1] - The width of the texture.
  19. * @param {number} [height=1] - The height of the texture.
  20. * @param {number} [format=RGBAFormat] - The texture format.
  21. * @param {number} [type=UnsignedByteType] - The texture type.
  22. * @param {number} [mapping=Texture.DEFAULT_MAPPING] - The texture mapping.
  23. * @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.
  24. * @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.
  25. * @param {number} [magFilter=NearestFilter] - The mag filter value.
  26. * @param {number} [minFilter=NearestFilter] - The min filter value.
  27. * @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
  28. * @param {string} [colorSpace=NoColorSpace] - The color space.
  29. */
  30. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) {
  31. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  32. /**
  33. * This flag can be used for type testing.
  34. *
  35. * @type {boolean}
  36. * @readonly
  37. * @default true
  38. */
  39. this.isDataTexture = true;
  40. /**
  41. * The image definition of a data texture.
  42. *
  43. * @type {{data:TypedArray,width:number,height:number}}
  44. */
  45. this.image = { data: data, width: width, height: height };
  46. /**
  47. * Whether to generate mipmaps (if possible) for a texture.
  48. *
  49. * Overwritten and set to `false` by default.
  50. *
  51. * @type {boolean}
  52. * @default false
  53. */
  54. this.generateMipmaps = false;
  55. /**
  56. * If set to `true`, the texture is flipped along the vertical axis when
  57. * uploaded to the GPU.
  58. *
  59. * Overwritten and set to `false` by default.
  60. *
  61. * @type {boolean}
  62. * @default false
  63. */
  64. this.flipY = false;
  65. /**
  66. * Specifies the alignment requirements for the start of each pixel row in memory.
  67. *
  68. * Overwritten and set to `1` by default.
  69. *
  70. * @type {boolean}
  71. * @default 1
  72. */
  73. this.unpackAlignment = 1;
  74. }
  75. }
  76. export { DataTexture };
粤ICP备19079148号