2445 lines
226 KiB
JavaScript
2445 lines
226 KiB
JavaScript
|
/**
|
||
|
* Cesium - https://github.com/AnalyticalGraphicsInc/cesium
|
||
|
*
|
||
|
* Copyright 2011-2017 Cesium Contributors
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*
|
||
|
* Columbus View (Pat. Pend.)
|
||
|
*
|
||
|
* Portions licensed separately.
|
||
|
* See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
|
||
|
*/
|
||
|
(function () {
|
||
|
define('Core/defined',[],function() {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* @exports defined
|
||
|
*
|
||
|
* @param {*} value The object.
|
||
|
* @returns {Boolean} Returns true if the object is defined, returns false otherwise.
|
||
|
*
|
||
|
* @example
|
||
|
* if (Cesium.defined(positions)) {
|
||
|
* doSomething();
|
||
|
* } else {
|
||
|
* doSomethingElse();
|
||
|
* }
|
||
|
*/
|
||
|
function defined(value) {
|
||
|
return value !== undefined && value !== null;
|
||
|
}
|
||
|
|
||
|
return defined;
|
||
|
});
|
||
|
|
||
|
define('Core/defineProperties',[
|
||
|
'./defined'
|
||
|
], function(
|
||
|
defined) {
|
||
|
'use strict';
|
||
|
|
||
|
var definePropertyWorks = (function() {
|
||
|
try {
|
||
|
return 'x' in Object.defineProperty({}, 'x', {});
|
||
|
} catch (e) {
|
||
|
return false;
|
||
|
}
|
||
|
})();
|
||
|
|
||
|
/**
|
||
|
* Defines properties on an object, using Object.defineProperties if available,
|
||
|
* otherwise returns the object unchanged. This function should be used in
|
||
|
* setup code to prevent errors from completely halting JavaScript execution
|
||
|
* in legacy browsers.
|
||
|
*
|
||
|
* @private
|
||
|
*
|
||
|
* @exports defineProperties
|
||
|
*/
|
||
|
var defineProperties = Object.defineProperties;
|
||
|
if (!definePropertyWorks || !defined(defineProperties)) {
|
||
|
defineProperties = function(o) {
|
||
|
return o;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
return defineProperties;
|
||
|
});
|
||
|
|
||
|
define('Core/CompressedTextureBuffer',[
|
||
|
'./defined',
|
||
|
'./defineProperties'
|
||
|
], function(
|
||
|
defined,
|
||
|
defineProperties) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Describes a compressed texture and contains a compressed texture buffer.
|
||
|
* @alias CompressedTextureBuffer
|
||
|
* @constructor
|
||
|
*
|
||
|
* @param {PixelFormat} internalFormat The pixel format of the compressed texture.
|
||
|
* @param {Number} width The width of the texture.
|
||
|
* @param {Number} height The height of the texture.
|
||
|
* @param {Uint8Array} buffer The compressed texture buffer.
|
||
|
*/
|
||
|
function CompressedTextureBuffer(internalFormat, width, height, buffer) {
|
||
|
this._format = internalFormat;
|
||
|
this._width = width;
|
||
|
this._height = height;
|
||
|
this._buffer = buffer;
|
||
|
}
|
||
|
|
||
|
defineProperties(CompressedTextureBuffer.prototype, {
|
||
|
/**
|
||
|
* The format of the compressed texture.
|
||
|
* @type PixelFormat
|
||
|
* @readonly
|
||
|
* @memberof CompressedTextureBuffer.prototype
|
||
|
*/
|
||
|
internalFormat : {
|
||
|
get : function() {
|
||
|
return this._format;
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* The width of the texture.
|
||
|
* @type Number
|
||
|
* @readonly
|
||
|
* @memberof CompressedTextureBuffer.prototype
|
||
|
*/
|
||
|
width : {
|
||
|
get : function() {
|
||
|
return this._width;
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* The height of the texture.
|
||
|
* @type Number
|
||
|
* @readonly
|
||
|
* @memberof CompressedTextureBuffer.prototype
|
||
|
*/
|
||
|
height : {
|
||
|
get : function() {
|
||
|
return this._height;
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* The compressed texture buffer.
|
||
|
* @type Uint8Array
|
||
|
* @readonly
|
||
|
* @memberof CompressedTextureBuffer.prototype
|
||
|
*/
|
||
|
bufferView : {
|
||
|
get : function() {
|
||
|
return this._buffer;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Creates a shallow clone of a compressed texture buffer.
|
||
|
*
|
||
|
* @param {CompressedTextureBuffer} object The compressed texture buffer to be cloned.
|
||
|
* @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
|
||
|
*/
|
||
|
CompressedTextureBuffer.clone = function(object) {
|
||
|
if (!defined(object)) {
|
||
|
return undefined;
|
||
|
}
|
||
|
|
||
|
return new CompressedTextureBuffer(object._format, object._width, object._height, object._buffer);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Creates a shallow clone of this compressed texture buffer.
|
||
|
*
|
||
|
* @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
|
||
|
*/
|
||
|
CompressedTextureBuffer.prototype.clone = function() {
|
||
|
return CompressedTextureBuffer.clone(this);
|
||
|
};
|
||
|
|
||
|
return CompressedTextureBuffer;
|
||
|
});
|
||
|
|
||
|
define('Core/freezeObject',[
|
||
|
'./defined'
|
||
|
], function(
|
||
|
defined) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Freezes an object, using Object.freeze if available, otherwise returns
|
||
|
* the object unchanged. This function should be used in setup code to prevent
|
||
|
* errors from completely halting JavaScript execution in legacy browsers.
|
||
|
*
|
||
|
* @private
|
||
|
*
|
||
|
* @exports freezeObject
|
||
|
*/
|
||
|
var freezeObject = Object.freeze;
|
||
|
if (!defined(freezeObject)) {
|
||
|
freezeObject = function(o) {
|
||
|
return o;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
return freezeObject;
|
||
|
});
|
||
|
|
||
|
define('Core/WebGLConstants',[
|
||
|
'./freezeObject'
|
||
|
], function(
|
||
|
freezeObject) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Enum containing WebGL Constant values by name.
|
||
|
* for use without an active WebGL context, or in cases where certain constants are unavailable using the WebGL context
|
||
|
* (For example, in [Safari 9]{@link https://github.com/AnalyticalGraphicsInc/cesium/issues/2989}).
|
||
|
*
|
||
|
* These match the constants from the [WebGL 1.0]{@link https://www.khronos.org/registry/webgl/specs/latest/1.0/}
|
||
|
* and [WebGL 2.0]{@link https://www.khronos.org/registry/webgl/specs/latest/2.0/}
|
||
|
* specifications.
|
||
|
*
|
||
|
* @exports WebGLConstants
|
||
|
*/
|
||
|
var WebGLConstants = {
|
||
|
DEPTH_BUFFER_BIT : 0x00000100,
|
||
|
STENCIL_BUFFER_BIT : 0x00000400,
|
||
|
COLOR_BUFFER_BIT : 0x00004000,
|
||
|
POINTS : 0x0000,
|
||
|
LINES : 0x0001,
|
||
|
LINE_LOOP : 0x0002,
|
||
|
LINE_STRIP : 0x0003,
|
||
|
TRIANGLES : 0x0004,
|
||
|
TRIANGLE_STRIP : 0x0005,
|
||
|
TRIANGLE_FAN : 0x0006,
|
||
|
ZERO : 0,
|
||
|
ONE : 1,
|
||
|
SRC_COLOR : 0x0300,
|
||
|
ONE_MINUS_SRC_COLOR : 0x0301,
|
||
|
SRC_ALPHA : 0x0302,
|
||
|
ONE_MINUS_SRC_ALPHA : 0x0303,
|
||
|
DST_ALPHA : 0x0304,
|
||
|
ONE_MINUS_DST_ALPHA : 0x0305,
|
||
|
DST_COLOR : 0x0306,
|
||
|
ONE_MINUS_DST_COLOR : 0x0307,
|
||
|
SRC_ALPHA_SATURATE : 0x0308,
|
||
|
FUNC_ADD : 0x8006,
|
||
|
BLEND_EQUATION : 0x8009,
|
||
|
BLEND_EQUATION_RGB : 0x8009, // same as BLEND_EQUATION
|
||
|
BLEND_EQUATION_ALPHA : 0x883D,
|
||
|
FUNC_SUBTRACT : 0x800A,
|
||
|
FUNC_REVERSE_SUBTRACT : 0x800B,
|
||
|
BLEND_DST_RGB : 0x80C8,
|
||
|
BLEND_SRC_RGB : 0x80C9,
|
||
|
BLEND_DST_ALPHA : 0x80CA,
|
||
|
BLEND_SRC_ALPHA : 0x80CB,
|
||
|
CONSTANT_COLOR : 0x8001,
|
||
|
ONE_MINUS_CONSTANT_COLOR : 0x8002,
|
||
|
CONSTANT_ALPHA : 0x8003,
|
||
|
ONE_MINUS_CONSTANT_ALPHA : 0x8004,
|
||
|
BLEND_COLOR : 0x8005,
|
||
|
ARRAY_BUFFER : 0x8892,
|
||
|
ELEMENT_ARRAY_BUFFER : 0x8893,
|
||
|
ARRAY_BUFFER_BINDING : 0x8894,
|
||
|
ELEMENT_ARRAY_BUFFER_BINDING : 0x8895,
|
||
|
STREAM_DRAW : 0x88E0,
|
||
|
STATIC_DRAW : 0x88E4,
|
||
|
DYNAMIC_DRAW : 0x88E8,
|
||
|
BUFFER_SIZE : 0x8764,
|
||
|
BUFFER_USAGE : 0x8765,
|
||
|
CURRENT_VERTEX_ATTRIB : 0x8626,
|
||
|
FRONT : 0x0404,
|
||
|
BACK : 0x0405,
|
||
|
FRONT_AND_BACK : 0x0408,
|
||
|
CULL_FACE : 0x0B44,
|
||
|
BLEND : 0x0BE2,
|
||
|
DITHER : 0x0BD0,
|
||
|
STENCIL_TEST : 0x0B90,
|
||
|
DEPTH_TEST : 0x0B71,
|
||
|
SCISSOR_TEST : 0x0C11,
|
||
|
POLYGON_OFFSET_FILL : 0x8037,
|
||
|
SAMPLE_ALPHA_TO_COVERAGE : 0x809E,
|
||
|
SAMPLE_COVERAGE : 0x80A0,
|
||
|
NO_ERROR : 0,
|
||
|
INVALID_ENUM : 0x0500,
|
||
|
INVALID_VALUE : 0x0501,
|
||
|
INVALID_OPERATION : 0x0502,
|
||
|
OUT_OF_MEMORY : 0x0505,
|
||
|
CW : 0x0900,
|
||
|
CCW : 0x0901,
|
||
|
LINE_WIDTH : 0x0B21,
|
||
|
ALIASED_POINT_SIZE_RANGE : 0x846D,
|
||
|
ALIASED_LINE_WIDTH_RANGE : 0x846E,
|
||
|
CULL_FACE_MODE : 0x0B45,
|
||
|
FRONT_FACE : 0x0B46,
|
||
|
DEPTH_RANGE : 0x0B70,
|
||
|
DEPTH_WRITEMASK : 0x0B72,
|
||
|
DEPTH_CLEAR_VALUE : 0x0B73,
|
||
|
DEPTH_FUNC : 0x0B74,
|
||
|
STENCIL_CLEAR_VALUE : 0x0B91,
|
||
|
STENCIL_FUNC : 0x0B92,
|
||
|
STENCIL_FAIL : 0x0B94,
|
||
|
STENCIL_PASS_DEPTH_FAIL : 0x0B95,
|
||
|
STENCIL_PASS_DEPTH_PASS : 0x0B96,
|
||
|
STENCIL_REF : 0x0B97,
|
||
|
STENCIL_VALUE_MASK : 0x0B93,
|
||
|
STENCIL_WRITEMASK : 0x0B98,
|
||
|
STENCIL_BACK_FUNC : 0x8800,
|
||
|
STENCIL_BACK_FAIL : 0x8801,
|
||
|
STENCIL_BACK_PASS_DEPTH_FAIL : 0x8802,
|
||
|
STENCIL_BACK_PASS_DEPTH_PASS : 0x8803,
|
||
|
STENCIL_BACK_REF : 0x8CA3,
|
||
|
STENCIL_BACK_VALUE_MASK : 0x8CA4,
|
||
|
STENCIL_BACK_WRITEMASK : 0x8CA5,
|
||
|
VIEWPORT : 0x0BA2,
|
||
|
SCISSOR_BOX : 0x0C10,
|
||
|
COLOR_CLEAR_VALUE : 0x0C22,
|
||
|
COLOR_WRITEMASK : 0x0C23,
|
||
|
UNPACK_ALIGNMENT : 0x0CF5,
|
||
|
PACK_ALIGNMENT : 0x0D05,
|
||
|
MAX_TEXTURE_SIZE : 0x0D33,
|
||
|
MAX_VIEWPORT_DIMS : 0x0D3A,
|
||
|
SUBPIXEL_BITS : 0x0D50,
|
||
|
RED_BITS : 0x0D52,
|
||
|
GREEN_BITS : 0x0D53,
|
||
|
BLUE_BITS : 0x0D54,
|
||
|
ALPHA_BITS : 0x0D55,
|
||
|
DEPTH_BITS : 0x0D56,
|
||
|
STENCIL_BITS : 0x0D57,
|
||
|
POLYGON_OFFSET_UNITS : 0x2A00,
|
||
|
POLYGON_OFFSET_FACTOR : 0x8038,
|
||
|
TEXTURE_BINDING_2D : 0x8069,
|
||
|
SAMPLE_BUFFERS : 0x80A8,
|
||
|
SAMPLES : 0x80A9,
|
||
|
SAMPLE_COVERAGE_VALUE : 0x80AA,
|
||
|
SAMPLE_COVERAGE_INVERT : 0x80AB,
|
||
|
COMPRESSED_TEXTURE_FORMATS : 0x86A3,
|
||
|
DONT_CARE : 0x1100,
|
||
|
FASTEST : 0x1101,
|
||
|
NICEST : 0x1102,
|
||
|
GENERATE_MIPMAP_HINT : 0x8192,
|
||
|
BYTE : 0x1400,
|
||
|
UNSIGNED_BYTE : 0x1401,
|
||
|
SHORT : 0x1402,
|
||
|
UNSIGNED_SHORT : 0x1403,
|
||
|
INT : 0x1404,
|
||
|
UNSIGNED_INT : 0x1405,
|
||
|
FLOAT : 0x1406,
|
||
|
DEPTH_COMPONENT : 0x1902,
|
||
|
ALPHA : 0x1906,
|
||
|
RGB : 0x1907,
|
||
|
RGBA : 0x1908,
|
||
|
LUMINANCE : 0x1909,
|
||
|
LUMINANCE_ALPHA : 0x190A,
|
||
|
UNSIGNED_SHORT_4_4_4_4 : 0x8033,
|
||
|
UNSIGNED_SHORT_5_5_5_1 : 0x8034,
|
||
|
UNSIGNED_SHORT_5_6_5 : 0x8363,
|
||
|
FRAGMENT_SHADER : 0x8B30,
|
||
|
VERTEX_SHADER : 0x8B31,
|
||
|
MAX_VERTEX_ATTRIBS : 0x8869,
|
||
|
MAX_VERTEX_UNIFORM_VECTORS : 0x8DFB,
|
||
|
MAX_VARYING_VECTORS : 0x8DFC,
|
||
|
MAX_COMBINED_TEXTURE_IMAGE_UNITS : 0x8B4D,
|
||
|
MAX_VERTEX_TEXTURE_IMAGE_UNITS : 0x8B4C,
|
||
|
MAX_TEXTURE_IMAGE_UNITS : 0x8872,
|
||
|
MAX_FRAGMENT_UNIFORM_VECTORS : 0x8DFD,
|
||
|
SHADER_TYPE : 0x8B4F,
|
||
|
DELETE_STATUS : 0x8B80,
|
||
|
LINK_STATUS : 0x8B82,
|
||
|
VALIDATE_STATUS : 0x8B83,
|
||
|
ATTACHED_SHADERS : 0x8B85,
|
||
|
ACTIVE_UNIFORMS : 0x8B86,
|
||
|
ACTIVE_ATTRIBUTES : 0x8B89,
|
||
|
SHADING_LANGUAGE_VERSION : 0x8B8C,
|
||
|
CURRENT_PROGRAM : 0x8B8D,
|
||
|
NEVER : 0x0200,
|
||
|
LESS : 0x0201,
|
||
|
EQUAL : 0x0202,
|
||
|
LEQUAL : 0x0203,
|
||
|
GREATER : 0x0204,
|
||
|
NOTEQUAL : 0x0205,
|
||
|
GEQUAL : 0x0206,
|
||
|
ALWAYS : 0x0207,
|
||
|
KEEP : 0x1E00,
|
||
|
REPLACE : 0x1E01,
|
||
|
INCR : 0x1E02,
|
||
|
DECR : 0x1E03,
|
||
|
INVERT : 0x150A,
|
||
|
INCR_WRAP : 0x8507,
|
||
|
DECR_WRAP : 0x8508,
|
||
|
VENDOR : 0x1F00,
|
||
|
RENDERER : 0x1F01,
|
||
|
VERSION : 0x1F02,
|
||
|
NEAREST : 0x2600,
|
||
|
LINEAR : 0x2601,
|
||
|
NEAREST_MIPMAP_NEAREST : 0x2700,
|
||
|
LINEAR_MIPMAP_NEAREST : 0x2701,
|
||
|
NEAREST_MIPMAP_LINEAR : 0x2702,
|
||
|
LINEAR_MIPMAP_LINEAR : 0x2703,
|
||
|
TEXTURE_MAG_FILTER : 0x2800,
|
||
|
TEXTURE_MIN_FILTER : 0x2801,
|
||
|
TEXTURE_WRAP_S : 0x2802,
|
||
|
TEXTURE_WRAP_T : 0x2803,
|
||
|
TEXTURE_2D : 0x0DE1,
|
||
|
TEXTURE : 0x1702,
|
||
|
TEXTURE_CUBE_MAP : 0x8513,
|
||
|
TEXTURE_BINDING_CUBE_MAP : 0x8514,
|
||
|
TEXTURE_CUBE_MAP_POSITIVE_X : 0x8515,
|
||
|
TEXTURE_CUBE_MAP_NEGATIVE_X : 0x8516,
|
||
|
TEXTURE_CUBE_MAP_POSITIVE_Y : 0x8517,
|
||
|
TEXTURE_CUBE_MAP_NEGATIVE_Y : 0x8518,
|
||
|
TEXTURE_CUBE_MAP_POSITIVE_Z : 0x8519,
|
||
|
TEXTURE_CUBE_MAP_NEGATIVE_Z : 0x851A,
|
||
|
MAX_CUBE_MAP_TEXTURE_SIZE : 0x851C,
|
||
|
TEXTURE0 : 0x84C0,
|
||
|
TEXTURE1 : 0x84C1,
|
||
|
TEXTURE2 : 0x84C2,
|
||
|
TEXTURE3 : 0x84C3,
|
||
|
TEXTURE4 : 0x84C4,
|
||
|
TEXTURE5 : 0x84C5,
|
||
|
TEXTURE6 : 0x84C6,
|
||
|
TEXTURE7 : 0x84C7,
|
||
|
TEXTURE8 : 0x84C8,
|
||
|
TEXTURE9 : 0x84C9,
|
||
|
TEXTURE10 : 0x84CA,
|
||
|
TEXTURE11 : 0x84CB,
|
||
|
TEXTURE12 : 0x84CC,
|
||
|
TEXTURE13 : 0x84CD,
|
||
|
TEXTURE14 : 0x84CE,
|
||
|
TEXTURE15 : 0x84CF,
|
||
|
TEXTURE16 : 0x84D0,
|
||
|
TEXTURE17 : 0x84D1,
|
||
|
TEXTURE18 : 0x84D2,
|
||
|
TEXTURE19 : 0x84D3,
|
||
|
TEXTURE20 : 0x84D4,
|
||
|
TEXTURE21 : 0x84D5,
|
||
|
TEXTURE22 : 0x84D6,
|
||
|
TEXTURE23 : 0x84D7,
|
||
|
TEXTURE24 : 0x84D8,
|
||
|
TEXTURE25 : 0x84D9,
|
||
|
TEXTURE26 : 0x84DA,
|
||
|
TEXTURE27 : 0x84DB,
|
||
|
TEXTURE28 : 0x84DC,
|
||
|
TEXTURE29 : 0x84DD,
|
||
|
TEXTURE30 : 0x84DE,
|
||
|
TEXTURE31 : 0x84DF,
|
||
|
ACTIVE_TEXTURE : 0x84E0,
|
||
|
REPEAT : 0x2901,
|
||
|
CLAMP_TO_EDGE : 0x812F,
|
||
|
MIRRORED_REPEAT : 0x8370,
|
||
|
FLOAT_VEC2 : 0x8B50,
|
||
|
FLOAT_VEC3 : 0x8B51,
|
||
|
FLOAT_VEC4 : 0x8B52,
|
||
|
INT_VEC2 : 0x8B53,
|
||
|
INT_VEC3 : 0x8B54,
|
||
|
INT_VEC4 : 0x8B55,
|
||
|
BOOL : 0x8B56,
|
||
|
BOOL_VEC2 : 0x8B57,
|
||
|
BOOL_VEC3 : 0x8B58,
|
||
|
BOOL_VEC4 : 0x8B59,
|
||
|
FLOAT_MAT2 : 0x8B5A,
|
||
|
FLOAT_MAT3 : 0x8B5B,
|
||
|
FLOAT_MAT4 : 0x8B5C,
|
||
|
SAMPLER_2D : 0x8B5E,
|
||
|
SAMPLER_CUBE : 0x8B60,
|
||
|
VERTEX_ATTRIB_ARRAY_ENABLED : 0x8622,
|
||
|
VERTEX_ATTRIB_ARRAY_SIZE : 0x8623,
|
||
|
VERTEX_ATTRIB_ARRAY_STRIDE : 0x8624,
|
||
|
VERTEX_ATTRIB_ARRAY_TYPE : 0x8625,
|
||
|
VERTEX_ATTRIB_ARRAY_NORMALIZED : 0x886A,
|
||
|
VERTEX_ATTRIB_ARRAY_POINTER : 0x8645,
|
||
|
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING : 0x889F,
|
||
|
IMPLEMENTATION_COLOR_READ_TYPE : 0x8B9A,
|
||
|
IMPLEMENTATION_COLOR_READ_FORMAT : 0x8B9B,
|
||
|
COMPILE_STATUS : 0x8B81,
|
||
|
LOW_FLOAT : 0x8DF0,
|
||
|
MEDIUM_FLOAT : 0x8DF1,
|
||
|
HIGH_FLOAT : 0x8DF2,
|
||
|
LOW_INT : 0x8DF3,
|
||
|
MEDIUM_INT : 0x8DF4,
|
||
|
HIGH_INT : 0x8DF5,
|
||
|
FRAMEBUFFER : 0x8D40,
|
||
|
RENDERBUFFER : 0x8D41,
|
||
|
RGBA4 : 0x8056,
|
||
|
RGB5_A1 : 0x8057,
|
||
|
RGB565 : 0x8D62,
|
||
|
DEPTH_COMPONENT16 : 0x81A5,
|
||
|
STENCIL_INDEX : 0x1901,
|
||
|
STENCIL_INDEX8 : 0x8D48,
|
||
|
DEPTH_STENCIL : 0x84F9,
|
||
|
RENDERBUFFER_WIDTH : 0x8D42,
|
||
|
RENDERBUFFER_HEIGHT : 0x8D43,
|
||
|
RENDERBUFFER_INTERNAL_FORMAT : 0x8D44,
|
||
|
RENDERBUFFER_RED_SIZE : 0x8D50,
|
||
|
RENDERBUFFER_GREEN_SIZE : 0x8D51,
|
||
|
RENDERBUFFER_BLUE_SIZE : 0x8D52,
|
||
|
RENDERBUFFER_ALPHA_SIZE : 0x8D53,
|
||
|
RENDERBUFFER_DEPTH_SIZE : 0x8D54,
|
||
|
RENDERBUFFER_STENCIL_SIZE : 0x8D55,
|
||
|
FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE : 0x8CD0,
|
||
|
FRAMEBUFFER_ATTACHMENT_OBJECT_NAME : 0x8CD1,
|
||
|
FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL : 0x8CD2,
|
||
|
FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE : 0x8CD3,
|
||
|
COLOR_ATTACHMENT0 : 0x8CE0,
|
||
|
DEPTH_ATTACHMENT : 0x8D00,
|
||
|
STENCIL_ATTACHMENT : 0x8D20,
|
||
|
DEPTH_STENCIL_ATTACHMENT : 0x821A,
|
||
|
NONE : 0,
|
||
|
FRAMEBUFFER_COMPLETE : 0x8CD5,
|
||
|
FRAMEBUFFER_INCOMPLETE_ATTACHMENT : 0x8CD6,
|
||
|
FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : 0x8CD7,
|
||
|
FRAMEBUFFER_INCOMPLETE_DIMENSIONS : 0x8CD9,
|
||
|
FRAMEBUFFER_UNSUPPORTED : 0x8CDD,
|
||
|
FRAMEBUFFER_BINDING : 0x8CA6,
|
||
|
RENDERBUFFER_BINDING : 0x8CA7,
|
||
|
MAX_RENDERBUFFER_SIZE : 0x84E8,
|
||
|
INVALID_FRAMEBUFFER_OPERATION : 0x0506,
|
||
|
UNPACK_FLIP_Y_WEBGL : 0x9240,
|
||
|
UNPACK_PREMULTIPLY_ALPHA_WEBGL : 0x9241,
|
||
|
CONTEXT_LOST_WEBGL : 0x9242,
|
||
|
UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
|
||
|
BROWSER_DEFAULT_WEBGL : 0x9244,
|
||
|
|
||
|
// WEBGL_compressed_texture_s3tc
|
||
|
COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0,
|
||
|
COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1,
|
||
|
COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2,
|
||
|
COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3,
|
||
|
|
||
|
// WEBGL_compressed_texture_pvrtc
|
||
|
COMPRESSED_RGB_PVRTC_4BPPV1_IMG : 0x8C00,
|
||
|
COMPRESSED_RGB_PVRTC_2BPPV1_IMG : 0x8C01,
|
||
|
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : 0x8C02,
|
||
|
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG : 0x8C03,
|
||
|
|
||
|
// WEBGL_compressed_texture_etc1
|
||
|
COMPRESSED_RGB_ETC1_WEBGL : 0x8D64,
|
||
|
|
||
|
// EXT_color_buffer_half_float
|
||
|
HALF_FLOAT_OES : 0x8D61,
|
||
|
|
||
|
// Desktop OpenGL
|
||
|
DOUBLE : 0x140A,
|
||
|
|
||
|
// WebGL 2
|
||
|
READ_BUFFER : 0x0C02,
|
||
|
UNPACK_ROW_LENGTH : 0x0CF2,
|
||
|
UNPACK_SKIP_ROWS : 0x0CF3,
|
||
|
UNPACK_SKIP_PIXELS : 0x0CF4,
|
||
|
PACK_ROW_LENGTH : 0x0D02,
|
||
|
PACK_SKIP_ROWS : 0x0D03,
|
||
|
PACK_SKIP_PIXELS : 0x0D04,
|
||
|
COLOR : 0x1800,
|
||
|
DEPTH : 0x1801,
|
||
|
STENCIL : 0x1802,
|
||
|
RED : 0x1903,
|
||
|
RGB8 : 0x8051,
|
||
|
RGBA8 : 0x8058,
|
||
|
RGB10_A2 : 0x8059,
|
||
|
TEXTURE_BINDING_3D : 0x806A,
|
||
|
UNPACK_SKIP_IMAGES : 0x806D,
|
||
|
UNPACK_IMAGE_HEIGHT : 0x806E,
|
||
|
TEXTURE_3D : 0x806F,
|
||
|
TEXTURE_WRAP_R : 0x8072,
|
||
|
MAX_3D_TEXTURE_SIZE : 0x8073,
|
||
|
UNSIGNED_INT_2_10_10_10_REV : 0x8368,
|
||
|
MAX_ELEMENTS_VERTICES : 0x80E8,
|
||
|
MAX_ELEMENTS_INDICES : 0x80E9,
|
||
|
TEXTURE_MIN_LOD : 0x813A,
|
||
|
TEXTURE_MAX_LOD : 0x813B,
|
||
|
TEXTURE_BASE_LEVEL : 0x813C,
|
||
|
TEXTURE_MAX_LEVEL : 0x813D,
|
||
|
MIN : 0x8007,
|
||
|
MAX : 0x8008,
|
||
|
DEPTH_COMPONENT24 : 0x81A6,
|
||
|
MAX_TEXTURE_LOD_BIAS : 0x84FD,
|
||
|
TEXTURE_COMPARE_MODE : 0x884C,
|
||
|
TEXTURE_COMPARE_FUNC : 0x884D,
|
||
|
CURRENT_QUERY : 0x8865,
|
||
|
QUERY_RESULT : 0x8866,
|
||
|
QUERY_RESULT_AVAILABLE : 0x8867,
|
||
|
STREAM_READ : 0x88E1,
|
||
|
STREAM_COPY : 0x88E2,
|
||
|
STATIC_READ : 0x88E5,
|
||
|
STATIC_COPY : 0x88E6,
|
||
|
DYNAMIC_READ : 0x88E9,
|
||
|
DYNAMIC_COPY : 0x88EA,
|
||
|
MAX_DRAW_BUFFERS : 0x8824,
|
||
|
DRAW_BUFFER0 : 0x8825,
|
||
|
DRAW_BUFFER1 : 0x8826,
|
||
|
DRAW_BUFFER2 : 0x8827,
|
||
|
DRAW_BUFFER3 : 0x8828,
|
||
|
DRAW_BUFFER4 : 0x8829,
|
||
|
DRAW_BUFFER5 : 0x882A,
|
||
|
DRAW_BUFFER6 : 0x882B,
|
||
|
DRAW_BUFFER7 : 0x882C,
|
||
|
DRAW_BUFFER8 : 0x882D,
|
||
|
DRAW_BUFFER9 : 0x882E,
|
||
|
DRAW_BUFFER10 : 0x882F,
|
||
|
DRAW_BUFFER11 : 0x8830,
|
||
|
DRAW_BUFFER12 : 0x8831,
|
||
|
DRAW_BUFFER13 : 0x8832,
|
||
|
DRAW_BUFFER14 : 0x8833,
|
||
|
DRAW_BUFFER15 : 0x8834,
|
||
|
MAX_FRAGMENT_UNIFORM_COMPONENTS : 0x8B49,
|
||
|
MAX_VERTEX_UNIFORM_COMPONENTS : 0x8B4A,
|
||
|
SAMPLER_3D : 0x8B5F,
|
||
|
SAMPLER_2D_SHADOW : 0x8B62,
|
||
|
FRAGMENT_SHADER_DERIVATIVE_HINT : 0x8B8B,
|
||
|
PIXEL_PACK_BUFFER : 0x88EB,
|
||
|
PIXEL_UNPACK_BUFFER : 0x88EC,
|
||
|
PIXEL_PACK_BUFFER_BINDING : 0x88ED,
|
||
|
PIXEL_UNPACK_BUFFER_BINDING : 0x88EF,
|
||
|
FLOAT_MAT2x3 : 0x8B65,
|
||
|
FLOAT_MAT2x4 : 0x8B66,
|
||
|
FLOAT_MAT3x2 : 0x8B67,
|
||
|
FLOAT_MAT3x4 : 0x8B68,
|
||
|
FLOAT_MAT4x2 : 0x8B69,
|
||
|
FLOAT_MAT4x3 : 0x8B6A,
|
||
|
SRGB : 0x8C40,
|
||
|
SRGB8 : 0x8C41,
|
||
|
SRGB8_ALPHA8 : 0x8C43,
|
||
|
COMPARE_REF_TO_TEXTURE : 0x884E,
|
||
|
RGBA32F : 0x8814,
|
||
|
RGB32F : 0x8815,
|
||
|
RGBA16F : 0x881A,
|
||
|
RGB16F : 0x881B,
|
||
|
VERTEX_ATTRIB_ARRAY_INTEGER : 0x88FD,
|
||
|
MAX_ARRAY_TEXTURE_LAYERS : 0x88FF,
|
||
|
MIN_PROGRAM_TEXEL_OFFSET : 0x8904,
|
||
|
MAX_PROGRAM_TEXEL_OFFSET : 0x8905,
|
||
|
MAX_VARYING_COMPONENTS : 0x8B4B,
|
||
|
TEXTURE_2D_ARRAY : 0x8C1A,
|
||
|
TEXTURE_BINDING_2D_ARRAY : 0x8C1D,
|
||
|
R11F_G11F_B10F : 0x8C3A,
|
||
|
UNSIGNED_INT_10F_11F_11F_REV : 0x8C3B,
|
||
|
RGB9_E5 : 0x8C3D,
|
||
|
UNSIGNED_INT_5_9_9_9_REV : 0x8C3E,
|
||
|
TRANSFORM_FEEDBACK_BUFFER_MODE : 0x8C7F,
|
||
|
MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS : 0x8C80,
|
||
|
TRANSFORM_FEEDBACK_VARYINGS : 0x8C83,
|
||
|
TRANSFORM_FEEDBACK_BUFFER_START : 0x8C84,
|
||
|
TRANSFORM_FEEDBACK_BUFFER_SIZE : 0x8C85,
|
||
|
TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN : 0x8C88,
|
||
|
RASTERIZER_DISCARD : 0x8C89,
|
||
|
MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS : 0x8C8A,
|
||
|
MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS : 0x8C8B,
|
||
|
INTERLEAVED_ATTRIBS : 0x8C8C,
|
||
|
SEPARATE_ATTRIBS : 0x8C8D,
|
||
|
TRANSFORM_FEEDBACK_BUFFER : 0x8C8E,
|
||
|
TRANSFORM_FEEDBACK_BUFFER_BINDING : 0x8C8F,
|
||
|
RGBA32UI : 0x8D70,
|
||
|
RGB32UI : 0x8D71,
|
||
|
RGBA16UI : 0x8D76,
|
||
|
RGB16UI : 0x8D77,
|
||
|
RGBA8UI : 0x8D7C,
|
||
|
RGB8UI : 0x8D7D,
|
||
|
RGBA32I : 0x8D82,
|
||
|
RGB32I : 0x8D83,
|
||
|
RGBA16I : 0x8D88,
|
||
|
RGB16I : 0x8D89,
|
||
|
RGBA8I : 0x8D8E,
|
||
|
RGB8I : 0x8D8F,
|
||
|
RED_INTEGER : 0x8D94,
|
||
|
RGB_INTEGER : 0x8D98,
|
||
|
RGBA_INTEGER : 0x8D99,
|
||
|
SAMPLER_2D_ARRAY : 0x8DC1,
|
||
|
SAMPLER_2D_ARRAY_SHADOW : 0x8DC4,
|
||
|
SAMPLER_CUBE_SHADOW : 0x8DC5,
|
||
|
UNSIGNED_INT_VEC2 : 0x8DC6,
|
||
|
UNSIGNED_INT_VEC3 : 0x8DC7,
|
||
|
UNSIGNED_INT_VEC4 : 0x8DC8,
|
||
|
INT_SAMPLER_2D : 0x8DCA,
|
||
|
INT_SAMPLER_3D : 0x8DCB,
|
||
|
INT_SAMPLER_CUBE : 0x8DCC,
|
||
|
INT_SAMPLER_2D_ARRAY : 0x8DCF,
|
||
|
UNSIGNED_INT_SAMPLER_2D : 0x8DD2,
|
||
|
UNSIGNED_INT_SAMPLER_3D : 0x8DD3,
|
||
|
UNSIGNED_INT_SAMPLER_CUBE : 0x8DD4,
|
||
|
UNSIGNED_INT_SAMPLER_2D_ARRAY : 0x8DD7,
|
||
|
DEPTH_COMPONENT32F : 0x8CAC,
|
||
|
DEPTH32F_STENCIL8 : 0x8CAD,
|
||
|
FLOAT_32_UNSIGNED_INT_24_8_REV : 0x8DAD,
|
||
|
FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING : 0x8210,
|
||
|
FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE : 0x8211,
|
||
|
FRAMEBUFFER_ATTACHMENT_RED_SIZE : 0x8212,
|
||
|
FRAMEBUFFER_ATTACHMENT_GREEN_SIZE : 0x8213,
|
||
|
FRAMEBUFFER_ATTACHMENT_BLUE_SIZE : 0x8214,
|
||
|
FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE : 0x8215,
|
||
|
FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE : 0x8216,
|
||
|
FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE : 0x8217,
|
||
|
FRAMEBUFFER_DEFAULT : 0x8218,
|
||
|
UNSIGNED_INT_24_8 : 0x84FA,
|
||
|
DEPTH24_STENCIL8 : 0x88F0,
|
||
|
UNSIGNED_NORMALIZED : 0x8C17,
|
||
|
DRAW_FRAMEBUFFER_BINDING : 0x8CA6, // Same as FRAMEBUFFER_BINDING
|
||
|
READ_FRAMEBUFFER : 0x8CA8,
|
||
|
DRAW_FRAMEBUFFER : 0x8CA9,
|
||
|
READ_FRAMEBUFFER_BINDING : 0x8CAA,
|
||
|
RENDERBUFFER_SAMPLES : 0x8CAB,
|
||
|
FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER : 0x8CD4,
|
||
|
MAX_COLOR_ATTACHMENTS : 0x8CDF,
|
||
|
COLOR_ATTACHMENT1 : 0x8CE1,
|
||
|
COLOR_ATTACHMENT2 : 0x8CE2,
|
||
|
COLOR_ATTACHMENT3 : 0x8CE3,
|
||
|
COLOR_ATTACHMENT4 : 0x8CE4,
|
||
|
COLOR_ATTACHMENT5 : 0x8CE5,
|
||
|
COLOR_ATTACHMENT6 : 0x8CE6,
|
||
|
COLOR_ATTACHMENT7 : 0x8CE7,
|
||
|
COLOR_ATTACHMENT8 : 0x8CE8,
|
||
|
COLOR_ATTACHMENT9 : 0x8CE9,
|
||
|
COLOR_ATTACHMENT10 : 0x8CEA,
|
||
|
COLOR_ATTACHMENT11 : 0x8CEB,
|
||
|
COLOR_ATTACHMENT12 : 0x8CEC,
|
||
|
COLOR_ATTACHMENT13 : 0x8CED,
|
||
|
COLOR_ATTACHMENT14 : 0x8CEE,
|
||
|
COLOR_ATTACHMENT15 : 0x8CEF,
|
||
|
FRAMEBUFFER_INCOMPLETE_MULTISAMPLE : 0x8D56,
|
||
|
MAX_SAMPLES : 0x8D57,
|
||
|
HALF_FLOAT : 0x140B,
|
||
|
RG : 0x8227,
|
||
|
RG_INTEGER : 0x8228,
|
||
|
R8 : 0x8229,
|
||
|
RG8 : 0x822B,
|
||
|
R16F : 0x822D,
|
||
|
R32F : 0x822E,
|
||
|
RG16F : 0x822F,
|
||
|
RG32F : 0x8230,
|
||
|
R8I : 0x8231,
|
||
|
R8UI : 0x8232,
|
||
|
R16I : 0x8233,
|
||
|
R16UI : 0x8234,
|
||
|
R32I : 0x8235,
|
||
|
R32UI : 0x8236,
|
||
|
RG8I : 0x8237,
|
||
|
RG8UI : 0x8238,
|
||
|
RG16I : 0x8239,
|
||
|
RG16UI : 0x823A,
|
||
|
RG32I : 0x823B,
|
||
|
RG32UI : 0x823C,
|
||
|
VERTEX_ARRAY_BINDING : 0x85B5,
|
||
|
R8_SNORM : 0x8F94,
|
||
|
RG8_SNORM : 0x8F95,
|
||
|
RGB8_SNORM : 0x8F96,
|
||
|
RGBA8_SNORM : 0x8F97,
|
||
|
SIGNED_NORMALIZED : 0x8F9C,
|
||
|
COPY_READ_BUFFER : 0x8F36,
|
||
|
COPY_WRITE_BUFFER : 0x8F37,
|
||
|
COPY_READ_BUFFER_BINDING : 0x8F36, // Same as COPY_READ_BUFFER
|
||
|
COPY_WRITE_BUFFER_BINDING : 0x8F37, // Same as COPY_WRITE_BUFFER
|
||
|
UNIFORM_BUFFER : 0x8A11,
|
||
|
UNIFORM_BUFFER_BINDING : 0x8A28,
|
||
|
UNIFORM_BUFFER_START : 0x8A29,
|
||
|
UNIFORM_BUFFER_SIZE : 0x8A2A,
|
||
|
MAX_VERTEX_UNIFORM_BLOCKS : 0x8A2B,
|
||
|
MAX_FRAGMENT_UNIFORM_BLOCKS : 0x8A2D,
|
||
|
MAX_COMBINED_UNIFORM_BLOCKS : 0x8A2E,
|
||
|
MAX_UNIFORM_BUFFER_BINDINGS : 0x8A2F,
|
||
|
MAX_UNIFORM_BLOCK_SIZE : 0x8A30,
|
||
|
MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS : 0x8A31,
|
||
|
MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS : 0x8A33,
|
||
|
UNIFORM_BUFFER_OFFSET_ALIGNMENT : 0x8A34,
|
||
|
ACTIVE_UNIFORM_BLOCKS : 0x8A36,
|
||
|
UNIFORM_TYPE : 0x8A37,
|
||
|
UNIFORM_SIZE : 0x8A38,
|
||
|
UNIFORM_BLOCK_INDEX : 0x8A3A,
|
||
|
UNIFORM_OFFSET : 0x8A3B,
|
||
|
UNIFORM_ARRAY_STRIDE : 0x8A3C,
|
||
|
UNIFORM_MATRIX_STRIDE : 0x8A3D,
|
||
|
UNIFORM_IS_ROW_MAJOR : 0x8A3E,
|
||
|
UNIFORM_BLOCK_BINDING : 0x8A3F,
|
||
|
UNIFORM_BLOCK_DATA_SIZE : 0x8A40,
|
||
|
UNIFORM_BLOCK_ACTIVE_UNIFORMS : 0x8A42,
|
||
|
UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES : 0x8A43,
|
||
|
UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER : 0x8A44,
|
||
|
UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER : 0x8A46,
|
||
|
INVALID_INDEX : 0xFFFFFFFF,
|
||
|
MAX_VERTEX_OUTPUT_COMPONENTS : 0x9122,
|
||
|
MAX_FRAGMENT_INPUT_COMPONENTS : 0x9125,
|
||
|
MAX_SERVER_WAIT_TIMEOUT : 0x9111,
|
||
|
OBJECT_TYPE : 0x9112,
|
||
|
SYNC_CONDITION : 0x9113,
|
||
|
SYNC_STATUS : 0x9114,
|
||
|
SYNC_FLAGS : 0x9115,
|
||
|
SYNC_FENCE : 0x9116,
|
||
|
SYNC_GPU_COMMANDS_COMPLETE : 0x9117,
|
||
|
UNSIGNALED : 0x9118,
|
||
|
SIGNALED : 0x9119,
|
||
|
ALREADY_SIGNALED : 0x911A,
|
||
|
TIMEOUT_EXPIRED : 0x911B,
|
||
|
CONDITION_SATISFIED : 0x911C,
|
||
|
WAIT_FAILED : 0x911D,
|
||
|
SYNC_FLUSH_COMMANDS_BIT : 0x00000001,
|
||
|
VERTEX_ATTRIB_ARRAY_DIVISOR : 0x88FE,
|
||
|
ANY_SAMPLES_PASSED : 0x8C2F,
|
||
|
ANY_SAMPLES_PASSED_CONSERVATIVE : 0x8D6A,
|
||
|
SAMPLER_BINDING : 0x8919,
|
||
|
RGB10_A2UI : 0x906F,
|
||
|
INT_2_10_10_10_REV : 0x8D9F,
|
||
|
TRANSFORM_FEEDBACK : 0x8E22,
|
||
|
TRANSFORM_FEEDBACK_PAUSED : 0x8E23,
|
||
|
TRANSFORM_FEEDBACK_ACTIVE : 0x8E24,
|
||
|
TRANSFORM_FEEDBACK_BINDING : 0x8E25,
|
||
|
COMPRESSED_R11_EAC : 0x9270,
|
||
|
COMPRESSED_SIGNED_R11_EAC : 0x9271,
|
||
|
COMPRESSED_RG11_EAC : 0x9272,
|
||
|
COMPRESSED_SIGNED_RG11_EAC : 0x9273,
|
||
|
COMPRESSED_RGB8_ETC2 : 0x9274,
|
||
|
COMPRESSED_SRGB8_ETC2 : 0x9275,
|
||
|
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9276,
|
||
|
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9277,
|
||
|
COMPRESSED_RGBA8_ETC2_EAC : 0x9278,
|
||
|
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : 0x9279,
|
||
|
TEXTURE_IMMUTABLE_FORMAT : 0x912F,
|
||
|
MAX_ELEMENT_INDEX : 0x8D6B,
|
||
|
TEXTURE_IMMUTABLE_LEVELS : 0x82DF,
|
||
|
|
||
|
// Extensions
|
||
|
MAX_TEXTURE_MAX_ANISOTROPY_EXT : 0x84FF
|
||
|
};
|
||
|
|
||
|
return freezeObject(WebGLConstants);
|
||
|
});
|
||
|
|
||
|
define('Renderer/PixelDatatype',[
|
||
|
'../Core/freezeObject',
|
||
|
'../Core/WebGLConstants'
|
||
|
], function(
|
||
|
freezeObject,
|
||
|
WebGLConstants) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
var PixelDatatype = {
|
||
|
UNSIGNED_BYTE : WebGLConstants.UNSIGNED_BYTE,
|
||
|
UNSIGNED_SHORT : WebGLConstants.UNSIGNED_SHORT,
|
||
|
UNSIGNED_INT : WebGLConstants.UNSIGNED_INT,
|
||
|
FLOAT : WebGLConstants.FLOAT,
|
||
|
HALF_FLOAT : WebGLConstants.HALF_FLOAT_OES,
|
||
|
UNSIGNED_INT_24_8 : WebGLConstants.UNSIGNED_INT_24_8,
|
||
|
UNSIGNED_SHORT_4_4_4_4 : WebGLConstants.UNSIGNED_SHORT_4_4_4_4,
|
||
|
UNSIGNED_SHORT_5_5_5_1 : WebGLConstants.UNSIGNED_SHORT_5_5_5_1,
|
||
|
UNSIGNED_SHORT_5_6_5 : WebGLConstants.UNSIGNED_SHORT_5_6_5,
|
||
|
|
||
|
isPacked : function(pixelDatatype) {
|
||
|
return pixelDatatype === PixelDatatype.UNSIGNED_INT_24_8 ||
|
||
|
pixelDatatype === PixelDatatype.UNSIGNED_SHORT_4_4_4_4 ||
|
||
|
pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_5_5_1 ||
|
||
|
pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_6_5;
|
||
|
},
|
||
|
|
||
|
sizeInBytes : function(pixelDatatype) {
|
||
|
switch (pixelDatatype) {
|
||
|
case PixelDatatype.UNSIGNED_BYTE:
|
||
|
return 1;
|
||
|
case PixelDatatype.UNSIGNED_SHORT:
|
||
|
case PixelDatatype.UNSIGNED_SHORT_4_4_4_4:
|
||
|
case PixelDatatype.UNSIGNED_SHORT_5_5_5_1:
|
||
|
case PixelDatatype.UNSIGNED_SHORT_5_6_5:
|
||
|
case PixelDatatype.HALF_FLOAT:
|
||
|
return 2;
|
||
|
case PixelDatatype.UNSIGNED_INT:
|
||
|
case PixelDatatype.FLOAT:
|
||
|
case PixelDatatype.UNSIGNED_INT_24_8:
|
||
|
return 4;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
validate : function(pixelDatatype) {
|
||
|
return ((pixelDatatype === PixelDatatype.UNSIGNED_BYTE) ||
|
||
|
(pixelDatatype === PixelDatatype.UNSIGNED_SHORT) ||
|
||
|
(pixelDatatype === PixelDatatype.UNSIGNED_INT) ||
|
||
|
(pixelDatatype === PixelDatatype.FLOAT) ||
|
||
|
(pixelDatatype === PixelDatatype.HALF_FLOAT) ||
|
||
|
(pixelDatatype === PixelDatatype.UNSIGNED_INT_24_8) ||
|
||
|
(pixelDatatype === PixelDatatype.UNSIGNED_SHORT_4_4_4_4) ||
|
||
|
(pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_5_5_1) ||
|
||
|
(pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_6_5));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return freezeObject(PixelDatatype);
|
||
|
});
|
||
|
|
||
|
define('Core/PixelFormat',[
|
||
|
'../Renderer/PixelDatatype',
|
||
|
'./freezeObject',
|
||
|
'./WebGLConstants'
|
||
|
], function(
|
||
|
PixelDatatype,
|
||
|
freezeObject,
|
||
|
WebGLConstants) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* The format of a pixel, i.e., the number of components it has and what they represent.
|
||
|
*
|
||
|
* @exports PixelFormat
|
||
|
*/
|
||
|
var PixelFormat = {
|
||
|
/**
|
||
|
* A pixel format containing a depth value.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
DEPTH_COMPONENT : WebGLConstants.DEPTH_COMPONENT,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing a depth and stencil value, most often used with {@link PixelDatatype.UNSIGNED_INT_24_8}.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
DEPTH_STENCIL : WebGLConstants.DEPTH_STENCIL,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing an alpha channel.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
ALPHA : WebGLConstants.ALPHA,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, and blue channels.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGB : WebGLConstants.RGB,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, blue, and alpha channels.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGBA : WebGLConstants.RGBA,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing a luminance (intensity) channel.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
LUMINANCE : WebGLConstants.LUMINANCE,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing luminance (intensity) and alpha channels.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
LUMINANCE_ALPHA : WebGLConstants.LUMINANCE_ALPHA,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, and blue channels that is DXT1 compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGB_DXT1 : WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, blue, and alpha channels that is DXT1 compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGBA_DXT1 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, blue, and alpha channels that is DXT3 compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGBA_DXT3 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, blue, and alpha channels that is DXT5 compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGBA_DXT5 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, and blue channels that is PVR 4bpp compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGB_PVRTC_4BPPV1 : WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, and blue channels that is PVR 2bpp compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGB_PVRTC_2BPPV1 : WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, blue, and alpha channels that is PVR 4bpp compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGBA_PVRTC_4BPPV1 : WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, blue, and alpha channels that is PVR 2bpp compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGBA_PVRTC_2BPPV1 : WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
|
||
|
|
||
|
/**
|
||
|
* A pixel format containing red, green, and blue channels that is ETC1 compressed.
|
||
|
*
|
||
|
* @type {Number}
|
||
|
* @constant
|
||
|
*/
|
||
|
RGB_ETC1 : WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL,
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
componentsLength : function(pixelFormat) {
|
||
|
switch (pixelFormat) {
|
||
|
case PixelFormat.RGB:
|
||
|
return 3;
|
||
|
case PixelFormat.RGBA:
|
||
|
return 4;
|
||
|
case PixelFormat.LUMINANCE_ALPHA:
|
||
|
return 2;
|
||
|
case PixelFormat.ALPHA:
|
||
|
case PixelFormat.LUMINANCE:
|
||
|
return 1;
|
||
|
default:
|
||
|
return 1;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
validate : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.DEPTH_COMPONENT ||
|
||
|
pixelFormat === PixelFormat.DEPTH_STENCIL ||
|
||
|
pixelFormat === PixelFormat.ALPHA ||
|
||
|
pixelFormat === PixelFormat.RGB ||
|
||
|
pixelFormat === PixelFormat.RGBA ||
|
||
|
pixelFormat === PixelFormat.LUMINANCE ||
|
||
|
pixelFormat === PixelFormat.LUMINANCE_ALPHA ||
|
||
|
pixelFormat === PixelFormat.RGB_DXT1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT3 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT5 ||
|
||
|
pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGB_ETC1;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
isColorFormat : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.ALPHA ||
|
||
|
pixelFormat === PixelFormat.RGB ||
|
||
|
pixelFormat === PixelFormat.RGBA ||
|
||
|
pixelFormat === PixelFormat.LUMINANCE ||
|
||
|
pixelFormat === PixelFormat.LUMINANCE_ALPHA;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
isDepthFormat : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.DEPTH_COMPONENT ||
|
||
|
pixelFormat === PixelFormat.DEPTH_STENCIL;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
isCompressedFormat : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.RGB_DXT1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT3 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT5 ||
|
||
|
pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGB_ETC1;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
isDXTFormat : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.RGB_DXT1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT3 ||
|
||
|
pixelFormat === PixelFormat.RGBA_DXT5;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
isPVRTCFormat : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
|
||
|
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
isETC1Format : function(pixelFormat) {
|
||
|
return pixelFormat === PixelFormat.RGB_ETC1;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
compressedTextureSizeInBytes : function(pixelFormat, width, height) {
|
||
|
switch (pixelFormat) {
|
||
|
case PixelFormat.RGB_DXT1:
|
||
|
case PixelFormat.RGBA_DXT1:
|
||
|
case PixelFormat.RGB_ETC1:
|
||
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
|
||
|
|
||
|
case PixelFormat.RGBA_DXT3:
|
||
|
case PixelFormat.RGBA_DXT5:
|
||
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
|
||
|
|
||
|
case PixelFormat.RGB_PVRTC_4BPPV1:
|
||
|
case PixelFormat.RGBA_PVRTC_4BPPV1:
|
||
|
return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);
|
||
|
|
||
|
case PixelFormat.RGB_PVRTC_2BPPV1:
|
||
|
case PixelFormat.RGBA_PVRTC_2BPPV1:
|
||
|
return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);
|
||
|
|
||
|
default:
|
||
|
return 0;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
textureSizeInBytes : function(pixelFormat, pixelDatatype, width, height) {
|
||
|
var componentsLength = PixelFormat.componentsLength(pixelFormat);
|
||
|
if (PixelDatatype.isPacked(pixelDatatype)) {
|
||
|
componentsLength = 1;
|
||
|
}
|
||
|
return componentsLength * PixelDatatype.sizeInBytes(pixelDatatype) * width * height;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
alignmentInBytes : function(pixelFormat, pixelDatatype, width) {
|
||
|
var mod = PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, 1) % 4;
|
||
|
return mod === 0 ? 4 : (mod === 2 ? 2 : 1);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
createTypedArray : function(pixelFormat, pixelDatatype, width, height) {
|
||
|
var constructor;
|
||
|
var sizeInBytes = PixelDatatype.sizeInBytes(pixelDatatype);
|
||
|
if (sizeInBytes === Uint8Array.BYTES_PER_ELEMENT) {
|
||
|
constructor = Uint8Array;
|
||
|
} else if (sizeInBytes === Uint16Array.BYTES_PER_ELEMENT) {
|
||
|
constructor = Uint16Array;
|
||
|
} else if (sizeInBytes === Float32Array.BYTES_PER_ELEMENT && pixelDatatype === PixelDatatype.FLOAT) {
|
||
|
constructor = Float32Array;
|
||
|
} else {
|
||
|
constructor = Uint32Array;
|
||
|
}
|
||
|
|
||
|
var size = PixelFormat.componentsLength(pixelFormat) * width * height;
|
||
|
return new constructor(size);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
flipY : function(bufferView, pixelFormat, pixelDatatype, width, height) {
|
||
|
if (height === 1) {
|
||
|
return bufferView;
|
||
|
}
|
||
|
var flipped = PixelFormat.createTypedArray(pixelFormat, pixelDatatype, width, height);
|
||
|
var numberOfComponents = PixelFormat.componentsLength(pixelFormat);
|
||
|
var textureWidth = width * numberOfComponents;
|
||
|
for (var i = 0; i < height; ++i) {
|
||
|
var row = i * height * numberOfComponents;
|
||
|
var flippedRow = (height - i - 1) * height * numberOfComponents;
|
||
|
for (var j = 0; j < textureWidth; ++j) {
|
||
|
flipped[flippedRow + j] = bufferView[row + j];
|
||
|
}
|
||
|
}
|
||
|
return flipped;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return freezeObject(PixelFormat);
|
||
|
});
|
||
|
|
||
|
define('Core/RuntimeError',[
|
||
|
'./defined'
|
||
|
], function(
|
||
|
defined) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,
|
||
|
* out of memory, could not compile shader, etc. If a function may throw this
|
||
|
* exception, the calling code should be prepared to catch it.
|
||
|
* <br /><br />
|
||
|
* On the other hand, a {@link DeveloperError} indicates an exception due
|
||
|
* to a developer error, e.g., invalid argument, that usually indicates a bug in the
|
||
|
* calling code.
|
||
|
*
|
||
|
* @alias RuntimeError
|
||
|
* @constructor
|
||
|
* @extends Error
|
||
|
*
|
||
|
* @param {String} [message] The error message for this exception.
|
||
|
*
|
||
|
* @see DeveloperError
|
||
|
*/
|
||
|
function RuntimeError(message) {
|
||
|
/**
|
||
|
* 'RuntimeError' indicating that this exception was thrown due to a runtime error.
|
||
|
* @type {String}
|
||
|
* @readonly
|
||
|
*/
|
||
|
this.name = 'RuntimeError';
|
||
|
|
||
|
/**
|
||
|
* The explanation for why this exception was thrown.
|
||
|
* @type {String}
|
||
|
* @readonly
|
||
|
*/
|
||
|
this.message = message;
|
||
|
|
||
|
//Browsers such as IE don't have a stack property until you actually throw the error.
|
||
|
var stack;
|
||
|
try {
|
||
|
throw new Error();
|
||
|
} catch (e) {
|
||
|
stack = e.stack;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* The stack trace of this exception, if available.
|
||
|
* @type {String}
|
||
|
* @readonly
|
||
|
*/
|
||
|
this.stack = stack;
|
||
|
}
|
||
|
|
||
|
if (defined(Object.create)) {
|
||
|
RuntimeError.prototype = Object.create(Error.prototype);
|
||
|
RuntimeError.prototype.constructor = RuntimeError;
|
||
|
}
|
||
|
|
||
|
RuntimeError.prototype.toString = function() {
|
||
|
var str = this.name + ': ' + this.message;
|
||
|
|
||
|
if (defined(this.stack)) {
|
||
|
str += '\n' + this.stack.toString();
|
||
|
}
|
||
|
|
||
|
return str;
|
||
|
};
|
||
|
|
||
|
return RuntimeError;
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* @licence
|
||
|
* crunch/crnlib uses the ZLIB license:
|
||
|
* http://opensource.org/licenses/Zlib
|
||
|
*
|
||
|
* Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
||
|
*
|
||
|
* This software is provided 'as-is', without any express or implied
|
||
|
* warranty. In no event will the authors be held liable for any damages
|
||
|
* arising from the use of this software.
|
||
|
*
|
||
|
* Permission is granted to anyone to use this software for any purpose,
|
||
|
* including commercial applications, and to alter it and redistribute it
|
||
|
* freely, subject to the following restrictions:
|
||
|
*
|
||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||
|
* claim that you wrote the original software. If you use this software
|
||
|
* in a product, an acknowledgment in the product documentation would be
|
||
|
* appreciated but is not required.
|
||
|
*
|
||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||
|
* misrepresented as being the original software.
|
||
|
*
|
||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||
|
*/
|
||
|
|
||
|
// The C++ code was compiled to Javascript with Emcripten.
|
||
|
// For instructions, see: https://github.com/BinomialLLC/crunch
|
||
|
|
||
|
define('ThirdParty/crunch',[], function() {
|
||
|
|
||
|
var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;if(Module["ENVIRONMENT"]){if(Module["ENVIRONMENT"]==="WEB"){ENVIRONMENT_IS_WEB=true}else if(Module["ENVIRONMENT"]==="WORKER"){ENVIRONMENT_IS_WORKER=true}else if(Module["ENVIRONMENT"]==="NODE"){ENVIRONMENT_IS_NODE=true}else if(Module["ENVIRONMENT"]==="SHELL"){ENVIRONMENT_IS_SHELL=true}else{throw new Error("The provided Module['ENVIRONMENT'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.")}}else{ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER}if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=console.log;if(!Module["printErr"])Module["printErr"]=console.warn;var nodeFS;var nodePath;Module["read"]=function shell_read(filename,binary){if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](filename);return binary?ret:ret.toString()};Module["readBinary"]=function readBinary(filename){var ret=Module["read"](filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};Module["load"]=function load(f){globalEval(read(f))};if(!Module["thisProgram"]){if(process["argv"].length>1){Module["thisProgram"]=process["argv"][1].replace(/\\/g,"/")}else{Module["thisProgram"]="unknown-program"}}Module["arguments"]=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}));Module["inspect"]=(function(){return"[Emscripten Module object]"})}else if(ENVIRONMENT_IS_SHELL){if(!Module["print"])Module["print"]=print;if(typeof printErr!="undefined")Module["printErr"]=printErr;if(typeof read!="undefined"){Module["read"]=read}else{Module["read"]=function shell_read(){throw"no read() available"}}Module["readBinary"]=function readBinary(f){if(typeof readbuffer==="function"){return new Uint8Array(readbuffer(f))}var data=read(f,"binary");assert(typeof data==="object");return data};if(typeof scriptArgs!="undefined"){Module["arguments"]=scriptArgs}else if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof quit==="function"){Module["quit"]=(function(status,toThrow){quit(status)})}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){Module["read"]=function shell_read(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){Module["readBinary"]=function readBinary(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}Module["readAsync"]=function readAsync(url,onload,onerror){var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function xhr_onload(){if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response)}else{onerror()}};xhr.onerror=onerror;xhr.send(null)};if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof console!=="undefined"){if(!Module["print"])Module["print"]=function shell_print(x){console.log(x)};if(!Module["printErr"])Module["printErr"]=function shell_printErr(x){console.warn(x)}}else{var TRY_USE_DUMP=false;if(!Module["print"])Module["print"]=TRY_USE_DUMP&&typeof dump!=="undefined"?(function(x){dump(x)}):(function(x){})}if(ENVIRONMENT_IS_WORKER){Module["load"]=importScripts}if(typeof Module["setWindowTitle"]==="undefined"){Module["setWindowTitle"]=(function(title){document.title=title})}}else{throw"Unknown runtime environment. Where are we?"}function globalEval(x){eval.call(null,x)}if(!Module["load"]&&Modul
|
||
|
var asm=(function(global,env,buffer) {
|
||
|
"almost asm";var a=global.Int8Array;var b=new a(buffer);var c=global.Int16Array;var d=new c(buffer);var e=global.Int32Array;var f=new e(buffer);var g=global.Uint8Array;var h=new g(buffer);var i=global.Uint16Array;var j=new i(buffer);var k=global.Uint32Array;var l=new k(buffer);var m=global.Float32Array;var n=new m(buffer);var o=global.Float64Array;var p=new o(buffer);var q=global.byteLength;var r=env.DYNAMICTOP_PTR|0;var s=env.tempDoublePtr|0;var t=env.ABORT|0;var u=env.STACKTOP|0;var v=env.STACK_MAX|0;var w=env.cttz_i8|0;var x=0;var y=0;var z=0;var A=0;var B=global.NaN,C=global.Infinity;var D=0,E=0,F=0,G=0,H=0.0;var I=0;var J=global.Math.floor;var K=global.Math.abs;var L=global.Math.sqrt;var M=global.Math.pow;var N=global.Math.cos;var O=global.Math.sin;var P=global.Math.tan;var Q=global.Math.acos;var R=global.Math.asin;var S=global.Math.atan;var T=global.Math.atan2;var U=global.Math.exp;var V=global.Math.log;var W=global.Math.ceil;var X=global.Math.imul;var Y=global.Math.min;var Z=global.Math.max;var _=global.Math.clz32;var $=env.abort;var aa=env.assert;var ba=env.enlargeMemory;var ca=env.getTotalMemory;var da=env.abortOnCannotGrowMemory;var ea=env.invoke_iiii;var fa=env.invoke_viiiii;var ga=env.invoke_vi;var ha=env.invoke_ii;var ia=env.invoke_viii;var ja=env.invoke_v;var ka=env.invoke_viiiiii;var la=env.invoke_viiii;var ma=env._pthread_getspecific;var na=env.___syscall54;var oa=env._pthread_setspecific;var pa=env.___gxx_personality_v0;var qa=env.___syscall6;var ra=env.___setErrNo;var sa=env._abort;var ta=env.___cxa_begin_catch;var ua=env._pthread_once;var va=env._emscripten_memcpy_big;var wa=env._pthread_key_create;var xa=env.___syscall140;var ya=env.___resumeException;var za=env.___cxa_find_matching_catch;var Aa=env.___syscall146;var Ba=env.__ZSt18uncaught_exceptionv;var Ca=0.0;function Da(newBuffer){if(q(newBuffer)&16777215||q(newBuffer)<=16777215||q(newBuffer)>2147483648)return false;b=new a(newBuffer);d=new c(newBuffer);f=new e(newBuffer);h=new g(newBuffer);j=new i(newBuffer);l=new k(newBuffer);n=new m(newBuffer);p=new o(newBuffer);buffer=newBuffer;return true}
|
||
|
// EMSCRIPTEN_START_FUNCS
|
||
|
function Ma(a){a=a|0;var b=0,c=0,d=0,e=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,v=0,w=0,x=0;x=u;u=u+16|0;n=x;do if(a>>>0<245){k=a>>>0<11?16:a+11&-8;a=k>>>3;m=f[1144]|0;c=m>>>a;if(c&3|0){b=(c&1^1)+a|0;a=4616+(b<<1<<2)|0;c=a+8|0;d=f[c>>2]|0;e=d+8|0;g=f[e>>2]|0;if((a|0)==(g|0))f[1144]=m&~(1<<b);else{f[g+12>>2]=a;f[c>>2]=g}w=b<<3;f[d+4>>2]=w|3;w=d+w+4|0;f[w>>2]=f[w>>2]|1;w=e;u=x;return w|0}l=f[1146]|0;if(k>>>0>l>>>0){if(c|0){b=2<<a;b=c<<a&(b|0-b);b=(b&0-b)+-1|0;h=b>>>12&16;b=b>>>h;c=b>>>5&8;b=b>>>c;e=b>>>2&4;b=b>>>e;a=b>>>1&2;b=b>>>a;d=b>>>1&1;d=(c|h|e|a|d)+(b>>>d)|0;b=4616+(d<<1<<2)|0;a=b+8|0;e=f[a>>2]|0;h=e+8|0;c=f[h>>2]|0;if((b|0)==(c|0)){a=m&~(1<<d);f[1144]=a}else{f[c+12>>2]=b;f[a>>2]=c;a=m}g=(d<<3)-k|0;f[e+4>>2]=k|3;d=e+k|0;f[d+4>>2]=g|1;f[d+g>>2]=g;if(l|0){e=f[1149]|0;b=l>>>3;c=4616+(b<<1<<2)|0;b=1<<b;if(!(a&b)){f[1144]=a|b;b=c;a=c+8|0}else{a=c+8|0;b=f[a>>2]|0}f[a>>2]=e;f[b+12>>2]=e;f[e+8>>2]=b;f[e+12>>2]=c}f[1146]=g;f[1149]=d;w=h;u=x;return w|0}i=f[1145]|0;if(i){c=(i&0-i)+-1|0;h=c>>>12&16;c=c>>>h;g=c>>>5&8;c=c>>>g;j=c>>>2&4;c=c>>>j;d=c>>>1&2;c=c>>>d;a=c>>>1&1;a=f[4880+((g|h|j|d|a)+(c>>>a)<<2)>>2]|0;c=(f[a+4>>2]&-8)-k|0;d=f[a+16+(((f[a+16>>2]|0)==0&1)<<2)>>2]|0;if(!d){j=a;g=c}else{do{h=(f[d+4>>2]&-8)-k|0;j=h>>>0<c>>>0;c=j?h:c;a=j?d:a;d=f[d+16+(((f[d+16>>2]|0)==0&1)<<2)>>2]|0}while((d|0)!=0);j=a;g=c}h=j+k|0;if(j>>>0<h>>>0){e=f[j+24>>2]|0;b=f[j+12>>2]|0;do if((b|0)==(j|0)){a=j+20|0;b=f[a>>2]|0;if(!b){a=j+16|0;b=f[a>>2]|0;if(!b){c=0;break}}while(1){c=b+20|0;d=f[c>>2]|0;if(d|0){b=d;a=c;continue}c=b+16|0;d=f[c>>2]|0;if(!d)break;else{b=d;a=c}}f[a>>2]=0;c=b}else{c=f[j+8>>2]|0;f[c+12>>2]=b;f[b+8>>2]=c;c=b}while(0);do if(e|0){b=f[j+28>>2]|0;a=4880+(b<<2)|0;if((j|0)==(f[a>>2]|0)){f[a>>2]=c;if(!c){f[1145]=i&~(1<<b);break}}else{f[e+16+(((f[e+16>>2]|0)!=(j|0)&1)<<2)>>2]=c;if(!c)break}f[c+24>>2]=e;b=f[j+16>>2]|0;if(b|0){f[c+16>>2]=b;f[b+24>>2]=c}b=f[j+20>>2]|0;if(b|0){f[c+20>>2]=b;f[b+24>>2]=c}}while(0);if(g>>>0<16){w=g+k|0;f[j+4>>2]=w|3;w=j+w+4|0;f[w>>2]=f[w>>2]|1}else{f[j+4>>2]=k|3;f[h+4>>2]=g|1;f[h+g>>2]=g;if(l|0){d=f[1149]|0;b=l>>>3;c=4616+(b<<1<<2)|0;b=1<<b;if(!(m&b)){f[1144]=m|b;b=c;a=c+8|0}else{a=c+8|0;b=f[a>>2]|0}f[a>>2]=d;f[b+12>>2]=d;f[d+8>>2]=b;f[d+12>>2]=c}f[1146]=g;f[1149]=h}w=j+8|0;u=x;return w|0}else m=k}else m=k}else m=k}else if(a>>>0<=4294967231){a=a+11|0;k=a&-8;j=f[1145]|0;if(j){d=0-k|0;a=a>>>8;if(a)if(k>>>0>16777215)i=31;else{m=(a+1048320|0)>>>16&8;v=a<<m;l=(v+520192|0)>>>16&4;v=v<<l;i=(v+245760|0)>>>16&2;i=14-(l|m|i)+(v<<i>>>15)|0;i=k>>>(i+7|0)&1|i<<1}else i=0;c=f[4880+(i<<2)>>2]|0;a:do if(!c){c=0;a=0;v=57}else{a=0;h=k<<((i|0)==31?0:25-(i>>>1)|0);g=0;while(1){e=(f[c+4>>2]&-8)-k|0;if(e>>>0<d>>>0)if(!e){a=c;d=0;e=c;v=61;break a}else{a=c;d=e}e=f[c+20>>2]|0;c=f[c+16+(h>>>31<<2)>>2]|0;g=(e|0)==0|(e|0)==(c|0)?g:e;e=(c|0)==0;if(e){c=g;v=57;break}else h=h<<((e^1)&1)}}while(0);if((v|0)==57){if((c|0)==0&(a|0)==0){a=2<<i;a=j&(a|0-a);if(!a){m=k;break}m=(a&0-a)+-1|0;h=m>>>12&16;m=m>>>h;g=m>>>5&8;m=m>>>g;i=m>>>2&4;m=m>>>i;l=m>>>1&2;m=m>>>l;c=m>>>1&1;a=0;c=f[4880+((g|h|i|l|c)+(m>>>c)<<2)>>2]|0}if(!c){i=a;h=d}else{e=c;v=61}}if((v|0)==61)while(1){v=0;c=(f[e+4>>2]&-8)-k|0;m=c>>>0<d>>>0;c=m?c:d;a=m?e:a;e=f[e+16+(((f[e+16>>2]|0)==0&1)<<2)>>2]|0;if(!e){i=a;h=c;break}else{d=c;v=61}}if((i|0)!=0?h>>>0<((f[1146]|0)-k|0)>>>0:0){g=i+k|0;if(i>>>0>=g>>>0){w=0;u=x;return w|0}e=f[i+24>>2]|0;b=f[i+12>>2]|0;do if((b|0)==(i|0)){a=i+20|0;b=f[a>>2]|0;if(!b){a=i+16|0;b=f[a>>2]|0;if(!b){b=0;break}}while(1){c=b+20|0;d=f[c>>2]|0;if(d|0){b=d;a=c;continue}c=b+16|0;d=f[c>>2]|0;if(!d)break;else{b=d;a=c}}f[a>>2]=0}else{w=f[i+8>>2]|0;f[w+12>>2]=b;f[b+8>>2]=w}while(0);do if(e){a=f[i+28>>2]|0;c=4880+(a<<2)|0;if((i|0)==(f[c>>2]|0)){f[c>>2]=b;if(!b){d=j&~(1<<a);f[1145]=d;break}}else{f[e+16+(((f[e+16>>2]|0)!=(i|0)&1)<<2)>>2]=b;if(!b){d=j;break}}f[b+24>>2]=e;a=f[i+16>>2]|0;if(a|0){f[b+16>>2]=a;f[a+24>>2]=b}a=f[i+20>>2]|0;if(a){f[b+20>>2]=a;f[a+24>>2]=b;d=j}else d=j}else d=j;while(0);do if(h>>>0>=16){f[i+4>>2]=k|3;f[g+4>>2]=h|1;f[g+h>>2]=h;b=h>>>3;if(h>>>0<256){c=4616+(b<<1<<2)|0;a=f[1144]|0;b=1<<b;if(!(a&b)){f[1144]=a|b;b=c;a=c+8|0}else{a=c+8|0;b
|
||
|
|
||
|
// EMSCRIPTEN_END_FUNCS
|
||
|
var Ea=[gd,mb,Yb,$b,lc,Kb,gd,gd];var Fa=[Zc,Hb,nb,Zc];var Ga=[wd,sd,_c,sd,sd,_c,tc,wd];var Ha=[rd,sc];var Ia=[id];var Ja=[yd,Bb,xc,yd];var Ka=[Wc,cc,Vb,Wc];var La=[dd,dc,Xb,dd];return{stackSave:vd,_i64Subtract:Cc,_crn_get_bytes_per_block:ib,setThrew:Xc,dynCall_viii:Oc,_bitshift64Lshr:zc,_bitshift64Shl:yc,dynCall_viiii:Hc,setTempRet0:od,_crn_decompress:$a,_memset:Ib,_sbrk:ac,_memcpy:kb,stackAlloc:Pc,_crn_get_height:pc,dynCall_vi:fd,getTempRet0:ud,_crn_get_levels:oc,_crn_get_uncompressed_size:hb,_i64Add:Gc,dynCall_iiii:Lc,_emscripten_get_global_libc:qd,dynCall_ii:bd,___udivdi3:Uc,_llvm_bswap_i32:Vc,dynCall_viiiii:Ec,___cxa_can_catch:hc,_free:Ta,runPostSets:Bc,dynCall_viiiiii:wc,establishStackSpace:cd,___uremdi3:mc,___cxa_is_pointer_type:Kc,stackRestore:md,_malloc:Ma,_emscripten_replace_memory:Da,dynCall_v:kd,_crn_get_width:qc,_crn_get_dxt_format:nc}})
|
||
|
|
||
|
|
||
|
// EMSCRIPTEN_END_ASM
|
||
|
(Module.asmGlobalArg,Module.asmLibraryArg,buffer);var stackSave=Module["stackSave"]=asm["stackSave"];var getTempRet0=Module["getTempRet0"]=asm["getTempRet0"];var _memset=Module["_memset"]=asm["_memset"];var setThrew=Module["setThrew"]=asm["setThrew"];var _bitshift64Lshr=Module["_bitshift64Lshr"]=asm["_bitshift64Lshr"];var _bitshift64Shl=Module["_bitshift64Shl"]=asm["_bitshift64Shl"];var setTempRet0=Module["setTempRet0"]=asm["setTempRet0"];var _crn_decompress=Module["_crn_decompress"]=asm["_crn_decompress"];var _crn_get_bytes_per_block=Module["_crn_get_bytes_per_block"]=asm["_crn_get_bytes_per_block"];var _sbrk=Module["_sbrk"]=asm["_sbrk"];var _memcpy=Module["_memcpy"]=asm["_memcpy"];var stackAlloc=Module["stackAlloc"]=asm["stackAlloc"];var _crn_get_height=Module["_crn_get_height"]=asm["_crn_get_height"];var _i64Subtract=Module["_i64Subtract"]=asm["_i64Subtract"];var _crn_get_levels=Module["_crn_get_levels"]=asm["_crn_get_levels"];var _crn_get_uncompressed_size=Module["_crn_get_uncompressed_size"]=asm["_crn_get_uncompressed_size"];var _i64Add=Module["_i64Add"]=asm["_i64Add"];var _emscripten_get_global_libc=Module["_emscripten_get_global_libc"]=asm["_emscripten_get_global_libc"];var ___udivdi3=Module["___udivdi3"]=asm["___udivdi3"];var _llvm_bswap_i32=Module["_llvm_bswap_i32"]=asm["_llvm_bswap_i32"];var ___cxa_can_catch=Module["___cxa_can_catch"]=asm["___cxa_can_catch"];var _free=Module["_free"]=asm["_free"];var runPostSets=Module["runPostSets"]=asm["runPostSets"];var establishStackSpace=Module["establishStackSpace"]=asm["establishStackSpace"];var ___uremdi3=Module["___uremdi3"]=asm["___uremdi3"];var ___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=asm["___cxa_is_pointer_type"];var stackRestore=Module["stackRestore"]=asm["stackRestore"];var _malloc=Module["_malloc"]=asm["_malloc"];var _emscripten_replace_memory=Module["_emscripten_replace_memory"]=asm["_emscripten_replace_memory"];var _crn_get_width=Module["_crn_get_width"]=asm["_crn_get_width"];var _crn_get_dxt_format=Module["_crn_get_dxt_format"]=asm["_crn_get_dxt_format"];var dynCall_iiii=Module["dynCall_iiii"]=asm["dynCall_iiii"];var dynCall_viiiii=Module["dynCall_viiiii"]=asm["dynCall_viiiii"];var dynCall_vi=Module["dynCall_vi"]=asm["dynCall_vi"];var dynCall_ii=Module["dynCall_ii"]=asm["dynCall_ii"];var dynCall_viii=Module["dynCall_viii"]=asm["dynCall_viii"];var dynCall_v=Module["dynCall_v"]=asm["dynCall_v"];var dynCall_viiiiii=Module["dynCall_viiiiii"]=asm["dynCall_viiiiii"];var dynCall_viiii=Module["dynCall_viiii"]=asm["dynCall_viiii"];Runtime.stackAlloc=Module["stackAlloc"];Runtime.stackSave=Module["stackSave"];Runtime.stackRestore=Module["stackRestore"];Runtime.establishStackSpace=Module["establishStackSpace"];Runtime.setTempRet0=Module["setTempRet0"];Runtime.getTempRet0=Module["getTempRet0"];Module["asm"]=asm;function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;var initialStackTop;var preloadStartTime=null;var calledMain=false;dependenciesFulfilled=function runCaller(){if(!Module["calledRun"])run();if(!Module["calledRun"])dependenciesFulfilled=runCaller};Module["callMain"]=Module.callMain=function callMain(args){args=args||[];ensureInitRuntime();var argc=args.length+1;function pad(){for(var i=0;i<4-1;i++){argv.push(0)}}var argv=[allocate(intArrayFromString(Module["thisProgram"]),"i8",ALLOC_NORMAL)];pad();for(var i=0;i<argc-1;i=i+1){argv.push(allocate(intArrayFromString(args[i]),"i8",ALLOC_NORMAL));pad()}argv.push(0);argv=allocate(argv,"i32",ALLOC_NORMAL);try{var ret=Module["_main"](argc,argv,0);exit(ret,true)}catch(e){if(e instanceof ExitStatus){return}else if(e=="SimulateInfiniteLoop"){Module["noExitRuntime"]=true;return}else{var toLog=e;if(e&&typeof e==="object"&&e.stack){toLog=[e,e.stack]}Module.printErr("exception thrown: "+toLog);Module["quit"](1,e)}}finally{calledMain=true}};function run(args){args=args||Module["arguments"];if(preloadStartTime===null)preloadStartTime=Date.now();if(runDependencies>0){retu
|
||
|
|
||
|
return Module;
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
@license
|
||
|
when.js - https://github.com/cujojs/when
|
||
|
|
||
|
MIT License (c) copyright B Cavalier & J Hann
|
||
|
|
||
|
* A lightweight CommonJS Promises/A and when() implementation
|
||
|
* when is part of the cujo.js family of libraries (http://cujojs.com/)
|
||
|
*
|
||
|
* Licensed under the MIT License at:
|
||
|
* http://www.opensource.org/licenses/mit-license.php
|
||
|
*
|
||
|
* @version 1.7.1
|
||
|
*/
|
||
|
|
||
|
(function(define) { 'use strict';
|
||
|
define('ThirdParty/when',[],function () {
|
||
|
var reduceArray, slice, undef;
|
||
|
|
||
|
//
|
||
|
// Public API
|
||
|
//
|
||
|
|
||
|
when.defer = defer; // Create a deferred
|
||
|
when.resolve = resolve; // Create a resolved promise
|
||
|
when.reject = reject; // Create a rejected promise
|
||
|
|
||
|
when.join = join; // Join 2 or more promises
|
||
|
|
||
|
when.all = all; // Resolve a list of promises
|
||
|
when.map = map; // Array.map() for promises
|
||
|
when.reduce = reduce; // Array.reduce() for promises
|
||
|
|
||
|
when.any = any; // One-winner race
|
||
|
when.some = some; // Multi-winner race
|
||
|
|
||
|
when.chain = chain; // Make a promise trigger another resolver
|
||
|
|
||
|
when.isPromise = isPromise; // Determine if a thing is a promise
|
||
|
|
||
|
/**
|
||
|
* Register an observer for a promise or immediate value.
|
||
|
*
|
||
|
* @param {*} promiseOrValue
|
||
|
* @param {function?} [onFulfilled] callback to be called when promiseOrValue is
|
||
|
* successfully fulfilled. If promiseOrValue is an immediate value, callback
|
||
|
* will be invoked immediately.
|
||
|
* @param {function?} [onRejected] callback to be called when promiseOrValue is
|
||
|
* rejected.
|
||
|
* @param {function?} [onProgress] callback to be called when progress updates
|
||
|
* are issued for promiseOrValue.
|
||
|
* @returns {Promise} a new {@link Promise} that will complete with the return
|
||
|
* value of callback or errback or the completion value of promiseOrValue if
|
||
|
* callback and/or errback is not supplied.
|
||
|
*/
|
||
|
function when(promiseOrValue, onFulfilled, onRejected, onProgress) {
|
||
|
// Get a trusted promise for the input promiseOrValue, and then
|
||
|
// register promise handlers
|
||
|
return resolve(promiseOrValue).then(onFulfilled, onRejected, onProgress);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns promiseOrValue if promiseOrValue is a {@link Promise}, a new Promise if
|
||
|
* promiseOrValue is a foreign promise, or a new, already-fulfilled {@link Promise}
|
||
|
* whose value is promiseOrValue if promiseOrValue is an immediate value.
|
||
|
*
|
||
|
* @param {*} promiseOrValue
|
||
|
* @returns Guaranteed to return a trusted Promise. If promiseOrValue is a when.js {@link Promise}
|
||
|
* returns promiseOrValue, otherwise, returns a new, already-resolved, when.js {@link Promise}
|
||
|
* whose resolution value is:
|
||
|
* * the resolution value of promiseOrValue if it's a foreign promise, or
|
||
|
* * promiseOrValue if it's a value
|
||
|
*/
|
||
|
function resolve(promiseOrValue) {
|
||
|
var promise, deferred;
|
||
|
|
||
|
if(promiseOrValue instanceof Promise) {
|
||
|
// It's a when.js promise, so we trust it
|
||
|
promise = promiseOrValue;
|
||
|
|
||
|
} else {
|
||
|
// It's not a when.js promise. See if it's a foreign promise or a value.
|
||
|
if(isPromise(promiseOrValue)) {
|
||
|
// It's a thenable, but we don't know where it came from, so don't trust
|
||
|
// its implementation entirely. Introduce a trusted middleman when.js promise
|
||
|
deferred = defer();
|
||
|
|
||
|
// IMPORTANT: This is the only place when.js should ever call .then() on an
|
||
|
// untrusted promise. Don't expose the return value to the untrusted promise
|
||
|
promiseOrValue.then(
|
||
|
function(value) { deferred.resolve(value); },
|
||
|
function(reason) { deferred.reject(reason); },
|
||
|
function(update) { deferred.progress(update); }
|
||
|
);
|
||
|
|
||
|
promise = deferred.promise;
|
||
|
|
||
|
} else {
|
||
|
// It's a value, not a promise. Create a resolved promise for it.
|
||
|
promise = fulfilled(promiseOrValue);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return promise;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns a rejected promise for the supplied promiseOrValue. The returned
|
||
|
* promise will be rejected with:
|
||
|
* - promiseOrValue, if it is a value, or
|
||
|
* - if promiseOrValue is a promise
|
||
|
* - promiseOrValue's value after it is fulfilled
|
||
|
* - promiseOrValue's reason after it is rejected
|
||
|
* @param {*} promiseOrValue the rejected value of the returned {@link Promise}
|
||
|
* @returns {Promise} rejected {@link Promise}
|
||
|
*/
|
||
|
function reject(promiseOrValue) {
|
||
|
return when(promiseOrValue, rejected);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Trusted Promise constructor. A Promise created from this constructor is
|
||
|
* a trusted when.js promise. Any other duck-typed promise is considered
|
||
|
* untrusted.
|
||
|
* @constructor
|
||
|
* @name Promise
|
||
|
*/
|
||
|
function Promise(then) {
|
||
|
this.then = then;
|
||
|
}
|
||
|
|
||
|
Promise.prototype = {
|
||
|
/**
|
||
|
* Register a callback that will be called when a promise is
|
||
|
* fulfilled or rejected. Optionally also register a progress handler.
|
||
|
* Shortcut for .then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress)
|
||
|
* @param {function?} [onFulfilledOrRejected]
|
||
|
* @param {function?} [onProgress]
|
||
|
* @returns {Promise}
|
||
|
*/
|
||
|
always: function(onFulfilledOrRejected, onProgress) {
|
||
|
return this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Register a rejection handler. Shortcut for .then(undefined, onRejected)
|
||
|
* @param {function?} onRejected
|
||
|
* @returns {Promise}
|
||
|
*/
|
||
|
otherwise: function(onRejected) {
|
||
|
return this.then(undef, onRejected);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Shortcut for .then(function() { return value; })
|
||
|
* @param {*} value
|
||
|
* @returns {Promise} a promise that:
|
||
|
* - is fulfilled if value is not a promise, or
|
||
|
* - if value is a promise, will fulfill with its value, or reject
|
||
|
* with its reason.
|
||
|
*/
|
||
|
yield: function(value) {
|
||
|
return this.then(function() {
|
||
|
return value;
|
||
|
});
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Assumes that this promise will fulfill with an array, and arranges
|
||
|
* for the onFulfilled to be called with the array as its argument list
|
||
|
* i.e. onFulfilled.spread(undefined, array).
|
||
|
* @param {function} onFulfilled function to receive spread arguments
|
||
|
* @returns {Promise}
|
||
|
*/
|
||
|
spread: function(onFulfilled) {
|
||
|
return this.then(function(array) {
|
||
|
// array may contain promises, so resolve its contents.
|
||
|
return all(array, function(array) {
|
||
|
return onFulfilled.apply(undef, array);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Create an already-resolved promise for the supplied value
|
||
|
* @private
|
||
|
*
|
||
|
* @param {*} value
|
||
|
* @returns {Promise} fulfilled promise
|
||
|
*/
|
||
|
function fulfilled(value) {
|
||
|
var p = new Promise(function(onFulfilled) {
|
||
|
// TODO: Promises/A+ check typeof onFulfilled
|
||
|
try {
|
||
|
return resolve(onFulfilled ? onFulfilled(value) : value);
|
||
|
} catch(e) {
|
||
|
return rejected(e);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return p;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Create an already-rejected {@link Promise} with the supplied
|
||
|
* rejection reason.
|
||
|
* @private
|
||
|
*
|
||
|
* @param {*} reason
|
||
|
* @returns {Promise} rejected promise
|
||
|
*/
|
||
|
function rejected(reason) {
|
||
|
var p = new Promise(function(_, onRejected) {
|
||
|
// TODO: Promises/A+ check typeof onRejected
|
||
|
try {
|
||
|
return onRejected ? resolve(onRejected(reason)) : rejected(reason);
|
||
|
} catch(e) {
|
||
|
return rejected(e);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return p;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates a new, Deferred with fully isolated resolver and promise parts,
|
||
|
* either or both of which may be given out safely to consumers.
|
||
|
* The Deferred itself has the full API: resolve, reject, progress, and
|
||
|
* then. The resolver has resolve, reject, and progress. The promise
|
||
|
* only has then.
|
||
|
*
|
||
|
* @returns {Deferred}
|
||
|
*/
|
||
|
function defer() {
|
||
|
var deferred, promise, handlers, progressHandlers,
|
||
|
_then, _progress, _resolve;
|
||
|
|
||
|
/**
|
||
|
* The promise for the new deferred
|
||
|
* @type {Promise}
|
||
|
*/
|
||
|
promise = new Promise(then);
|
||
|
|
||
|
/**
|
||
|
* The full Deferred object, with {@link Promise} and {@link Resolver} parts
|
||
|
* @class Deferred
|
||
|
* @name Deferred
|
||
|
*/
|
||
|
deferred = {
|
||
|
then: then, // DEPRECATED: use deferred.promise.then
|
||
|
resolve: promiseResolve,
|
||
|
reject: promiseReject,
|
||
|
// TODO: Consider renaming progress() to notify()
|
||
|
progress: promiseProgress,
|
||
|
|
||
|
promise: promise,
|
||
|
|
||
|
resolver: {
|
||
|
resolve: promiseResolve,
|
||
|
reject: promiseReject,
|
||
|
progress: promiseProgress
|
||
|
}
|
||
|
};
|
||
|
|
||
|
handlers = [];
|
||
|
progressHandlers = [];
|
||
|
|
||
|
/**
|
||
|
* Pre-resolution then() that adds the supplied callback, errback, and progback
|
||
|
* functions to the registered listeners
|
||
|
* @private
|
||
|
*
|
||
|
* @param {function?} [onFulfilled] resolution handler
|
||
|
* @param {function?} [onRejected] rejection handler
|
||
|
* @param {function?} [onProgress] progress handler
|
||
|
*/
|
||
|
_then = function(onFulfilled, onRejected, onProgress) {
|
||
|
// TODO: Promises/A+ check typeof onFulfilled, onRejected, onProgress
|
||
|
var deferred, progressHandler;
|
||
|
|
||
|
deferred = defer();
|
||
|
|
||
|
progressHandler = typeof onProgress === 'function'
|
||
|
? function(update) {
|
||
|
try {
|
||
|
// Allow progress handler to transform progress event
|
||
|
deferred.progress(onProgress(update));
|
||
|
} catch(e) {
|
||
|
// Use caught value as progress
|
||
|
deferred.progress(e);
|
||
|
}
|
||
|
}
|
||
|
: function(update) { deferred.progress(update); };
|
||
|
|
||
|
handlers.push(function(promise) {
|
||
|
promise.then(onFulfilled, onRejected)
|
||
|
.then(deferred.resolve, deferred.reject, progressHandler);
|
||
|
});
|
||
|
|
||
|
progressHandlers.push(progressHandler);
|
||
|
|
||
|
return deferred.promise;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Issue a progress event, notifying all progress listeners
|
||
|
* @private
|
||
|
* @param {*} update progress event payload to pass to all listeners
|
||
|
*/
|
||
|
_progress = function(update) {
|
||
|
processQueue(progressHandlers, update);
|
||
|
return update;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Transition from pre-resolution state to post-resolution state, notifying
|
||
|
* all listeners of the resolution or rejection
|
||
|
* @private
|
||
|
* @param {*} value the value of this deferred
|
||
|
*/
|
||
|
_resolve = function(value) {
|
||
|
value = resolve(value);
|
||
|
|
||
|
// Replace _then with one that directly notifies with the result.
|
||
|
_then = value.then;
|
||
|
// Replace _resolve so that this Deferred can only be resolved once
|
||
|
_resolve = resolve;
|
||
|
// Make _progress a noop, to disallow progress for the resolved promise.
|
||
|
_progress = noop;
|
||
|
|
||
|
// Notify handlers
|
||
|
processQueue(handlers, value);
|
||
|
|
||
|
// Free progressHandlers array since we'll never issue progress events
|
||
|
progressHandlers = handlers = undef;
|
||
|
|
||
|
return value;
|
||
|
};
|
||
|
|
||
|
return deferred;
|
||
|
|
||
|
/**
|
||
|
* Wrapper to allow _then to be replaced safely
|
||
|
* @param {function?} [onFulfilled] resolution handler
|
||
|
* @param {function?} [onRejected] rejection handler
|
||
|
* @param {function?} [onProgress] progress handler
|
||
|
* @returns {Promise} new promise
|
||
|
*/
|
||
|
function then(onFulfilled, onRejected, onProgress) {
|
||
|
// TODO: Promises/A+ check typeof onFulfilled, onRejected, onProgress
|
||
|
return _then(onFulfilled, onRejected, onProgress);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Wrapper to allow _resolve to be replaced
|
||
|
*/
|
||
|
function promiseResolve(val) {
|
||
|
return _resolve(val);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Wrapper to allow _reject to be replaced
|
||
|
*/
|
||
|
function promiseReject(err) {
|
||
|
return _resolve(rejected(err));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Wrapper to allow _progress to be replaced
|
||
|
*/
|
||
|
function promiseProgress(update) {
|
||
|
return _progress(update);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determines if promiseOrValue is a promise or not. Uses the feature
|
||
|
* test from http://wiki.commonjs.org/wiki/Promises/A to determine if
|
||
|
* promiseOrValue is a promise.
|
||
|
*
|
||
|
* @param {*} promiseOrValue anything
|
||
|
* @returns {boolean} true if promiseOrValue is a {@link Promise}
|
||
|
*/
|
||
|
function isPromise(promiseOrValue) {
|
||
|
return promiseOrValue && typeof promiseOrValue.then === 'function';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Initiates a competitive race, returning a promise that will resolve when
|
||
|
* howMany of the supplied promisesOrValues have resolved, or will reject when
|
||
|
* it becomes impossible for howMany to resolve, for example, when
|
||
|
* (promisesOrValues.length - howMany) + 1 input promises reject.
|
||
|
*
|
||
|
* @param {Array} promisesOrValues array of anything, may contain a mix
|
||
|
* of promises and values
|
||
|
* @param howMany {number} number of promisesOrValues to resolve
|
||
|
* @param {function?} [onFulfilled] resolution handler
|
||
|
* @param {function?} [onRejected] rejection handler
|
||
|
* @param {function?} [onProgress] progress handler
|
||
|
* @returns {Promise} promise that will resolve to an array of howMany values that
|
||
|
* resolved first, or will reject with an array of (promisesOrValues.length - howMany) + 1
|
||
|
* rejection reasons.
|
||
|
*/
|
||
|
function some(promisesOrValues, howMany, onFulfilled, onRejected, onProgress) {
|
||
|
|
||
|
checkCallbacks(2, arguments);
|
||
|
|
||
|
return when(promisesOrValues, function(promisesOrValues) {
|
||
|
|
||
|
var toResolve, toReject, values, reasons, deferred, fulfillOne, rejectOne, progress, len, i;
|
||
|
|
||
|
len = promisesOrValues.length >>> 0;
|
||
|
|
||
|
toResolve = Math.max(0, Math.min(howMany, len));
|
||
|
values = [];
|
||
|
|
||
|
toReject = (len - toResolve) + 1;
|
||
|
reasons = [];
|
||
|
|
||
|
deferred = defer();
|
||
|
|
||
|
// No items in the input, resolve immediately
|
||
|
if (!toResolve) {
|
||
|
deferred.resolve(values);
|
||
|
|
||
|
} else {
|
||
|
progress = deferred.progress;
|
||
|
|
||
|
rejectOne = function(reason) {
|
||
|
reasons.push(reason);
|
||
|
if(!--toReject) {
|
||
|
fulfillOne = rejectOne = noop;
|
||
|
deferred.reject(reasons);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
fulfillOne = function(val) {
|
||
|
// This orders the values based on promise resolution order
|
||
|
// Another strategy would be to use the original position of
|
||
|
// the corresponding promise.
|
||
|
values.push(val);
|
||
|
|
||
|
if (!--toResolve) {
|
||
|
fulfillOne = rejectOne = noop;
|
||
|
deferred.resolve(values);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
for(i = 0; i < len; ++i) {
|
||
|
if(i in promisesOrValues) {
|
||
|
when(promisesOrValues[i], fulfiller, rejecter, progress);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return deferred.then(onFulfilled, onRejected, onProgress);
|
||
|
|
||
|
function rejecter(reason) {
|
||
|
rejectOne(reason);
|
||
|
}
|
||
|
|
||
|
function fulfiller(val) {
|
||
|
fulfillOne(val);
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Initiates a competitive race, returning a promise that will resolve when
|
||
|
* any one of the supplied promisesOrValues has resolved or will reject when
|
||
|
* *all* promisesOrValues have rejected.
|
||
|
*
|
||
|
* @param {Array|Promise} promisesOrValues array of anything, may contain a mix
|
||
|
* of {@link Promise}s and values
|
||
|
* @param {function?} [onFulfilled] resolution handler
|
||
|
* @param {function?} [onRejected] rejection handler
|
||
|
* @param {function?} [onProgress] progress handler
|
||
|
* @returns {Promise} promise that will resolve to the value that resolved first, or
|
||
|
* will reject with an array of all rejected inputs.
|
||
|
*/
|
||
|
function any(promisesOrValues, onFulfilled, onRejected, onProgress) {
|
||
|
|
||
|
function unwrapSingleResult(val) {
|
||
|
return onFulfilled ? onFulfilled(val[0]) : val[0];
|
||
|
}
|
||
|
|
||
|
return some(promisesOrValues, 1, unwrapSingleResult, onRejected, onProgress);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a promise that will resolve only once all the supplied promisesOrValues
|
||
|
* have resolved. The resolution value of the returned promise will be an array
|
||
|
* containing the resolution values of each of the promisesOrValues.
|
||
|
* @memberOf when
|
||
|
*
|
||
|
* @param {Array|Promise} promisesOrValues array of anything, may contain a mix
|
||
|
* of {@link Promise}s and values
|
||
|
* @param {function?} [onFulfilled] resolution handler
|
||
|
* @param {function?} [onRejected] rejection handler
|
||
|
* @param {function?} [onProgress] progress handler
|
||
|
* @returns {Promise}
|
||
|
*/
|
||
|
function all(promisesOrValues, onFulfilled, onRejected, onProgress) {
|
||
|
checkCallbacks(1, arguments);
|
||
|
return map(promisesOrValues, identity).then(onFulfilled, onRejected, onProgress);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Joins multiple promises into a single returned promise.
|
||
|
* @returns {Promise} a promise that will fulfill when *all* the input promises
|
||
|
* have fulfilled, or will reject when *any one* of the input promises rejects.
|
||
|
*/
|
||
|
function join(/* ...promises */) {
|
||
|
return map(arguments, identity);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Traditional map function, similar to `Array.prototype.map()`, but allows
|
||
|
* input to contain {@link Promise}s and/or values, and mapFunc may return
|
||
|
* either a value or a {@link Promise}
|
||
|
*
|
||
|
* @param {Array|Promise} promise array of anything, may contain a mix
|
||
|
* of {@link Promise}s and values
|
||
|
* @param {function} mapFunc mapping function mapFunc(value) which may return
|
||
|
* either a {@link Promise} or value
|
||
|
* @returns {Promise} a {@link Promise} that will resolve to an array containing
|
||
|
* the mapped output values.
|
||
|
*/
|
||
|
function map(promise, mapFunc) {
|
||
|
return when(promise, function(array) {
|
||
|
var results, len, toResolve, resolve, i, d;
|
||
|
|
||
|
// Since we know the resulting length, we can preallocate the results
|
||
|
// array to avoid array expansions.
|
||
|
toResolve = len = array.length >>> 0;
|
||
|
results = [];
|
||
|
d = defer();
|
||
|
|
||
|
if(!toResolve) {
|
||
|
d.resolve(results);
|
||
|
} else {
|
||
|
|
||
|
resolve = function resolveOne(item, i) {
|
||
|
when(item, mapFunc).then(function(mapped) {
|
||
|
results[i] = mapped;
|
||
|
|
||
|
if(!--toResolve) {
|
||
|
d.resolve(results);
|
||
|
}
|
||
|
}, d.reject);
|
||
|
};
|
||
|
|
||
|
// Since mapFunc may be async, get all invocations of it into flight
|
||
|
for(i = 0; i < len; i++) {
|
||
|
if(i in array) {
|
||
|
resolve(array[i], i);
|
||
|
} else {
|
||
|
--toResolve;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return d.promise;
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Traditional reduce function, similar to `Array.prototype.reduce()`, but
|
||
|
* input may contain promises and/or values, and reduceFunc
|
||
|
* may return either a value or a promise, *and* initialValue may
|
||
|
* be a promise for the starting value.
|
||
|
*
|
||
|
* @param {Array|Promise} promise array or promise for an array of anything,
|
||
|
* may contain a mix of promises and values.
|
||
|
* @param {function} reduceFunc reduce function reduce(currentValue, nextValue, index, total),
|
||
|
* where total is the total number of items being reduced, and will be the same
|
||
|
* in each call to reduceFunc.
|
||
|
* @returns {Promise} that will resolve to the final reduced value
|
||
|
*/
|
||
|
function reduce(promise, reduceFunc /*, initialValue */) {
|
||
|
var args = slice.call(arguments, 1);
|
||
|
|
||
|
return when(promise, function(array) {
|
||
|
var total;
|
||
|
|
||
|
total = array.length;
|
||
|
|
||
|
// Wrap the supplied reduceFunc with one that handles promises and then
|
||
|
// delegates to the supplied.
|
||
|
args[0] = function (current, val, i) {
|
||
|
return when(current, function (c) {
|
||
|
return when(val, function (value) {
|
||
|
return reduceFunc(c, value, i, total);
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
return reduceArray.apply(array, args);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Ensure that resolution of promiseOrValue will trigger resolver with the
|
||
|
* value or reason of promiseOrValue, or instead with resolveValue if it is provided.
|
||
|
*
|
||
|
* @param promiseOrValue
|
||
|
* @param {Object} resolver
|
||
|
* @param {function} resolver.resolve
|
||
|
* @param {function} resolver.reject
|
||
|
* @param {*} [resolveValue]
|
||
|
* @returns {Promise}
|
||
|
*/
|
||
|
function chain(promiseOrValue, resolver, resolveValue) {
|
||
|
var useResolveValue = arguments.length > 2;
|
||
|
|
||
|
return when(promiseOrValue,
|
||
|
function(val) {
|
||
|
val = useResolveValue ? resolveValue : val;
|
||
|
resolver.resolve(val);
|
||
|
return val;
|
||
|
},
|
||
|
function(reason) {
|
||
|
resolver.reject(reason);
|
||
|
return rejected(reason);
|
||
|
},
|
||
|
resolver.progress
|
||
|
);
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Utility functions
|
||
|
//
|
||
|
|
||
|
/**
|
||
|
* Apply all functions in queue to value
|
||
|
* @param {Array} queue array of functions to execute
|
||
|
* @param {*} value argument passed to each function
|
||
|
*/
|
||
|
function processQueue(queue, value) {
|
||
|
var handler, i = 0;
|
||
|
|
||
|
while (handler = queue[i++]) {
|
||
|
handler(value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Helper that checks arrayOfCallbacks to ensure that each element is either
|
||
|
* a function, or null or undefined.
|
||
|
* @private
|
||
|
* @param {number} start index at which to start checking items in arrayOfCallbacks
|
||
|
* @param {Array} arrayOfCallbacks array to check
|
||
|
* @throws {Error} if any element of arrayOfCallbacks is something other than
|
||
|
* a functions, null, or undefined.
|
||
|
*/
|
||
|
function checkCallbacks(start, arrayOfCallbacks) {
|
||
|
// TODO: Promises/A+ update type checking and docs
|
||
|
var arg, i = arrayOfCallbacks.length;
|
||
|
|
||
|
while(i > start) {
|
||
|
arg = arrayOfCallbacks[--i];
|
||
|
|
||
|
if (arg != null && typeof arg != 'function') {
|
||
|
throw new Error('arg '+i+' must be a function');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* No-Op function used in method replacement
|
||
|
* @private
|
||
|
*/
|
||
|
function noop() {}
|
||
|
|
||
|
slice = [].slice;
|
||
|
|
||
|
// ES5 reduce implementation if native not available
|
||
|
// See: http://es5.github.com/#x15.4.4.21 as there are many
|
||
|
// specifics and edge cases.
|
||
|
reduceArray = [].reduce ||
|
||
|
function(reduceFunc /*, initialValue */) {
|
||
|
/*jshint maxcomplexity: 7*/
|
||
|
|
||
|
// ES5 dictates that reduce.length === 1
|
||
|
|
||
|
// This implementation deviates from ES5 spec in the following ways:
|
||
|
// 1. It does not check if reduceFunc is a Callable
|
||
|
|
||
|
var arr, args, reduced, len, i;
|
||
|
|
||
|
i = 0;
|
||
|
// This generates a jshint warning, despite being valid
|
||
|
// "Missing 'new' prefix when invoking a constructor."
|
||
|
// See https://github.com/jshint/jshint/issues/392
|
||
|
arr = Object(this);
|
||
|
len = arr.length >>> 0;
|
||
|
args = arguments;
|
||
|
|
||
|
// If no initialValue, use first item of array (we know length !== 0 here)
|
||
|
// and adjust i to start at second item
|
||
|
if(args.length <= 1) {
|
||
|
// Skip to the first real element in the array
|
||
|
for(;;) {
|
||
|
if(i in arr) {
|
||
|
reduced = arr[i++];
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
// If we reached the end of the array without finding any real
|
||
|
// elements, it's a TypeError
|
||
|
if(++i >= len) {
|
||
|
throw new TypeError();
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
// If initialValue provided, use it
|
||
|
reduced = args[1];
|
||
|
}
|
||
|
|
||
|
// Do the actual reduce
|
||
|
for(;i < len; ++i) {
|
||
|
// Skip holes
|
||
|
if(i in arr) {
|
||
|
reduced = reduceFunc(reduced, arr[i], i, arr);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return reduced;
|
||
|
};
|
||
|
|
||
|
function identity(x) {
|
||
|
return x;
|
||
|
}
|
||
|
|
||
|
return when;
|
||
|
});
|
||
|
})(typeof define == 'function' && define.amd
|
||
|
? define
|
||
|
: function (factory) { typeof exports === 'object'
|
||
|
? (module.exports = factory())
|
||
|
: (this.when = factory());
|
||
|
}
|
||
|
// Boilerplate for AMD, Node, and browser global
|
||
|
);
|
||
|
|
||
|
define('Core/defaultValue',[
|
||
|
'./freezeObject'
|
||
|
], function(
|
||
|
freezeObject) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Returns the first parameter if not undefined, otherwise the second parameter.
|
||
|
* Useful for setting a default value for a parameter.
|
||
|
*
|
||
|
* @exports defaultValue
|
||
|
*
|
||
|
* @param {*} a
|
||
|
* @param {*} b
|
||
|
* @returns {*} Returns the first parameter if not undefined, otherwise the second parameter.
|
||
|
*
|
||
|
* @example
|
||
|
* param = Cesium.defaultValue(param, 'default');
|
||
|
*/
|
||
|
function defaultValue(a, b) {
|
||
|
if (a !== undefined && a !== null) {
|
||
|
return a;
|
||
|
}
|
||
|
return b;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* A frozen empty object that can be used as the default value for options passed as
|
||
|
* an object literal.
|
||
|
* @type {Object}
|
||
|
*/
|
||
|
defaultValue.EMPTY_OBJECT = freezeObject({});
|
||
|
|
||
|
return defaultValue;
|
||
|
});
|
||
|
|
||
|
define('Core/formatError',[
|
||
|
'./defined'
|
||
|
], function(
|
||
|
defined) {
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Formats an error object into a String. If available, uses name, message, and stack
|
||
|
* properties, otherwise, falls back on toString().
|
||
|
*
|
||
|
* @exports formatError
|
||
|
*
|
||
|
* @param {*} object The item to find in the array.
|
||
|
* @returns {String} A string containing the formatted error.
|
||
|
*/
|
||
|
function formatError(object) {
|
||
|
var result;
|
||
|
|
||
|
var name = object.name;
|
||
|
var message = object.message;
|
||
|
if (defined(name) && defined(message)) {
|
||
|
result = name + ': ' + message;
|
||
|
} else {
|
||
|
result = object.toString();
|
||
|
}
|
||
|
|
||
|
var stack = object.stack;
|
||
|
if (defined(stack)) {
|
||
|
result += '\n' + stack;
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
return formatError;
|
||
|
});
|
||
|
|
||
|
define('Workers/createTaskProcessorWorker',[
|
||
|
'../ThirdParty/when',
|
||
|
'../Core/defaultValue',
|
||
|
'../Core/defined',
|
||
|
'../Core/formatError'
|
||
|
], function(
|
||
|
when,
|
||
|
defaultValue,
|
||
|
defined,
|
||
|
formatError) {
|
||
|
'use strict';
|
||
|
|
||
|
// createXXXGeometry functions may return Geometry or a Promise that resolves to Geometry
|
||
|
// if the function requires access to ApproximateTerrainHeights.
|
||
|
// For fully synchronous functions, just wrapping the function call in a `when` Promise doesn't
|
||
|
// handle errors correctly, hence try-catch
|
||
|
function callAndWrap(workerFunction, parameters, transferableObjects) {
|
||
|
var resultOrPromise;
|
||
|
try {
|
||
|
resultOrPromise = workerFunction(parameters, transferableObjects);
|
||
|
return resultOrPromise; // errors handled by Promise
|
||
|
} catch (e) {
|
||
|
return when.reject(e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates an adapter function to allow a calculation function to operate as a Web Worker,
|
||
|
* paired with TaskProcessor, to receive tasks and return results.
|
||
|
*
|
||
|
* @exports createTaskProcessorWorker
|
||
|
*
|
||
|
* @param {createTaskProcessorWorker~WorkerFunction} workerFunction The calculation function,
|
||
|
* which takes parameters and returns a result.
|
||
|
* @returns {createTaskProcessorWorker~TaskProcessorWorkerFunction} A function that adapts the
|
||
|
* calculation function to work as a Web Worker onmessage listener with TaskProcessor.
|
||
|
*
|
||
|
*
|
||
|
* @example
|
||
|
* function doCalculation(parameters, transferableObjects) {
|
||
|
* // calculate some result using the inputs in parameters
|
||
|
* return result;
|
||
|
* }
|
||
|
*
|
||
|
* return Cesium.createTaskProcessorWorker(doCalculation);
|
||
|
* // the resulting function is compatible with TaskProcessor
|
||
|
*
|
||
|
* @see TaskProcessor
|
||
|
* @see {@link http://www.w3.org/TR/workers/|Web Workers}
|
||
|
* @see {@link http://www.w3.org/TR/html5/common-dom-interfaces.html#transferable-objects|Transferable objects}
|
||
|
*/
|
||
|
function createTaskProcessorWorker(workerFunction) {
|
||
|
var postMessage;
|
||
|
|
||
|
return function(event) {
|
||
|
/*global self*/
|
||
|
var data = event.data;
|
||
|
|
||
|
var transferableObjects = [];
|
||
|
var responseMessage = {
|
||
|
id : data.id,
|
||
|
result : undefined,
|
||
|
error : undefined
|
||
|
};
|
||
|
|
||
|
return when(callAndWrap(workerFunction, data.parameters, transferableObjects))
|
||
|
.then(function(result) {
|
||
|
responseMessage.result = result;
|
||
|
})
|
||
|
.otherwise(function(e) {
|
||
|
if (e instanceof Error) {
|
||
|
// Errors can't be posted in a message, copy the properties
|
||
|
responseMessage.error = {
|
||
|
name : e.name,
|
||
|
message : e.message,
|
||
|
stack : e.stack
|
||
|
};
|
||
|
} else {
|
||
|
responseMessage.error = e;
|
||
|
}
|
||
|
})
|
||
|
.always(function() {
|
||
|
if (!defined(postMessage)) {
|
||
|
postMessage = defaultValue(self.webkitPostMessage, self.postMessage);
|
||
|
}
|
||
|
|
||
|
if (!data.canTransferArrayBuffer) {
|
||
|
transferableObjects.length = 0;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
postMessage(responseMessage, transferableObjects);
|
||
|
} catch (e) {
|
||
|
// something went wrong trying to post the message, post a simpler
|
||
|
// error that we can be sure will be cloneable
|
||
|
responseMessage.result = undefined;
|
||
|
responseMessage.error = 'postMessage failed with error: ' + formatError(e) + '\n with responseMessage: ' + JSON.stringify(responseMessage);
|
||
|
postMessage(responseMessage);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* A function that performs a calculation in a Web Worker.
|
||
|
* @callback createTaskProcessorWorker~WorkerFunction
|
||
|
*
|
||
|
* @param {Object} parameters Parameters to the calculation.
|
||
|
* @param {Array} transferableObjects An array that should be filled with references to objects inside
|
||
|
* the result that should be transferred back to the main document instead of copied.
|
||
|
* @returns {Object} The result of the calculation.
|
||
|
*
|
||
|
* @example
|
||
|
* function calculate(parameters, transferableObjects) {
|
||
|
* // perform whatever calculation is necessary.
|
||
|
* var typedArray = new Float32Array(0);
|
||
|
*
|
||
|
* // typed arrays are transferable
|
||
|
* transferableObjects.push(typedArray)
|
||
|
*
|
||
|
* return {
|
||
|
* typedArray : typedArray
|
||
|
* };
|
||
|
* }
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* A Web Worker message event handler function that handles the interaction with TaskProcessor,
|
||
|
* specifically, task ID management and posting a response message containing the result.
|
||
|
* @callback createTaskProcessorWorker~TaskProcessorWorkerFunction
|
||
|
*
|
||
|
* @param {Object} event The onmessage event object.
|
||
|
*/
|
||
|
|
||
|
return createTaskProcessorWorker;
|
||
|
});
|
||
|
|
||
|
define('Workers/transcodeCRNToDXT',[
|
||
|
'../Core/CompressedTextureBuffer',
|
||
|
'../Core/defined',
|
||
|
'../Core/PixelFormat',
|
||
|
'../Core/RuntimeError',
|
||
|
'../ThirdParty/crunch',
|
||
|
'./createTaskProcessorWorker'
|
||
|
], function(
|
||
|
CompressedTextureBuffer,
|
||
|
defined,
|
||
|
PixelFormat,
|
||
|
RuntimeError,
|
||
|
crunch,
|
||
|
createTaskProcessorWorker) {
|
||
|
'use strict';
|
||
|
|
||
|
// Modified from texture-tester
|
||
|
// See:
|
||
|
// https://github.com/toji/texture-tester/blob/master/js/webgl-texture-util.js
|
||
|
// http://toji.github.io/texture-tester/
|
||
|
|
||
|
/**
|
||
|
* @license
|
||
|
*
|
||
|
* Copyright (c) 2014, Brandon Jones. All rights reserved.
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||
|
* are permitted provided that the following conditions are met:
|
||
|
*
|
||
|
* * Redistributions of source code must retain the above copyright notice, this
|
||
|
* list of conditions and the following disclaimer.
|
||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||
|
* this list of conditions and the following disclaimer in the documentation
|
||
|
* and/or other materials provided with the distribution.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
*/
|
||
|
|
||
|
// Taken from crnlib.h
|
||
|
var CRN_FORMAT = {
|
||
|
cCRNFmtInvalid: -1,
|
||
|
|
||
|
cCRNFmtDXT1: 0,
|
||
|
// cCRNFmtDXT3 is not currently supported when writing to CRN - only DDS.
|
||
|
cCRNFmtDXT3: 1,
|
||
|
cCRNFmtDXT5: 2
|
||
|
|
||
|
// Crunch supports more formats than this, but we can't use them here.
|
||
|
};
|
||
|
|
||
|
// Mapping of Crunch formats to DXT formats.
|
||
|
var DXT_FORMAT_MAP = {};
|
||
|
DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT1] = PixelFormat.RGB_DXT1;
|
||
|
DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT3] = PixelFormat.RGBA_DXT3;
|
||
|
DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT5] = PixelFormat.RGBA_DXT5;
|
||
|
|
||
|
var dst;
|
||
|
var dxtData;
|
||
|
var cachedDstSize = 0;
|
||
|
|
||
|
// Copy an array of bytes into or out of the emscripten heap.
|
||
|
function arrayBufferCopy(src, dst, dstByteOffset, numBytes) {
|
||
|
var i;
|
||
|
var dst32Offset = dstByteOffset / 4;
|
||
|
var tail = (numBytes % 4);
|
||
|
var src32 = new Uint32Array(src.buffer, 0, (numBytes - tail) / 4);
|
||
|
var dst32 = new Uint32Array(dst.buffer);
|
||
|
for (i = 0; i < src32.length; i++) {
|
||
|
dst32[dst32Offset + i] = src32[i];
|
||
|
}
|
||
|
for (i = numBytes - tail; i < numBytes; i++) {
|
||
|
dst[dstByteOffset + i] = src[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @private
|
||
|
*/
|
||
|
function transcodeCRNToDXT(arrayBuffer, transferableObjects) {
|
||
|
// Copy the contents of the arrayBuffer into emscriptens heap.
|
||
|
var srcSize = arrayBuffer.byteLength;
|
||
|
var bytes = new Uint8Array(arrayBuffer);
|
||
|
var src = crunch._malloc(srcSize);
|
||
|
arrayBufferCopy(bytes, crunch.HEAPU8, src, srcSize);
|
||
|
|
||
|
// Determine what type of compressed data the file contains.
|
||
|
var crnFormat = crunch._crn_get_dxt_format(src, srcSize);
|
||
|
var format = DXT_FORMAT_MAP[crnFormat];
|
||
|
if (!defined(format)) {
|
||
|
throw new RuntimeError('Unsupported compressed format.');
|
||
|
}
|
||
|
|
||
|
// Gather basic metrics about the DXT data.
|
||
|
var levels = crunch._crn_get_levels(src, srcSize);
|
||
|
var width = crunch._crn_get_width(src, srcSize);
|
||
|
var height = crunch._crn_get_height(src, srcSize);
|
||
|
|
||
|
// Determine the size of the decoded DXT data.
|
||
|
var dstSize = 0;
|
||
|
var i;
|
||
|
for (i = 0; i < levels; ++i) {
|
||
|
dstSize += PixelFormat.compressedTextureSizeInBytes(format, width >> i, height >> i);
|
||
|
}
|
||
|
|
||
|
// Allocate enough space on the emscripten heap to hold the decoded DXT data
|
||
|
// or reuse the existing allocation if a previous call to this function has
|
||
|
// already acquired a large enough buffer.
|
||
|
if(cachedDstSize < dstSize) {
|
||
|
if(defined(dst)) {
|
||
|
crunch._free(dst);
|
||
|
}
|
||
|
dst = crunch._malloc(dstSize);
|
||
|
dxtData = new Uint8Array(crunch.HEAPU8.buffer, dst, dstSize);
|
||
|
cachedDstSize = dstSize;
|
||
|
}
|
||
|
|
||
|
// Decompress the DXT data from the Crunch file into the allocated space.
|
||
|
crunch._crn_decompress(src, srcSize, dst, dstSize, 0, levels);
|
||
|
|
||
|
// Release the crunch file data from the emscripten heap.
|
||
|
crunch._free(src);
|
||
|
|
||
|
// Mipmaps are unsupported, so copy the level 0 texture
|
||
|
// When mipmaps are supported, a copy will still be necessary as dxtData is a view on the heap.
|
||
|
var length = PixelFormat.compressedTextureSizeInBytes(format, width, height);
|
||
|
|
||
|
// Get a copy of the 0th mip level. dxtData will exceed length when there are more mip levels.
|
||
|
// Equivalent to dxtData.slice(0, length), which is not supported in IE11
|
||
|
var level0DXTDataView = dxtData.subarray(0, length);
|
||
|
var level0DXTData = new Uint8Array(length);
|
||
|
level0DXTData.set(level0DXTDataView, 0);
|
||
|
|
||
|
transferableObjects.push(level0DXTData.buffer);
|
||
|
return new CompressedTextureBuffer(format, width, height, level0DXTData);
|
||
|
}
|
||
|
|
||
|
return createTaskProcessorWorker(transcodeCRNToDXT);
|
||
|
});
|
||
|
|
||
|
}());
|