ComponentDatatype-69643096.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './WebGLConstants-497deb20'], function (exports, defined, Check, freezeObject, defaultValue, WebGLConstants) { 'use strict';
  3. /**
  4. * WebGL component datatypes. Components are intrinsics,
  5. * which form attributes, which form vertices.
  6. *
  7. * @exports ComponentDatatype
  8. */
  9. var ComponentDatatype = {
  10. /**
  11. * 8-bit signed byte corresponding to <code>gl.BYTE</code> and the type
  12. * of an element in <code>Int8Array</code>.
  13. *
  14. * @type {Number}
  15. * @constant
  16. */
  17. BYTE : WebGLConstants.WebGLConstants.BYTE,
  18. /**
  19. * 8-bit unsigned byte corresponding to <code>UNSIGNED_BYTE</code> and the type
  20. * of an element in <code>Uint8Array</code>.
  21. *
  22. * @type {Number}
  23. * @constant
  24. */
  25. UNSIGNED_BYTE : WebGLConstants.WebGLConstants.UNSIGNED_BYTE,
  26. /**
  27. * 16-bit signed short corresponding to <code>SHORT</code> and the type
  28. * of an element in <code>Int16Array</code>.
  29. *
  30. * @type {Number}
  31. * @constant
  32. */
  33. SHORT : WebGLConstants.WebGLConstants.SHORT,
  34. /**
  35. * 16-bit unsigned short corresponding to <code>UNSIGNED_SHORT</code> and the type
  36. * of an element in <code>Uint16Array</code>.
  37. *
  38. * @type {Number}
  39. * @constant
  40. */
  41. UNSIGNED_SHORT : WebGLConstants.WebGLConstants.UNSIGNED_SHORT,
  42. /**
  43. * 32-bit signed int corresponding to <code>INT</code> and the type
  44. * of an element in <code>Int32Array</code>.
  45. *
  46. * @memberOf ComponentDatatype
  47. *
  48. * @type {Number}
  49. * @constant
  50. */
  51. INT : WebGLConstants.WebGLConstants.INT,
  52. /**
  53. * 32-bit unsigned int corresponding to <code>UNSIGNED_INT</code> and the type
  54. * of an element in <code>Uint32Array</code>.
  55. *
  56. * @memberOf ComponentDatatype
  57. *
  58. * @type {Number}
  59. * @constant
  60. */
  61. UNSIGNED_INT : WebGLConstants.WebGLConstants.UNSIGNED_INT,
  62. /**
  63. * 32-bit floating-point corresponding to <code>FLOAT</code> and the type
  64. * of an element in <code>Float32Array</code>.
  65. *
  66. * @type {Number}
  67. * @constant
  68. */
  69. FLOAT : WebGLConstants.WebGLConstants.FLOAT,
  70. /**
  71. * 64-bit floating-point corresponding to <code>gl.DOUBLE</code> (in Desktop OpenGL;
  72. * this is not supported in WebGL, and is emulated in Cesium via {@link GeometryPipeline.encodeAttribute})
  73. * and the type of an element in <code>Float64Array</code>.
  74. *
  75. * @memberOf ComponentDatatype
  76. *
  77. * @type {Number}
  78. * @constant
  79. * @default 0x140A
  80. */
  81. DOUBLE : WebGLConstants.WebGLConstants.DOUBLE
  82. };
  83. /**
  84. * Returns the size, in bytes, of the corresponding datatype.
  85. *
  86. * @param {ComponentDatatype} componentDatatype The component datatype to get the size of.
  87. * @returns {Number} The size in bytes.
  88. *
  89. * @exception {DeveloperError} componentDatatype is not a valid value.
  90. *
  91. * @example
  92. * // Returns Int8Array.BYTES_PER_ELEMENT
  93. * var size = Cesium.ComponentDatatype.getSizeInBytes(Cesium.ComponentDatatype.BYTE);
  94. */
  95. ComponentDatatype.getSizeInBytes = function(componentDatatype){
  96. //>>includeStart('debug', pragmas.debug);
  97. if (!defined.defined(componentDatatype)) {
  98. throw new Check.DeveloperError('value is required.');
  99. }
  100. //>>includeEnd('debug');
  101. switch (componentDatatype) {
  102. case ComponentDatatype.BYTE:
  103. return Int8Array.BYTES_PER_ELEMENT;
  104. case ComponentDatatype.UNSIGNED_BYTE:
  105. return Uint8Array.BYTES_PER_ELEMENT;
  106. case ComponentDatatype.SHORT:
  107. return Int16Array.BYTES_PER_ELEMENT;
  108. case ComponentDatatype.UNSIGNED_SHORT:
  109. return Uint16Array.BYTES_PER_ELEMENT;
  110. case ComponentDatatype.INT:
  111. return Int32Array.BYTES_PER_ELEMENT;
  112. case ComponentDatatype.UNSIGNED_INT:
  113. return Uint32Array.BYTES_PER_ELEMENT;
  114. case ComponentDatatype.FLOAT:
  115. return Float32Array.BYTES_PER_ELEMENT;
  116. case ComponentDatatype.DOUBLE:
  117. return Float64Array.BYTES_PER_ELEMENT;
  118. //>>includeStart('debug', pragmas.debug);
  119. default:
  120. throw new Check.DeveloperError('componentDatatype is not a valid value.');
  121. //>>includeEnd('debug');
  122. }
  123. };
  124. /**
  125. * Gets the {@link ComponentDatatype} for the provided TypedArray instance.
  126. *
  127. * @param {TypedArray} array The typed array.
  128. * @returns {ComponentDatatype} The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.
  129. */
  130. ComponentDatatype.fromTypedArray = function(array) {
  131. if (array instanceof Int8Array) {
  132. return ComponentDatatype.BYTE;
  133. }
  134. if (array instanceof Uint8Array) {
  135. return ComponentDatatype.UNSIGNED_BYTE;
  136. }
  137. if (array instanceof Int16Array) {
  138. return ComponentDatatype.SHORT;
  139. }
  140. if (array instanceof Uint16Array) {
  141. return ComponentDatatype.UNSIGNED_SHORT;
  142. }
  143. if (array instanceof Int32Array) {
  144. return ComponentDatatype.INT;
  145. }
  146. if (array instanceof Uint32Array) {
  147. return ComponentDatatype.UNSIGNED_INT;
  148. }
  149. if (array instanceof Float32Array) {
  150. return ComponentDatatype.FLOAT;
  151. }
  152. if (array instanceof Float64Array) {
  153. return ComponentDatatype.DOUBLE;
  154. }
  155. };
  156. /**
  157. * Validates that the provided component datatype is a valid {@link ComponentDatatype}
  158. *
  159. * @param {ComponentDatatype} componentDatatype The component datatype to validate.
  160. * @returns {Boolean} <code>true</code> if the provided component datatype is a valid value; otherwise, <code>false</code>.
  161. *
  162. * @example
  163. * if (!Cesium.ComponentDatatype.validate(componentDatatype)) {
  164. * throw new Cesium.DeveloperError('componentDatatype must be a valid value.');
  165. * }
  166. */
  167. ComponentDatatype.validate = function(componentDatatype) {
  168. return defined.defined(componentDatatype) &&
  169. (componentDatatype === ComponentDatatype.BYTE ||
  170. componentDatatype === ComponentDatatype.UNSIGNED_BYTE ||
  171. componentDatatype === ComponentDatatype.SHORT ||
  172. componentDatatype === ComponentDatatype.UNSIGNED_SHORT ||
  173. componentDatatype === ComponentDatatype.INT ||
  174. componentDatatype === ComponentDatatype.UNSIGNED_INT ||
  175. componentDatatype === ComponentDatatype.FLOAT ||
  176. componentDatatype === ComponentDatatype.DOUBLE);
  177. };
  178. /**
  179. * Creates a typed array corresponding to component data type.
  180. *
  181. * @param {ComponentDatatype} componentDatatype The component data type.
  182. * @param {Number|Array} valuesOrLength The length of the array to create or an array.
  183. * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array.
  184. *
  185. * @exception {DeveloperError} componentDatatype is not a valid value.
  186. *
  187. * @example
  188. * // creates a Float32Array with length of 100
  189. * var typedArray = Cesium.ComponentDatatype.createTypedArray(Cesium.ComponentDatatype.FLOAT, 100);
  190. */
  191. ComponentDatatype.createTypedArray = function(componentDatatype, valuesOrLength) {
  192. //>>includeStart('debug', pragmas.debug);
  193. if (!defined.defined(componentDatatype)) {
  194. throw new Check.DeveloperError('componentDatatype is required.');
  195. }
  196. if (!defined.defined(valuesOrLength)) {
  197. throw new Check.DeveloperError('valuesOrLength is required.');
  198. }
  199. //>>includeEnd('debug');
  200. switch (componentDatatype) {
  201. case ComponentDatatype.BYTE:
  202. return new Int8Array(valuesOrLength);
  203. case ComponentDatatype.UNSIGNED_BYTE:
  204. return new Uint8Array(valuesOrLength);
  205. case ComponentDatatype.SHORT:
  206. return new Int16Array(valuesOrLength);
  207. case ComponentDatatype.UNSIGNED_SHORT:
  208. return new Uint16Array(valuesOrLength);
  209. case ComponentDatatype.INT:
  210. return new Int32Array(valuesOrLength);
  211. case ComponentDatatype.UNSIGNED_INT:
  212. return new Uint32Array(valuesOrLength);
  213. case ComponentDatatype.FLOAT:
  214. return new Float32Array(valuesOrLength);
  215. case ComponentDatatype.DOUBLE:
  216. return new Float64Array(valuesOrLength);
  217. //>>includeStart('debug', pragmas.debug);
  218. default:
  219. throw new Check.DeveloperError('componentDatatype is not a valid value.');
  220. //>>includeEnd('debug');
  221. }
  222. };
  223. /**
  224. * Creates a typed view of an array of bytes.
  225. *
  226. * @param {ComponentDatatype} componentDatatype The type of the view to create.
  227. * @param {ArrayBuffer} buffer The buffer storage to use for the view.
  228. * @param {Number} [byteOffset] The offset, in bytes, to the first element in the view.
  229. * @param {Number} [length] The number of elements in the view.
  230. * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array view of the buffer.
  231. *
  232. * @exception {DeveloperError} componentDatatype is not a valid value.
  233. */
  234. ComponentDatatype.createArrayBufferView = function(componentDatatype, buffer, byteOffset, length) {
  235. //>>includeStart('debug', pragmas.debug);
  236. if (!defined.defined(componentDatatype)) {
  237. throw new Check.DeveloperError('componentDatatype is required.');
  238. }
  239. if (!defined.defined(buffer)) {
  240. throw new Check.DeveloperError('buffer is required.');
  241. }
  242. //>>includeEnd('debug');
  243. byteOffset = defaultValue.defaultValue(byteOffset, 0);
  244. length = defaultValue.defaultValue(length, (buffer.byteLength - byteOffset) / ComponentDatatype.getSizeInBytes(componentDatatype));
  245. switch (componentDatatype) {
  246. case ComponentDatatype.BYTE:
  247. return new Int8Array(buffer, byteOffset, length);
  248. case ComponentDatatype.UNSIGNED_BYTE:
  249. return new Uint8Array(buffer, byteOffset, length);
  250. case ComponentDatatype.SHORT:
  251. return new Int16Array(buffer, byteOffset, length);
  252. case ComponentDatatype.UNSIGNED_SHORT:
  253. return new Uint16Array(buffer, byteOffset, length);
  254. case ComponentDatatype.INT:
  255. return new Int32Array(buffer, byteOffset, length);
  256. case ComponentDatatype.UNSIGNED_INT:
  257. return new Uint32Array(buffer, byteOffset, length);
  258. case ComponentDatatype.FLOAT:
  259. return new Float32Array(buffer, byteOffset, length);
  260. case ComponentDatatype.DOUBLE:
  261. return new Float64Array(buffer, byteOffset, length);
  262. //>>includeStart('debug', pragmas.debug);
  263. default:
  264. throw new Check.DeveloperError('componentDatatype is not a valid value.');
  265. //>>includeEnd('debug');
  266. }
  267. };
  268. /**
  269. * Get the ComponentDatatype from its name.
  270. *
  271. * @param {String} name The name of the ComponentDatatype.
  272. * @returns {ComponentDatatype} The ComponentDatatype.
  273. *
  274. * @exception {DeveloperError} name is not a valid value.
  275. */
  276. ComponentDatatype.fromName = function(name) {
  277. switch (name) {
  278. case 'BYTE':
  279. return ComponentDatatype.BYTE;
  280. case 'UNSIGNED_BYTE':
  281. return ComponentDatatype.UNSIGNED_BYTE;
  282. case 'SHORT':
  283. return ComponentDatatype.SHORT;
  284. case 'UNSIGNED_SHORT':
  285. return ComponentDatatype.UNSIGNED_SHORT;
  286. case 'INT':
  287. return ComponentDatatype.INT;
  288. case 'UNSIGNED_INT':
  289. return ComponentDatatype.UNSIGNED_INT;
  290. case 'FLOAT':
  291. return ComponentDatatype.FLOAT;
  292. case 'DOUBLE':
  293. return ComponentDatatype.DOUBLE;
  294. //>>includeStart('debug', pragmas.debug);
  295. default:
  296. throw new Check.DeveloperError('name is not a valid value.');
  297. //>>includeEnd('debug');
  298. }
  299. };
  300. var ComponentDatatype$1 = freezeObject.freezeObject(ComponentDatatype);
  301. exports.ComponentDatatype = ComponentDatatype$1;
  302. });