IndexDatatype-3de60176.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './Math-fa6e45cb', './WebGLConstants-497deb20'], function (exports, defined, Check, freezeObject, _Math, WebGLConstants) { 'use strict';
  3. /**
  4. * Constants for WebGL index datatypes. These corresponds to the
  5. * <code>type</code> parameter of {@link http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDrawElements.xml|drawElements}.
  6. *
  7. * @exports IndexDatatype
  8. */
  9. var IndexDatatype = {
  10. /**
  11. * 8-bit unsigned byte corresponding to <code>UNSIGNED_BYTE</code> and the type
  12. * of an element in <code>Uint8Array</code>.
  13. *
  14. * @type {Number}
  15. * @constant
  16. */
  17. UNSIGNED_BYTE : WebGLConstants.WebGLConstants.UNSIGNED_BYTE,
  18. /**
  19. * 16-bit unsigned short corresponding to <code>UNSIGNED_SHORT</code> and the type
  20. * of an element in <code>Uint16Array</code>.
  21. *
  22. * @type {Number}
  23. * @constant
  24. */
  25. UNSIGNED_SHORT : WebGLConstants.WebGLConstants.UNSIGNED_SHORT,
  26. /**
  27. * 32-bit unsigned int corresponding to <code>UNSIGNED_INT</code> and the type
  28. * of an element in <code>Uint32Array</code>.
  29. *
  30. * @type {Number}
  31. * @constant
  32. */
  33. UNSIGNED_INT : WebGLConstants.WebGLConstants.UNSIGNED_INT
  34. };
  35. /**
  36. * Returns the size, in bytes, of the corresponding datatype.
  37. *
  38. * @param {IndexDatatype} indexDatatype The index datatype to get the size of.
  39. * @returns {Number} The size in bytes.
  40. *
  41. * @example
  42. * // Returns 2
  43. * var size = Cesium.IndexDatatype.getSizeInBytes(Cesium.IndexDatatype.UNSIGNED_SHORT);
  44. */
  45. IndexDatatype.getSizeInBytes = function(indexDatatype) {
  46. switch(indexDatatype) {
  47. case IndexDatatype.UNSIGNED_BYTE:
  48. return Uint8Array.BYTES_PER_ELEMENT;
  49. case IndexDatatype.UNSIGNED_SHORT:
  50. return Uint16Array.BYTES_PER_ELEMENT;
  51. case IndexDatatype.UNSIGNED_INT:
  52. return Uint32Array.BYTES_PER_ELEMENT;
  53. }
  54. //>>includeStart('debug', pragmas.debug);
  55. throw new Check.DeveloperError('indexDatatype is required and must be a valid IndexDatatype constant.');
  56. //>>includeEnd('debug');
  57. };
  58. /**
  59. * Gets the datatype with a given size in bytes.
  60. *
  61. * @param {Number} sizeInBytes The size of a single index in bytes.
  62. * @returns {IndexDatatype} The index datatype with the given size.
  63. */
  64. IndexDatatype.fromSizeInBytes = function(sizeInBytes) {
  65. switch (sizeInBytes) {
  66. case 2:
  67. return IndexDatatype.UNSIGNED_SHORT;
  68. case 4:
  69. return IndexDatatype.UNSIGNED_INT;
  70. case 1:
  71. return IndexDatatype.UNSIGNED_BYTE;
  72. //>>includeStart('debug', pragmas.debug);
  73. default:
  74. throw new Check.DeveloperError('Size in bytes cannot be mapped to an IndexDatatype');
  75. //>>includeEnd('debug');
  76. }
  77. };
  78. /**
  79. * Validates that the provided index datatype is a valid {@link IndexDatatype}.
  80. *
  81. * @param {IndexDatatype} indexDatatype The index datatype to validate.
  82. * @returns {Boolean} <code>true</code> if the provided index datatype is a valid value; otherwise, <code>false</code>.
  83. *
  84. * @example
  85. * if (!Cesium.IndexDatatype.validate(indexDatatype)) {
  86. * throw new Cesium.DeveloperError('indexDatatype must be a valid value.');
  87. * }
  88. */
  89. IndexDatatype.validate = function(indexDatatype) {
  90. return defined.defined(indexDatatype) &&
  91. (indexDatatype === IndexDatatype.UNSIGNED_BYTE ||
  92. indexDatatype === IndexDatatype.UNSIGNED_SHORT ||
  93. indexDatatype === IndexDatatype.UNSIGNED_INT);
  94. };
  95. /**
  96. * Creates a typed array that will store indices, using either <code><Uint16Array</code>
  97. * or <code>Uint32Array</code> depending on the number of vertices.
  98. *
  99. * @param {Number} numberOfVertices Number of vertices that the indices will reference.
  100. * @param {Number|Array} indicesLengthOrArray Passed through to the typed array constructor.
  101. * @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>indicesLengthOrArray</code>.
  102. *
  103. * @example
  104. * this.indices = Cesium.IndexDatatype.createTypedArray(positions.length / 3, numberOfIndices);
  105. */
  106. IndexDatatype.createTypedArray = function(numberOfVertices, indicesLengthOrArray) {
  107. //>>includeStart('debug', pragmas.debug);
  108. if (!defined.defined(numberOfVertices)) {
  109. throw new Check.DeveloperError('numberOfVertices is required.');
  110. }
  111. //>>includeEnd('debug');
  112. if (numberOfVertices >= _Math.CesiumMath.SIXTY_FOUR_KILOBYTES) {
  113. return new Uint32Array(indicesLengthOrArray);
  114. }
  115. return new Uint16Array(indicesLengthOrArray);
  116. };
  117. /**
  118. * Creates a typed array from a source array buffer. The resulting typed array will store indices, using either <code><Uint16Array</code>
  119. * or <code>Uint32Array</code> depending on the number of vertices.
  120. *
  121. * @param {Number} numberOfVertices Number of vertices that the indices will reference.
  122. * @param {ArrayBuffer} sourceArray Passed through to the typed array constructor.
  123. * @param {Number} byteOffset Passed through to the typed array constructor.
  124. * @param {Number} length Passed through to the typed array constructor.
  125. * @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>sourceArray</code>, <code>byteOffset</code>, and <code>length</code>.
  126. *
  127. */
  128. IndexDatatype.createTypedArrayFromArrayBuffer = function(numberOfVertices, sourceArray, byteOffset, length) {
  129. //>>includeStart('debug', pragmas.debug);
  130. if (!defined.defined(numberOfVertices)) {
  131. throw new Check.DeveloperError('numberOfVertices is required.');
  132. }
  133. if (!defined.defined(sourceArray)) {
  134. throw new Check.DeveloperError('sourceArray is required.');
  135. }
  136. if (!defined.defined(byteOffset)) {
  137. throw new Check.DeveloperError('byteOffset is required.');
  138. }
  139. //>>includeEnd('debug');
  140. if (numberOfVertices >= _Math.CesiumMath.SIXTY_FOUR_KILOBYTES) {
  141. return new Uint32Array(sourceArray, byteOffset, length);
  142. }
  143. return new Uint16Array(sourceArray, byteOffset, length);
  144. };
  145. var IndexDatatype$1 = freezeObject.freezeObject(IndexDatatype);
  146. exports.IndexDatatype = IndexDatatype$1;
  147. });