CompressedTextureBuffer.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import defined from "./defined.js";
  2. /**
  3. * Describes a compressed texture and contains a compressed texture buffer.
  4. * @alias CompressedTextureBuffer
  5. * @constructor
  6. *
  7. * @param {PixelFormat} internalFormat The pixel format of the compressed texture.
  8. * @param {PixelDatatype} pixelDatatype The pixel datatype of the compressed texture.
  9. * @param {number} width The width of the texture.
  10. * @param {number} height The height of the texture.
  11. * @param {Uint8Array} buffer The compressed texture buffer.
  12. */
  13. function CompressedTextureBuffer(
  14. internalFormat,
  15. pixelDatatype,
  16. width,
  17. height,
  18. buffer
  19. ) {
  20. this._format = internalFormat;
  21. this._datatype = pixelDatatype;
  22. this._width = width;
  23. this._height = height;
  24. this._buffer = buffer;
  25. }
  26. Object.defineProperties(CompressedTextureBuffer.prototype, {
  27. /**
  28. * The format of the compressed texture.
  29. * @type {PixelFormat}
  30. * @readonly
  31. * @memberof CompressedTextureBuffer.prototype
  32. */
  33. internalFormat: {
  34. get: function () {
  35. return this._format;
  36. },
  37. },
  38. /**
  39. * The datatype of the compressed texture.
  40. * @type {PixelDatatype}
  41. * @readonly
  42. * @memberof CompressedTextureBuffer.prototype
  43. */
  44. pixelDatatype: {
  45. get: function () {
  46. return this._datatype;
  47. },
  48. },
  49. /**
  50. * The width of the texture.
  51. * @type {number}
  52. * @readonly
  53. * @memberof CompressedTextureBuffer.prototype
  54. */
  55. width: {
  56. get: function () {
  57. return this._width;
  58. },
  59. },
  60. /**
  61. * The height of the texture.
  62. * @type {number}
  63. * @readonly
  64. * @memberof CompressedTextureBuffer.prototype
  65. */
  66. height: {
  67. get: function () {
  68. return this._height;
  69. },
  70. },
  71. /**
  72. * The compressed texture buffer.
  73. * @type {Uint8Array}
  74. * @readonly
  75. * @memberof CompressedTextureBuffer.prototype
  76. */
  77. bufferView: {
  78. get: function () {
  79. return this._buffer;
  80. },
  81. },
  82. });
  83. /**
  84. * Creates a shallow clone of a compressed texture buffer.
  85. *
  86. * @param {CompressedTextureBuffer} object The compressed texture buffer to be cloned.
  87. * @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
  88. */
  89. CompressedTextureBuffer.clone = function (object) {
  90. if (!defined(object)) {
  91. return undefined;
  92. }
  93. return new CompressedTextureBuffer(
  94. object._format,
  95. object._datatype,
  96. object._width,
  97. object._height,
  98. object._buffer
  99. );
  100. };
  101. /**
  102. * Creates a shallow clone of this compressed texture buffer.
  103. *
  104. * @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
  105. */
  106. CompressedTextureBuffer.prototype.clone = function () {
  107. return CompressedTextureBuffer.clone(this);
  108. };
  109. export default CompressedTextureBuffer;