DataArrayTexture.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { Texture } from './Texture.js';
  2. import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
  3. /**
  4. * Creates an array of textures directly from raw buffer data.
  5. *
  6. * @augments Texture
  7. */
  8. class DataArrayTexture extends Texture {
  9. /**
  10. * Constructs a new data array texture.
  11. *
  12. * @param {?TypedArray} [data=null] - The buffer data.
  13. * @param {number} [width=1] - The width of the texture.
  14. * @param {number} [height=1] - The height of the texture.
  15. * @param {number} [depth=1] - The depth of the texture.
  16. */
  17. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  18. super( null );
  19. /**
  20. * This flag can be used for type testing.
  21. *
  22. * @type {boolean}
  23. * @readonly
  24. * @default true
  25. */
  26. this.isDataArrayTexture = true;
  27. /**
  28. * The image definition of a data texture.
  29. *
  30. * @type {{data:TypedArray,width:number,height:number,depth:number}}
  31. */
  32. this.image = { data, width, height, depth };
  33. /**
  34. * How the texture is sampled when a texel covers more than one pixel.
  35. *
  36. * Overwritten and set to `NearestFilter` by default.
  37. *
  38. * @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
  39. * @default NearestFilter
  40. */
  41. this.magFilter = NearestFilter;
  42. /**
  43. * How the texture is sampled when a texel covers less than one pixel.
  44. *
  45. * Overwritten and set to `NearestFilter` by default.
  46. *
  47. * @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
  48. * @default NearestFilter
  49. */
  50. this.minFilter = NearestFilter;
  51. /**
  52. * This defines how the texture is wrapped in the depth and corresponds to
  53. * *W* in UVW mapping.
  54. *
  55. * @type {(RepeatWrapping|ClampToEdgeWrapping|MirroredRepeatWrapping)}
  56. * @default ClampToEdgeWrapping
  57. */
  58. this.wrapR = ClampToEdgeWrapping;
  59. /**
  60. * Whether to generate mipmaps (if possible) for a texture.
  61. *
  62. * Overwritten and set to `false` by default.
  63. *
  64. * @type {boolean}
  65. * @default false
  66. */
  67. this.generateMipmaps = false;
  68. /**
  69. * If set to `true`, the texture is flipped along the vertical axis when
  70. * uploaded to the GPU.
  71. *
  72. * Overwritten and set to `false` by default.
  73. *
  74. * @type {boolean}
  75. * @default false
  76. */
  77. this.flipY = false;
  78. /**
  79. * Specifies the alignment requirements for the start of each pixel row in memory.
  80. *
  81. * Overwritten and set to `1` by default.
  82. *
  83. * @type {boolean}
  84. * @default 1
  85. */
  86. this.unpackAlignment = 1;
  87. /**
  88. * A set of all layers which need to be updated in the texture.
  89. *
  90. * @type {Set<number>}
  91. */
  92. this.layerUpdates = new Set();
  93. }
  94. /**
  95. * Describes that a specific layer of the texture needs to be updated.
  96. * Normally when {@link Texture#needsUpdate} is set to `true`, the
  97. * entire data texture array is sent to the GPU. Marking specific
  98. * layers will only transmit subsets of all mipmaps associated with a
  99. * specific depth in the array which is often much more performant.
  100. *
  101. * @param {number} layerIndex - The layer index that should be updated.
  102. */
  103. addLayerUpdate( layerIndex ) {
  104. this.layerUpdates.add( layerIndex );
  105. }
  106. /**
  107. * Resets the layer updates registry.
  108. */
  109. clearLayerUpdates() {
  110. this.layerUpdates.clear();
  111. }
  112. }
  113. export { DataArrayTexture };
粤ICP备19079148号