Created
February 9, 2019 13:09
-
-
Save floooh/ae2250dce2dfd700eb959b802d7d247a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(typeof process!=="undefined"){var Module={};}// Copyright 2010 The Emscripten Authors. All rights reserved. | |
| // Emscripten is available under two separate licenses, the MIT license and the | |
| // University of Illinois/NCSA Open Source License. Both these licenses can be | |
| // found in the LICENSE file. | |
| var Module = Module; | |
| var ENVIRONMENT_IS_NODE = typeof process === 'object'; | |
| if (ENVIRONMENT_IS_NODE) { | |
| var fs = require('fs'); | |
| Module['wasm'] = fs.readFileSync(__dirname + '/clear-emsc.wasm'); | |
| } | |
| // Redefine these in a --pre-js to override behavior. If you would like to | |
| // remove out() or err() altogether, you can no-op it out to function() {}, | |
| // and build with --closure 1 to get Closure optimize out all the uses | |
| // altogether. | |
| function out(text) { | |
| console.log(text); | |
| } | |
| function err(text) { | |
| console.error(text); | |
| } | |
| // Override this function in a --pre-js file to get a signal for when | |
| // compilation is ready. In that callback, call the function run() to start | |
| // the program. | |
| function ready() { | |
| run(); | |
| } | |
| // --pre-jses are emitted after the Module integration code, so that they can | |
| // refer to Module (if they choose; they can also define Module) | |
| // {{PRE_JSES}} | |
| /** @type {function(number, string, boolean=)} */ | |
| function getValue(ptr, type, noSafe) { | |
| type = type || 'i8'; | |
| if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit | |
| switch(type) { | |
| case 'i1': return HEAP8[((ptr)>>0)]; | |
| case 'i8': return HEAP8[((ptr)>>0)]; | |
| case 'i16': return HEAP16[((ptr)>>1)]; | |
| case 'i32': return HEAP32[((ptr)>>2)]; | |
| case 'i64': return HEAP32[((ptr)>>2)]; | |
| case 'float': return HEAPF32[((ptr)>>2)]; | |
| case 'double': return HEAPF64[((ptr)>>3)]; | |
| default: abort('invalid type for getValue: ' + type); | |
| } | |
| return null; | |
| } | |
| /** @type {function(*, string=)} */ | |
| function assert(condition, text) { | |
| if (!condition) throw text; | |
| } | |
| function abort(what) { | |
| throw what; | |
| } | |
| function abortStackOverflow(allocSize) { | |
| abort('Stack overflow when attempting to allocate ' + allocSize + ' bytes on the stack!'); | |
| } | |
| var tempRet0 = 0; | |
| var setTempRet0 = function(value) { | |
| tempRet0 = value; | |
| } | |
| var getTempRet0 = function() { | |
| return tempRet0; | |
| } | |
| function alignUp(x, multiple) { | |
| if (x % multiple > 0) { | |
| x += multiple - (x % multiple); | |
| } | |
| return x; | |
| } | |
| // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns | |
| // a copy of that string as a Javascript String object. | |
| var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined; | |
| /** | |
| * @param {number} idx | |
| * @param {number=} maxBytesToRead | |
| * @return {string} | |
| */ | |
| function UTF8ArrayToString(u8Array, idx, maxBytesToRead) { | |
| var endIdx = idx + maxBytesToRead; | |
| var endPtr = idx; | |
| // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself. | |
| // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage. | |
| // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity) | |
| while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr; | |
| if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) { | |
| return UTF8Decoder.decode(u8Array.subarray(idx, endPtr)); | |
| } else { | |
| var str = ''; | |
| // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that | |
| while (idx < endPtr) { | |
| // For UTF8 byte structure, see: | |
| // http://en.wikipedia.org/wiki/UTF-8#Description | |
| // https://www.ietf.org/rfc/rfc2279.txt | |
| // https://tools.ietf.org/html/rfc3629 | |
| var u0 = u8Array[idx++]; | |
| if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; } | |
| var u1 = u8Array[idx++] & 63; | |
| if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; } | |
| var u2 = u8Array[idx++] & 63; | |
| if ((u0 & 0xF0) == 0xE0) { | |
| u0 = ((u0 & 15) << 12) | (u1 << 6) | u2; | |
| } else { | |
| if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte 0x' + u0.toString(16) + ' encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!'); | |
| u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (u8Array[idx++] & 63); | |
| } | |
| if (u0 < 0x10000) { | |
| str += String.fromCharCode(u0); | |
| } else { | |
| var ch = u0 - 0x10000; | |
| str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF)); | |
| } | |
| } | |
| } | |
| return str; | |
| } | |
| // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a | |
| // copy of that string as a Javascript String object. | |
| // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit | |
| // this parameter to scan the string until the first \0 byte. If maxBytesToRead is | |
| // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the | |
| // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will | |
| // not produce a string of exact length [ptr, ptr+maxBytesToRead[) | |
| // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may | |
| // throw JS JIT optimizations off, so it is worth to consider consistently using one | |
| // style or the other. | |
| /** | |
| * @param {number} ptr | |
| * @param {number=} maxBytesToRead | |
| * @return {string} | |
| */ | |
| function UTF8ToString(ptr, maxBytesToRead) { | |
| return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ''; | |
| } | |
| // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx', | |
| // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP. | |
| // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write. | |
| // Parameters: | |
| // str: the Javascript string to copy. | |
| // outU8Array: the array to copy to. Each index in this array is assumed to be one 8-byte element. | |
| // outIdx: The starting offset in the array to begin the copying. | |
| // maxBytesToWrite: The maximum number of bytes this function can write to the array. | |
| // This count should include the null terminator, | |
| // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else. | |
| // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator. | |
| // Returns the number of bytes written, EXCLUDING the null terminator. | |
| function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) { | |
| if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes. | |
| return 0; | |
| var startIdx = outIdx; | |
| var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator. | |
| for (var i = 0; i < str.length; ++i) { | |
| // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. | |
| // See http://unicode.org/faq/utf_bom.html#utf16-3 | |
| // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629 | |
| var u = str.charCodeAt(i); // possibly a lead surrogate | |
| if (u >= 0xD800 && u <= 0xDFFF) { | |
| var u1 = str.charCodeAt(++i); | |
| u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF); | |
| } | |
| if (u <= 0x7F) { | |
| if (outIdx >= endIdx) break; | |
| outU8Array[outIdx++] = u; | |
| } else if (u <= 0x7FF) { | |
| if (outIdx + 1 >= endIdx) break; | |
| outU8Array[outIdx++] = 0xC0 | (u >> 6); | |
| outU8Array[outIdx++] = 0x80 | (u & 63); | |
| } else if (u <= 0xFFFF) { | |
| if (outIdx + 2 >= endIdx) break; | |
| outU8Array[outIdx++] = 0xE0 | (u >> 12); | |
| outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63); | |
| outU8Array[outIdx++] = 0x80 | (u & 63); | |
| } else { | |
| if (outIdx + 3 >= endIdx) break; | |
| if (u >= 0x200000) warnOnce('Invalid Unicode code point 0x' + u.toString(16) + ' encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF).'); | |
| outU8Array[outIdx++] = 0xF0 | (u >> 18); | |
| outU8Array[outIdx++] = 0x80 | ((u >> 12) & 63); | |
| outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63); | |
| outU8Array[outIdx++] = 0x80 | (u & 63); | |
| } | |
| } | |
| // Null-terminate the pointer to the buffer. | |
| outU8Array[outIdx] = 0; | |
| return outIdx - startIdx; | |
| } | |
| // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr', | |
| // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP. | |
| // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write. | |
| // Returns the number of bytes written, EXCLUDING the null terminator. | |
| function stringToUTF8(str, outPtr, maxBytesToWrite) { | |
| assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!'); | |
| return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite); | |
| } | |
| // Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte. | |
| function lengthBytesUTF8(str) { | |
| var len = 0; | |
| for (var i = 0; i < str.length; ++i) { | |
| // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. | |
| // See http://unicode.org/faq/utf_bom.html#utf16-3 | |
| var u = str.charCodeAt(i); // possibly a lead surrogate | |
| if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF); | |
| if (u <= 0x7F) ++len; | |
| else if (u <= 0x7FF) len += 2; | |
| else if (u <= 0xFFFF) len += 3; | |
| else len += 4; | |
| } | |
| return len; | |
| } | |
| var GLOBAL_BASE = 1024, | |
| TOTAL_STACK = 5242880, | |
| TOTAL_MEMORY = 134217728, | |
| STATIC_BASE = 1024, | |
| STACK_BASE = 6992, | |
| STACKTOP = STACK_BASE, | |
| STACK_MAX = 5249872 | |
| , DYNAMICTOP_PTR = 6736 | |
| ; | |
| var wasmMaximumMemory = TOTAL_MEMORY; | |
| var wasmMemory = new WebAssembly.Memory({ | |
| 'initial': TOTAL_MEMORY >> 16 | |
| , 'maximum': wasmMaximumMemory >> 16 | |
| }); | |
| var buffer = wasmMemory.buffer; | |
| var WASM_PAGE_SIZE = 65536; | |
| assert(STACK_BASE % 16 === 0, 'stack must start aligned'); | |
| assert((5249872) % 16 === 0, 'heap must start aligned'); | |
| assert(TOTAL_MEMORY >= TOTAL_STACK, 'TOTAL_MEMORY should be larger than TOTAL_STACK, was ' + TOTAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')'); | |
| assert(TOTAL_MEMORY % WASM_PAGE_SIZE === 0); | |
| assert(buffer.byteLength === TOTAL_MEMORY); | |
| var HEAP8 = new Int8Array(buffer); | |
| var HEAP16 = new Int16Array(buffer); | |
| var HEAP32 = new Int32Array(buffer); | |
| var HEAPU8 = new Uint8Array(buffer); | |
| var HEAPU16 = new Uint16Array(buffer); | |
| var HEAPU32 = new Uint32Array(buffer); | |
| var HEAPF32 = new Float32Array(buffer); | |
| var HEAPF64 = new Float64Array(buffer); | |
| HEAP32[DYNAMICTOP_PTR>>2] = 5249872; | |
| // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode. | |
| function writeStackCookie() { | |
| assert((STACK_MAX & 3) == 0); | |
| HEAPU32[(STACK_MAX >> 2)-1] = 0x02135467; | |
| HEAPU32[(STACK_MAX >> 2)-2] = 0x89BACDFE; | |
| } | |
| function checkStackCookie() { | |
| if (HEAPU32[(STACK_MAX >> 2)-1] != 0x02135467 || HEAPU32[(STACK_MAX >> 2)-2] != 0x89BACDFE) { | |
| abort('Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x02135467, but received 0x' + HEAPU32[(STACK_MAX >> 2)-2].toString(16) + ' ' + HEAPU32[(STACK_MAX >> 2)-1].toString(16)); | |
| } | |
| // Also test the global address 0 for integrity. | |
| if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) throw 'Runtime error: The application has corrupted its heap memory area (address zero)!'; | |
| } | |
| HEAP32[0] = 0x63736d65; /* 'emsc' */ | |
| var runtimeInitialized = false; | |
| // This is always false in minimal_runtime - the runtime does not have a concept of exiting (keeping this variable here for now since it is referenced from generated code) | |
| var runtimeExited = false; | |
| function unSign(value, bits, ignore) { | |
| if (value >= 0) { | |
| return value; | |
| } | |
| return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts | |
| : Math.pow(2, bits) + value; | |
| } | |
| function reSign(value, bits, ignore) { | |
| if (value <= 0) { | |
| return value; | |
| } | |
| var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32 | |
| : Math.pow(2, bits-1); | |
| if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that | |
| // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors | |
| // TODO: In i64 mode 1, resign the two parts separately and safely | |
| value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts | |
| } | |
| return value; | |
| } | |
| assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); | |
| assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); | |
| assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); | |
| assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); | |
| var Math_abs = Math.abs; | |
| var Math_cos = Math.cos; | |
| var Math_sin = Math.sin; | |
| var Math_tan = Math.tan; | |
| var Math_acos = Math.acos; | |
| var Math_asin = Math.asin; | |
| var Math_atan = Math.atan; | |
| var Math_atan2 = Math.atan2; | |
| var Math_exp = Math.exp; | |
| var Math_log = Math.log; | |
| var Math_sqrt = Math.sqrt; | |
| var Math_ceil = Math.ceil; | |
| var Math_floor = Math.floor; | |
| var Math_pow = Math.pow; | |
| var Math_imul = Math.imul; | |
| var Math_fround = Math.fround; | |
| var Math_round = Math.round; | |
| var Math_min = Math.min; | |
| var Math_max = Math.max; | |
| var Math_clz32 = Math.clz32; | |
| var Math_trunc = Math.trunc; | |
| var memoryInitializer = null; | |
| // === Body === | |
| var ASM_CONSTS = []; | |
| // STATICTOP = STATIC_BASE + 5968; | |
| /* no memory initializer */ | |
| var tempDoublePtr = 6976 | |
| assert(tempDoublePtr % 8 == 0); | |
| function copyTempFloat(ptr) { // functions, because inlining this code increases code size too much | |
| HEAP8[tempDoublePtr] = HEAP8[ptr]; | |
| HEAP8[tempDoublePtr+1] = HEAP8[ptr+1]; | |
| HEAP8[tempDoublePtr+2] = HEAP8[ptr+2]; | |
| HEAP8[tempDoublePtr+3] = HEAP8[ptr+3]; | |
| } | |
| function copyTempDouble(ptr) { | |
| HEAP8[tempDoublePtr] = HEAP8[ptr]; | |
| HEAP8[tempDoublePtr+1] = HEAP8[ptr+1]; | |
| HEAP8[tempDoublePtr+2] = HEAP8[ptr+2]; | |
| HEAP8[tempDoublePtr+3] = HEAP8[ptr+3]; | |
| HEAP8[tempDoublePtr+4] = HEAP8[ptr+4]; | |
| HEAP8[tempDoublePtr+5] = HEAP8[ptr+5]; | |
| HEAP8[tempDoublePtr+6] = HEAP8[ptr+6]; | |
| HEAP8[tempDoublePtr+7] = HEAP8[ptr+7]; | |
| } | |
| // {{PRE_LIBRARY}} | |
| function ___assert_fail(condition, filename, line, func) { | |
| abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']); | |
| } | |
| function ___lock() {} | |
| var SYSCALLS={buffers:[null,[],[]],printChar:function (stream, curr) { | |
| var buffer = SYSCALLS.buffers[stream]; | |
| assert(buffer); | |
| if (curr === 0 || curr === 10) { | |
| (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)); | |
| buffer.length = 0; | |
| } else { | |
| buffer.push(curr); | |
| } | |
| },varargs:0,get:function (varargs) { | |
| SYSCALLS.varargs += 4; | |
| var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)]; | |
| return ret; | |
| },getStr:function () { | |
| var ret = UTF8ToString(SYSCALLS.get()); | |
| return ret; | |
| },get64:function () { | |
| var low = SYSCALLS.get(), high = SYSCALLS.get(); | |
| if (low >= 0) assert(high === 0); | |
| else assert(high === -1); | |
| return low; | |
| },getZero:function () { | |
| assert(SYSCALLS.get() === 0); | |
| }};function ___syscall140(which, varargs) {SYSCALLS.varargs = varargs; | |
| try { | |
| // llseek | |
| var stream = SYSCALLS.getStreamFromFD(), offset_high = SYSCALLS.get(), offset_low = SYSCALLS.get(), result = SYSCALLS.get(), whence = SYSCALLS.get(); | |
| // NOTE: offset_high is unused - Emscripten's off_t is 32-bit | |
| var offset = offset_low; | |
| FS.llseek(stream, offset, whence); | |
| HEAP32[((result)>>2)]=stream.position; | |
| if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state | |
| return 0; | |
| } catch (e) { | |
| if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e); | |
| return -e.errno; | |
| } | |
| } | |
| function flush_NO_FILESYSTEM() { | |
| // flush anything remaining in the buffers during shutdown | |
| var fflush = Module["_fflush"]; | |
| if (fflush) fflush(0); | |
| var buffers = SYSCALLS.buffers; | |
| if (buffers[1].length) SYSCALLS.printChar(1, 10); | |
| if (buffers[2].length) SYSCALLS.printChar(2, 10); | |
| }function ___syscall146(which, varargs) {SYSCALLS.varargs = varargs; | |
| try { | |
| // writev | |
| // hack to support printf in FILESYSTEM=0 | |
| var stream = SYSCALLS.get(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get(); | |
| var ret = 0; | |
| for (var i = 0; i < iovcnt; i++) { | |
| var ptr = HEAP32[(((iov)+(i*8))>>2)]; | |
| var len = HEAP32[(((iov)+(i*8 + 4))>>2)]; | |
| for (var j = 0; j < len; j++) { | |
| SYSCALLS.printChar(stream, HEAPU8[ptr+j]); | |
| } | |
| ret += len; | |
| } | |
| return ret; | |
| } catch (e) { | |
| if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e); | |
| return -e.errno; | |
| } | |
| } | |
| function ___syscall54(which, varargs) {SYSCALLS.varargs = varargs; | |
| try { | |
| // ioctl | |
| return 0; | |
| } catch (e) { | |
| if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e); | |
| return -e.errno; | |
| } | |
| } | |
| function ___syscall6(which, varargs) {SYSCALLS.varargs = varargs; | |
| try { | |
| // close | |
| var stream = SYSCALLS.getStreamFromFD(); | |
| FS.close(stream); | |
| return 0; | |
| } catch (e) { | |
| if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e); | |
| return -e.errno; | |
| } | |
| } | |
| function ___unlock() {} | |
| var JSEvents={keyEvent:0,mouseEvent:0,wheelEvent:0,uiEvent:0,focusEvent:0,deviceOrientationEvent:0,deviceMotionEvent:0,fullscreenChangeEvent:0,pointerlockChangeEvent:0,visibilityChangeEvent:0,touchEvent:0,previousFullscreenElement:null,previousScreenX:null,previousScreenY:null,removeEventListenersRegistered:false,removeAllEventListeners:function () { | |
| for(var i = JSEvents.eventHandlers.length-1; i >= 0; --i) { | |
| JSEvents._removeHandler(i); | |
| } | |
| JSEvents.eventHandlers = []; | |
| JSEvents.deferredCalls = []; | |
| },findEventTarget:function (target) { | |
| try { | |
| // The sensible "default" target varies between events, but use window as the default | |
| // since DOM events mostly can default to that. Specific callback registrations | |
| // override their own defaults. | |
| if (!target) return window; | |
| if (typeof target === "number") target = UTF8ToString(target); | |
| if (target === '#window') return window; | |
| else if (target === '#document') return document; | |
| else if (target === '#screen') return window.screen; | |
| else if (target === '#canvas') return Module['canvas']; | |
| return (typeof target === 'string') ? document.getElementById(target) : target; | |
| } catch(e) { | |
| // In Web Workers, some objects above, such as '#document' do not exist. Gracefully | |
| // return null for them. | |
| return null; | |
| } | |
| },findCanvasEventTarget:function (target) { | |
| if (typeof target === 'number') target = UTF8ToString(target); | |
| if (!target || target === '#canvas') { | |
| if (typeof GL !== 'undefined' && GL.offscreenCanvases['canvas']) return GL.offscreenCanvases['canvas']; // TODO: Remove this line, target '#canvas' should refer only to Module['canvas'], not to GL.offscreenCanvases['canvas'] - but need stricter tests to be able to remove this line. | |
| return Module['canvas']; | |
| } | |
| if (typeof GL !== 'undefined' && GL.offscreenCanvases[target]) return GL.offscreenCanvases[target]; | |
| return JSEvents.findEventTarget(target); | |
| },deferredCalls:[],deferCall:function (targetFunction, precedence, argsList) { | |
| function arraysHaveEqualContent(arrA, arrB) { | |
| if (arrA.length != arrB.length) return false; | |
| for(var i in arrA) { | |
| if (arrA[i] != arrB[i]) return false; | |
| } | |
| return true; | |
| } | |
| // Test if the given call was already queued, and if so, don't add it again. | |
| for(var i in JSEvents.deferredCalls) { | |
| var call = JSEvents.deferredCalls[i]; | |
| if (call.targetFunction == targetFunction && arraysHaveEqualContent(call.argsList, argsList)) { | |
| return; | |
| } | |
| } | |
| JSEvents.deferredCalls.push({ | |
| targetFunction: targetFunction, | |
| precedence: precedence, | |
| argsList: argsList | |
| }); | |
| JSEvents.deferredCalls.sort(function(x,y) { return x.precedence < y.precedence; }); | |
| },removeDeferredCalls:function (targetFunction) { | |
| for(var i = 0; i < JSEvents.deferredCalls.length; ++i) { | |
| if (JSEvents.deferredCalls[i].targetFunction == targetFunction) { | |
| JSEvents.deferredCalls.splice(i, 1); | |
| --i; | |
| } | |
| } | |
| },canPerformEventHandlerRequests:function () { | |
| return JSEvents.inEventHandler && JSEvents.currentEventHandler.allowsDeferredCalls; | |
| },runDeferredCalls:function () { | |
| if (!JSEvents.canPerformEventHandlerRequests()) { | |
| return; | |
| } | |
| for(var i = 0; i < JSEvents.deferredCalls.length; ++i) { | |
| var call = JSEvents.deferredCalls[i]; | |
| JSEvents.deferredCalls.splice(i, 1); | |
| --i; | |
| call.targetFunction.apply(this, call.argsList); | |
| } | |
| },inEventHandler:0,currentEventHandler:null,eventHandlers:[],isInternetExplorer:function () { return navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0; },removeAllHandlersOnTarget:function (target, eventTypeString) { | |
| for(var i = 0; i < JSEvents.eventHandlers.length; ++i) { | |
| if (JSEvents.eventHandlers[i].target == target && | |
| (!eventTypeString || eventTypeString == JSEvents.eventHandlers[i].eventTypeString)) { | |
| JSEvents._removeHandler(i--); | |
| } | |
| } | |
| },_removeHandler:function (i) { | |
| var h = JSEvents.eventHandlers[i]; | |
| h.target.removeEventListener(h.eventTypeString, h.eventListenerFunc, h.useCapture); | |
| JSEvents.eventHandlers.splice(i, 1); | |
| },registerOrRemoveHandler:function (eventHandler) { | |
| var jsEventHandler = function jsEventHandler(event) { | |
| // Increment nesting count for the event handler. | |
| ++JSEvents.inEventHandler; | |
| JSEvents.currentEventHandler = eventHandler; | |
| // Process any old deferred calls the user has placed. | |
| JSEvents.runDeferredCalls(); | |
| // Process the actual event, calls back to user C code handler. | |
| eventHandler.handlerFunc(event); | |
| // Process any new deferred calls that were placed right now from this event handler. | |
| JSEvents.runDeferredCalls(); | |
| // Out of event handler - restore nesting count. | |
| --JSEvents.inEventHandler; | |
| } | |
| if (eventHandler.callbackfunc) { | |
| eventHandler.eventListenerFunc = jsEventHandler; | |
| eventHandler.target.addEventListener(eventHandler.eventTypeString, jsEventHandler, eventHandler.useCapture); | |
| JSEvents.eventHandlers.push(eventHandler); | |
| } else { | |
| for(var i = 0; i < JSEvents.eventHandlers.length; ++i) { | |
| if (JSEvents.eventHandlers[i].target == eventHandler.target | |
| && JSEvents.eventHandlers[i].eventTypeString == eventHandler.eventTypeString) { | |
| JSEvents._removeHandler(i--); | |
| } | |
| } | |
| } | |
| },getBoundingClientRectOrZeros:function (target) { | |
| return target.getBoundingClientRect ? target.getBoundingClientRect() : { left: 0, top: 0 }; | |
| },pageScrollPos:function () { | |
| if (window.pageXOffset > 0 || window.pageYOffset > 0) { | |
| return [window.pageXOffset, window.pageYOffset]; | |
| } | |
| if (typeof document.documentElement.scrollLeft !== 'undefined' || typeof document.documentElement.scrollTop !== 'undefined') { | |
| return [document.documentElement.scrollLeft, document.documentElement.scrollTop]; | |
| } | |
| return [document.body.scrollLeft|0, document.body.scrollTop|0]; | |
| },getNodeNameForTarget:function (target) { | |
| if (!target) return ''; | |
| if (target == window) return '#window'; | |
| if (target == window.screen) return '#screen'; | |
| return (target && target.nodeName) ? target.nodeName : ''; | |
| },tick:function () { | |
| if (window['performance'] && window['performance']['now']) return window['performance']['now'](); | |
| else return Date.now(); | |
| },fullscreenEnabled:function () { | |
| return document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled; | |
| }};function _emscripten_get_element_css_size(target, width, height) { | |
| if (target) target = JSEvents.findEventTarget(target); | |
| else target = Module['canvas']; | |
| if (!target) return -4; | |
| if (target.getBoundingClientRect) { | |
| var rect = target.getBoundingClientRect(); | |
| HEAPF64[((width)>>3)]=rect.right - rect.left; | |
| HEAPF64[((height)>>3)]=rect.bottom - rect.top; | |
| } else { | |
| HEAPF64[((width)>>3)]=target.clientWidth; | |
| HEAPF64[((height)>>3)]=target.clientHeight; | |
| } | |
| return 0; | |
| } | |
| function _emscripten_request_animation_frame_loop(cb, userData) { | |
| function tick(timeStamp) { | |
| if (dynCall_idi(cb, timeStamp, userData)) { | |
| requestAnimationFrame(tick); | |
| } | |
| } | |
| return requestAnimationFrame(tick); | |
| } | |
| function _emscripten_set_canvas_element_size(target, width, height) { | |
| var canvas = JSEvents.findCanvasEventTarget(target); | |
| if (!canvas) return -4; | |
| canvas.width = width; | |
| canvas.height = height; | |
| return 0; | |
| } | |
| function __registerUiEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { | |
| if (!JSEvents.uiEvent) JSEvents.uiEvent = _malloc( 36 ); | |
| if (eventTypeString == "scroll" && !target) { | |
| target = document; // By default read scroll events on document rather than window. | |
| } else { | |
| target = JSEvents.findEventTarget(target); | |
| } | |
| var uiEventHandlerFunc = function(event) { | |
| var e = event || window.event; | |
| if (e.target != target) { | |
| // Never take ui events such as scroll via a 'bubbled' route, but always from the direct element that | |
| // was targeted. Otherwise e.g. if app logs a message in response to a page scroll, the Emscripten log | |
| // message box could cause to scroll, generating a new (bubbled) scroll message, causing a new log print, | |
| // causing a new scroll, etc.. | |
| return; | |
| } | |
| var scrollPos = JSEvents.pageScrollPos(); | |
| var uiEvent = JSEvents.uiEvent; | |
| HEAP32[((uiEvent)>>2)]=e.detail; | |
| HEAP32[(((uiEvent)+(4))>>2)]=document.body.clientWidth; | |
| HEAP32[(((uiEvent)+(8))>>2)]=document.body.clientHeight; | |
| HEAP32[(((uiEvent)+(12))>>2)]=window.innerWidth; | |
| HEAP32[(((uiEvent)+(16))>>2)]=window.innerHeight; | |
| HEAP32[(((uiEvent)+(20))>>2)]=window.outerWidth; | |
| HEAP32[(((uiEvent)+(24))>>2)]=window.outerHeight; | |
| HEAP32[(((uiEvent)+(28))>>2)]=scrollPos[0]; | |
| HEAP32[(((uiEvent)+(32))>>2)]=scrollPos[1]; | |
| if (dynCall_iiii(callbackfunc, eventTypeId, uiEvent, userData)) e.preventDefault(); | |
| }; | |
| var eventHandler = { | |
| target: target, | |
| allowsDeferredCalls: false, // Neither scroll or resize events allow running requests inside them. | |
| eventTypeString: eventTypeString, | |
| callbackfunc: callbackfunc, | |
| handlerFunc: uiEventHandlerFunc, | |
| useCapture: useCapture | |
| }; | |
| JSEvents.registerOrRemoveHandler(eventHandler); | |
| }function _emscripten_set_resize_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) { | |
| __registerUiEventCallback(target, userData, useCapture, callbackfunc, 10, "resize", targetThread); | |
| return 0; | |
| } | |
| var GL={counter:1,lastError:0,buffers:[],mappedBuffers:{},programs:[],framebuffers:[],renderbuffers:[],textures:[],uniforms:[],shaders:[],vaos:[],contexts:{},currentContext:null,offscreenCanvases:{},timerQueriesEXT:[],queries:[],samplers:[],transformFeedbacks:[],syncs:[],programInfos:{},stringCache:{},stringiCache:{},unpackAlignment:4,init:function () { | |
| GL.miniTempBuffer = new Float32Array(GL.MINI_TEMP_BUFFER_SIZE); | |
| for (var i = 0; i < GL.MINI_TEMP_BUFFER_SIZE; i++) { | |
| GL.miniTempBufferViews[i] = GL.miniTempBuffer.subarray(0, i+1); | |
| } | |
| },recordError:function recordError(errorCode) { | |
| if (!GL.lastError) { | |
| GL.lastError = errorCode; | |
| } | |
| },getNewId:function (table) { | |
| var ret = GL.counter++; | |
| for (var i = table.length; i < ret; i++) { | |
| table[i] = null; | |
| } | |
| return ret; | |
| },MINI_TEMP_BUFFER_SIZE:256,miniTempBuffer:null,miniTempBufferViews:[0],getSource:function (shader, count, string, length) { | |
| var source = ''; | |
| for (var i = 0; i < count; ++i) { | |
| var len = length ? HEAP32[(((length)+(i*4))>>2)] : -1; | |
| source += UTF8ToString(HEAP32[(((string)+(i*4))>>2)], len < 0 ? undefined : len); | |
| } | |
| return source; | |
| },createContext:function (canvas, webGLContextAttributes) { | |
| var ctx = | |
| (webGLContextAttributes.majorVersion > 1) ? canvas.getContext("webgl2", webGLContextAttributes) : | |
| (canvas.getContext("webgl", webGLContextAttributes) || canvas.getContext("experimental-webgl", webGLContextAttributes)); | |
| return ctx && GL.registerContext(ctx, webGLContextAttributes); | |
| },registerContext:function (ctx, webGLContextAttributes) { | |
| var handle = _malloc(8); // Make space on the heap to store GL context attributes that need to be accessible as shared between threads. | |
| var context = { | |
| handle: handle, | |
| attributes: webGLContextAttributes, | |
| version: webGLContextAttributes.majorVersion, | |
| GLctx: ctx | |
| }; | |
| // BUG: Workaround Chrome WebGL 2 issue: the first shipped versions of WebGL 2 in Chrome did not actually implement the new WebGL 2 functions. | |
| // Those are supported only in Chrome 58 and newer. | |
| function getChromeVersion() { | |
| var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); | |
| return raw ? parseInt(raw[2], 10) : false; | |
| } | |
| context.supportsWebGL2EntryPoints = (context.version >= 2) && (getChromeVersion() === false || getChromeVersion() >= 58); | |
| // Store the created context object so that we can access the context given a canvas without having to pass the parameters again. | |
| if (ctx.canvas) ctx.canvas.GLctxObject = context; | |
| GL.contexts[handle] = context; | |
| if (typeof webGLContextAttributes.enableExtensionsByDefault === 'undefined' || webGLContextAttributes.enableExtensionsByDefault) { | |
| GL.initExtensions(context); | |
| } | |
| return handle; | |
| },makeContextCurrent:function (contextHandle) { | |
| GL.currentContext = GL.contexts[contextHandle]; // Active Emscripten GL layer context object. | |
| Module.ctx = GLctx = GL.currentContext && GL.currentContext.GLctx; // Active WebGL context object. | |
| return !(contextHandle && !GLctx); | |
| },getContext:function (contextHandle) { | |
| return GL.contexts[contextHandle]; | |
| },deleteContext:function (contextHandle) { | |
| if (GL.currentContext === GL.contexts[contextHandle]) GL.currentContext = null; | |
| if (typeof JSEvents === 'object') JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all JS event handlers on the DOM element that the GL context is associated with since the context is now deleted. | |
| if (GL.contexts[contextHandle] && GL.contexts[contextHandle].GLctx.canvas) GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined; // Make sure the canvas object no longer refers to the context object so there are no GC surprises. | |
| _free(GL.contexts[contextHandle]); | |
| GL.contexts[contextHandle] = null; | |
| },initExtensions:function (context) { | |
| // If this function is called without a specific context object, init the extensions of the currently active context. | |
| if (!context) context = GL.currentContext; | |
| if (context.initExtensionsDone) return; | |
| context.initExtensionsDone = true; | |
| var GLctx = context.GLctx; | |
| // Detect the presence of a few extensions manually, this GL interop layer itself will need to know if they exist. | |
| if (context.version < 2) { | |
| // Extension available from Firefox 26 and Google Chrome 30 | |
| var instancedArraysExt = GLctx.getExtension('ANGLE_instanced_arrays'); | |
| if (instancedArraysExt) { | |
| GLctx['vertexAttribDivisor'] = function(index, divisor) { instancedArraysExt['vertexAttribDivisorANGLE'](index, divisor); }; | |
| GLctx['drawArraysInstanced'] = function(mode, first, count, primcount) { instancedArraysExt['drawArraysInstancedANGLE'](mode, first, count, primcount); }; | |
| GLctx['drawElementsInstanced'] = function(mode, count, type, indices, primcount) { instancedArraysExt['drawElementsInstancedANGLE'](mode, count, type, indices, primcount); }; | |
| } | |
| // Extension available from Firefox 25 and WebKit | |
| var vaoExt = GLctx.getExtension('OES_vertex_array_object'); | |
| if (vaoExt) { | |
| GLctx['createVertexArray'] = function() { return vaoExt['createVertexArrayOES'](); }; | |
| GLctx['deleteVertexArray'] = function(vao) { vaoExt['deleteVertexArrayOES'](vao); }; | |
| GLctx['bindVertexArray'] = function(vao) { vaoExt['bindVertexArrayOES'](vao); }; | |
| GLctx['isVertexArray'] = function(vao) { return vaoExt['isVertexArrayOES'](vao); }; | |
| } | |
| var drawBuffersExt = GLctx.getExtension('WEBGL_draw_buffers'); | |
| if (drawBuffersExt) { | |
| GLctx['drawBuffers'] = function(n, bufs) { drawBuffersExt['drawBuffersWEBGL'](n, bufs); }; | |
| } | |
| } | |
| GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query"); | |
| // These are the 'safe' feature-enabling extensions that don't add any performance impact related to e.g. debugging, and | |
| // should be enabled by default so that client GLES2/GL code will not need to go through extra hoops to get its stuff working. | |
| // As new extensions are ratified at http://www.khronos.org/registry/webgl/extensions/ , feel free to add your new extensions | |
| // here, as long as they don't produce a performance impact for users that might not be using those extensions. | |
| // E.g. debugging-related extensions should probably be off by default. | |
| var automaticallyEnabledExtensions = [ // Khronos ratified WebGL extensions ordered by number (no debug extensions): | |
| "OES_texture_float", "OES_texture_half_float", "OES_standard_derivatives", | |
| "OES_vertex_array_object", "WEBGL_compressed_texture_s3tc", "WEBGL_depth_texture", | |
| "OES_element_index_uint", "EXT_texture_filter_anisotropic", "EXT_frag_depth", | |
| "WEBGL_draw_buffers", "ANGLE_instanced_arrays", "OES_texture_float_linear", | |
| "OES_texture_half_float_linear", "EXT_blend_minmax", "EXT_shader_texture_lod", | |
| // Community approved WebGL extensions ordered by number: | |
| "WEBGL_compressed_texture_pvrtc", "EXT_color_buffer_half_float", "WEBGL_color_buffer_float", | |
| "EXT_sRGB", "WEBGL_compressed_texture_etc1", "EXT_disjoint_timer_query", | |
| "WEBGL_compressed_texture_etc", "WEBGL_compressed_texture_astc", "EXT_color_buffer_float", | |
| "WEBGL_compressed_texture_s3tc_srgb", "EXT_disjoint_timer_query_webgl2"]; | |
| function shouldEnableAutomatically(extension) { | |
| var ret = false; | |
| automaticallyEnabledExtensions.forEach(function(include) { | |
| if (extension.indexOf(include) != -1) { | |
| ret = true; | |
| } | |
| }); | |
| return ret; | |
| } | |
| var exts = GLctx.getSupportedExtensions(); | |
| if (exts && exts.length > 0) { | |
| GLctx.getSupportedExtensions().forEach(function(ext) { | |
| if (automaticallyEnabledExtensions.indexOf(ext) != -1) { | |
| GLctx.getExtension(ext); // Calling .getExtension enables that extension permanently, no need to store the return value to be enabled. | |
| } | |
| }); | |
| } | |
| },populateUniformTable:function (program) { | |
| var p = GL.programs[program]; | |
| var ptable = GL.programInfos[program] = { | |
| uniforms: {}, | |
| maxUniformLength: 0, // This is eagerly computed below, since we already enumerate all uniforms anyway. | |
| maxAttributeLength: -1, // This is lazily computed and cached, computed when/if first asked, "-1" meaning not computed yet. | |
| maxUniformBlockNameLength: -1 // Lazily computed as well | |
| }; | |
| var utable = ptable.uniforms; | |
| // A program's uniform table maps the string name of an uniform to an integer location of that uniform. | |
| // The global GL.uniforms map maps integer locations to WebGLUniformLocations. | |
| var numUniforms = GLctx.getProgramParameter(p, 0x8B86/*GL_ACTIVE_UNIFORMS*/); | |
| for (var i = 0; i < numUniforms; ++i) { | |
| var u = GLctx.getActiveUniform(p, i); | |
| var name = u.name; | |
| ptable.maxUniformLength = Math.max(ptable.maxUniformLength, name.length+1); | |
| // Strip off any trailing array specifier we might have got, e.g. "[0]". | |
| var ls = name.lastIndexOf('['); | |
| if (ls > 0) { | |
| name = name.slice(0, ls); | |
| } | |
| // Optimize memory usage slightly: If we have an array of uniforms, e.g. 'vec3 colors[3];', then | |
| // only store the string 'colors' in utable, and 'colors[0]', 'colors[1]' and 'colors[2]' will be parsed as 'colors'+i. | |
| // Note that for the GL.uniforms table, we still need to fetch the all WebGLUniformLocations for all the indices. | |
| var loc = GLctx.getUniformLocation(p, name); | |
| if (loc) { | |
| var id = GL.getNewId(GL.uniforms); | |
| utable[name] = [u.size, id]; | |
| GL.uniforms[id] = loc; | |
| for (var j = 1; j < u.size; ++j) { | |
| var n = name + '['+j+']'; | |
| loc = GLctx.getUniformLocation(p, n); | |
| id = GL.getNewId(GL.uniforms); | |
| GL.uniforms[id] = loc; | |
| } | |
| } | |
| } | |
| }}; | |
| var __emscripten_webgl_power_preferences=['default', 'low-power', 'high-performance'];function _emscripten_webgl_do_create_context(target, attributes) { | |
| var contextAttributes = {}; | |
| var a = attributes >> 2; | |
| contextAttributes['alpha'] = !!HEAP32[a + (0>>2)]; | |
| contextAttributes['depth'] = !!HEAP32[a + (4>>2)]; | |
| contextAttributes['stencil'] = !!HEAP32[a + (8>>2)]; | |
| contextAttributes['antialias'] = !!HEAP32[a + (12>>2)]; | |
| contextAttributes['premultipliedAlpha'] = !!HEAP32[a + (16>>2)]; | |
| contextAttributes['preserveDrawingBuffer'] = !!HEAP32[a + (20>>2)]; | |
| var powerPreference = HEAP32[a + (24>>2)]; | |
| contextAttributes['powerPreference'] = __emscripten_webgl_power_preferences[powerPreference]; | |
| contextAttributes['failIfMajorPerformanceCaveat'] = !!HEAP32[a + (28>>2)]; | |
| contextAttributes.majorVersion = HEAP32[a + (32>>2)]; | |
| contextAttributes.minorVersion = HEAP32[a + (36>>2)]; | |
| contextAttributes.enableExtensionsByDefault = HEAP32[a + (40>>2)]; | |
| contextAttributes.explicitSwapControl = HEAP32[a + (44>>2)]; | |
| contextAttributes.proxyContextToMainThread = HEAP32[a + (48>>2)]; | |
| contextAttributes.renderViaOffscreenBackBuffer = HEAP32[a + (52>>2)]; | |
| target = UTF8ToString(target); | |
| var canvas; | |
| if ((!target || target === '#canvas') && Module['canvas']) { | |
| canvas = (Module['canvas'].id && GL.offscreenCanvases[Module['canvas'].id]) ? (GL.offscreenCanvases[Module['canvas'].id].offscreenCanvas || JSEvents.findEventTarget(Module['canvas'].id)) : Module['canvas']; | |
| } else { | |
| canvas = GL.offscreenCanvases[target] ? GL.offscreenCanvases[target].offscreenCanvas : JSEvents.findEventTarget(target); | |
| } | |
| if (!canvas) { | |
| return 0; | |
| } | |
| if (contextAttributes.explicitSwapControl) { | |
| return 0; | |
| } | |
| var contextHandle = GL.createContext(canvas, contextAttributes); | |
| return contextHandle; | |
| }function _emscripten_webgl_create_context(a0,a1 | |
| /*``*/) { | |
| return _emscripten_webgl_do_create_context(a0,a1); | |
| } | |
| function _emscripten_webgl_init_context_attributes(attributes) { | |
| var a = attributes >> 2; | |
| for(var i = 0; i < (56>>2); ++i) { | |
| HEAP32[a+i] = 0; | |
| } | |
| HEAP32[a + (0>>2)] = | |
| HEAP32[a + (4>>2)] = | |
| HEAP32[a + (12>>2)] = | |
| HEAP32[a + (16>>2)] = | |
| HEAP32[a + (32>>2)] = | |
| HEAP32[a + (40>>2)] = 1; | |
| } | |
| function _emscripten_webgl_make_context_current(contextHandle) { | |
| var success = GL.makeContextCurrent(contextHandle); | |
| return success ? 0 : -5; | |
| } | |
| function _glBindBuffer(target, buffer) { | |
| if (target == 0x88EB /*GL_PIXEL_PACK_BUFFER*/) { | |
| // In WebGL 2 glReadPixels entry point, we need to use a different WebGL 2 API function call when a buffer is bound to | |
| // GL_PIXEL_PACK_BUFFER_BINDING point, so must keep track whether that binding point is non-null to know what is | |
| // the proper API function to call. | |
| GLctx.currentPixelPackBufferBinding = buffer; | |
| } else if (target == 0x88EC /*GL_PIXEL_UNPACK_BUFFER*/) { | |
| // In WebGL 2 gl(Compressed)Tex(Sub)Image[23]D entry points, we need to | |
| // use a different WebGL 2 API function call when a buffer is bound to | |
| // GL_PIXEL_UNPACK_BUFFER_BINDING point, so must keep track whether that | |
| // binding point is non-null to know what is the proper API function to | |
| // call. | |
| GLctx.currentPixelUnpackBufferBinding = buffer; | |
| } | |
| GLctx.bindBuffer(target, GL.buffers[buffer]); | |
| } | |
| function _glBindFramebuffer(target, framebuffer) { | |
| GLctx.bindFramebuffer(target, GL.framebuffers[framebuffer]); | |
| } | |
| function _glBlendColor(x0, x1, x2, x3) { GLctx['blendColor'](x0, x1, x2, x3) } | |
| function _glBlendEquationSeparate(x0, x1) { GLctx['blendEquationSeparate'](x0, x1) } | |
| function _glBlendFuncSeparate(x0, x1, x2, x3) { GLctx['blendFuncSeparate'](x0, x1, x2, x3) } | |
| function _glClear(x0) { GLctx['clear'](x0) } | |
| function _glClearColor(x0, x1, x2, x3) { GLctx['clearColor'](x0, x1, x2, x3) } | |
| function _glClearDepthf(x0) { GLctx['clearDepth'](x0) } | |
| function _glClearStencil(x0) { GLctx['clearStencil'](x0) } | |
| function _glColorMask(red, green, blue, alpha) { | |
| GLctx.colorMask(!!red, !!green, !!blue, !!alpha); | |
| } | |
| function _glCullFace(x0) { GLctx['cullFace'](x0) } | |
| function _glDepthFunc(x0) { GLctx['depthFunc'](x0) } | |
| function _glDepthMask(flag) { | |
| GLctx.depthMask(!!flag); | |
| } | |
| function _glDisable(x0) { GLctx['disable'](x0) } | |
| function _glDisableVertexAttribArray(index) { | |
| GLctx.disableVertexAttribArray(index); | |
| } | |
| function _glEnable(x0) { GLctx['enable'](x0) } | |
| function _glFrontFace(x0) { GLctx['frontFace'](x0) } | |
| function _glGetError() { | |
| // First return any GL error generated by the emscripten library_gl.js interop layer. | |
| if (GL.lastError) { | |
| var error = GL.lastError; | |
| GL.lastError = 0/*GL_NO_ERROR*/; | |
| return error; | |
| } else | |
| { // If there were none, return the GL error from the browser GL context. | |
| return GLctx.getError(); | |
| } | |
| } | |
| function emscriptenWebGLGet(name_, p, type) { | |
| // Guard against user passing a null pointer. | |
| // Note that GLES2 spec does not say anything about how passing a null pointer should be treated. | |
| // Testing on desktop core GL 3, the application crashes on glGetIntegerv to a null pointer, but | |
| // better to report an error instead of doing anything random. | |
| if (!p) { | |
| GL.recordError(0x0501 /* GL_INVALID_VALUE */); | |
| return; | |
| } | |
| var ret = undefined; | |
| switch(name_) { // Handle a few trivial GLES values | |
| case 0x8DFA: // GL_SHADER_COMPILER | |
| ret = 1; | |
| break; | |
| case 0x8DF8: // GL_SHADER_BINARY_FORMATS | |
| if (type !== 'Integer' && type !== 'Integer64') { | |
| GL.recordError(0x0500); // GL_INVALID_ENUM | |
| } | |
| return; // Do not write anything to the out pointer, since no binary formats are supported. | |
| case 0x87FE: // GL_NUM_PROGRAM_BINARY_FORMATS | |
| case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS | |
| ret = 0; | |
| break; | |
| case 0x86A2: // GL_NUM_COMPRESSED_TEXTURE_FORMATS | |
| // WebGL doesn't have GL_NUM_COMPRESSED_TEXTURE_FORMATS (it's obsolete since GL_COMPRESSED_TEXTURE_FORMATS returns a JS array that can be queried for length), | |
| // so implement it ourselves to allow C++ GLES2 code get the length. | |
| var formats = GLctx.getParameter(0x86A3 /*GL_COMPRESSED_TEXTURE_FORMATS*/); | |
| ret = formats ? formats.length : 0; | |
| break; | |
| case 0x821D: // GL_NUM_EXTENSIONS | |
| if (GL.currentContext.version < 2) { | |
| GL.recordError(0x0502 /* GL_INVALID_OPERATION */); // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context | |
| return; | |
| } | |
| var exts = GLctx.getSupportedExtensions(); | |
| ret = 2 * exts.length; // each extension is duplicated, first in unprefixed WebGL form, and then a second time with "GL_" prefix. | |
| break; | |
| case 0x821B: // GL_MAJOR_VERSION | |
| case 0x821C: // GL_MINOR_VERSION | |
| if (GL.currentContext.version < 2) { | |
| GL.recordError(0x0500); // GL_INVALID_ENUM | |
| return; | |
| } | |
| ret = name_ == 0x821B ? 3 : 0; // return version 3.0 | |
| break; | |
| } | |
| if (ret === undefined) { | |
| var result = GLctx.getParameter(name_); | |
| switch (typeof(result)) { | |
| case "number": | |
| ret = result; | |
| break; | |
| case "boolean": | |
| ret = result ? 1 : 0; | |
| break; | |
| case "string": | |
| GL.recordError(0x0500); // GL_INVALID_ENUM | |
| return; | |
| case "object": | |
| if (result === null) { | |
| // null is a valid result for some (e.g., which buffer is bound - perhaps nothing is bound), but otherwise | |
| // can mean an invalid name_, which we need to report as an error | |
| switch(name_) { | |
| case 0x8894: // ARRAY_BUFFER_BINDING | |
| case 0x8B8D: // CURRENT_PROGRAM | |
| case 0x8895: // ELEMENT_ARRAY_BUFFER_BINDING | |
| case 0x8CA6: // FRAMEBUFFER_BINDING | |
| case 0x8CA7: // RENDERBUFFER_BINDING | |
| case 0x8069: // TEXTURE_BINDING_2D | |
| case 0x85B5: // WebGL 2 GL_VERTEX_ARRAY_BINDING, or WebGL 1 extension OES_vertex_array_object GL_VERTEX_ARRAY_BINDING_OES | |
| case 0x8919: // GL_SAMPLER_BINDING | |
| case 0x8E25: // GL_TRANSFORM_FEEDBACK_BINDING | |
| case 0x8514: { // TEXTURE_BINDING_CUBE_MAP | |
| ret = 0; | |
| break; | |
| } | |
| default: { | |
| GL.recordError(0x0500); // GL_INVALID_ENUM | |
| return; | |
| } | |
| } | |
| } else if (result instanceof Float32Array || | |
| result instanceof Uint32Array || | |
| result instanceof Int32Array || | |
| result instanceof Array) { | |
| for (var i = 0; i < result.length; ++i) { | |
| switch (type) { | |
| case 'Integer': HEAP32[(((p)+(i*4))>>2)]=result[i]; break; | |
| case 'Float': HEAPF32[(((p)+(i*4))>>2)]=result[i]; break; | |
| case 'Boolean': HEAP8[(((p)+(i))>>0)]=result[i] ? 1 : 0; break; | |
| default: throw 'internal glGet error, bad type: ' + type; | |
| } | |
| } | |
| return; | |
| } else { | |
| try { | |
| ret = result.name | 0; | |
| } catch(e) { | |
| GL.recordError(0x0500); // GL_INVALID_ENUM | |
| err('GL_INVALID_ENUM in glGet' + type + 'v: Unknown object returned from WebGL getParameter(' + name_ + ')! (error: ' + e + ')'); | |
| return; | |
| } | |
| } | |
| break; | |
| default: | |
| GL.recordError(0x0500); // GL_INVALID_ENUM | |
| return; | |
| } | |
| } | |
| switch (type) { | |
| case 'Integer64': (tempI64 = [ret>>>0,(tempDouble=ret,(+(Math_abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math_min((+(Math_floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((p)>>2)]=tempI64[0],HEAP32[(((p)+(4))>>2)]=tempI64[1]); break; | |
| case 'Integer': HEAP32[((p)>>2)]=ret; break; | |
| case 'Float': HEAPF32[((p)>>2)]=ret; break; | |
| case 'Boolean': HEAP8[((p)>>0)]=ret ? 1 : 0; break; | |
| default: throw 'internal glGet error, bad type: ' + type; | |
| } | |
| }function _glGetIntegerv(name_, p) { | |
| emscriptenWebGLGet(name_, p, 'Integer'); | |
| } | |
| function stringToNewUTF8(jsString) { | |
| var length = lengthBytesUTF8(jsString)+1; | |
| var cString = _malloc(length); | |
| stringToUTF8(jsString, cString, length); | |
| return cString; | |
| }function _glGetString(name_) { | |
| if (GL.stringCache[name_]) return GL.stringCache[name_]; | |
| var ret; | |
| switch(name_) { | |
| case 0x1F03 /* GL_EXTENSIONS */: | |
| var exts = GLctx.getSupportedExtensions(); | |
| var gl_exts = []; | |
| for (var i = 0; i < exts.length; ++i) { | |
| gl_exts.push(exts[i]); | |
| gl_exts.push("GL_" + exts[i]); | |
| } | |
| ret = stringToNewUTF8(gl_exts.join(' ')); | |
| break; | |
| case 0x1F00 /* GL_VENDOR */: | |
| case 0x1F01 /* GL_RENDERER */: | |
| case 0x9245 /* UNMASKED_VENDOR_WEBGL */: | |
| case 0x9246 /* UNMASKED_RENDERER_WEBGL */: | |
| var s = GLctx.getParameter(name_); | |
| if (!s) { | |
| GL.recordError(0x0500/*GL_INVALID_ENUM*/); | |
| } | |
| ret = stringToNewUTF8(s); | |
| break; | |
| case 0x1F02 /* GL_VERSION */: | |
| var glVersion = GLctx.getParameter(GLctx.VERSION); | |
| // return GLES version string corresponding to the version of the WebGL context | |
| if (GL.currentContext.version >= 2) glVersion = 'OpenGL ES 3.0 (' + glVersion + ')'; | |
| else | |
| { | |
| glVersion = 'OpenGL ES 2.0 (' + glVersion + ')'; | |
| } | |
| ret = stringToNewUTF8(glVersion); | |
| break; | |
| case 0x8B8C /* GL_SHADING_LANGUAGE_VERSION */: | |
| var glslVersion = GLctx.getParameter(GLctx.SHADING_LANGUAGE_VERSION); | |
| // extract the version number 'N.M' from the string 'WebGL GLSL ES N.M ...' | |
| var ver_re = /^WebGL GLSL ES ([0-9]\.[0-9][0-9]?)(?:$| .*)/; | |
| var ver_num = glslVersion.match(ver_re); | |
| if (ver_num !== null) { | |
| if (ver_num[1].length == 3) ver_num[1] = ver_num[1] + '0'; // ensure minor version has 2 digits | |
| glslVersion = 'OpenGL ES GLSL ES ' + ver_num[1] + ' (' + glslVersion + ')'; | |
| } | |
| ret = stringToNewUTF8(glslVersion); | |
| break; | |
| default: | |
| GL.recordError(0x0500/*GL_INVALID_ENUM*/); | |
| return 0; | |
| } | |
| GL.stringCache[name_] = ret; | |
| return ret; | |
| } | |
| function _glPolygonOffset(x0, x1) { GLctx['polygonOffset'](x0, x1) } | |
| function _glScissor(x0, x1, x2, x3) { GLctx['scissor'](x0, x1, x2, x3) } | |
| function _glStencilFunc(x0, x1, x2) { GLctx['stencilFunc'](x0, x1, x2) } | |
| function _glStencilMask(x0) { GLctx['stencilMask'](x0) } | |
| function _glStencilOp(x0, x1, x2) { GLctx['stencilOp'](x0, x1, x2) } | |
| function _glViewport(x0, x1, x2, x3) { GLctx['viewport'](x0, x1, x2, x3) } | |
| var _Int8Array=undefined; | |
| var _Int32Array=undefined; | |
| function ___setErrNo(value) { | |
| if (Module['___errno_location']) HEAP32[((Module['___errno_location']())>>2)]=value; | |
| else err('failed to set errno from JS'); | |
| return value; | |
| } | |
| function _emscripten_get_heap_size() { | |
| return TOTAL_MEMORY; | |
| } | |
| function abortOnCannotGrowMemory(requestedSize) { | |
| abort('Cannot enlarge memory arrays to size ' + requestedSize + ' bytes. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + TOTAL_MEMORY + ', (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 '); | |
| }function _emscripten_resize_heap(requestedSize) { | |
| abortOnCannotGrowMemory(requestedSize); | |
| } | |
| var GLctx; GL.init(); | |
| // ASM_LIBRARY EXTERN PRIMITIVES: Int8Array,Int32Array | |
| function nullFunc_idi(x) { err("Invalid function pointer called with signature 'idi'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x) } | |
| function nullFunc_ii(x) { err("Invalid function pointer called with signature 'ii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x) } | |
| function nullFunc_iiii(x) { err("Invalid function pointer called with signature 'iiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x) } | |
| var asmGlobalArg = {} | |
| var asmLibraryArg = { "abort": abort, "setTempRet0": setTempRet0, "getTempRet0": getTempRet0, "abortStackOverflow": abortStackOverflow, "nullFunc_idi": nullFunc_idi, "nullFunc_ii": nullFunc_ii, "nullFunc_iiii": nullFunc_iiii, "___assert_fail": ___assert_fail, "___lock": ___lock, "___setErrNo": ___setErrNo, "___syscall140": ___syscall140, "___syscall146": ___syscall146, "___syscall54": ___syscall54, "___syscall6": ___syscall6, "___unlock": ___unlock, "__registerUiEventCallback": __registerUiEventCallback, "_emscripten_get_element_css_size": _emscripten_get_element_css_size, "_emscripten_get_heap_size": _emscripten_get_heap_size, "_emscripten_request_animation_frame_loop": _emscripten_request_animation_frame_loop, "_emscripten_resize_heap": _emscripten_resize_heap, "_emscripten_set_canvas_element_size": _emscripten_set_canvas_element_size, "_emscripten_set_resize_callback_on_thread": _emscripten_set_resize_callback_on_thread, "_emscripten_webgl_create_context": _emscripten_webgl_create_context, "_emscripten_webgl_do_create_context": _emscripten_webgl_do_create_context, "_emscripten_webgl_init_context_attributes": _emscripten_webgl_init_context_attributes, "_emscripten_webgl_make_context_current": _emscripten_webgl_make_context_current, "_glBindBuffer": _glBindBuffer, "_glBindFramebuffer": _glBindFramebuffer, "_glBlendColor": _glBlendColor, "_glBlendEquationSeparate": _glBlendEquationSeparate, "_glBlendFuncSeparate": _glBlendFuncSeparate, "_glClear": _glClear, "_glClearColor": _glClearColor, "_glClearDepthf": _glClearDepthf, "_glClearStencil": _glClearStencil, "_glColorMask": _glColorMask, "_glCullFace": _glCullFace, "_glDepthFunc": _glDepthFunc, "_glDepthMask": _glDepthMask, "_glDisable": _glDisable, "_glDisableVertexAttribArray": _glDisableVertexAttribArray, "_glEnable": _glEnable, "_glFrontFace": _glFrontFace, "_glGetError": _glGetError, "_glGetIntegerv": _glGetIntegerv, "_glGetString": _glGetString, "_glPolygonOffset": _glPolygonOffset, "_glScissor": _glScissor, "_glStencilFunc": _glStencilFunc, "_glStencilMask": _glStencilMask, "_glStencilOp": _glStencilOp, "_glViewport": _glViewport, "abortOnCannotGrowMemory": abortOnCannotGrowMemory, "emscriptenWebGLGet": emscriptenWebGLGet, "flush_NO_FILESYSTEM": flush_NO_FILESYSTEM, "stringToNewUTF8": stringToNewUTF8, "tempDoublePtr": tempDoublePtr, "DYNAMICTOP_PTR": DYNAMICTOP_PTR } | |
| // EMSCRIPTEN_START_ASM | |
| var asm =Module["asm"]// EMSCRIPTEN_END_ASM | |
| ; | |
| // === Auto-generated postamble setup entry stuff === | |
| if (!Module["intArrayFromString"]) Module["intArrayFromString"] = function() { abort("'intArrayFromString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["intArrayToString"]) Module["intArrayToString"] = function() { abort("'intArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["ccall"]) Module["ccall"] = function() { abort("'ccall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["cwrap"]) Module["cwrap"] = function() { abort("'cwrap' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["setValue"]) Module["setValue"] = function() { abort("'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getValue"]) Module["getValue"] = function() { abort("'getValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["allocate"]) Module["allocate"] = function() { abort("'allocate' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getMemory"]) Module["getMemory"] = function() { abort("'getMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["AsciiToString"]) Module["AsciiToString"] = function() { abort("'AsciiToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stringToAscii"]) Module["stringToAscii"] = function() { abort("'stringToAscii' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["UTF8ArrayToString"]) Module["UTF8ArrayToString"] = function() { abort("'UTF8ArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["UTF8ToString"]) Module["UTF8ToString"] = function() { abort("'UTF8ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stringToUTF8Array"]) Module["stringToUTF8Array"] = function() { abort("'stringToUTF8Array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stringToUTF8"]) Module["stringToUTF8"] = function() { abort("'stringToUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["lengthBytesUTF8"]) Module["lengthBytesUTF8"] = function() { abort("'lengthBytesUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["UTF16ToString"]) Module["UTF16ToString"] = function() { abort("'UTF16ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stringToUTF16"]) Module["stringToUTF16"] = function() { abort("'stringToUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["lengthBytesUTF16"]) Module["lengthBytesUTF16"] = function() { abort("'lengthBytesUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["UTF32ToString"]) Module["UTF32ToString"] = function() { abort("'UTF32ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stringToUTF32"]) Module["stringToUTF32"] = function() { abort("'stringToUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["lengthBytesUTF32"]) Module["lengthBytesUTF32"] = function() { abort("'lengthBytesUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["allocateUTF8"]) Module["allocateUTF8"] = function() { abort("'allocateUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stackTrace"]) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addOnPreRun"]) Module["addOnPreRun"] = function() { abort("'addOnPreRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addOnInit"]) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addOnPreMain"]) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addOnExit"]) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addOnPostRun"]) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["writeStringToMemory"]) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["writeArrayToMemory"]) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["writeAsciiToMemory"]) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addRunDependency"]) Module["addRunDependency"] = function() { abort("'addRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["removeRunDependency"]) Module["removeRunDependency"] = function() { abort("'removeRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["ENV"]) Module["ENV"] = function() { abort("'ENV' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["FS"]) Module["FS"] = function() { abort("'FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["FS_createFolder"]) Module["FS_createFolder"] = function() { abort("'FS_createFolder' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_createPath"]) Module["FS_createPath"] = function() { abort("'FS_createPath' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_createDataFile"]) Module["FS_createDataFile"] = function() { abort("'FS_createDataFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_createPreloadedFile"]) Module["FS_createPreloadedFile"] = function() { abort("'FS_createPreloadedFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_createLazyFile"]) Module["FS_createLazyFile"] = function() { abort("'FS_createLazyFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_createLink"]) Module["FS_createLink"] = function() { abort("'FS_createLink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_createDevice"]) Module["FS_createDevice"] = function() { abort("'FS_createDevice' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["FS_unlink"]) Module["FS_unlink"] = function() { abort("'FS_unlink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; | |
| if (!Module["GL"]) Module["GL"] = function() { abort("'GL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["dynamicAlloc"]) Module["dynamicAlloc"] = function() { abort("'dynamicAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["warnOnce"]) Module["warnOnce"] = function() { abort("'warnOnce' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["loadDynamicLibrary"]) Module["loadDynamicLibrary"] = function() { abort("'loadDynamicLibrary' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["loadWebAssemblyModule"]) Module["loadWebAssemblyModule"] = function() { abort("'loadWebAssemblyModule' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getLEB"]) Module["getLEB"] = function() { abort("'getLEB' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getFunctionTables"]) Module["getFunctionTables"] = function() { abort("'getFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["alignFunctionTables"]) Module["alignFunctionTables"] = function() { abort("'alignFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["registerFunctions"]) Module["registerFunctions"] = function() { abort("'registerFunctions' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["addFunction"]) Module["addFunction"] = function() { abort("'addFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["removeFunction"]) Module["removeFunction"] = function() { abort("'removeFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getFuncWrapper"]) Module["getFuncWrapper"] = function() { abort("'getFuncWrapper' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["prettyPrint"]) Module["prettyPrint"] = function() { abort("'prettyPrint' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["makeBigInt"]) Module["makeBigInt"] = function() { abort("'makeBigInt' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["dynCall"]) Module["dynCall"] = function() { abort("'dynCall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getCompilerSetting"]) Module["getCompilerSetting"] = function() { abort("'getCompilerSetting' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stackSave"]) Module["stackSave"] = function() { abort("'stackSave' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stackRestore"]) Module["stackRestore"] = function() { abort("'stackRestore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["stackAlloc"]) Module["stackAlloc"] = function() { abort("'stackAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["establishStackSpace"]) Module["establishStackSpace"] = function() { abort("'establishStackSpace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["print"]) Module["print"] = function() { abort("'print' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["printErr"]) Module["printErr"] = function() { abort("'printErr' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["getTempRet0"]) Module["getTempRet0"] = function() { abort("'getTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; | |
| if (!Module["setTempRet0"]) Module["setTempRet0"] = function() { abort("'setTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };if (!Module["ALLOC_NORMAL"]) Object.defineProperty(Module, "ALLOC_NORMAL", { get: function() { abort("'ALLOC_NORMAL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); | |
| if (!Module["ALLOC_STACK"]) Object.defineProperty(Module, "ALLOC_STACK", { get: function() { abort("'ALLOC_STACK' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); | |
| if (!Module["ALLOC_DYNAMIC"]) Object.defineProperty(Module, "ALLOC_DYNAMIC", { get: function() { abort("'ALLOC_DYNAMIC' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); | |
| if (!Module["ALLOC_NONE"]) Object.defineProperty(Module, "ALLOC_NONE", { get: function() { abort("'ALLOC_NONE' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); | |
| function run() { | |
| var ret = _main(); | |
| checkStackCookie(); | |
| } | |
| function initRuntime(asm) { | |
| runtimeInitialized = true; | |
| writeStackCookie(); | |
| } | |
| // Initialize wasm (asynchronous) | |
| var env = asmLibraryArg; | |
| env['memory'] = wasmMemory; | |
| env['table'] = new WebAssembly.Table({ 'initial': 18 | |
| , 'maximum': 18 | |
| , 'element': 'anyfunc' }); | |
| env['__memory_base'] = STATIC_BASE; | |
| env['__table_base'] = 0; | |
| var imports = { | |
| 'env': env | |
| , 'global': { | |
| 'NaN': NaN, | |
| 'Infinity': Infinity | |
| }, | |
| 'global.Math': Math, | |
| 'asm2wasm': { | |
| 'f64-rem': function(x, y) { return x % y; }, | |
| 'debugger': function() { debugger; } | |
| } | |
| }; | |
| if (!Module['wasm']) throw 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM'; | |
| var ___errno_location,_fflush,_free,_main,_malloc,_memset,_sbrk,dynCall_idi,dynCall_ii,dynCall_iiii; | |
| WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { | |
| var asm = output.instance.exports; | |
| ___errno_location = asm["___errno_location"]; | |
| _fflush = asm["_fflush"]; | |
| _free = asm["_free"]; | |
| _main = asm["_main"]; | |
| _malloc = asm["_malloc"]; | |
| _memset = asm["_memset"]; | |
| _sbrk = asm["_sbrk"]; | |
| dynCall_idi = asm["dynCall_idi"]; | |
| dynCall_ii = asm["dynCall_ii"]; | |
| dynCall_iiii = asm["dynCall_iiii"]; | |
| initRuntime(asm); | |
| ready(); | |
| }) | |
| .catch(function(error) { | |
| console.error(error); | |
| }) | |
| ; | |
| // {{MODULE_ADDITIONS}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment