rawTexture2DArray.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Texture } from "./texture.js";
  2. import "../../Engines/Extensions/engine.rawTexture.js";
  3. /**
  4. * Class used to store 2D array textures containing user data
  5. */
  6. export class RawTexture2DArray extends Texture {
  7. /**
  8. * Gets the number of layers of the texture
  9. */
  10. get depth() {
  11. return this._depth;
  12. }
  13. /**
  14. * Create a new RawTexture2DArray
  15. * @param data defines the data of the texture
  16. * @param width defines the width of the texture
  17. * @param height defines the height of the texture
  18. * @param depth defines the number of layers of the texture
  19. * @param format defines the texture format to use
  20. * @param scene defines the hosting scene
  21. * @param generateMipMaps defines a boolean indicating if mip levels should be generated (true by default)
  22. * @param invertY defines if texture must be stored with Y axis inverted
  23. * @param samplingMode defines the sampling mode to use (Texture.TRILINEAR_SAMPLINGMODE by default)
  24. * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)
  25. * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)
  26. */
  27. constructor(data, width, height, depth,
  28. /** Gets or sets the texture format to use */
  29. format, scene, generateMipMaps = true, invertY = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, textureType = 0, creationFlags) {
  30. super(null, scene, !generateMipMaps, invertY);
  31. this.format = format;
  32. this._texture = scene.getEngine().createRawTexture2DArray(data, width, height, depth, format, generateMipMaps, invertY, samplingMode, null, textureType, creationFlags);
  33. this._depth = depth;
  34. this.is2DArray = true;
  35. }
  36. /**
  37. * Update the texture with new data
  38. * @param data defines the data to store in the texture
  39. */
  40. update(data) {
  41. if (!this._texture) {
  42. return;
  43. }
  44. this._getEngine().updateRawTexture2DArray(this._texture, data, this._texture.format, this._texture.invertY, null, this._texture.type);
  45. }
  46. /**
  47. * Creates a RGBA texture from some data.
  48. * @param data Define the texture data
  49. * @param width Define the width of the texture
  50. * @param height Define the height of the texture
  51. * @param depth defines the number of layers of the texture
  52. * @param scene defines the scene the texture will belong to
  53. * @param generateMipMaps Define whether or not to create mip maps for the texture
  54. * @param invertY define if the data should be flipped on Y when uploaded to the GPU
  55. * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)
  56. * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)
  57. * @returns the RGBA texture
  58. */
  59. static CreateRGBATexture(data, width, height, depth, scene, generateMipMaps = true, invertY = false, samplingMode = 3, type = 0) {
  60. return new RawTexture2DArray(data, width, height, depth, 5, scene, generateMipMaps, invertY, samplingMode, type);
  61. }
  62. }
  63. //# sourceMappingURL=rawTexture2DArray.js.map