CompressedTextureBuffer.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 {Number} width The width of the texture.
  9. * @param {Number} height The height of the texture.
  10. * @param {Uint8Array} buffer The compressed texture buffer.
  11. */
  12. function CompressedTextureBuffer(internalFormat, width, height, buffer) {
  13. this._format = internalFormat;
  14. this._width = width;
  15. this._height = height;
  16. this._buffer = buffer;
  17. }
  18. Object.defineProperties(CompressedTextureBuffer.prototype, {
  19. /**
  20. * The format of the compressed texture.
  21. * @type PixelFormat
  22. * @readonly
  23. * @memberof CompressedTextureBuffer.prototype
  24. */
  25. internalFormat: {
  26. get: function () {
  27. return this._format;
  28. },
  29. },
  30. /**
  31. * The width of the texture.
  32. * @type Number
  33. * @readonly
  34. * @memberof CompressedTextureBuffer.prototype
  35. */
  36. width: {
  37. get: function () {
  38. return this._width;
  39. },
  40. },
  41. /**
  42. * The height of the texture.
  43. * @type Number
  44. * @readonly
  45. * @memberof CompressedTextureBuffer.prototype
  46. */
  47. height: {
  48. get: function () {
  49. return this._height;
  50. },
  51. },
  52. /**
  53. * The compressed texture buffer.
  54. * @type Uint8Array
  55. * @readonly
  56. * @memberof CompressedTextureBuffer.prototype
  57. */
  58. bufferView: {
  59. get: function () {
  60. return this._buffer;
  61. },
  62. },
  63. });
  64. /**
  65. * Creates a shallow clone of a compressed texture buffer.
  66. *
  67. * @param {CompressedTextureBuffer} object The compressed texture buffer to be cloned.
  68. * @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
  69. */
  70. CompressedTextureBuffer.clone = function (object) {
  71. if (!defined(object)) {
  72. return undefined;
  73. }
  74. return new CompressedTextureBuffer(
  75. object._format,
  76. object._width,
  77. object._height,
  78. object._buffer
  79. );
  80. };
  81. /**
  82. * Creates a shallow clone of this compressed texture buffer.
  83. *
  84. * @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
  85. */
  86. CompressedTextureBuffer.prototype.clone = function () {
  87. return CompressedTextureBuffer.clone(this);
  88. };
  89. export default CompressedTextureBuffer;