4928 lines
179 KiB
JavaScript
4928 lines
179 KiB
JavaScript
// include: shell.js
|
|
// The Module object: Our interface to the outside world. We import
|
|
// and export values on it. There are various ways Module can be used:
|
|
// 1. Not defined. We create it here
|
|
// 2. A function parameter, function(moduleArg) => Promise<Module>
|
|
// 3. pre-run appended it, var Module = {}; ..generated code..
|
|
// 4. External script tag defines var Module.
|
|
// We need to check if Module already exists (e.g. case 3 above).
|
|
// Substitution will be replaced with actual code on later stage of the build,
|
|
// this way Closure Compiler will not mangle it (e.g. case 4. above).
|
|
// Note that if you want to run closure, and also to use Module
|
|
// after the generated code, you will need to define var Module = {};
|
|
// before the code. Then that object will be used in the code, and you
|
|
// can continue to use Module afterwards as well.
|
|
var Module = typeof Module != 'undefined' ? Module : {};
|
|
|
|
// Determine the runtime environment we are in. You can customize this by
|
|
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|
|
|
// Attempt to auto-detect the environment
|
|
var ENVIRONMENT_IS_WEB = typeof window == 'object';
|
|
var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != 'undefined';
|
|
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|
// also a web environment.
|
|
var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string' && process.type != 'renderer';
|
|
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
|
|
|
if (ENVIRONMENT_IS_NODE) {
|
|
|
|
}
|
|
|
|
// --pre-jses are emitted after the Module integration code, so that they can
|
|
// refer to Module (if they choose; they can also define Module)
|
|
|
|
|
|
// Sometimes an existing Module object exists with properties
|
|
// meant to overwrite the default module functionality. Here
|
|
// we collect those properties and reapply _after_ we configure
|
|
// the current environment's defaults to avoid having to be so
|
|
// defensive during initialization.
|
|
var moduleOverrides = {...Module};
|
|
|
|
var arguments_ = [];
|
|
var thisProgram = './this.program';
|
|
var quit_ = (status, toThrow) => {
|
|
throw toThrow;
|
|
};
|
|
|
|
// `/` should be present at the end if `scriptDirectory` is not empty
|
|
var scriptDirectory = '';
|
|
function locateFile(path) {
|
|
if (Module['locateFile']) {
|
|
return Module['locateFile'](path, scriptDirectory);
|
|
}
|
|
return scriptDirectory + path;
|
|
}
|
|
|
|
// Hooks that are implemented differently in different runtime environments.
|
|
var readAsync, readBinary;
|
|
|
|
if (ENVIRONMENT_IS_NODE) {
|
|
if (typeof process == 'undefined' || !process.release || process.release.name !== 'node') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
|
|
|
|
var nodeVersion = process.versions.node;
|
|
var numericVersion = nodeVersion.split('.').slice(0, 3);
|
|
numericVersion = (numericVersion[0] * 10000) + (numericVersion[1] * 100) + (numericVersion[2].split('-')[0] * 1);
|
|
var minVersion = 230000;
|
|
if (numericVersion < 230000) {
|
|
throw new Error('This emscripten-generated code requires node v23.0.0 (detected v' + nodeVersion + ')');
|
|
}
|
|
|
|
// These modules will usually be used on Node.js. Load them eagerly to avoid
|
|
// the complexity of lazy-loading.
|
|
var fs = require('fs');
|
|
var nodePath = require('path');
|
|
|
|
scriptDirectory = __dirname + '/';
|
|
|
|
// include: node_shell_read.js
|
|
readBinary = (filename) => {
|
|
// We need to re-wrap `file://` strings to URLs.
|
|
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
var ret = fs.readFileSync(filename);
|
|
assert(Buffer.isBuffer(ret));
|
|
return ret;
|
|
};
|
|
|
|
readAsync = async (filename, binary = true) => {
|
|
// See the comment in the `readBinary` function.
|
|
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
var ret = fs.readFileSync(filename, binary ? undefined : 'utf8');
|
|
assert(binary ? Buffer.isBuffer(ret) : typeof ret == 'string');
|
|
return ret;
|
|
};
|
|
// end include: node_shell_read.js
|
|
if (!Module['thisProgram'] && process.argv.length > 1) {
|
|
thisProgram = process.argv[1].replace(/\\/g, '/');
|
|
}
|
|
|
|
arguments_ = process.argv.slice(2);
|
|
|
|
if (typeof module != 'undefined') {
|
|
module['exports'] = Module;
|
|
}
|
|
|
|
quit_ = (status, toThrow) => {
|
|
process.exitCode = status;
|
|
throw toThrow;
|
|
};
|
|
|
|
} else
|
|
if (ENVIRONMENT_IS_SHELL) {
|
|
|
|
if ((typeof process == 'object' && typeof require === 'function') || typeof window == 'object' || typeof WorkerGlobalScope != 'undefined') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
|
|
|
|
} else
|
|
|
|
// Note that this includes Node.js workers when relevant (pthreads is enabled).
|
|
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|
// ENVIRONMENT_IS_NODE.
|
|
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
|
|
scriptDirectory = self.location.href;
|
|
} else if (typeof document != 'undefined' && document.currentScript) { // web
|
|
scriptDirectory = document.currentScript.src;
|
|
}
|
|
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
|
|
// otherwise, slice off the final part of the url to find the script directory.
|
|
// if scriptDirectory does not contain a slash, lastIndexOf will return -1,
|
|
// and scriptDirectory will correctly be replaced with an empty string.
|
|
// If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
|
|
// they are removed because they could contain a slash.
|
|
if (scriptDirectory.startsWith('blob:')) {
|
|
scriptDirectory = '';
|
|
} else {
|
|
scriptDirectory = scriptDirectory.slice(0, scriptDirectory.replace(/[?#].*/, '').lastIndexOf('/')+1);
|
|
}
|
|
|
|
if (!(typeof window == 'object' || typeof WorkerGlobalScope != 'undefined')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
|
|
|
|
{
|
|
// include: web_or_worker_shell_read.js
|
|
if (ENVIRONMENT_IS_WORKER) {
|
|
readBinary = (url) => {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('GET', url, false);
|
|
xhr.responseType = 'arraybuffer';
|
|
xhr.send(null);
|
|
return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
|
|
};
|
|
}
|
|
|
|
readAsync = async (url) => {
|
|
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
|
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
|
// Cordova or Electron apps are typically loaded from a file:// url.
|
|
// So use XHR on webview if URL is a file URL.
|
|
if (isFileURI(url)) {
|
|
return new Promise((resolve, reject) => {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('GET', url, true);
|
|
xhr.responseType = 'arraybuffer';
|
|
xhr.onload = () => {
|
|
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
|
resolve(xhr.response);
|
|
return;
|
|
}
|
|
reject(xhr.status);
|
|
};
|
|
xhr.onerror = reject;
|
|
xhr.send(null);
|
|
});
|
|
}
|
|
var response = await fetch(url, { credentials: 'same-origin' });
|
|
if (response.ok) {
|
|
return response.arrayBuffer();
|
|
}
|
|
throw new Error(response.status + ' : ' + response.url);
|
|
};
|
|
// end include: web_or_worker_shell_read.js
|
|
}
|
|
} else
|
|
{
|
|
throw new Error('environment detection error');
|
|
}
|
|
|
|
var out = Module['print'] || console.log.bind(console);
|
|
var err = Module['printErr'] || console.error.bind(console);
|
|
|
|
// Merge back in the overrides
|
|
Object.assign(Module, moduleOverrides);
|
|
// Free the object hierarchy contained in the overrides, this lets the GC
|
|
// reclaim data used.
|
|
moduleOverrides = null;
|
|
checkIncomingModuleAPI();
|
|
|
|
// Emit code to handle expected values on the Module object. This applies Module.x
|
|
// to the proper local x. This has two benefits: first, we only emit it if it is
|
|
// expected to arrive, and second, by using a local everywhere else that can be
|
|
// minified.
|
|
|
|
if (Module['arguments']) arguments_ = Module['arguments'];legacyModuleProp('arguments', 'arguments_');
|
|
|
|
if (Module['thisProgram']) thisProgram = Module['thisProgram'];legacyModuleProp('thisProgram', 'thisProgram');
|
|
|
|
// perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
|
|
// Assertions on removed incoming Module JS APIs.
|
|
assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
|
|
assert(typeof Module['pthreadMainPrefixURL'] == 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
|
|
assert(typeof Module['cdInitializerPrefixURL'] == 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
|
|
assert(typeof Module['filePackagePrefixURL'] == 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
|
|
assert(typeof Module['read'] == 'undefined', 'Module.read option was removed');
|
|
assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
|
|
assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
|
|
assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)');
|
|
assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
|
|
legacyModuleProp('asm', 'wasmExports');
|
|
legacyModuleProp('readAsync', 'readAsync');
|
|
legacyModuleProp('readBinary', 'readBinary');
|
|
legacyModuleProp('setWindowTitle', 'setWindowTitle');
|
|
var IDBFS = 'IDBFS is no longer included by default; build with -lidbfs.js';
|
|
var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js';
|
|
var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js';
|
|
var FETCHFS = 'FETCHFS is no longer included by default; build with -lfetchfs.js';
|
|
var ICASEFS = 'ICASEFS is no longer included by default; build with -licasefs.js';
|
|
var JSFILEFS = 'JSFILEFS is no longer included by default; build with -ljsfilefs.js';
|
|
var OPFS = 'OPFS is no longer included by default; build with -lopfs.js';
|
|
|
|
var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
|
|
|
|
assert(!ENVIRONMENT_IS_SHELL, 'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.');
|
|
|
|
// end include: shell.js
|
|
|
|
// include: preamble.js
|
|
// === Preamble library stuff ===
|
|
|
|
// Documentation for the public APIs defined in this file must be updated in:
|
|
// site/source/docs/api_reference/preamble.js.rst
|
|
// A prebuilt local version of the documentation is available at:
|
|
// site/build/text/docs/api_reference/preamble.js.txt
|
|
// You can also build docs locally as HTML or other formats in site/
|
|
// An online HTML version (which may be of a different version of Emscripten)
|
|
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
|
|
|
|
var wasmBinary = Module['wasmBinary'];legacyModuleProp('wasmBinary', 'wasmBinary');
|
|
|
|
if (typeof WebAssembly != 'object') {
|
|
err('no native wasm support detected');
|
|
}
|
|
|
|
// Wasm globals
|
|
|
|
var wasmMemory;
|
|
|
|
//========================================
|
|
// Runtime essentials
|
|
//========================================
|
|
|
|
// whether we are quitting the application. no code should run after this.
|
|
// set in exit() and abort()
|
|
var ABORT = false;
|
|
|
|
// set by exit() and abort(). Passed to 'onExit' handler.
|
|
// NOTE: This is also used as the process return code code in shell environments
|
|
// but only when noExitRuntime is false.
|
|
var EXITSTATUS;
|
|
|
|
// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we
|
|
// don't define it at all in release modes. This matches the behaviour of
|
|
// MINIMAL_RUNTIME.
|
|
// TODO(sbc): Make this the default even without STRICT enabled.
|
|
/** @type {function(*, string=)} */
|
|
function assert(condition, text) {
|
|
if (!condition) {
|
|
abort('Assertion failed' + (text ? ': ' + text : ''));
|
|
}
|
|
}
|
|
|
|
// We used to include malloc/free by default in the past. Show a helpful error in
|
|
// builds with assertions.
|
|
function _free() {
|
|
// Show a helpful error since we used to include free by default in the past.
|
|
abort('free() called but not included in the build - add `_free` to EXPORTED_FUNCTIONS');
|
|
}
|
|
|
|
// Memory management
|
|
|
|
var HEAP,
|
|
/** @type {!Int8Array} */
|
|
HEAP8,
|
|
/** @type {!Uint8Array} */
|
|
HEAPU8,
|
|
/** @type {!Int16Array} */
|
|
HEAP16,
|
|
/** @type {!Uint16Array} */
|
|
HEAPU16,
|
|
/** @type {!Int32Array} */
|
|
HEAP32,
|
|
/** @type {!Uint32Array} */
|
|
HEAPU32,
|
|
/** @type {!Float32Array} */
|
|
HEAPF32,
|
|
/* BigInt64Array type is not correctly defined in closure
|
|
/** not-@type {!BigInt64Array} */
|
|
HEAP64,
|
|
/* BigUint64Array type is not correctly defined in closure
|
|
/** not-t@type {!BigUint64Array} */
|
|
HEAPU64,
|
|
/** @type {!Float64Array} */
|
|
HEAPF64;
|
|
|
|
var runtimeInitialized = false;
|
|
|
|
/**
|
|
* Indicates whether filename is delivered via file protocol (as opposed to http/https)
|
|
* @noinline
|
|
*/
|
|
var isFileURI = (filename) => filename.startsWith('file://');
|
|
|
|
// include: runtime_shared.js
|
|
// include: runtime_stack_check.js
|
|
// Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
|
|
function writeStackCookie() {
|
|
var max = _emscripten_stack_get_end();
|
|
assert((max & 3) == 0);
|
|
// If the stack ends at address zero we write our cookies 4 bytes into the
|
|
// stack. This prevents interference with SAFE_HEAP and ASAN which also
|
|
// monitor writes to address zero.
|
|
if (max == 0) {
|
|
max += 4;
|
|
}
|
|
// The stack grow downwards towards _emscripten_stack_get_end.
|
|
// We write cookies to the final two words in the stack and detect if they are
|
|
// ever overwritten.
|
|
HEAPU32[((max)/4)] = 0x02135467;
|
|
HEAPU32[(((max)+(4))/4)] = 0x89BACDFE;
|
|
// Also test the global address 0 for integrity.
|
|
HEAPU32[((0)/4)] = 1668509029;
|
|
}
|
|
|
|
function checkStackCookie() {
|
|
if (ABORT) return;
|
|
var max = _emscripten_stack_get_end();
|
|
// See writeStackCookie().
|
|
if (max == 0) {
|
|
max += 4;
|
|
}
|
|
var cookie1 = HEAPU32[((max)/4)];
|
|
var cookie2 = HEAPU32[(((max)+(4))/4)];
|
|
if (cookie1 != 0x02135467 || cookie2 != 0x89BACDFE) {
|
|
abort(`Stack overflow! Stack cookie has been overwritten at ${ptrToString(max)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${ptrToString(cookie2)} ${ptrToString(cookie1)}`);
|
|
}
|
|
// Also test the global address 0 for integrity.
|
|
if (HEAPU32[((0)/4)] != 0x63736d65 /* 'emsc' */) {
|
|
abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
|
|
}
|
|
}
|
|
// end include: runtime_stack_check.js
|
|
// include: runtime_exceptions.js
|
|
// end include: runtime_exceptions.js
|
|
// include: runtime_debug.js
|
|
// Endianness check
|
|
(() => {
|
|
var h16 = new Int16Array(1);
|
|
var h8 = new Int8Array(h16.buffer);
|
|
h16[0] = 0x6373;
|
|
if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)';
|
|
})();
|
|
|
|
if (Module['ENVIRONMENT']) {
|
|
throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
|
|
}
|
|
|
|
function legacyModuleProp(prop, newName, incoming=true) {
|
|
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
Object.defineProperty(Module, prop, {
|
|
configurable: true,
|
|
get() {
|
|
let extra = incoming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : '';
|
|
abort(`\`Module.${prop}\` has been replaced by \`${newName}\`` + extra);
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function consumedModuleProp(prop) {
|
|
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
Object.defineProperty(Module, prop, {
|
|
configurable: true,
|
|
set() {
|
|
abort(`Attempt to set \`Module.${prop}\` after it has already been processed. This can happen, for example, when code is injected via '--post-js' rather than '--pre-js'`);
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function ignoredModuleProp(prop) {
|
|
if (Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
abort(`\`Module.${prop}\` was supplied but \`${prop}\` not included in INCOMING_MODULE_JS_API`);
|
|
}
|
|
}
|
|
|
|
// forcing the filesystem exports a few things by default
|
|
function isExportedByForceFilesystem(name) {
|
|
return name === 'FS_createPath' ||
|
|
name === 'FS_createDataFile' ||
|
|
name === 'FS_createPreloadedFile' ||
|
|
name === 'FS_unlink' ||
|
|
name === 'addRunDependency' ||
|
|
// The old FS has some functionality that WasmFS lacks.
|
|
name === 'FS_createLazyFile' ||
|
|
name === 'FS_createDevice' ||
|
|
name === 'removeRunDependency';
|
|
}
|
|
|
|
/**
|
|
* Intercept access to a global symbol. This enables us to give informative
|
|
* warnings/errors when folks attempt to use symbols they did not include in
|
|
* their build, or no symbols that no longer exist.
|
|
*/
|
|
function hookGlobalSymbolAccess(sym, func) {
|
|
if (typeof globalThis != 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
|
|
Object.defineProperty(globalThis, sym, {
|
|
configurable: true,
|
|
get() {
|
|
func();
|
|
return undefined;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function missingGlobal(sym, msg) {
|
|
hookGlobalSymbolAccess(sym, () => {
|
|
warnOnce(`\`${sym}\` is not longer defined by emscripten. ${msg}`);
|
|
});
|
|
}
|
|
|
|
missingGlobal('buffer', 'Please use HEAP8.buffer or wasmMemory.buffer');
|
|
missingGlobal('asm', 'Please use wasmExports instead');
|
|
|
|
function missingLibrarySymbol(sym) {
|
|
hookGlobalSymbolAccess(sym, () => {
|
|
// Can't `abort()` here because it would break code that does runtime
|
|
// checks. e.g. `if (typeof SDL === 'undefined')`.
|
|
var msg = `\`${sym}\` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line`;
|
|
// DEFAULT_LIBRARY_FUNCS_TO_INCLUDE requires the name as it appears in
|
|
// library.js, which means $name for a JS name with no prefix, or name
|
|
// for a JS name like _name.
|
|
var librarySymbol = sym;
|
|
if (!librarySymbol.startsWith('_')) {
|
|
librarySymbol = '$' + sym;
|
|
}
|
|
msg += ` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${librarySymbol}')`;
|
|
if (isExportedByForceFilesystem(sym)) {
|
|
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
|
|
}
|
|
warnOnce(msg);
|
|
});
|
|
|
|
// Any symbol that is not included from the JS library is also (by definition)
|
|
// not exported on the Module object.
|
|
unexportedRuntimeSymbol(sym);
|
|
}
|
|
|
|
function unexportedRuntimeSymbol(sym) {
|
|
if (!Object.getOwnPropertyDescriptor(Module, sym)) {
|
|
Object.defineProperty(Module, sym, {
|
|
configurable: true,
|
|
get() {
|
|
var msg = `'${sym}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;
|
|
if (isExportedByForceFilesystem(sym)) {
|
|
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
|
|
}
|
|
abort(msg);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
var runtimeDebug = true; // Switch to false at runtime to disable logging at the right times
|
|
|
|
// Used by XXXXX_DEBUG settings to output debug messages.
|
|
function dbg(...args) {
|
|
if (!runtimeDebug && typeof runtimeDebug != 'undefined') return;
|
|
// TODO(sbc): Make this configurable somehow. Its not always convenient for
|
|
// logging to show up as warnings.
|
|
console.warn(...args);
|
|
}
|
|
// end include: runtime_debug.js
|
|
// include: memoryprofiler.js
|
|
// end include: memoryprofiler.js
|
|
|
|
|
|
function updateMemoryViews() {
|
|
var b = wasmMemory.buffer;
|
|
Module['HEAP8'] = HEAP8 = new Int8Array(b);
|
|
Module['HEAP16'] = HEAP16 = new Int16Array(b);
|
|
Module['HEAPU8'] = HEAPU8 = new Uint8Array(b);
|
|
Module['HEAPU16'] = HEAPU16 = new Uint16Array(b);
|
|
Module['HEAP32'] = HEAP32 = new Int32Array(b);
|
|
Module['HEAPU32'] = HEAPU32 = new Uint32Array(b);
|
|
Module['HEAPF32'] = HEAPF32 = new Float32Array(b);
|
|
Module['HEAPF64'] = HEAPF64 = new Float64Array(b);
|
|
Module['HEAP64'] = HEAP64 = new BigInt64Array(b);
|
|
Module['HEAPU64'] = HEAPU64 = new BigUint64Array(b);
|
|
}
|
|
|
|
// end include: runtime_shared.js
|
|
assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time')
|
|
|
|
assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
|
|
'JS engine does not provide full typed array support');
|
|
|
|
// If memory is defined in wasm, the user can't provide it, or set INITIAL_MEMORY
|
|
assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally');
|
|
assert(!Module['INITIAL_MEMORY'], 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
|
|
|
|
function preRun() {
|
|
if (Module['preRun']) {
|
|
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
|
|
while (Module['preRun'].length) {
|
|
addOnPreRun(Module['preRun'].shift());
|
|
}
|
|
}
|
|
consumedModuleProp('preRun');
|
|
callRuntimeCallbacks(onPreRuns);
|
|
}
|
|
|
|
function initRuntime() {
|
|
assert(!runtimeInitialized);
|
|
runtimeInitialized = true;
|
|
|
|
checkStackCookie();
|
|
|
|
|
|
|
|
wasmExports['__wasm_call_ctors']();
|
|
|
|
|
|
}
|
|
|
|
function preMain() {
|
|
checkStackCookie();
|
|
|
|
}
|
|
|
|
function postRun() {
|
|
checkStackCookie();
|
|
|
|
if (Module['postRun']) {
|
|
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
|
|
while (Module['postRun'].length) {
|
|
addOnPostRun(Module['postRun'].shift());
|
|
}
|
|
}
|
|
consumedModuleProp('postRun');
|
|
|
|
callRuntimeCallbacks(onPostRuns);
|
|
}
|
|
|
|
// A counter of dependencies for calling run(). If we need to
|
|
// do asynchronous work before running, increment this and
|
|
// decrement it. Incrementing must happen in a place like
|
|
// Module.preRun (used by emcc to add file preloading).
|
|
// Note that you can add dependencies in preRun, even though
|
|
// it happens right before run - run will be postponed until
|
|
// the dependencies are met.
|
|
var runDependencies = 0;
|
|
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
|
|
var runDependencyTracking = {};
|
|
var runDependencyWatcher = null;
|
|
|
|
function getUniqueRunDependency(id) {
|
|
var orig = id;
|
|
while (1) {
|
|
if (!runDependencyTracking[id]) return id;
|
|
id = orig + Math.random();
|
|
}
|
|
}
|
|
|
|
function addRunDependency(id) {
|
|
runDependencies++;
|
|
|
|
Module['monitorRunDependencies']?.(runDependencies);
|
|
|
|
if (id) {
|
|
assert(!runDependencyTracking[id]);
|
|
runDependencyTracking[id] = 1;
|
|
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
|
|
// Check for missing dependencies every few seconds
|
|
runDependencyWatcher = setInterval(() => {
|
|
if (ABORT) {
|
|
clearInterval(runDependencyWatcher);
|
|
runDependencyWatcher = null;
|
|
return;
|
|
}
|
|
var shown = false;
|
|
for (var dep in runDependencyTracking) {
|
|
if (!shown) {
|
|
shown = true;
|
|
err('still waiting on run dependencies:');
|
|
}
|
|
err(`dependency: ${dep}`);
|
|
}
|
|
if (shown) {
|
|
err('(end of list)');
|
|
}
|
|
}, 10000);
|
|
}
|
|
} else {
|
|
err('warning: run dependency added without ID');
|
|
}
|
|
}
|
|
|
|
function removeRunDependency(id) {
|
|
runDependencies--;
|
|
|
|
Module['monitorRunDependencies']?.(runDependencies);
|
|
|
|
if (id) {
|
|
assert(runDependencyTracking[id]);
|
|
delete runDependencyTracking[id];
|
|
} else {
|
|
err('warning: run dependency removed without ID');
|
|
}
|
|
if (runDependencies == 0) {
|
|
if (runDependencyWatcher !== null) {
|
|
clearInterval(runDependencyWatcher);
|
|
runDependencyWatcher = null;
|
|
}
|
|
if (dependenciesFulfilled) {
|
|
var callback = dependenciesFulfilled;
|
|
dependenciesFulfilled = null;
|
|
callback(); // can add another dependenciesFulfilled
|
|
}
|
|
}
|
|
}
|
|
|
|
/** @param {string|number=} what */
|
|
function abort(what) {
|
|
Module['onAbort']?.(what);
|
|
|
|
what = 'Aborted(' + what + ')';
|
|
// TODO(sbc): Should we remove printing and leave it up to whoever
|
|
// catches the exception?
|
|
err(what);
|
|
|
|
ABORT = true;
|
|
|
|
// Use a wasm runtime error, because a JS error might be seen as a foreign
|
|
// exception, which means we'd run destructors on it. We need the error to
|
|
// simply make the program stop.
|
|
// FIXME This approach does not work in Wasm EH because it currently does not assume
|
|
// all RuntimeErrors are from traps; it decides whether a RuntimeError is from
|
|
// a trap or not based on a hidden field within the object. So at the moment
|
|
// we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
|
|
// allows this in the wasm spec.
|
|
|
|
// Suppress closure compiler warning here. Closure compiler's builtin extern
|
|
// definition for WebAssembly.RuntimeError claims it takes no arguments even
|
|
// though it can.
|
|
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
|
|
/** @suppress {checkTypes} */
|
|
var e = new WebAssembly.RuntimeError(what);
|
|
|
|
// Throw the error whether or not MODULARIZE is set because abort is used
|
|
// in code paths apart from instantiation where an exception is expected
|
|
// to be thrown when abort is called.
|
|
throw e;
|
|
}
|
|
|
|
// show errors on likely calls to FS when it was not included
|
|
var FS = {
|
|
error() {
|
|
abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM');
|
|
},
|
|
init() { FS.error() },
|
|
createDataFile() { FS.error() },
|
|
createPreloadedFile() { FS.error() },
|
|
createLazyFile() { FS.error() },
|
|
open() { FS.error() },
|
|
mkdev() { FS.error() },
|
|
registerDevice() { FS.error() },
|
|
analyzePath() { FS.error() },
|
|
|
|
ErrnoError() { FS.error() },
|
|
};
|
|
Module['FS_createDataFile'] = FS.createDataFile;
|
|
Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
|
|
|
|
function createExportWrapper(name, nargs) {
|
|
return (...args) => {
|
|
assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
|
|
var f = wasmExports[name];
|
|
assert(f, `exported native function \`${name}\` not found`);
|
|
// Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.
|
|
assert(args.length <= nargs, `native function \`${name}\` called with ${args.length} args but expects ${nargs}`);
|
|
return f(...args);
|
|
};
|
|
}
|
|
|
|
var wasmBinaryFile;
|
|
|
|
function findWasmBinary() {
|
|
return locateFile('index.wasm');
|
|
}
|
|
|
|
function getBinarySync(file) {
|
|
if (file == wasmBinaryFile && wasmBinary) {
|
|
return new Uint8Array(wasmBinary);
|
|
}
|
|
if (readBinary) {
|
|
return readBinary(file);
|
|
}
|
|
throw 'both async and sync fetching of the wasm failed';
|
|
}
|
|
|
|
async function getWasmBinary(binaryFile) {
|
|
// If we don't have the binary yet, load it asynchronously using readAsync.
|
|
if (!wasmBinary) {
|
|
// Fetch the binary using readAsync
|
|
try {
|
|
var response = await readAsync(binaryFile);
|
|
return new Uint8Array(response);
|
|
} catch {
|
|
// Fall back to getBinarySync below;
|
|
}
|
|
}
|
|
|
|
// Otherwise, getBinarySync should be able to get it synchronously
|
|
return getBinarySync(binaryFile);
|
|
}
|
|
|
|
async function instantiateArrayBuffer(binaryFile, imports) {
|
|
try {
|
|
var binary = await getWasmBinary(binaryFile);
|
|
var instance = await WebAssembly.instantiate(binary, imports);
|
|
return instance;
|
|
} catch (reason) {
|
|
err(`failed to asynchronously prepare wasm: ${reason}`);
|
|
|
|
// Warn on some common problems.
|
|
if (isFileURI(wasmBinaryFile)) {
|
|
err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
|
|
}
|
|
abort(reason);
|
|
}
|
|
}
|
|
|
|
async function instantiateAsync(binary, binaryFile, imports) {
|
|
if (!binary && typeof WebAssembly.instantiateStreaming == 'function'
|
|
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
|
|
&& !isFileURI(binaryFile)
|
|
// Avoid instantiateStreaming() on Node.js environment for now, as while
|
|
// Node.js v18.1.0 implements it, it does not have a full fetch()
|
|
// implementation yet.
|
|
//
|
|
// Reference:
|
|
// https://github.com/emscripten-core/emscripten/pull/16917
|
|
&& !ENVIRONMENT_IS_NODE
|
|
) {
|
|
try {
|
|
var response = fetch(binaryFile, { credentials: 'same-origin' });
|
|
var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
|
|
return instantiationResult;
|
|
} catch (reason) {
|
|
// We expect the most common failure cause to be a bad MIME type for the binary,
|
|
// in which case falling back to ArrayBuffer instantiation should work.
|
|
err(`wasm streaming compile failed: ${reason}`);
|
|
err('falling back to ArrayBuffer instantiation');
|
|
// fall back of instantiateArrayBuffer below
|
|
};
|
|
}
|
|
return instantiateArrayBuffer(binaryFile, imports);
|
|
}
|
|
|
|
function getWasmImports() {
|
|
// prepare imports
|
|
return {
|
|
'env': wasmImports,
|
|
'wasi_snapshot_preview1': wasmImports,
|
|
}
|
|
}
|
|
|
|
// Create the wasm instance.
|
|
// Receives the wasm imports, returns the exports.
|
|
async function createWasm() {
|
|
// Load the wasm module and create an instance of using native support in the JS engine.
|
|
// handle a generated wasm instance, receiving its exports and
|
|
// performing other necessary setup
|
|
/** @param {WebAssembly.Module=} module*/
|
|
function receiveInstance(instance, module) {
|
|
wasmExports = instance.exports;
|
|
|
|
wasmExports = applySignatureConversions(wasmExports);
|
|
|
|
|
|
|
|
wasmMemory = wasmExports['memory'];
|
|
|
|
assert(wasmMemory, 'memory not found in wasm exports');
|
|
updateMemoryViews();
|
|
|
|
wasmTable = wasmExports['__indirect_function_table'];
|
|
|
|
assert(wasmTable, 'table not found in wasm exports');
|
|
|
|
removeRunDependency('wasm-instantiate');
|
|
return wasmExports;
|
|
}
|
|
// wait for the pthread pool (if any)
|
|
addRunDependency('wasm-instantiate');
|
|
|
|
// Prefer streaming instantiation if available.
|
|
// Async compilation can be confusing when an error on the page overwrites Module
|
|
// (for example, if the order of elements is wrong, and the one defining Module is
|
|
// later), so we save Module and check it later.
|
|
var trueModule = Module;
|
|
function receiveInstantiationResult(result) {
|
|
// 'result' is a ResultObject object which has both the module and instance.
|
|
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
|
|
assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
|
|
trueModule = null;
|
|
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
|
|
// When the regression is fixed, can restore the above PTHREADS-enabled path.
|
|
return receiveInstance(result['instance']);
|
|
}
|
|
|
|
var info = getWasmImports();
|
|
|
|
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
|
|
// to manually instantiate the Wasm module themselves. This allows pages to
|
|
// run the instantiation parallel to any other async startup actions they are
|
|
// performing.
|
|
// Also pthreads and wasm workers initialize the wasm instance through this
|
|
// path.
|
|
if (Module['instantiateWasm']) {
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
Module['instantiateWasm'](info, (mod, inst) => {
|
|
receiveInstance(mod, inst);
|
|
resolve(mod.exports);
|
|
});
|
|
} catch(e) {
|
|
err(`Module.instantiateWasm callback failed with error: ${e}`);
|
|
reject(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
wasmBinaryFile ??= findWasmBinary();
|
|
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
|
|
var exports = receiveInstantiationResult(result);
|
|
return exports;
|
|
}
|
|
|
|
// end include: preamble.js
|
|
|
|
// Begin JS library code
|
|
|
|
|
|
class ExitStatus {
|
|
name = 'ExitStatus';
|
|
constructor(status) {
|
|
this.message = `Program terminated with exit(${status})`;
|
|
this.status = status;
|
|
}
|
|
}
|
|
|
|
var callRuntimeCallbacks = (callbacks) => {
|
|
while (callbacks.length > 0) {
|
|
// Pass the module as the first argument.
|
|
callbacks.shift()(Module);
|
|
}
|
|
};
|
|
var onPostRuns = [];
|
|
var addOnPostRun = (cb) => onPostRuns.unshift(cb);
|
|
|
|
var onPreRuns = [];
|
|
var addOnPreRun = (cb) => onPreRuns.unshift(cb);
|
|
|
|
|
|
|
|
/**
|
|
* @param {number} ptr
|
|
* @param {string} type
|
|
*/
|
|
function getValue(ptr, type = 'i8') {
|
|
if (type.endsWith('*')) type = '*';
|
|
switch (type) {
|
|
case 'i1': return HEAP8[ptr];
|
|
case 'i8': return HEAP8[ptr];
|
|
case 'i16': return HEAP16[((ptr)/2)];
|
|
case 'i32': return HEAP32[((ptr)/4)];
|
|
case 'i64': return HEAP64[((ptr)/8)];
|
|
case 'float': return HEAPF32[((ptr)/4)];
|
|
case 'double': return HEAPF64[((ptr)/8)];
|
|
case '*': return Number(HEAPU64[((ptr)/8)]);
|
|
default: abort(`invalid type for getValue: ${type}`);
|
|
}
|
|
}
|
|
|
|
var noExitRuntime = Module['noExitRuntime'] || true;
|
|
|
|
var ptrToString = (ptr) => {
|
|
assert(typeof ptr === 'number');
|
|
return '0x' + ptr.toString(16).padStart(8, '0');
|
|
};
|
|
|
|
|
|
/**
|
|
* @param {number} ptr
|
|
* @param {number} value
|
|
* @param {string} type
|
|
*/
|
|
function setValue(ptr, value, type = 'i8') {
|
|
if (type.endsWith('*')) type = '*';
|
|
switch (type) {
|
|
case 'i1': HEAP8[ptr] = value; break;
|
|
case 'i8': HEAP8[ptr] = value; break;
|
|
case 'i16': HEAP16[((ptr)/2)] = value; break;
|
|
case 'i32': HEAP32[((ptr)/4)] = value; break;
|
|
case 'i64': HEAP64[((ptr)/8)] = BigInt(value); break;
|
|
case 'float': HEAPF32[((ptr)/4)] = value; break;
|
|
case 'double': HEAPF64[((ptr)/8)] = value; break;
|
|
case '*': HEAPU64[((ptr)/8)] = BigInt(value); break;
|
|
default: abort(`invalid type for setValue: ${type}`);
|
|
}
|
|
}
|
|
|
|
var stackRestore = (val) => __emscripten_stack_restore(val);
|
|
|
|
var stackSave = () => _emscripten_stack_get_current();
|
|
|
|
var warnOnce = (text) => {
|
|
warnOnce.shown ||= {};
|
|
if (!warnOnce.shown[text]) {
|
|
warnOnce.shown[text] = 1;
|
|
if (ENVIRONMENT_IS_NODE) text = 'warning: ' + text;
|
|
err(text);
|
|
}
|
|
};
|
|
|
|
var INT53_MAX = 9007199254740992;
|
|
|
|
var INT53_MIN = -9007199254740992;
|
|
var bigintToI53Checked = (num) => (num < INT53_MIN || num > INT53_MAX) ? NaN : Number(num);
|
|
|
|
var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder() : undefined;
|
|
|
|
/**
|
|
* Given a pointer 'idx' 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.
|
|
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
* @param {number=} idx
|
|
* @param {number=} maxBytesToRead
|
|
* @return {string}
|
|
*/
|
|
var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
|
|
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/NaN means Infinity)
|
|
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
|
|
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
}
|
|
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 = heapOrArray[idx++];
|
|
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
var u1 = heapOrArray[idx++] & 63;
|
|
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
var u2 = heapOrArray[idx++] & 63;
|
|
if ((u0 & 0xF0) == 0xE0) {
|
|
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
} else {
|
|
if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte ' + ptrToString(u0) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
|
|
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[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.
|
|
*
|
|
* @param {number} ptr
|
|
* @param {number=} 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
|
|
* @return {string}
|
|
*/
|
|
function UTF8ToString(ptr, maxBytesToRead) {
|
|
ptr = bigintToI53Checked(ptr);
|
|
|
|
|
|
assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
|
|
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
|
|
;
|
|
}
|
|
function ___assert_fail(condition, filename, line, func) {
|
|
condition = bigintToI53Checked(condition);
|
|
filename = bigintToI53Checked(filename);
|
|
func = bigintToI53Checked(func);
|
|
|
|
return abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
|
|
}
|
|
|
|
var __abort_js = () =>
|
|
abort('native code called abort()');
|
|
|
|
|
|
var _emscripten_set_main_loop_timing = (mode, value) => {
|
|
MainLoop.timingMode = mode;
|
|
MainLoop.timingValue = value;
|
|
|
|
if (!MainLoop.func) {
|
|
err('emscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up.');
|
|
return 1; // Return non-zero on failure, can't set timing mode when there is no main loop.
|
|
}
|
|
|
|
if (!MainLoop.running) {
|
|
|
|
MainLoop.running = true;
|
|
}
|
|
if (mode == 0) {
|
|
MainLoop.scheduler = function MainLoop_scheduler_setTimeout() {
|
|
var timeUntilNextTick = Math.max(0, MainLoop.tickStartTime + value - _emscripten_get_now())|0;
|
|
setTimeout(MainLoop.runner, timeUntilNextTick); // doing this each time means that on exception, we stop
|
|
};
|
|
MainLoop.method = 'timeout';
|
|
} else if (mode == 1) {
|
|
MainLoop.scheduler = function MainLoop_scheduler_rAF() {
|
|
MainLoop.requestAnimationFrame(MainLoop.runner);
|
|
};
|
|
MainLoop.method = 'rAF';
|
|
} else if (mode == 2) {
|
|
if (typeof MainLoop.setImmediate == 'undefined') {
|
|
if (typeof setImmediate == 'undefined') {
|
|
// Emulate setImmediate. (note: not a complete polyfill, we don't emulate clearImmediate() to keep code size to minimum, since not needed)
|
|
var setImmediates = [];
|
|
var emscriptenMainLoopMessageId = 'setimmediate';
|
|
/** @param {Event} event */
|
|
var MainLoop_setImmediate_messageHandler = (event) => {
|
|
// When called in current thread or Worker, the main loop ID is structured slightly different to accommodate for --proxy-to-worker runtime listening to Worker events,
|
|
// so check for both cases.
|
|
if (event.data === emscriptenMainLoopMessageId || event.data.target === emscriptenMainLoopMessageId) {
|
|
event.stopPropagation();
|
|
setImmediates.shift()();
|
|
}
|
|
};
|
|
addEventListener("message", MainLoop_setImmediate_messageHandler, true);
|
|
MainLoop.setImmediate = /** @type{function(function(): ?, ...?): number} */((func) => {
|
|
setImmediates.push(func);
|
|
if (ENVIRONMENT_IS_WORKER) {
|
|
Module['setImmediates'] ??= [];
|
|
Module['setImmediates'].push(func);
|
|
postMessage({target: emscriptenMainLoopMessageId}); // In --proxy-to-worker, route the message via proxyClient.js
|
|
} else postMessage(emscriptenMainLoopMessageId, "*"); // On the main thread, can just send the message to itself.
|
|
});
|
|
} else {
|
|
MainLoop.setImmediate = setImmediate;
|
|
}
|
|
}
|
|
MainLoop.scheduler = function MainLoop_scheduler_setImmediate() {
|
|
MainLoop.setImmediate(MainLoop.runner);
|
|
};
|
|
MainLoop.method = 'immediate';
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
var _emscripten_get_now = () => performance.now();
|
|
|
|
|
|
var runtimeKeepaliveCounter = 0;
|
|
var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
|
|
var _proc_exit = (code) => {
|
|
EXITSTATUS = code;
|
|
if (!keepRuntimeAlive()) {
|
|
Module['onExit']?.(code);
|
|
ABORT = true;
|
|
}
|
|
quit_(code, new ExitStatus(code));
|
|
};
|
|
|
|
|
|
/** @suppress {duplicate } */
|
|
/** @param {boolean|number=} implicit */
|
|
var exitJS = (status, implicit) => {
|
|
EXITSTATUS = status;
|
|
|
|
checkUnflushedContent();
|
|
|
|
// if exit() was called explicitly, warn the user if the runtime isn't actually being shut down
|
|
if (keepRuntimeAlive() && !implicit) {
|
|
var msg = `program exited (with status: ${status}), but keepRuntimeAlive() is set (counter=${runtimeKeepaliveCounter}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;
|
|
err(msg);
|
|
}
|
|
|
|
_proc_exit(status);
|
|
};
|
|
var _exit = exitJS;
|
|
|
|
var handleException = (e) => {
|
|
// Certain exception types we do not treat as errors since they are used for
|
|
// internal control flow.
|
|
// 1. ExitStatus, which is thrown by exit()
|
|
// 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
|
|
// that wish to return to JS event loop.
|
|
if (e instanceof ExitStatus || e == 'unwind') {
|
|
return EXITSTATUS;
|
|
}
|
|
checkStackCookie();
|
|
if (e instanceof WebAssembly.RuntimeError) {
|
|
if (_emscripten_stack_get_current() <= 0) {
|
|
err('Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to 65536)');
|
|
}
|
|
}
|
|
quit_(1, e);
|
|
};
|
|
|
|
var maybeExit = () => {
|
|
if (!keepRuntimeAlive()) {
|
|
try {
|
|
_exit(EXITSTATUS);
|
|
} catch (e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @param {number=} arg
|
|
* @param {boolean=} noSetTiming
|
|
*/
|
|
var setMainLoop = (iterFunc, fps, simulateInfiniteLoop, arg, noSetTiming) => {
|
|
assert(!MainLoop.func, 'emscripten_set_main_loop: there can only be one main loop function at once: call emscripten_cancel_main_loop to cancel the previous one before setting a new one with different parameters.');
|
|
MainLoop.func = iterFunc;
|
|
MainLoop.arg = arg;
|
|
|
|
var thisMainLoopId = MainLoop.currentlyRunningMainloop;
|
|
function checkIsRunning() {
|
|
if (thisMainLoopId < MainLoop.currentlyRunningMainloop) {
|
|
|
|
maybeExit();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// We create the loop runner here but it is not actually running until
|
|
// _emscripten_set_main_loop_timing is called (which might happen a
|
|
// later time). This member signifies that the current runner has not
|
|
// yet been started so that we can call runtimeKeepalivePush when it
|
|
// gets it timing set for the first time.
|
|
MainLoop.running = false;
|
|
MainLoop.runner = function MainLoop_runner() {
|
|
if (ABORT) return;
|
|
if (MainLoop.queue.length > 0) {
|
|
var start = Date.now();
|
|
var blocker = MainLoop.queue.shift();
|
|
blocker.func(blocker.arg);
|
|
if (MainLoop.remainingBlockers) {
|
|
var remaining = MainLoop.remainingBlockers;
|
|
var next = remaining%1 == 0 ? remaining-1 : Math.floor(remaining);
|
|
if (blocker.counted) {
|
|
MainLoop.remainingBlockers = next;
|
|
} else {
|
|
// not counted, but move the progress along a tiny bit
|
|
next = next + 0.5; // do not steal all the next one's progress
|
|
MainLoop.remainingBlockers = (8*remaining + next)/9;
|
|
}
|
|
}
|
|
MainLoop.updateStatus();
|
|
|
|
// catches pause/resume main loop from blocker execution
|
|
if (!checkIsRunning()) return;
|
|
|
|
setTimeout(MainLoop.runner, 0);
|
|
return;
|
|
}
|
|
|
|
// catch pauses from non-main loop sources
|
|
if (!checkIsRunning()) return;
|
|
|
|
// Implement very basic swap interval control
|
|
MainLoop.currentFrameNumber = MainLoop.currentFrameNumber + 1 | 0;
|
|
if (MainLoop.timingMode == 1 && MainLoop.timingValue > 1 && MainLoop.currentFrameNumber % MainLoop.timingValue != 0) {
|
|
// Not the scheduled time to render this frame - skip.
|
|
MainLoop.scheduler();
|
|
return;
|
|
} else if (MainLoop.timingMode == 0) {
|
|
MainLoop.tickStartTime = _emscripten_get_now();
|
|
}
|
|
|
|
if (MainLoop.method === 'timeout' && Module['ctx']) {
|
|
warnOnce('Looks like you are rendering without using requestAnimationFrame for the main loop. You should use 0 for the frame rate in emscripten_set_main_loop in order to use requestAnimationFrame, as that can greatly improve your frame rates!');
|
|
MainLoop.method = ''; // just warn once per call to set main loop
|
|
}
|
|
|
|
MainLoop.runIter(iterFunc);
|
|
|
|
// catch pauses from the main loop itself
|
|
if (!checkIsRunning()) return;
|
|
|
|
MainLoop.scheduler();
|
|
}
|
|
|
|
if (!noSetTiming) {
|
|
if (fps > 0) {
|
|
_emscripten_set_main_loop_timing(0, 1000.0 / fps);
|
|
} else {
|
|
// Do rAF by rendering each frame (no decimating)
|
|
_emscripten_set_main_loop_timing(1, 1);
|
|
}
|
|
|
|
MainLoop.scheduler();
|
|
}
|
|
|
|
if (simulateInfiniteLoop) {
|
|
throw 'unwind';
|
|
}
|
|
};
|
|
|
|
|
|
var callUserCallback = (func) => {
|
|
if (ABORT) {
|
|
err('user callback triggered after runtime exited or application aborted. Ignoring.');
|
|
return;
|
|
}
|
|
try {
|
|
func();
|
|
maybeExit();
|
|
} catch (e) {
|
|
handleException(e);
|
|
}
|
|
};
|
|
|
|
var MainLoop = {
|
|
running:false,
|
|
scheduler:null,
|
|
method:"",
|
|
currentlyRunningMainloop:0,
|
|
func:null,
|
|
arg:0,
|
|
timingMode:0,
|
|
timingValue:0,
|
|
currentFrameNumber:0,
|
|
queue:[],
|
|
preMainLoop:[],
|
|
postMainLoop:[],
|
|
pause() {
|
|
MainLoop.scheduler = null;
|
|
// Incrementing this signals the previous main loop that it's now become old, and it must return.
|
|
MainLoop.currentlyRunningMainloop++;
|
|
},
|
|
resume() {
|
|
MainLoop.currentlyRunningMainloop++;
|
|
var timingMode = MainLoop.timingMode;
|
|
var timingValue = MainLoop.timingValue;
|
|
var func = MainLoop.func;
|
|
MainLoop.func = null;
|
|
// do not set timing and call scheduler, we will do it on the next lines
|
|
setMainLoop(func, 0, false, MainLoop.arg, true);
|
|
_emscripten_set_main_loop_timing(timingMode, timingValue);
|
|
MainLoop.scheduler();
|
|
},
|
|
updateStatus() {
|
|
if (Module['setStatus']) {
|
|
var message = Module['statusMessage'] || 'Please wait...';
|
|
var remaining = MainLoop.remainingBlockers ?? 0;
|
|
var expected = MainLoop.expectedBlockers ?? 0;
|
|
if (remaining) {
|
|
if (remaining < expected) {
|
|
Module['setStatus'](`{message} ({expected - remaining}/{expected})`);
|
|
} else {
|
|
Module['setStatus'](message);
|
|
}
|
|
} else {
|
|
Module['setStatus']('');
|
|
}
|
|
}
|
|
},
|
|
init() {
|
|
Module['preMainLoop'] && MainLoop.preMainLoop.push(Module['preMainLoop']);
|
|
Module['postMainLoop'] && MainLoop.postMainLoop.push(Module['postMainLoop']);
|
|
},
|
|
runIter(func) {
|
|
if (ABORT) return;
|
|
for (var pre of MainLoop.preMainLoop) {
|
|
if (pre() === false) {
|
|
return; // |return false| skips a frame
|
|
}
|
|
}
|
|
callUserCallback(func);
|
|
for (var post of MainLoop.postMainLoop) {
|
|
post();
|
|
}
|
|
checkStackCookie();
|
|
},
|
|
nextRAF:0,
|
|
fakeRequestAnimationFrame(func) {
|
|
// try to keep 60fps between calls to here
|
|
var now = Date.now();
|
|
if (MainLoop.nextRAF === 0) {
|
|
MainLoop.nextRAF = now + 1000/60;
|
|
} else {
|
|
while (now + 2 >= MainLoop.nextRAF) { // fudge a little, to avoid timer jitter causing us to do lots of delay:0
|
|
MainLoop.nextRAF += 1000/60;
|
|
}
|
|
}
|
|
var delay = Math.max(MainLoop.nextRAF - now, 0);
|
|
setTimeout(func, delay);
|
|
},
|
|
requestAnimationFrame(func) {
|
|
if (typeof requestAnimationFrame == 'function') {
|
|
requestAnimationFrame(func);
|
|
return;
|
|
}
|
|
var RAF = MainLoop.fakeRequestAnimationFrame;
|
|
RAF(func);
|
|
},
|
|
};
|
|
var _emscripten_cancel_main_loop = () => {
|
|
MainLoop.pause();
|
|
MainLoop.func = null;
|
|
};
|
|
|
|
var _emscripten_get_device_pixel_ratio = () => {
|
|
return (typeof devicePixelRatio == 'number' && devicePixelRatio) || 1.0;
|
|
};
|
|
|
|
var maybeCStringToJsString = (cString) => {
|
|
// "cString > 2" checks if the input is a number, and isn't of the special
|
|
// values we accept here, EMSCRIPTEN_EVENT_TARGET_* (which map to 0, 1, 2).
|
|
// In other words, if cString > 2 then it's a pointer to a valid place in
|
|
// memory, and points to a C string.
|
|
return cString > 2 ? UTF8ToString(cString) : cString;
|
|
};
|
|
|
|
/** @type {Object} */
|
|
var specialHTMLTargets = [0, typeof document != 'undefined' ? document : 0, typeof window != 'undefined' ? window : 0];
|
|
var findEventTarget = (target) => {
|
|
target = maybeCStringToJsString(target);
|
|
var domElement = specialHTMLTargets[target] || (typeof document != 'undefined' ? document.querySelector(target) : null);
|
|
return domElement;
|
|
};
|
|
|
|
var getBoundingClientRect = (e) => specialHTMLTargets.indexOf(e) < 0 ? e.getBoundingClientRect() : {'left':0,'top':0};
|
|
|
|
function _emscripten_get_element_css_size(target, width, height) {
|
|
target = bigintToI53Checked(target);
|
|
width = bigintToI53Checked(width);
|
|
height = bigintToI53Checked(height);
|
|
|
|
|
|
target = findEventTarget(target);
|
|
if (!target) return -4;
|
|
|
|
var rect = getBoundingClientRect(target);
|
|
HEAPF64[((width)/8)] = rect.width;
|
|
HEAPF64[((height)/8)] = rect.height;
|
|
|
|
return 0;
|
|
;
|
|
}
|
|
|
|
|
|
var _emscripten_performance_now = () => performance.now();
|
|
|
|
|
|
var wasmTableMirror = [];
|
|
|
|
/** @type {WebAssembly.Table} */
|
|
var wasmTable;
|
|
var getWasmTableEntry = (funcPtr) => {
|
|
// Function pointers should show up as numbers, even under wasm64, but
|
|
// we still have some places where bigint values can flow here.
|
|
// https://github.com/emscripten-core/emscripten/issues/18200
|
|
funcPtr = Number(funcPtr);
|
|
var func = wasmTableMirror[funcPtr];
|
|
if (!func) {
|
|
/** @suppress {checkTypes} */
|
|
wasmTableMirror[funcPtr] = func = wasmTable.get(BigInt(funcPtr));
|
|
}
|
|
/** @suppress {checkTypes} */
|
|
assert(wasmTable.get(BigInt(funcPtr)) == func, 'JavaScript-side Wasm function table mirror is out of date!');
|
|
return func;
|
|
};
|
|
var _emscripten_request_animation_frame_loop = function(cb, userData) {
|
|
cb = bigintToI53Checked(cb);
|
|
userData = bigintToI53Checked(userData);
|
|
|
|
|
|
function tick(timeStamp) {
|
|
if (((a1, a2) => getWasmTableEntry(cb).call(null, a1, BigInt(a2)))(timeStamp, userData)) {
|
|
requestAnimationFrame(tick);
|
|
}
|
|
}
|
|
return requestAnimationFrame(tick);
|
|
;
|
|
};
|
|
|
|
var abortOnCannotGrowMemory = (requestedSize) => {
|
|
abort(`Cannot enlarge memory arrays to size ${requestedSize} bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value ${HEAP8.length}, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0`);
|
|
};
|
|
|
|
function _emscripten_resize_heap(requestedSize) {
|
|
requestedSize = bigintToI53Checked(requestedSize);
|
|
|
|
|
|
var oldSize = HEAPU8.length;
|
|
abortOnCannotGrowMemory(requestedSize);
|
|
;
|
|
}
|
|
|
|
var onExits = [];
|
|
var addOnExit = (cb) => onExits.unshift(cb);
|
|
var JSEvents = {
|
|
memcpy(target, src, size) {
|
|
HEAP8.set(HEAP8.subarray(src, src + size), target);
|
|
},
|
|
removeAllEventListeners() {
|
|
while (JSEvents.eventHandlers.length) {
|
|
JSEvents._removeHandler(JSEvents.eventHandlers.length - 1);
|
|
}
|
|
JSEvents.deferredCalls = [];
|
|
},
|
|
inEventHandler:0,
|
|
deferredCalls:[],
|
|
deferCall(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 call of JSEvents.deferredCalls) {
|
|
if (call.targetFunction == targetFunction && arraysHaveEqualContent(call.argsList, argsList)) {
|
|
return;
|
|
}
|
|
}
|
|
JSEvents.deferredCalls.push({
|
|
targetFunction,
|
|
precedence,
|
|
argsList
|
|
});
|
|
|
|
JSEvents.deferredCalls.sort((x,y) => x.precedence < y.precedence);
|
|
},
|
|
removeDeferredCalls(targetFunction) {
|
|
JSEvents.deferredCalls = JSEvents.deferredCalls.filter((call) => call.targetFunction != targetFunction);
|
|
},
|
|
canPerformEventHandlerRequests() {
|
|
if (navigator.userActivation) {
|
|
// Verify against transient activation status from UserActivation API
|
|
// whether it is possible to perform a request here without needing to defer. See
|
|
// https://developer.mozilla.org/en-US/docs/Web/Security/User_activation#transient_activation
|
|
// and https://caniuse.com/mdn-api_useractivation
|
|
// At the time of writing, Firefox does not support this API: https://bugzilla.mozilla.org/show_bug.cgi?id=1791079
|
|
return navigator.userActivation.isActive;
|
|
}
|
|
|
|
return JSEvents.inEventHandler && JSEvents.currentEventHandler.allowsDeferredCalls;
|
|
},
|
|
runDeferredCalls() {
|
|
if (!JSEvents.canPerformEventHandlerRequests()) {
|
|
return;
|
|
}
|
|
var deferredCalls = JSEvents.deferredCalls;
|
|
JSEvents.deferredCalls = [];
|
|
for (var call of deferredCalls) {
|
|
call.targetFunction(...call.argsList);
|
|
}
|
|
},
|
|
eventHandlers:[],
|
|
removeAllHandlersOnTarget:(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(i) {
|
|
var h = JSEvents.eventHandlers[i];
|
|
h.target.removeEventListener(h.eventTypeString, h.eventListenerFunc, h.useCapture);
|
|
JSEvents.eventHandlers.splice(i, 1);
|
|
},
|
|
registerOrRemoveHandler(eventHandler) {
|
|
if (!eventHandler.target) {
|
|
err('registerOrRemoveHandler: the target element for event handler registration does not exist, when processing the following event handler registration:');
|
|
console.dir(eventHandler);
|
|
return -4;
|
|
}
|
|
if (eventHandler.callbackfunc) {
|
|
eventHandler.eventListenerFunc = function(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;
|
|
};
|
|
|
|
eventHandler.target.addEventListener(eventHandler.eventTypeString,
|
|
eventHandler.eventListenerFunc,
|
|
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--);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
},
|
|
getNodeNameForTarget(target) {
|
|
if (!target) return '';
|
|
if (target == window) return '#window';
|
|
if (target == screen) return '#screen';
|
|
return target?.nodeName || '';
|
|
},
|
|
fullscreenEnabled() {
|
|
return document.fullscreenEnabled
|
|
;
|
|
},
|
|
};
|
|
|
|
|
|
|
|
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
|
|
assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
|
|
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
// undefined and false each don't write out any bytes.
|
|
if (!(maxBytesToWrite > 0))
|
|
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;
|
|
heap[outIdx++] = u;
|
|
} else if (u <= 0x7FF) {
|
|
if (outIdx + 1 >= endIdx) break;
|
|
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
heap[outIdx++] = 0x80 | (u & 63);
|
|
} else if (u <= 0xFFFF) {
|
|
if (outIdx + 2 >= endIdx) break;
|
|
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
heap[outIdx++] = 0x80 | (u & 63);
|
|
} else {
|
|
if (outIdx + 3 >= endIdx) break;
|
|
if (u > 0x10FFFF) warnOnce('Invalid Unicode code point ' + ptrToString(u) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
|
|
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
heap[outIdx++] = 0x80 | (u & 63);
|
|
}
|
|
}
|
|
// Null-terminate the pointer to the buffer.
|
|
heap[outIdx] = 0;
|
|
return outIdx - startIdx;
|
|
};
|
|
var 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);
|
|
};
|
|
|
|
var registerFocusEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.focusEvent ||= _malloc(256);
|
|
|
|
var focusEventHandlerFunc = (e = event) => {
|
|
var nodeName = JSEvents.getNodeNameForTarget(e.target);
|
|
var id = e.target.id ? e.target.id : '';
|
|
|
|
var focusEvent = JSEvents.focusEvent;
|
|
stringToUTF8(nodeName, focusEvent + 0, 128);
|
|
stringToUTF8(id, focusEvent + 128, 128);
|
|
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, focusEvent, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target: findEventTarget(target),
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: focusEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
function _emscripten_set_blur_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerFocusEventCallback(target, userData, useCapture, callbackfunc, 12, "blur", targetThread);
|
|
}
|
|
|
|
var findCanvasEventTarget = findEventTarget;
|
|
|
|
function _emscripten_set_canvas_element_size(target, width, height) {
|
|
target = bigintToI53Checked(target);
|
|
|
|
|
|
var canvas = findCanvasEventTarget(target);
|
|
if (!canvas) return -4;
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
return 0;
|
|
;
|
|
}
|
|
|
|
|
|
function _emscripten_set_focus_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerFocusEventCallback(target, userData, useCapture, callbackfunc, 13, "focus", targetThread);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var registerKeyEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.keyEvent ||= _malloc(160);
|
|
|
|
var keyEventHandlerFunc = (e) => {
|
|
assert(e);
|
|
|
|
var keyEventData = JSEvents.keyEvent;
|
|
HEAPF64[((keyEventData)/8)] = e.timeStamp;
|
|
|
|
var idx = ((keyEventData)/4);
|
|
|
|
HEAP32[idx + 2] = e.location;
|
|
HEAP8[keyEventData + 12] = e.ctrlKey;
|
|
HEAP8[keyEventData + 13] = e.shiftKey;
|
|
HEAP8[keyEventData + 14] = e.altKey;
|
|
HEAP8[keyEventData + 15] = e.metaKey;
|
|
HEAP8[keyEventData + 16] = e.repeat;
|
|
HEAP32[idx + 5] = e.charCode;
|
|
HEAP32[idx + 6] = e.keyCode;
|
|
HEAP32[idx + 7] = e.which;
|
|
stringToUTF8(e.key || '', keyEventData + 32, 32);
|
|
stringToUTF8(e.code || '', keyEventData + 64, 32);
|
|
stringToUTF8(e.char || '', keyEventData + 96, 32);
|
|
stringToUTF8(e.locale || '', keyEventData + 128, 32);
|
|
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, keyEventData, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target: findEventTarget(target),
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: keyEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
function _emscripten_set_keydown_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerKeyEventCallback(target, userData, useCapture, callbackfunc, 2, "keydown", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_keypress_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerKeyEventCallback(target, userData, useCapture, callbackfunc, 1, "keypress", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_keyup_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerKeyEventCallback(target, userData, useCapture, callbackfunc, 3, "keyup", targetThread);
|
|
}
|
|
|
|
|
|
|
|
function _emscripten_set_main_loop(func, fps, simulateInfiniteLoop) {
|
|
func = bigintToI53Checked(func);
|
|
|
|
|
|
var iterFunc = getWasmTableEntry(func);
|
|
setMainLoop(iterFunc, fps, simulateInfiniteLoop);
|
|
;
|
|
}
|
|
|
|
|
|
var fillMouseEventData = (eventStruct, e, target) => {
|
|
assert(eventStruct % 4 == 0);
|
|
HEAPF64[((eventStruct)/8)] = e.timeStamp;
|
|
var idx = ((eventStruct)/4);
|
|
HEAP32[idx + 2] = e.screenX;
|
|
HEAP32[idx + 3] = e.screenY;
|
|
HEAP32[idx + 4] = e.clientX;
|
|
HEAP32[idx + 5] = e.clientY;
|
|
HEAP8[eventStruct + 24] = e.ctrlKey;
|
|
HEAP8[eventStruct + 25] = e.shiftKey;
|
|
HEAP8[eventStruct + 26] = e.altKey;
|
|
HEAP8[eventStruct + 27] = e.metaKey;
|
|
HEAP16[idx*2 + 14] = e.button;
|
|
HEAP16[idx*2 + 15] = e.buttons;
|
|
|
|
HEAP32[idx + 8] = e["movementX"]
|
|
;
|
|
|
|
HEAP32[idx + 9] = e["movementY"]
|
|
;
|
|
|
|
// Note: rect contains doubles (truncated to placate SAFE_HEAP, which is the same behaviour when writing to HEAP32 anyway)
|
|
var rect = getBoundingClientRect(target);
|
|
HEAP32[idx + 10] = e.clientX - (rect.left | 0);
|
|
HEAP32[idx + 11] = e.clientY - (rect.top | 0);
|
|
};
|
|
|
|
|
|
|
|
var registerMouseEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.mouseEvent ||= _malloc(64);
|
|
target = findEventTarget(target);
|
|
|
|
var mouseEventHandlerFunc = (e = event) => {
|
|
// TODO: Make this access thread safe, or this could update live while app is reading it.
|
|
fillMouseEventData(JSEvents.mouseEvent, e, target);
|
|
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, JSEvents.mouseEvent, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target,
|
|
allowsDeferredCalls: eventTypeString != 'mousemove' && eventTypeString != 'mouseenter' && eventTypeString != 'mouseleave', // Mouse move events do not allow fullscreen/pointer lock requests to be handled in them!
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: mouseEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
function _emscripten_set_mousedown_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerMouseEventCallback(target, userData, useCapture, callbackfunc, 5, "mousedown", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_mouseenter_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerMouseEventCallback(target, userData, useCapture, callbackfunc, 33, "mouseenter", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_mouseleave_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerMouseEventCallback(target, userData, useCapture, callbackfunc, 34, "mouseleave", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_mousemove_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerMouseEventCallback(target, userData, useCapture, callbackfunc, 8, "mousemove", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_mouseup_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerMouseEventCallback(target, userData, useCapture, callbackfunc, 6, "mouseup", targetThread);
|
|
}
|
|
|
|
|
|
|
|
var fillPointerlockChangeEventData = (eventStruct) => {
|
|
var pointerLockElement = document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement || document.msPointerLockElement;
|
|
var isPointerlocked = !!pointerLockElement;
|
|
// Assigning a boolean to HEAP32 with expected type coercion.
|
|
/** @suppress{checkTypes} */
|
|
HEAP8[eventStruct] = isPointerlocked;
|
|
var nodeName = JSEvents.getNodeNameForTarget(pointerLockElement);
|
|
var id = pointerLockElement?.id || '';
|
|
stringToUTF8(nodeName, eventStruct + 1, 128);
|
|
stringToUTF8(id, eventStruct + 129, 128);
|
|
};
|
|
|
|
|
|
var registerPointerlockChangeEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.pointerlockChangeEvent ||= _malloc(257);
|
|
|
|
var pointerlockChangeEventHandlerFunc = (e = event) => {
|
|
var pointerlockChangeEvent = JSEvents.pointerlockChangeEvent;
|
|
fillPointerlockChangeEventData(pointerlockChangeEvent);
|
|
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, pointerlockChangeEvent, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target,
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: pointerlockChangeEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
|
|
/** @suppress {missingProperties} */
|
|
function _emscripten_set_pointerlockchange_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
|
|
// TODO: Currently not supported in pthreads or in --proxy-to-worker mode. (In pthreads mode, document object is not defined)
|
|
if (!document || !document.body || (!document.body.requestPointerLock && !document.body.mozRequestPointerLock && !document.body.webkitRequestPointerLock && !document.body.msRequestPointerLock)) {
|
|
return -1;
|
|
}
|
|
|
|
target = findEventTarget(target);
|
|
if (!target) return -4;
|
|
registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "mozpointerlockchange", targetThread);
|
|
registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "webkitpointerlockchange", targetThread);
|
|
registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "mspointerlockchange", targetThread);
|
|
return registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "pointerlockchange", targetThread);
|
|
;
|
|
}
|
|
|
|
|
|
var registerPointerlockErrorEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
|
|
var pointerlockErrorEventHandlerFunc = (e = event) => {
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, 0, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target,
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: pointerlockErrorEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
|
|
/** @suppress {missingProperties} */
|
|
function _emscripten_set_pointerlockerror_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
|
|
// TODO: Currently not supported in pthreads or in --proxy-to-worker mode. (In pthreads mode, document object is not defined)
|
|
if (!document || !document.body.requestPointerLock && !document.body.mozRequestPointerLock && !document.body.webkitRequestPointerLock && !document.body.msRequestPointerLock) {
|
|
return -1;
|
|
}
|
|
|
|
target = findEventTarget(target);
|
|
|
|
if (!target) return -4;
|
|
registerPointerlockErrorEventCallback(target, userData, useCapture, callbackfunc, 38, "mozpointerlockerror", targetThread);
|
|
registerPointerlockErrorEventCallback(target, userData, useCapture, callbackfunc, 38, "webkitpointerlockerror", targetThread);
|
|
registerPointerlockErrorEventCallback(target, userData, useCapture, callbackfunc, 38, "mspointerlockerror", targetThread);
|
|
return registerPointerlockErrorEventCallback(target, userData, useCapture, callbackfunc, 38, "pointerlockerror", targetThread);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
var registerUiEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.uiEvent ||= _malloc(36);
|
|
|
|
target = findEventTarget(target);
|
|
|
|
var uiEventHandlerFunc = (e = 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 b = document.body; // Take document.body to a variable, Closure compiler does not outline access to it on its own.
|
|
if (!b) {
|
|
// During a page unload 'body' can be null, with "Cannot read property 'clientWidth' of null" being thrown
|
|
return;
|
|
}
|
|
var uiEvent = JSEvents.uiEvent;
|
|
HEAP32[((uiEvent)/4)] = 0; // always zero for resize and scroll
|
|
HEAP32[(((uiEvent)+(4))/4)] = b.clientWidth;
|
|
HEAP32[(((uiEvent)+(8))/4)] = b.clientHeight;
|
|
HEAP32[(((uiEvent)+(12))/4)] = innerWidth;
|
|
HEAP32[(((uiEvent)+(16))/4)] = innerHeight;
|
|
HEAP32[(((uiEvent)+(20))/4)] = outerWidth;
|
|
HEAP32[(((uiEvent)+(24))/4)] = outerHeight;
|
|
HEAP32[(((uiEvent)+(28))/4)] = pageXOffset | 0; // scroll offsets are float
|
|
HEAP32[(((uiEvent)+(32))/4)] = pageYOffset | 0;
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, uiEvent, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target,
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: uiEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
function _emscripten_set_resize_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerUiEventCallback(target, userData, useCapture, callbackfunc, 10, "resize", targetThread);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var registerTouchEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.touchEvent ||= _malloc(1552);
|
|
|
|
target = findEventTarget(target);
|
|
|
|
var touchEventHandlerFunc = (e) => {
|
|
assert(e);
|
|
var t, touches = {}, et = e.touches;
|
|
// To ease marshalling different kinds of touches that browser reports (all touches are listed in e.touches,
|
|
// only changed touches in e.changedTouches, and touches on target at a.targetTouches), mark a boolean in
|
|
// each Touch object so that we can later loop only once over all touches we see to marshall over to Wasm.
|
|
|
|
for (let t of et) {
|
|
// Browser might recycle the generated Touch objects between each frame (Firefox on Android), so reset any
|
|
// changed/target states we may have set from previous frame.
|
|
t.isChanged = t.onTarget = 0;
|
|
touches[t.identifier] = t;
|
|
}
|
|
// Mark which touches are part of the changedTouches list.
|
|
for (let t of e.changedTouches) {
|
|
t.isChanged = 1;
|
|
touches[t.identifier] = t;
|
|
}
|
|
// Mark which touches are part of the targetTouches list.
|
|
for (let t of e.targetTouches) {
|
|
touches[t.identifier].onTarget = 1;
|
|
}
|
|
|
|
var touchEvent = JSEvents.touchEvent;
|
|
HEAPF64[((touchEvent)/8)] = e.timeStamp;
|
|
HEAP8[touchEvent + 12] = e.ctrlKey;
|
|
HEAP8[touchEvent + 13] = e.shiftKey;
|
|
HEAP8[touchEvent + 14] = e.altKey;
|
|
HEAP8[touchEvent + 15] = e.metaKey;
|
|
var idx = touchEvent + 16;
|
|
var targetRect = getBoundingClientRect(target);
|
|
var numTouches = 0;
|
|
for (let t of Object.values(touches)) {
|
|
var idx32 = ((idx)/4); // Pre-shift the ptr to index to HEAP32 to save code size
|
|
HEAP32[idx32 + 0] = t.identifier;
|
|
HEAP32[idx32 + 1] = t.screenX;
|
|
HEAP32[idx32 + 2] = t.screenY;
|
|
HEAP32[idx32 + 3] = t.clientX;
|
|
HEAP32[idx32 + 4] = t.clientY;
|
|
HEAP32[idx32 + 5] = t.pageX;
|
|
HEAP32[idx32 + 6] = t.pageY;
|
|
HEAP8[idx + 28] = t.isChanged;
|
|
HEAP8[idx + 29] = t.onTarget;
|
|
HEAP32[idx32 + 8] = t.clientX - (targetRect.left | 0);
|
|
HEAP32[idx32 + 9] = t.clientY - (targetRect.top | 0);
|
|
|
|
idx += 48;
|
|
|
|
if (++numTouches > 31) {
|
|
break;
|
|
}
|
|
}
|
|
HEAP32[(((touchEvent)+(8))/4)] = numTouches;
|
|
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, touchEvent, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target,
|
|
allowsDeferredCalls: eventTypeString == 'touchstart' || eventTypeString == 'touchend',
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: touchEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
function _emscripten_set_touchcancel_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerTouchEventCallback(target, userData, useCapture, callbackfunc, 25, "touchcancel", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_touchend_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerTouchEventCallback(target, userData, useCapture, callbackfunc, 23, "touchend", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_touchmove_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerTouchEventCallback(target, userData, useCapture, callbackfunc, 24, "touchmove", targetThread);
|
|
}
|
|
|
|
|
|
function _emscripten_set_touchstart_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
return registerTouchEventCallback(target, userData, useCapture, callbackfunc, 22, "touchstart", targetThread);
|
|
}
|
|
|
|
|
|
|
|
var GLctx;
|
|
|
|
var webgl_enable_ANGLE_instanced_arrays = (ctx) => {
|
|
// Extension available in WebGL 1 from Firefox 26 and Google Chrome 30 onwards. Core feature in WebGL 2.
|
|
var ext = ctx.getExtension('ANGLE_instanced_arrays');
|
|
// Because this extension is a core function in WebGL 2, assign the extension entry points in place of
|
|
// where the core functions will reside in WebGL 2. This way the calling code can call these without
|
|
// having to dynamically branch depending if running against WebGL 1 or WebGL 2.
|
|
if (ext) {
|
|
ctx['vertexAttribDivisor'] = (index, divisor) => ext['vertexAttribDivisorANGLE'](index, divisor);
|
|
ctx['drawArraysInstanced'] = (mode, first, count, primcount) => ext['drawArraysInstancedANGLE'](mode, first, count, primcount);
|
|
ctx['drawElementsInstanced'] = (mode, count, type, indices, primcount) => ext['drawElementsInstancedANGLE'](mode, count, type, indices, primcount);
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
var webgl_enable_OES_vertex_array_object = (ctx) => {
|
|
// Extension available in WebGL 1 from Firefox 25 and WebKit 536.28/desktop Safari 6.0.3 onwards. Core feature in WebGL 2.
|
|
var ext = ctx.getExtension('OES_vertex_array_object');
|
|
if (ext) {
|
|
ctx['createVertexArray'] = () => ext['createVertexArrayOES']();
|
|
ctx['deleteVertexArray'] = (vao) => ext['deleteVertexArrayOES'](vao);
|
|
ctx['bindVertexArray'] = (vao) => ext['bindVertexArrayOES'](vao);
|
|
ctx['isVertexArray'] = (vao) => ext['isVertexArrayOES'](vao);
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
var webgl_enable_WEBGL_draw_buffers = (ctx) => {
|
|
// Extension available in WebGL 1 from Firefox 28 onwards. Core feature in WebGL 2.
|
|
var ext = ctx.getExtension('WEBGL_draw_buffers');
|
|
if (ext) {
|
|
ctx['drawBuffers'] = (n, bufs) => ext['drawBuffersWEBGL'](n, bufs);
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
var webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance = (ctx) =>
|
|
// Closure is expected to be allowed to minify the '.dibvbi' property, so not accessing it quoted.
|
|
!!(ctx.dibvbi = ctx.getExtension('WEBGL_draw_instanced_base_vertex_base_instance'));
|
|
|
|
var webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance = (ctx) => {
|
|
// Closure is expected to be allowed to minify the '.mdibvbi' property, so not accessing it quoted.
|
|
return !!(ctx.mdibvbi = ctx.getExtension('WEBGL_multi_draw_instanced_base_vertex_base_instance'));
|
|
};
|
|
|
|
var webgl_enable_EXT_polygon_offset_clamp = (ctx) =>
|
|
!!(ctx.extPolygonOffsetClamp = ctx.getExtension('EXT_polygon_offset_clamp'));
|
|
|
|
var webgl_enable_EXT_clip_control = (ctx) =>
|
|
!!(ctx.extClipControl = ctx.getExtension('EXT_clip_control'));
|
|
|
|
var webgl_enable_WEBGL_polygon_mode = (ctx) =>
|
|
!!(ctx.webglPolygonMode = ctx.getExtension('WEBGL_polygon_mode'));
|
|
|
|
var webgl_enable_WEBGL_multi_draw = (ctx) =>
|
|
// Closure is expected to be allowed to minify the '.multiDrawWebgl' property, so not accessing it quoted.
|
|
!!(ctx.multiDrawWebgl = ctx.getExtension('WEBGL_multi_draw'));
|
|
|
|
var getEmscriptenSupportedExtensions = (ctx) => {
|
|
// Restrict the list of advertised extensions to those that we actually
|
|
// support.
|
|
var supportedExtensions = [
|
|
// WebGL 1 extensions
|
|
'ANGLE_instanced_arrays',
|
|
'EXT_blend_minmax',
|
|
'EXT_disjoint_timer_query',
|
|
'EXT_frag_depth',
|
|
'EXT_shader_texture_lod',
|
|
'EXT_sRGB',
|
|
'OES_element_index_uint',
|
|
'OES_fbo_render_mipmap',
|
|
'OES_standard_derivatives',
|
|
'OES_texture_float',
|
|
'OES_texture_half_float',
|
|
'OES_texture_half_float_linear',
|
|
'OES_vertex_array_object',
|
|
'WEBGL_color_buffer_float',
|
|
'WEBGL_depth_texture',
|
|
'WEBGL_draw_buffers',
|
|
// WebGL 2 extensions
|
|
'EXT_color_buffer_float',
|
|
'EXT_conservative_depth',
|
|
'EXT_disjoint_timer_query_webgl2',
|
|
'EXT_texture_norm16',
|
|
'NV_shader_noperspective_interpolation',
|
|
'WEBGL_clip_cull_distance',
|
|
// WebGL 1 and WebGL 2 extensions
|
|
'EXT_clip_control',
|
|
'EXT_color_buffer_half_float',
|
|
'EXT_depth_clamp',
|
|
'EXT_float_blend',
|
|
'EXT_polygon_offset_clamp',
|
|
'EXT_texture_compression_bptc',
|
|
'EXT_texture_compression_rgtc',
|
|
'EXT_texture_filter_anisotropic',
|
|
'KHR_parallel_shader_compile',
|
|
'OES_texture_float_linear',
|
|
'WEBGL_blend_func_extended',
|
|
'WEBGL_compressed_texture_astc',
|
|
'WEBGL_compressed_texture_etc',
|
|
'WEBGL_compressed_texture_etc1',
|
|
'WEBGL_compressed_texture_s3tc',
|
|
'WEBGL_compressed_texture_s3tc_srgb',
|
|
'WEBGL_debug_renderer_info',
|
|
'WEBGL_debug_shaders',
|
|
'WEBGL_lose_context',
|
|
'WEBGL_multi_draw',
|
|
'WEBGL_polygon_mode'
|
|
];
|
|
// .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
|
|
return (ctx.getSupportedExtensions() || []).filter(ext => supportedExtensions.includes(ext));
|
|
};
|
|
|
|
|
|
var GL = {
|
|
counter:1,
|
|
buffers:[],
|
|
programs:[],
|
|
framebuffers:[],
|
|
renderbuffers:[],
|
|
textures:[],
|
|
shaders:[],
|
|
vaos:[],
|
|
contexts:[],
|
|
offscreenCanvases:{
|
|
},
|
|
queries:[],
|
|
samplers:[],
|
|
transformFeedbacks:[],
|
|
syncs:[],
|
|
stringCache:{
|
|
},
|
|
stringiCache:{
|
|
},
|
|
unpackAlignment:4,
|
|
unpackRowLength:0,
|
|
recordError:(errorCode) => {
|
|
if (!GL.lastError) {
|
|
GL.lastError = errorCode;
|
|
}
|
|
},
|
|
getNewId:(table) => {
|
|
var ret = GL.counter++;
|
|
for (var i = table.length; i < ret; i++) {
|
|
table[i] = null;
|
|
}
|
|
return ret;
|
|
},
|
|
genObject:(n, buffers, createFunction, objectTable
|
|
) => {
|
|
for (var i = 0; i < n; i++) {
|
|
var buffer = GLctx[createFunction]();
|
|
var id = buffer && GL.getNewId(objectTable);
|
|
if (buffer) {
|
|
buffer.name = id;
|
|
objectTable[id] = buffer;
|
|
} else {
|
|
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
|
|
}
|
|
HEAP32[(((buffers)+(i*4))/4)] = id;
|
|
}
|
|
},
|
|
getSource:(shader, count, string, length) => {
|
|
var source = '';
|
|
for (var i = 0; i < count; ++i) {
|
|
var len = length ? Number(HEAPU64[(((length)+(i*8))/8)]) : undefined;
|
|
source += UTF8ToString(Number(HEAPU64[(((string)+(i*8))/8)]), len);
|
|
}
|
|
return source;
|
|
},
|
|
createContext:(/** @type {HTMLCanvasElement} */ canvas, webGLContextAttributes) => {
|
|
|
|
var ctx =
|
|
(webGLContextAttributes.majorVersion > 1)
|
|
?
|
|
canvas.getContext("webgl2", webGLContextAttributes)
|
|
:
|
|
canvas.getContext("webgl", webGLContextAttributes);
|
|
|
|
if (!ctx) return 0;
|
|
|
|
var handle = GL.registerContext(ctx, webGLContextAttributes);
|
|
|
|
return handle;
|
|
},
|
|
registerContext:(ctx, webGLContextAttributes) => {
|
|
// without pthreads a context is just an integer ID
|
|
var handle = GL.getNewId(GL.contexts);
|
|
|
|
var context = {
|
|
handle,
|
|
attributes: webGLContextAttributes,
|
|
version: webGLContextAttributes.majorVersion,
|
|
GLctx: ctx
|
|
};
|
|
|
|
// 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:(contextHandle) => {
|
|
|
|
// Active Emscripten GL layer context object.
|
|
GL.currentContext = GL.contexts[contextHandle];
|
|
// Active WebGL context object.
|
|
Module['ctx'] = GLctx = GL.currentContext?.GLctx;
|
|
return !(contextHandle && !GLctx);
|
|
},
|
|
getContext:(contextHandle) => {
|
|
return GL.contexts[contextHandle];
|
|
},
|
|
deleteContext:(contextHandle) => {
|
|
if (GL.currentContext === GL.contexts[contextHandle]) {
|
|
GL.currentContext = null;
|
|
}
|
|
if (typeof JSEvents == 'object') {
|
|
// Release all JS event handlers on the DOM element that the GL context is
|
|
// associated with since the context is now deleted.
|
|
JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas);
|
|
}
|
|
// Make sure the canvas object no longer refers to the context object so
|
|
// there are no GC surprises.
|
|
if (GL.contexts[contextHandle]?.GLctx.canvas) {
|
|
GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined;
|
|
}
|
|
GL.contexts[contextHandle] = null;
|
|
},
|
|
initExtensions:(context) => {
|
|
// If this function is called without a specific context object, init the
|
|
// extensions of the currently active context.
|
|
context ||= GL.currentContext;
|
|
|
|
if (context.initExtensionsDone) return;
|
|
context.initExtensionsDone = true;
|
|
|
|
var GLctx = context.GLctx;
|
|
|
|
// Detect the presence of a few extensions manually, ction GL interop
|
|
// layer itself will need to know if they exist.
|
|
|
|
// Extensions that are available in both WebGL 1 and WebGL 2
|
|
webgl_enable_WEBGL_multi_draw(GLctx);
|
|
webgl_enable_EXT_polygon_offset_clamp(GLctx);
|
|
webgl_enable_EXT_clip_control(GLctx);
|
|
webgl_enable_WEBGL_polygon_mode(GLctx);
|
|
// Extensions that are only available in WebGL 1 (the calls will be no-ops
|
|
// if called on a WebGL 2 context active)
|
|
webgl_enable_ANGLE_instanced_arrays(GLctx);
|
|
webgl_enable_OES_vertex_array_object(GLctx);
|
|
webgl_enable_WEBGL_draw_buffers(GLctx);
|
|
// Extensions that are available from WebGL >= 2 (no-op if called on a WebGL 1 context active)
|
|
webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance(GLctx);
|
|
webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance(GLctx);
|
|
|
|
// On WebGL 2, EXT_disjoint_timer_query is replaced with an alternative
|
|
// that's based on core APIs, and exposes only the queryCounterEXT()
|
|
// entrypoint.
|
|
if (context.version >= 2) {
|
|
GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query_webgl2");
|
|
}
|
|
|
|
// However, Firefox exposes the WebGL 1 version on WebGL 2 as well and
|
|
// thus we look for the WebGL 1 version again if the WebGL 2 version
|
|
// isn't present. https://bugzilla.mozilla.org/show_bug.cgi?id=1328882
|
|
if (context.version < 2 || !GLctx.disjointTimerQueryExt)
|
|
{
|
|
GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query");
|
|
}
|
|
|
|
getEmscriptenSupportedExtensions(GLctx).forEach((ext) => {
|
|
// WEBGL_lose_context, WEBGL_debug_renderer_info and WEBGL_debug_shaders
|
|
// are not enabled by default.
|
|
if (!ext.includes('lose_context') && !ext.includes('debug')) {
|
|
// Call .getExtension() to enable that extension permanently.
|
|
GLctx.getExtension(ext);
|
|
}
|
|
});
|
|
},
|
|
};
|
|
|
|
var registerWebGlEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
|
|
var webGlEventHandlerFunc = (e = event) => {
|
|
if (getWasmTableEntry(callbackfunc)(eventTypeId, 0, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target: findEventTarget(target),
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: webGlEventHandlerFunc,
|
|
useCapture
|
|
};
|
|
JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
|
|
function _emscripten_set_webglcontextlost_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
|
|
registerWebGlEventCallback(target, userData, useCapture, callbackfunc, 31, "webglcontextlost", targetThread);
|
|
return 0;
|
|
;
|
|
}
|
|
|
|
|
|
|
|
function _emscripten_set_webglcontextrestored_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
|
|
registerWebGlEventCallback(target, userData, useCapture, callbackfunc, 32, "webglcontextrestored", targetThread);
|
|
return 0;
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
var registerWheelEventCallback = (target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) => {
|
|
JSEvents.wheelEvent ||= _malloc(96);
|
|
|
|
// The DOM Level 3 events spec event 'wheel'
|
|
var wheelHandlerFunc = (e = event) => {
|
|
var wheelEvent = JSEvents.wheelEvent;
|
|
fillMouseEventData(wheelEvent, e, target);
|
|
HEAPF64[(((wheelEvent)+(64))/8)] = e["deltaX"];
|
|
HEAPF64[(((wheelEvent)+(72))/8)] = e["deltaY"];
|
|
HEAPF64[(((wheelEvent)+(80))/8)] = e["deltaZ"];
|
|
HEAP32[(((wheelEvent)+(88))/4)] = e["deltaMode"];
|
|
if (((a1, a2, a3) => getWasmTableEntry(callbackfunc).call(null, a1, BigInt(a2), BigInt(a3)))(eventTypeId, wheelEvent, userData)) e.preventDefault();
|
|
};
|
|
|
|
var eventHandler = {
|
|
target,
|
|
allowsDeferredCalls: true,
|
|
eventTypeString,
|
|
callbackfunc,
|
|
handlerFunc: wheelHandlerFunc,
|
|
useCapture
|
|
};
|
|
return JSEvents.registerOrRemoveHandler(eventHandler);
|
|
};
|
|
|
|
|
|
function _emscripten_set_wheel_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
|
|
target = bigintToI53Checked(target);
|
|
userData = bigintToI53Checked(userData);
|
|
callbackfunc = bigintToI53Checked(callbackfunc);
|
|
targetThread = bigintToI53Checked(targetThread);
|
|
|
|
|
|
target = findEventTarget(target);
|
|
if (!target) return -4;
|
|
if (typeof target.onwheel != 'undefined') {
|
|
return registerWheelEventCallback(target, userData, useCapture, callbackfunc, 9, "wheel", targetThread);
|
|
} else {
|
|
return -1;
|
|
}
|
|
;
|
|
}
|
|
|
|
|
|
var webglPowerPreferences = ["default","low-power","high-performance"];
|
|
|
|
|
|
|
|
/** @suppress {duplicate } */
|
|
var _emscripten_webgl_do_create_context = function(target, attributes) {
|
|
target = bigintToI53Checked(target);
|
|
attributes = bigintToI53Checked(attributes);
|
|
|
|
var ret = (() => {
|
|
assert(attributes);
|
|
var attr32 = ((attributes)/4);
|
|
var powerPreference = HEAP32[attr32 + (8>>2)];
|
|
var contextAttributes = {
|
|
'alpha': !!HEAP8[attributes + 0],
|
|
'depth': !!HEAP8[attributes + 1],
|
|
'stencil': !!HEAP8[attributes + 2],
|
|
'antialias': !!HEAP8[attributes + 3],
|
|
'premultipliedAlpha': !!HEAP8[attributes + 4],
|
|
'preserveDrawingBuffer': !!HEAP8[attributes + 5],
|
|
'powerPreference': webglPowerPreferences[powerPreference],
|
|
'failIfMajorPerformanceCaveat': !!HEAP8[attributes + 12],
|
|
// The following are not predefined WebGL context attributes in the WebGL specification, so the property names can be minified by Closure.
|
|
majorVersion: HEAP32[attr32 + (16>>2)],
|
|
minorVersion: HEAP32[attr32 + (20>>2)],
|
|
enableExtensionsByDefault: HEAP8[attributes + 24],
|
|
explicitSwapControl: HEAP8[attributes + 25],
|
|
proxyContextToMainThread: HEAP32[attr32 + (28>>2)],
|
|
renderViaOffscreenBackBuffer: HEAP8[attributes + 32]
|
|
};
|
|
|
|
// TODO: Make these into hard errors at some point in the future
|
|
if (contextAttributes.majorVersion !== 1 && contextAttributes.majorVersion !== 2) {
|
|
err(`Invalid WebGL version requested: ${contextAttributes.majorVersion}`);
|
|
}
|
|
|
|
var canvas = findCanvasEventTarget(target);
|
|
|
|
if (!canvas) {
|
|
return 0;
|
|
}
|
|
|
|
if (contextAttributes.explicitSwapControl) {
|
|
return 0;
|
|
}
|
|
|
|
var contextHandle = GL.createContext(canvas, contextAttributes);
|
|
return contextHandle;
|
|
})();
|
|
return BigInt(ret);
|
|
};
|
|
var _emscripten_webgl_create_context = _emscripten_webgl_do_create_context;
|
|
|
|
|
|
function _emscripten_webgl_make_context_current(contextHandle) {
|
|
contextHandle = bigintToI53Checked(contextHandle);
|
|
|
|
|
|
var success = GL.makeContextCurrent(contextHandle);
|
|
return success ? 0 : -5;
|
|
;
|
|
}
|
|
|
|
var SYSCALLS = {
|
|
varargs:undefined,
|
|
getStr(ptr) {
|
|
var ret = UTF8ToString(ptr);
|
|
return ret;
|
|
},
|
|
};
|
|
var _fd_close = (fd) => {
|
|
abort('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM');
|
|
};
|
|
|
|
function _fd_seek(fd, offset, whence, newOffset) {
|
|
offset = bigintToI53Checked(offset);
|
|
newOffset = bigintToI53Checked(newOffset);
|
|
|
|
|
|
return 70;
|
|
;
|
|
}
|
|
|
|
var printCharBuffers = [null,[],[]];
|
|
|
|
var printChar = (stream, curr) => {
|
|
var buffer = printCharBuffers[stream];
|
|
assert(buffer);
|
|
if (curr === 0 || curr === 10) {
|
|
(stream === 1 ? out : err)(UTF8ArrayToString(buffer));
|
|
buffer.length = 0;
|
|
} else {
|
|
buffer.push(curr);
|
|
}
|
|
};
|
|
|
|
var flush_NO_FILESYSTEM = () => {
|
|
// flush anything remaining in the buffers during shutdown
|
|
_fflush(0);
|
|
if (printCharBuffers[1].length) printChar(1, 10);
|
|
if (printCharBuffers[2].length) printChar(2, 10);
|
|
};
|
|
|
|
|
|
|
|
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
iov = bigintToI53Checked(iov);
|
|
iovcnt = bigintToI53Checked(iovcnt);
|
|
pnum = bigintToI53Checked(pnum);
|
|
|
|
|
|
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
var num = 0;
|
|
for (var i = 0; i < iovcnt; i++) {
|
|
var ptr = Number(HEAPU64[((iov)/8)]);
|
|
var len = Number(HEAPU64[(((iov)+(8))/8)]);
|
|
iov += 16;
|
|
for (var j = 0; j < len; j++) {
|
|
printChar(fd, HEAPU8[ptr+j]);
|
|
}
|
|
num += len;
|
|
}
|
|
HEAPU64[((pnum)/8)] = BigInt(num);
|
|
return 0;
|
|
;
|
|
}
|
|
|
|
var _glActiveTexture = (x0) => GLctx.activeTexture(x0);
|
|
|
|
var _glAttachShader = (program, shader) => {
|
|
GLctx.attachShader(GL.programs[program], GL.shaders[shader]);
|
|
};
|
|
|
|
var _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]);
|
|
};
|
|
|
|
var _glBindBufferBase = (target, index, buffer) => {
|
|
GLctx.bindBufferBase(target, index, GL.buffers[buffer]);
|
|
};
|
|
|
|
var _glBindFramebuffer = (target, framebuffer) => {
|
|
|
|
GLctx.bindFramebuffer(target, GL.framebuffers[framebuffer]);
|
|
|
|
};
|
|
|
|
var _glBindRenderbuffer = (target, renderbuffer) => {
|
|
GLctx.bindRenderbuffer(target, GL.renderbuffers[renderbuffer]);
|
|
};
|
|
|
|
var _glBindSampler = (unit, sampler) => {
|
|
GLctx.bindSampler(unit, GL.samplers[sampler]);
|
|
};
|
|
|
|
var _glBindTexture = (target, texture) => {
|
|
GLctx.bindTexture(target, GL.textures[texture]);
|
|
};
|
|
|
|
var _glBindVertexArray = (vao) => {
|
|
GLctx.bindVertexArray(GL.vaos[vao]);
|
|
};
|
|
|
|
var _glBlendColor = (x0, x1, x2, x3) => GLctx.blendColor(x0, x1, x2, x3);
|
|
|
|
var _glBlendEquationSeparate = (x0, x1) => GLctx.blendEquationSeparate(x0, x1);
|
|
|
|
var _glBlendFuncSeparate = (x0, x1, x2, x3) => GLctx.blendFuncSeparate(x0, x1, x2, x3);
|
|
|
|
var _glBlitFramebuffer = (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) => GLctx.blitFramebuffer(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9);
|
|
|
|
|
|
function _glBufferData(target, size, data, usage) {
|
|
size = bigintToI53Checked(size);
|
|
data = bigintToI53Checked(data);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
// If size is zero, WebGL would interpret uploading the whole input
|
|
// arraybuffer (starting from given offset), which would not make sense in
|
|
// WebAssembly, so avoid uploading if size is zero. However we must still
|
|
// call bufferData to establish a backing storage of zero bytes.
|
|
if (data && size) {
|
|
GLctx.bufferData(target, HEAPU8, usage, data, size);
|
|
} else {
|
|
GLctx.bufferData(target, size, usage);
|
|
}
|
|
return;
|
|
}
|
|
// N.b. here first form specifies a heap subarray, second form an integer
|
|
// size, so the ?: code here is polymorphic. It is advised to avoid
|
|
// randomly mixing both uses in calling code, to avoid any potential JS
|
|
// engine JIT issues.
|
|
GLctx.bufferData(target, data ? HEAPU8.subarray(data, data+size) : size, usage);
|
|
;
|
|
}
|
|
|
|
|
|
function _glBufferSubData(target, offset, size, data) {
|
|
offset = bigintToI53Checked(offset);
|
|
size = bigintToI53Checked(size);
|
|
data = bigintToI53Checked(data);
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
size && GLctx.bufferSubData(target, offset, HEAPU8, data, size);
|
|
return;
|
|
}
|
|
GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data+size));
|
|
;
|
|
}
|
|
|
|
var _glClearBufferfi = (x0, x1, x2, x3) => GLctx.clearBufferfi(x0, x1, x2, x3);
|
|
|
|
function _glClearBufferfv(buffer, drawbuffer, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
GLctx.clearBufferfv(buffer, drawbuffer, HEAPF32, ((value)/4));
|
|
;
|
|
}
|
|
|
|
function _glClearBufferiv(buffer, drawbuffer, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
GLctx.clearBufferiv(buffer, drawbuffer, HEAP32, ((value)/4));
|
|
;
|
|
}
|
|
|
|
var _glColorMask = (red, green, blue, alpha) => {
|
|
GLctx.colorMask(!!red, !!green, !!blue, !!alpha);
|
|
};
|
|
|
|
var _glCompileShader = (shader) => {
|
|
GLctx.compileShader(GL.shaders[shader]);
|
|
};
|
|
|
|
|
|
function _glCompressedTexImage2D(target, level, internalFormat, width, height, border, imageSize, data) {
|
|
data = bigintToI53Checked(data);
|
|
|
|
|
|
// `data` may be null here, which means "allocate uniniitalized space but
|
|
// don't upload" in GLES parlance, but `compressedTexImage2D` requires the
|
|
// final data parameter, so we simply pass a heap view starting at zero
|
|
// effectively uploading whatever happens to be near address zero. See
|
|
// https://github.com/emscripten-core/emscripten/issues/19300.
|
|
if (GL.currentContext.version >= 2) {
|
|
if (GLctx.currentPixelUnpackBufferBinding || !imageSize) {
|
|
GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, imageSize, data);
|
|
return;
|
|
}
|
|
GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, HEAPU8, data, imageSize);
|
|
return;
|
|
}
|
|
GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, HEAPU8.subarray((data), data+imageSize));
|
|
;
|
|
}
|
|
|
|
function _glCompressedTexImage3D(target, level, internalFormat, width, height, depth, border, imageSize, data) {
|
|
data = bigintToI53Checked(data);
|
|
|
|
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.compressedTexImage3D(target, level, internalFormat, width, height, depth, border, imageSize, data);
|
|
} else {
|
|
GLctx.compressedTexImage3D(target, level, internalFormat, width, height, depth, border, HEAPU8, data, imageSize);
|
|
}
|
|
;
|
|
}
|
|
|
|
var _glCreateProgram = () => {
|
|
var id = GL.getNewId(GL.programs);
|
|
var program = GLctx.createProgram();
|
|
// Store additional information needed for each shader program:
|
|
program.name = id;
|
|
// Lazy cache results of
|
|
// glGetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH/GL_ACTIVE_ATTRIBUTE_MAX_LENGTH/GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH)
|
|
program.maxUniformLength = program.maxAttributeLength = program.maxUniformBlockNameLength = 0;
|
|
program.uniformIdCounter = 1;
|
|
GL.programs[id] = program;
|
|
return id;
|
|
};
|
|
|
|
var _glCreateShader = (shaderType) => {
|
|
var id = GL.getNewId(GL.shaders);
|
|
GL.shaders[id] = GLctx.createShader(shaderType);
|
|
|
|
return id;
|
|
};
|
|
|
|
var _glCullFace = (x0) => GLctx.cullFace(x0);
|
|
|
|
|
|
function _glDeleteBuffers(n, buffers) {
|
|
buffers = bigintToI53Checked(buffers);
|
|
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((buffers)+(i*4))/4)];
|
|
var buffer = GL.buffers[id];
|
|
|
|
// From spec: "glDeleteBuffers silently ignores 0's and names that do not
|
|
// correspond to existing buffer objects."
|
|
if (!buffer) continue;
|
|
|
|
GLctx.deleteBuffer(buffer);
|
|
buffer.name = 0;
|
|
GL.buffers[id] = null;
|
|
|
|
if (id == GLctx.currentPixelPackBufferBinding) GLctx.currentPixelPackBufferBinding = 0;
|
|
if (id == GLctx.currentPixelUnpackBufferBinding) GLctx.currentPixelUnpackBufferBinding = 0;
|
|
}
|
|
;
|
|
}
|
|
|
|
|
|
function _glDeleteFramebuffers(n, framebuffers) {
|
|
framebuffers = bigintToI53Checked(framebuffers);
|
|
|
|
|
|
for (var i = 0; i < n; ++i) {
|
|
var id = HEAP32[(((framebuffers)+(i*4))/4)];
|
|
var framebuffer = GL.framebuffers[id];
|
|
if (!framebuffer) continue; // GL spec: "glDeleteFramebuffers silently ignores 0s and names that do not correspond to existing framebuffer objects".
|
|
GLctx.deleteFramebuffer(framebuffer);
|
|
framebuffer.name = 0;
|
|
GL.framebuffers[id] = null;
|
|
}
|
|
;
|
|
}
|
|
|
|
var _glDeleteProgram = (id) => {
|
|
if (!id) return;
|
|
var program = GL.programs[id];
|
|
if (!program) {
|
|
// glDeleteProgram actually signals an error when deleting a nonexisting
|
|
// object, unlike some other GL delete functions.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
GLctx.deleteProgram(program);
|
|
program.name = 0;
|
|
GL.programs[id] = null;
|
|
};
|
|
|
|
|
|
function _glDeleteRenderbuffers(n, renderbuffers) {
|
|
renderbuffers = bigintToI53Checked(renderbuffers);
|
|
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((renderbuffers)+(i*4))/4)];
|
|
var renderbuffer = GL.renderbuffers[id];
|
|
if (!renderbuffer) continue; // GL spec: "glDeleteRenderbuffers silently ignores 0s and names that do not correspond to existing renderbuffer objects".
|
|
GLctx.deleteRenderbuffer(renderbuffer);
|
|
renderbuffer.name = 0;
|
|
GL.renderbuffers[id] = null;
|
|
}
|
|
;
|
|
}
|
|
|
|
function _glDeleteSamplers(n, samplers) {
|
|
samplers = bigintToI53Checked(samplers);
|
|
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((samplers)+(i*4))/4)];
|
|
var sampler = GL.samplers[id];
|
|
if (!sampler) continue;
|
|
GLctx.deleteSampler(sampler);
|
|
sampler.name = 0;
|
|
GL.samplers[id] = null;
|
|
}
|
|
;
|
|
}
|
|
|
|
var _glDeleteShader = (id) => {
|
|
if (!id) return;
|
|
var shader = GL.shaders[id];
|
|
if (!shader) {
|
|
// glDeleteShader actually signals an error when deleting a nonexisting
|
|
// object, unlike some other GL delete functions.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
GLctx.deleteShader(shader);
|
|
GL.shaders[id] = null;
|
|
};
|
|
|
|
|
|
function _glDeleteTextures(n, textures) {
|
|
textures = bigintToI53Checked(textures);
|
|
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((textures)+(i*4))/4)];
|
|
var texture = GL.textures[id];
|
|
// GL spec: "glDeleteTextures silently ignores 0s and names that do not
|
|
// correspond to existing textures".
|
|
if (!texture) continue;
|
|
GLctx.deleteTexture(texture);
|
|
texture.name = 0;
|
|
GL.textures[id] = null;
|
|
}
|
|
;
|
|
}
|
|
|
|
|
|
function _glDeleteVertexArrays(n, vaos) {
|
|
vaos = bigintToI53Checked(vaos);
|
|
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((vaos)+(i*4))/4)];
|
|
GLctx.deleteVertexArray(GL.vaos[id]);
|
|
GL.vaos[id] = null;
|
|
}
|
|
;
|
|
}
|
|
|
|
var _glDepthFunc = (x0) => GLctx.depthFunc(x0);
|
|
|
|
var _glDepthMask = (flag) => {
|
|
GLctx.depthMask(!!flag);
|
|
};
|
|
|
|
var _glDisable = (x0) => GLctx.disable(x0);
|
|
|
|
var _glDisableVertexAttribArray = (index) => {
|
|
GLctx.disableVertexAttribArray(index);
|
|
};
|
|
|
|
var _glDrawArrays = (mode, first, count) => {
|
|
|
|
GLctx.drawArrays(mode, first, count);
|
|
|
|
};
|
|
|
|
var _glDrawArraysInstanced = (mode, first, count, primcount) => {
|
|
GLctx.drawArraysInstanced(mode, first, count, primcount);
|
|
};
|
|
|
|
|
|
function _glDrawElements(mode, count, type, indices) {
|
|
indices = bigintToI53Checked(indices);
|
|
|
|
|
|
|
|
GLctx.drawElements(mode, count, type, indices);
|
|
|
|
;
|
|
}
|
|
|
|
|
|
function _glDrawElementsInstanced(mode, count, type, indices, primcount) {
|
|
indices = bigintToI53Checked(indices);
|
|
|
|
|
|
GLctx.drawElementsInstanced(mode, count, type, indices, primcount);
|
|
;
|
|
}
|
|
|
|
var _glEnable = (x0) => GLctx.enable(x0);
|
|
|
|
var _glEnableVertexAttribArray = (index) => {
|
|
GLctx.enableVertexAttribArray(index);
|
|
};
|
|
|
|
var _glFrontFace = (x0) => GLctx.frontFace(x0);
|
|
|
|
|
|
function _glGenBuffers(n, buffers) {
|
|
buffers = bigintToI53Checked(buffers);
|
|
|
|
|
|
GL.genObject(n, buffers, 'createBuffer', GL.buffers
|
|
);
|
|
;
|
|
}
|
|
|
|
|
|
function _glGenRenderbuffers(n, renderbuffers) {
|
|
renderbuffers = bigintToI53Checked(renderbuffers);
|
|
|
|
|
|
GL.genObject(n, renderbuffers, 'createRenderbuffer', GL.renderbuffers
|
|
);
|
|
;
|
|
}
|
|
|
|
function _glGenSamplers(n, samplers) {
|
|
samplers = bigintToI53Checked(samplers);
|
|
|
|
|
|
GL.genObject(n, samplers, 'createSampler', GL.samplers
|
|
);
|
|
;
|
|
}
|
|
|
|
|
|
function _glGenTextures(n, textures) {
|
|
textures = bigintToI53Checked(textures);
|
|
|
|
|
|
GL.genObject(n, textures, 'createTexture', GL.textures
|
|
);
|
|
;
|
|
}
|
|
|
|
|
|
function _glGenVertexArrays(n, arrays) {
|
|
arrays = bigintToI53Checked(arrays);
|
|
|
|
|
|
GL.genObject(n, arrays, 'createVertexArray', GL.vaos
|
|
);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
function _glGetAttribLocation(program, name) {
|
|
name = bigintToI53Checked(name);
|
|
|
|
return GLctx.getAttribLocation(GL.programs[program], UTF8ToString(name));
|
|
}
|
|
|
|
var _glGetError = () => {
|
|
var error = GLctx.getError() || GL.lastError;
|
|
GL.lastError = 0/*GL_NO_ERROR*/;
|
|
return error;
|
|
};
|
|
|
|
var readI53FromI64 = (ptr) => {
|
|
return HEAPU32[((ptr)/4)] + HEAP32[(((ptr)+(4))/4)] * 4294967296;
|
|
};
|
|
|
|
var readI53FromU64 = (ptr) => {
|
|
return HEAPU32[((ptr)/4)] + HEAPU32[(((ptr)+(4))/4)] * 4294967296;
|
|
};
|
|
var writeI53ToI64 = (ptr, num) => {
|
|
HEAPU32[((ptr)/4)] = num;
|
|
var lower = HEAPU32[((ptr)/4)];
|
|
HEAPU32[(((ptr)+(4))/4)] = (num - lower)/4294967296;
|
|
var deserialized = (num >= 0) ? readI53FromU64(ptr) : readI53FromI64(ptr);
|
|
var offset = ((ptr)/4);
|
|
if (deserialized != num) warnOnce(`writeI53ToI64() out of range: serialized JS Number ${num} to Wasm heap as bytes lo=${ptrToString(HEAPU32[offset])}, hi=${ptrToString(HEAPU32[offset+1])}, which deserializes back to ${deserialized} instead!`);
|
|
};
|
|
|
|
|
|
var webglGetExtensions = () => {
|
|
var exts = getEmscriptenSupportedExtensions(GLctx);
|
|
exts = exts.concat(exts.map((e) => "GL_" + e));
|
|
return exts;
|
|
};
|
|
|
|
var 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(0x501 /* 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 != 0 && type != 1) {
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
}
|
|
// Do not write anything to the out pointer, since no binary formats are
|
|
// supported.
|
|
return;
|
|
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) {
|
|
// Calling GLES3/WebGL2 function with a GLES2/WebGL1 context
|
|
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
|
|
return;
|
|
}
|
|
ret = webglGetExtensions().length;
|
|
break;
|
|
case 0x821B: // GL_MAJOR_VERSION
|
|
case 0x821C: // GL_MINOR_VERSION
|
|
if (GL.currentContext.version < 2) {
|
|
GL.recordError(0x500); // 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(0x500); // 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 or DRAW_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 0x8F36: // COPY_READ_BUFFER_BINDING or COPY_READ_BUFFER
|
|
case 0x8F37: // COPY_WRITE_BUFFER_BINDING or COPY_WRITE_BUFFER
|
|
case 0x88ED: // PIXEL_PACK_BUFFER_BINDING
|
|
case 0x88EF: // PIXEL_UNPACK_BUFFER_BINDING
|
|
case 0x8CAA: // READ_FRAMEBUFFER_BINDING
|
|
case 0x8919: // SAMPLER_BINDING
|
|
case 0x8C1D: // TEXTURE_BINDING_2D_ARRAY
|
|
case 0x806A: // TEXTURE_BINDING_3D
|
|
case 0x8E25: // TRANSFORM_FEEDBACK_BINDING
|
|
case 0x8C8F: // TRANSFORM_FEEDBACK_BUFFER_BINDING
|
|
case 0x8A28: // UNIFORM_BUFFER_BINDING
|
|
case 0x8514: { // TEXTURE_BINDING_CUBE_MAP
|
|
ret = 0;
|
|
break;
|
|
}
|
|
default: {
|
|
GL.recordError(0x500); // 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 0: HEAP32[(((p)+(i*4))/4)] = result[i]; break;
|
|
case 2: HEAPF32[(((p)+(i*4))/4)] = result[i]; break;
|
|
case 4: HEAP8[(p)+(i)] = result[i] ? 1 : 0; break;
|
|
}
|
|
}
|
|
return;
|
|
} else {
|
|
try {
|
|
ret = result.name | 0;
|
|
} catch(e) {
|
|
GL.recordError(0x500); // 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(0x500); // GL_INVALID_ENUM
|
|
err(`GL_INVALID_ENUM in glGet${type}v: Native code calling glGet${type}v(${name_}) and it returns ${result} of type ${typeof(result)}!`);
|
|
return;
|
|
}
|
|
}
|
|
|
|
switch (type) {
|
|
case 1: writeI53ToI64(p, ret); break;
|
|
case 0: HEAP32[((p)/4)] = ret; break;
|
|
case 2: HEAPF32[((p)/4)] = ret; break;
|
|
case 4: HEAP8[p] = ret ? 1 : 0; break;
|
|
}
|
|
};
|
|
|
|
|
|
function _glGetIntegerv(name_, p) {
|
|
p = bigintToI53Checked(p);
|
|
|
|
return emscriptenWebGLGet(name_, p, 0);
|
|
}
|
|
|
|
|
|
function _glGetProgramInfoLog(program, maxLength, length, infoLog) {
|
|
length = bigintToI53Checked(length);
|
|
infoLog = bigintToI53Checked(infoLog);
|
|
|
|
|
|
var log = GLctx.getProgramInfoLog(GL.programs[program]);
|
|
if (log === null) log = '(unknown error)';
|
|
var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0;
|
|
if (length) HEAP32[((length)/4)] = numBytesWrittenExclNull;
|
|
;
|
|
}
|
|
|
|
|
|
function _glGetProgramiv(program, pname, p) {
|
|
p = bigintToI53Checked(p);
|
|
|
|
|
|
if (!p) {
|
|
// GLES2 specification does not specify how to behave if p is a null
|
|
// pointer. Since calling this function does not make sense if p == null,
|
|
// issue a GL error to notify user about it.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
|
|
if (program >= GL.counter) {
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
|
|
program = GL.programs[program];
|
|
|
|
if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
|
|
var log = GLctx.getProgramInfoLog(program);
|
|
if (log === null) log = '(unknown error)';
|
|
HEAP32[((p)/4)] = log.length + 1;
|
|
} else if (pname == 0x8B87 /* GL_ACTIVE_UNIFORM_MAX_LENGTH */) {
|
|
if (!program.maxUniformLength) {
|
|
var numActiveUniforms = GLctx.getProgramParameter(program, 0x8B86/*GL_ACTIVE_UNIFORMS*/);
|
|
for (var i = 0; i < numActiveUniforms; ++i) {
|
|
program.maxUniformLength = Math.max(program.maxUniformLength, GLctx.getActiveUniform(program, i).name.length+1);
|
|
}
|
|
}
|
|
HEAP32[((p)/4)] = program.maxUniformLength;
|
|
} else if (pname == 0x8B8A /* GL_ACTIVE_ATTRIBUTE_MAX_LENGTH */) {
|
|
if (!program.maxAttributeLength) {
|
|
var numActiveAttributes = GLctx.getProgramParameter(program, 0x8B89/*GL_ACTIVE_ATTRIBUTES*/);
|
|
for (var i = 0; i < numActiveAttributes; ++i) {
|
|
program.maxAttributeLength = Math.max(program.maxAttributeLength, GLctx.getActiveAttrib(program, i).name.length+1);
|
|
}
|
|
}
|
|
HEAP32[((p)/4)] = program.maxAttributeLength;
|
|
} else if (pname == 0x8A35 /* GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */) {
|
|
if (!program.maxUniformBlockNameLength) {
|
|
var numActiveUniformBlocks = GLctx.getProgramParameter(program, 0x8A36/*GL_ACTIVE_UNIFORM_BLOCKS*/);
|
|
for (var i = 0; i < numActiveUniformBlocks; ++i) {
|
|
program.maxUniformBlockNameLength = Math.max(program.maxUniformBlockNameLength, GLctx.getActiveUniformBlockName(program, i).length+1);
|
|
}
|
|
}
|
|
HEAP32[((p)/4)] = program.maxUniformBlockNameLength;
|
|
} else {
|
|
HEAP32[((p)/4)] = GLctx.getProgramParameter(program, pname);
|
|
}
|
|
;
|
|
}
|
|
|
|
|
|
|
|
function _glGetShaderInfoLog(shader, maxLength, length, infoLog) {
|
|
length = bigintToI53Checked(length);
|
|
infoLog = bigintToI53Checked(infoLog);
|
|
|
|
|
|
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
|
|
if (log === null) log = '(unknown error)';
|
|
var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0;
|
|
if (length) HEAP32[((length)/4)] = numBytesWrittenExclNull;
|
|
;
|
|
}
|
|
|
|
|
|
function _glGetShaderiv(shader, pname, p) {
|
|
p = bigintToI53Checked(p);
|
|
|
|
|
|
if (!p) {
|
|
// GLES2 specification does not specify how to behave if p is a null
|
|
// pointer. Since calling this function does not make sense if p == null,
|
|
// issue a GL error to notify user about it.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
|
|
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
|
|
if (log === null) log = '(unknown error)';
|
|
// The GLES2 specification says that if the shader has an empty info log,
|
|
// a value of 0 is returned. Otherwise the log has a null char appended.
|
|
// (An empty string is falsey, so we can just check that instead of
|
|
// looking at log.length.)
|
|
var logLength = log ? log.length + 1 : 0;
|
|
HEAP32[((p)/4)] = logLength;
|
|
} else if (pname == 0x8B88) { // GL_SHADER_SOURCE_LENGTH
|
|
var source = GLctx.getShaderSource(GL.shaders[shader]);
|
|
// source may be a null, or the empty string, both of which are falsey
|
|
// values that we report a 0 length for.
|
|
var sourceLength = source ? source.length + 1 : 0;
|
|
HEAP32[((p)/4)] = sourceLength;
|
|
} else {
|
|
HEAP32[((p)/4)] = GLctx.getShaderParameter(GL.shaders[shader], pname);
|
|
}
|
|
;
|
|
}
|
|
|
|
|
|
var 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 c = str.charCodeAt(i); // possibly a lead surrogate
|
|
if (c <= 0x7F) {
|
|
len++;
|
|
} else if (c <= 0x7FF) {
|
|
len += 2;
|
|
} else if (c >= 0xD800 && c <= 0xDFFF) {
|
|
len += 4; ++i;
|
|
} else {
|
|
len += 3;
|
|
}
|
|
}
|
|
return len;
|
|
};
|
|
|
|
|
|
var stringToNewUTF8 = (str) => {
|
|
var size = lengthBytesUTF8(str) + 1;
|
|
var ret = _malloc(size);
|
|
if (ret) stringToUTF8(str, ret, size);
|
|
return ret;
|
|
};
|
|
|
|
var _glGetStringi = function(name, index) {
|
|
|
|
var ret = (() => {
|
|
if (GL.currentContext.version < 2) {
|
|
GL.recordError(0x502 /* GL_INVALID_OPERATION */); // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context
|
|
return 0;
|
|
}
|
|
var stringiCache = GL.stringiCache[name];
|
|
if (stringiCache) {
|
|
if (index < 0 || index >= stringiCache.length) {
|
|
GL.recordError(0x501/*GL_INVALID_VALUE*/);
|
|
return 0;
|
|
}
|
|
return stringiCache[index];
|
|
}
|
|
switch (name) {
|
|
case 0x1F03 /* GL_EXTENSIONS */:
|
|
var exts = webglGetExtensions().map(stringToNewUTF8);
|
|
stringiCache = GL.stringiCache[name] = exts;
|
|
if (index < 0 || index >= stringiCache.length) {
|
|
GL.recordError(0x501/*GL_INVALID_VALUE*/);
|
|
return 0;
|
|
}
|
|
return stringiCache[index];
|
|
default:
|
|
GL.recordError(0x500/*GL_INVALID_ENUM*/);
|
|
return 0;
|
|
}
|
|
})();
|
|
return BigInt(ret);
|
|
};
|
|
|
|
/** @suppress {checkTypes} */
|
|
var jstoi_q = (str) => parseInt(str);
|
|
|
|
/** @noinline */
|
|
var webglGetLeftBracePos = (name) => name.slice(-1) == ']' && name.lastIndexOf('[');
|
|
|
|
var webglPrepareUniformLocationsBeforeFirstUse = (program) => {
|
|
var uniformLocsById = program.uniformLocsById, // Maps GLuint -> WebGLUniformLocation
|
|
uniformSizeAndIdsByName = program.uniformSizeAndIdsByName, // Maps name -> [uniform array length, GLuint]
|
|
i, j;
|
|
|
|
// On the first time invocation of glGetUniformLocation on this shader program:
|
|
// initialize cache data structures and discover which uniforms are arrays.
|
|
if (!uniformLocsById) {
|
|
// maps GLint integer locations to WebGLUniformLocations
|
|
program.uniformLocsById = uniformLocsById = {};
|
|
// maps integer locations back to uniform name strings, so that we can lazily fetch uniform array locations
|
|
program.uniformArrayNamesById = {};
|
|
|
|
var numActiveUniforms = GLctx.getProgramParameter(program, 0x8B86/*GL_ACTIVE_UNIFORMS*/);
|
|
for (i = 0; i < numActiveUniforms; ++i) {
|
|
var u = GLctx.getActiveUniform(program, i);
|
|
var nm = u.name;
|
|
var sz = u.size;
|
|
var lb = webglGetLeftBracePos(nm);
|
|
var arrayName = lb > 0 ? nm.slice(0, lb) : nm;
|
|
|
|
// Assign a new location.
|
|
var id = program.uniformIdCounter;
|
|
program.uniformIdCounter += sz;
|
|
// Eagerly get the location of the uniformArray[0] base element.
|
|
// The remaining indices >0 will be left for lazy evaluation to
|
|
// improve performance. Those may never be needed to fetch, if the
|
|
// application fills arrays always in full starting from the first
|
|
// element of the array.
|
|
uniformSizeAndIdsByName[arrayName] = [sz, id];
|
|
|
|
// Store placeholder integers in place that highlight that these
|
|
// >0 index locations are array indices pending population.
|
|
for (j = 0; j < sz; ++j) {
|
|
uniformLocsById[id] = j;
|
|
program.uniformArrayNamesById[id++] = arrayName;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
function _glGetUniformLocation(program, name) {
|
|
name = bigintToI53Checked(name);
|
|
|
|
|
|
|
|
name = UTF8ToString(name);
|
|
|
|
if (program = GL.programs[program]) {
|
|
webglPrepareUniformLocationsBeforeFirstUse(program);
|
|
var uniformLocsById = program.uniformLocsById; // Maps GLuint -> WebGLUniformLocation
|
|
var arrayIndex = 0;
|
|
var uniformBaseName = name;
|
|
|
|
// Invariant: when populating integer IDs for uniform locations, we must
|
|
// maintain the precondition that arrays reside in contiguous addresses,
|
|
// i.e. for a 'vec4 colors[10];', colors[4] must be at location
|
|
// colors[0]+4. However, user might call glGetUniformLocation(program,
|
|
// "colors") for an array, so we cannot discover based on the user input
|
|
// arguments whether the uniform we are dealing with is an array. The only
|
|
// way to discover which uniforms are arrays is to enumerate over all the
|
|
// active uniforms in the program.
|
|
var leftBrace = webglGetLeftBracePos(name);
|
|
|
|
// If user passed an array accessor "[index]", parse the array index off the accessor.
|
|
if (leftBrace > 0) {
|
|
arrayIndex = jstoi_q(name.slice(leftBrace + 1)) >>> 0; // "index]", coerce parseInt(']') with >>>0 to treat "foo[]" as "foo[0]" and foo[-1] as unsigned out-of-bounds.
|
|
uniformBaseName = name.slice(0, leftBrace);
|
|
}
|
|
|
|
// Have we cached the location of this uniform before?
|
|
// A pair [array length, GLint of the uniform location]
|
|
var sizeAndId = program.uniformSizeAndIdsByName[uniformBaseName];
|
|
|
|
// If an uniform with this name exists, and if its index is within the
|
|
// array limits (if it's even an array), query the WebGLlocation, or
|
|
// return an existing cached location.
|
|
if (sizeAndId && arrayIndex < sizeAndId[0]) {
|
|
arrayIndex += sizeAndId[1]; // Add the base location of the uniform to the array index offset.
|
|
if ((uniformLocsById[arrayIndex] = uniformLocsById[arrayIndex] || GLctx.getUniformLocation(program, name))) {
|
|
return arrayIndex;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
// N.b. we are currently unable to distinguish between GL program IDs that
|
|
// never existed vs GL program IDs that have been deleted, so report
|
|
// GL_INVALID_VALUE in both cases.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
}
|
|
return -1;
|
|
;
|
|
}
|
|
|
|
var tempFixedLengthArray = [];
|
|
|
|
function _glInvalidateFramebuffer(target, numAttachments, attachments) {
|
|
attachments = bigintToI53Checked(attachments);
|
|
|
|
|
|
var list = tempFixedLengthArray[numAttachments];
|
|
for (var i = 0; i < numAttachments; i++) {
|
|
list[i] = HEAP32[(((attachments)+(i*4))/4)];
|
|
}
|
|
|
|
GLctx.invalidateFramebuffer(target, list);
|
|
;
|
|
}
|
|
|
|
var _glLinkProgram = (program) => {
|
|
program = GL.programs[program];
|
|
GLctx.linkProgram(program);
|
|
// Invalidate earlier computed uniform->ID mappings, those have now become stale
|
|
program.uniformLocsById = 0; // Mark as null-like so that glGetUniformLocation() knows to populate this again.
|
|
program.uniformSizeAndIdsByName = {};
|
|
|
|
};
|
|
|
|
var _glPixelStorei = (pname, param) => {
|
|
if (pname == 3317) {
|
|
GL.unpackAlignment = param;
|
|
} else if (pname == 3314) {
|
|
GL.unpackRowLength = param;
|
|
}
|
|
GLctx.pixelStorei(pname, param);
|
|
};
|
|
|
|
var _glPolygonOffset = (x0, x1) => GLctx.polygonOffset(x0, x1);
|
|
|
|
var _glReadBuffer = (x0) => GLctx.readBuffer(x0);
|
|
|
|
var _glRenderbufferStorageMultisample = (x0, x1, x2, x3, x4) => GLctx.renderbufferStorageMultisample(x0, x1, x2, x3, x4);
|
|
|
|
var _glSamplerParameterf = (sampler, pname, param) => {
|
|
GLctx.samplerParameterf(GL.samplers[sampler], pname, param);
|
|
};
|
|
|
|
var _glSamplerParameteri = (sampler, pname, param) => {
|
|
GLctx.samplerParameteri(GL.samplers[sampler], pname, param);
|
|
};
|
|
|
|
var _glScissor = (x0, x1, x2, x3) => GLctx.scissor(x0, x1, x2, x3);
|
|
|
|
|
|
function _glShaderSource(shader, count, string, length) {
|
|
string = bigintToI53Checked(string);
|
|
length = bigintToI53Checked(length);
|
|
|
|
|
|
var source = GL.getSource(shader, count, string, length);
|
|
|
|
GLctx.shaderSource(GL.shaders[shader], source);
|
|
;
|
|
}
|
|
|
|
var _glStencilFunc = (x0, x1, x2) => GLctx.stencilFunc(x0, x1, x2);
|
|
|
|
var _glStencilFuncSeparate = (x0, x1, x2, x3) => GLctx.stencilFuncSeparate(x0, x1, x2, x3);
|
|
|
|
var _glStencilMask = (x0) => GLctx.stencilMask(x0);
|
|
|
|
var _glStencilOp = (x0, x1, x2) => GLctx.stencilOp(x0, x1, x2);
|
|
|
|
var _glStencilOpSeparate = (x0, x1, x2, x3) => GLctx.stencilOpSeparate(x0, x1, x2, x3);
|
|
|
|
var computeUnpackAlignedImageSize = (width, height, sizePerPixel) => {
|
|
function roundedToNextMultipleOf(x, y) {
|
|
return (x + y - 1) & -y;
|
|
}
|
|
var plainRowSize = (GL.unpackRowLength || width) * sizePerPixel;
|
|
var alignedRowSize = roundedToNextMultipleOf(plainRowSize, GL.unpackAlignment);
|
|
return height * alignedRowSize;
|
|
};
|
|
|
|
var colorChannelsInGlTextureFormat = (format) => {
|
|
// Micro-optimizations for size: map format to size by subtracting smallest
|
|
// enum value (0x1902) from all values first. Also omit the most common
|
|
// size value (1) from the list, which is assumed by formats not on the
|
|
// list.
|
|
var colorChannels = {
|
|
// 0x1902 /* GL_DEPTH_COMPONENT */ - 0x1902: 1,
|
|
// 0x1906 /* GL_ALPHA */ - 0x1902: 1,
|
|
5: 3,
|
|
6: 4,
|
|
// 0x1909 /* GL_LUMINANCE */ - 0x1902: 1,
|
|
8: 2,
|
|
29502: 3,
|
|
29504: 4,
|
|
// 0x1903 /* GL_RED */ - 0x1902: 1,
|
|
26917: 2,
|
|
26918: 2,
|
|
// 0x8D94 /* GL_RED_INTEGER */ - 0x1902: 1,
|
|
29846: 3,
|
|
29847: 4
|
|
};
|
|
return colorChannels[format - 0x1902]||1;
|
|
};
|
|
|
|
var heapObjectForWebGLType = (type) => {
|
|
// Micro-optimization for size: Subtract lowest GL enum number (0x1400/* GL_BYTE */) from type to compare
|
|
// smaller values for the heap, for shorter generated code size.
|
|
// Also the type HEAPU16 is not tested for explicitly, but any unrecognized type will return out HEAPU16.
|
|
// (since most types are HEAPU16)
|
|
type -= 0x1400;
|
|
if (type == 0) return HEAP8;
|
|
|
|
if (type == 1) return HEAPU8;
|
|
|
|
if (type == 2) return HEAP16;
|
|
|
|
if (type == 4) return HEAP32;
|
|
|
|
if (type == 6) return HEAPF32;
|
|
|
|
if (type == 5
|
|
|| type == 28922
|
|
|| type == 28520
|
|
|| type == 30779
|
|
|| type == 30782
|
|
)
|
|
return HEAPU32;
|
|
|
|
return HEAPU16;
|
|
};
|
|
|
|
var toTypedArrayIndex = (pointer, heap) =>
|
|
pointer / heap.BYTES_PER_ELEMENT;
|
|
|
|
var emscriptenWebGLGetTexPixelData = (type, format, width, height, pixels, internalFormat) => {
|
|
var heap = heapObjectForWebGLType(type);
|
|
var sizePerPixel = colorChannelsInGlTextureFormat(format) * heap.BYTES_PER_ELEMENT;
|
|
var bytes = computeUnpackAlignedImageSize(width, height, sizePerPixel);
|
|
return heap.subarray(toTypedArrayIndex(pixels, heap), toTypedArrayIndex(pixels + bytes, heap));
|
|
};
|
|
|
|
|
|
|
|
|
|
function _glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels) {
|
|
pixels = bigintToI53Checked(pixels);
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
|
|
return;
|
|
}
|
|
if (pixels) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
var index = toTypedArrayIndex(pixels, heap);
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, index);
|
|
return;
|
|
}
|
|
}
|
|
var pixelData = pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, internalFormat) : null;
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixelData);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
function _glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, pixels) {
|
|
pixels = bigintToI53Checked(pixels);
|
|
|
|
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, pixels);
|
|
} else if (pixels) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, heap, toTypedArrayIndex(pixels, heap));
|
|
} else {
|
|
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, null);
|
|
}
|
|
;
|
|
}
|
|
|
|
var _glTexParameteri = (x0, x1, x2) => GLctx.texParameteri(x0, x1, x2);
|
|
|
|
var _glTexStorage2D = (x0, x1, x2, x3, x4) => GLctx.texStorage2D(x0, x1, x2, x3, x4);
|
|
|
|
var _glTexStorage3D = (x0, x1, x2, x3, x4, x5) => GLctx.texStorage3D(x0, x1, x2, x3, x4, x5);
|
|
|
|
|
|
|
|
|
|
|
|
function _glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) {
|
|
pixels = bigintToI53Checked(pixels);
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
|
return;
|
|
}
|
|
if (pixels) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, toTypedArrayIndex(pixels, heap));
|
|
return;
|
|
}
|
|
}
|
|
var pixelData = pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, 0) : null;
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixelData);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
function _glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) {
|
|
pixels = bigintToI53Checked(pixels);
|
|
|
|
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
|
|
} else if (pixels) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, heap, toTypedArrayIndex(pixels, heap));
|
|
} else {
|
|
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, null);
|
|
}
|
|
;
|
|
}
|
|
|
|
var webglGetUniformLocation = (location) => {
|
|
var p = GLctx.currentProgram;
|
|
|
|
if (p) {
|
|
var webglLoc = p.uniformLocsById[location];
|
|
// p.uniformLocsById[location] stores either an integer, or a
|
|
// WebGLUniformLocation.
|
|
// If an integer, we have not yet bound the location, so do it now. The
|
|
// integer value specifies the array index we should bind to.
|
|
if (typeof webglLoc == 'number') {
|
|
p.uniformLocsById[location] = webglLoc = GLctx.getUniformLocation(p, p.uniformArrayNamesById[location] + (webglLoc > 0 ? `[${webglLoc}]` : ''));
|
|
}
|
|
// Else an already cached WebGLUniformLocation, return it.
|
|
return webglLoc;
|
|
} else {
|
|
GL.recordError(0x502/*GL_INVALID_OPERATION*/);
|
|
}
|
|
};
|
|
|
|
var miniTempWebGLFloatBuffers = [];
|
|
|
|
|
|
function _glUniform1fv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, ((value)/4), count);
|
|
return;
|
|
}
|
|
|
|
if (count <= 288) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[count];
|
|
for (var i = 0; i < count; ++i) {
|
|
view[i] = HEAPF32[(((value)+(4*i))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((((value)/4)), ((value+count*4)/4));
|
|
}
|
|
GLctx.uniform1fv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
var _glUniform1i = (location, v0) => {
|
|
GLctx.uniform1i(webglGetUniformLocation(location), v0);
|
|
};
|
|
|
|
|
|
var miniTempWebGLIntBuffers = [];
|
|
|
|
|
|
function _glUniform1iv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, ((value)/4), count);
|
|
return;
|
|
}
|
|
|
|
if (count <= 288) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLIntBuffers[count];
|
|
for (var i = 0; i < count; ++i) {
|
|
view[i] = HEAP32[(((value)+(4*i))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((((value)/4)), ((value+count*4)/4));
|
|
}
|
|
GLctx.uniform1iv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniform2fv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, ((value)/4), count*2);
|
|
return;
|
|
}
|
|
|
|
if (count <= 144) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
count *= 2;
|
|
var view = miniTempWebGLFloatBuffers[count];
|
|
for (var i = 0; i < count; i += 2) {
|
|
view[i] = HEAPF32[(((value)+(4*i))/4)];
|
|
view[i+1] = HEAPF32[(((value)+(4*i+4))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((((value)/4)), ((value+count*8)/4));
|
|
}
|
|
GLctx.uniform2fv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniform2iv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform2iv(webglGetUniformLocation(location), HEAP32, ((value)/4), count*2);
|
|
return;
|
|
}
|
|
|
|
if (count <= 144) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
count *= 2;
|
|
var view = miniTempWebGLIntBuffers[count];
|
|
for (var i = 0; i < count; i += 2) {
|
|
view[i] = HEAP32[(((value)+(4*i))/4)];
|
|
view[i+1] = HEAP32[(((value)+(4*i+4))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((((value)/4)), ((value+count*8)/4));
|
|
}
|
|
GLctx.uniform2iv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniform3fv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, ((value)/4), count*3);
|
|
return;
|
|
}
|
|
|
|
if (count <= 96) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
count *= 3;
|
|
var view = miniTempWebGLFloatBuffers[count];
|
|
for (var i = 0; i < count; i += 3) {
|
|
view[i] = HEAPF32[(((value)+(4*i))/4)];
|
|
view[i+1] = HEAPF32[(((value)+(4*i+4))/4)];
|
|
view[i+2] = HEAPF32[(((value)+(4*i+8))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((((value)/4)), ((value+count*12)/4));
|
|
}
|
|
GLctx.uniform3fv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniform3iv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform3iv(webglGetUniformLocation(location), HEAP32, ((value)/4), count*3);
|
|
return;
|
|
}
|
|
|
|
if (count <= 96) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
count *= 3;
|
|
var view = miniTempWebGLIntBuffers[count];
|
|
for (var i = 0; i < count; i += 3) {
|
|
view[i] = HEAP32[(((value)+(4*i))/4)];
|
|
view[i+1] = HEAP32[(((value)+(4*i+4))/4)];
|
|
view[i+2] = HEAP32[(((value)+(4*i+8))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((((value)/4)), ((value+count*12)/4));
|
|
}
|
|
GLctx.uniform3iv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniform4fv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, ((value)/4), count*4);
|
|
return;
|
|
}
|
|
|
|
if (count <= 72) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[4*count];
|
|
// hoist the heap out of the loop for size and for pthreads+growth.
|
|
var heap = HEAPF32;
|
|
value = ((value)/4);
|
|
count *= 4;
|
|
for (var i = 0; i < count; i += 4) {
|
|
var dst = value + i;
|
|
view[i] = heap[dst];
|
|
view[i + 1] = heap[dst + 1];
|
|
view[i + 2] = heap[dst + 2];
|
|
view[i + 3] = heap[dst + 3];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((((value)/4)), ((value+count*16)/4));
|
|
}
|
|
GLctx.uniform4fv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniform4iv(location, count, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, ((value)/4), count*4);
|
|
return;
|
|
}
|
|
|
|
if (count <= 72) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
count *= 4;
|
|
var view = miniTempWebGLIntBuffers[count];
|
|
for (var i = 0; i < count; i += 4) {
|
|
view[i] = HEAP32[(((value)+(4*i))/4)];
|
|
view[i+1] = HEAP32[(((value)+(4*i+4))/4)];
|
|
view[i+2] = HEAP32[(((value)+(4*i+8))/4)];
|
|
view[i+3] = HEAP32[(((value)+(4*i+12))/4)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((((value)/4)), ((value+count*16)/4));
|
|
}
|
|
GLctx.uniform4iv(webglGetUniformLocation(location), view);
|
|
;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _glUniformMatrix4fv(location, count, transpose, value) {
|
|
value = bigintToI53Checked(value);
|
|
|
|
|
|
|
|
if (GL.currentContext.version >= 2) {
|
|
count && GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, ((value)/4), count*16);
|
|
return;
|
|
}
|
|
|
|
if (count <= 18) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[16*count];
|
|
// hoist the heap out of the loop for size and for pthreads+growth.
|
|
var heap = HEAPF32;
|
|
value = ((value)/4);
|
|
count *= 16;
|
|
for (var i = 0; i < count; i += 16) {
|
|
var dst = value + i;
|
|
view[i] = heap[dst];
|
|
view[i + 1] = heap[dst + 1];
|
|
view[i + 2] = heap[dst + 2];
|
|
view[i + 3] = heap[dst + 3];
|
|
view[i + 4] = heap[dst + 4];
|
|
view[i + 5] = heap[dst + 5];
|
|
view[i + 6] = heap[dst + 6];
|
|
view[i + 7] = heap[dst + 7];
|
|
view[i + 8] = heap[dst + 8];
|
|
view[i + 9] = heap[dst + 9];
|
|
view[i + 10] = heap[dst + 10];
|
|
view[i + 11] = heap[dst + 11];
|
|
view[i + 12] = heap[dst + 12];
|
|
view[i + 13] = heap[dst + 13];
|
|
view[i + 14] = heap[dst + 14];
|
|
view[i + 15] = heap[dst + 15];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((((value)/4)), ((value+count*64)/4));
|
|
}
|
|
GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, view);
|
|
;
|
|
}
|
|
|
|
var _glUseProgram = (program) => {
|
|
program = GL.programs[program];
|
|
GLctx.useProgram(program);
|
|
// Record the currently active program so that we can access the uniform
|
|
// mapping table of that program.
|
|
GLctx.currentProgram = program;
|
|
};
|
|
|
|
var _glVertexAttribDivisor = (index, divisor) => {
|
|
GLctx.vertexAttribDivisor(index, divisor);
|
|
};
|
|
|
|
function _glVertexAttribIPointer(index, size, type, stride, ptr) {
|
|
ptr = bigintToI53Checked(ptr);
|
|
|
|
|
|
GLctx.vertexAttribIPointer(index, size, type, stride, ptr);
|
|
;
|
|
}
|
|
|
|
|
|
function _glVertexAttribPointer(index, size, type, normalized, stride, ptr) {
|
|
ptr = bigintToI53Checked(ptr);
|
|
|
|
|
|
GLctx.vertexAttribPointer(index, size, type, !!normalized, stride, ptr);
|
|
;
|
|
}
|
|
|
|
var _glViewport = (x0, x1, x2, x3) => GLctx.viewport(x0, x1, x2, x3);
|
|
|
|
var _wasm_debug_break = () => {
|
|
debugger;
|
|
};
|
|
|
|
var _wasm_write_string = (s_count, s_data, log_flag) => {
|
|
function js_string_from_jai_string(pointer, length) {
|
|
const text_decoder = new TextDecoder();
|
|
const u8 = new Uint8Array(wasmMemory.buffer)
|
|
const bytes = u8.subarray(Number(pointer), Number(pointer) + Number(length));
|
|
return text_decoder.decode(bytes);
|
|
}
|
|
|
|
const string = js_string_from_jai_string(s_data, s_count);
|
|
|
|
switch (log_flag) {
|
|
case /* ERROR */ 0x1: { console.error(string); } break;
|
|
case /* WARNING */ 0x2: { console.warn(string); } break;
|
|
case /* CONTENT */ 0x4: { console.info(`%c${string}`, "color: #3949ab;"); } break;
|
|
default: { console.log(string); }
|
|
}
|
|
// Module.print(string);
|
|
};
|
|
|
|
|
|
|
|
|
|
var withStackSave = (f) => {
|
|
var stack = stackSave();
|
|
var ret = f();
|
|
stackRestore(stack);
|
|
return ret;
|
|
};
|
|
|
|
|
|
|
|
var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
|
|
var stringToUTF8OnStack = (str) => {
|
|
var size = lengthBytesUTF8(str) + 1;
|
|
var ret = stackAlloc(size);
|
|
stringToUTF8(str, ret, size);
|
|
return ret;
|
|
};
|
|
|
|
|
|
Module['requestAnimationFrame'] = MainLoop.requestAnimationFrame;
|
|
Module['pauseMainLoop'] = MainLoop.pause;
|
|
Module['resumeMainLoop'] = MainLoop.resume;
|
|
MainLoop.init();;
|
|
for (let i = 0; i < 32; ++i) tempFixedLengthArray.push(new Array(i));;
|
|
var miniTempWebGLFloatBuffersStorage = new Float32Array(288);
|
|
// Create GL_POOL_TEMP_BUFFERS_SIZE+1 temporary buffers, for uploads of size 0 through GL_POOL_TEMP_BUFFERS_SIZE inclusive
|
|
for (/**@suppress{duplicate}*/var i = 0; i <= 288; ++i) {
|
|
miniTempWebGLFloatBuffers[i] = miniTempWebGLFloatBuffersStorage.subarray(0, i);
|
|
};
|
|
var miniTempWebGLIntBuffersStorage = new Int32Array(288);
|
|
// Create GL_POOL_TEMP_BUFFERS_SIZE+1 temporary buffers, for uploads of size 0 through GL_POOL_TEMP_BUFFERS_SIZE inclusive
|
|
for (/**@suppress{duplicate}*/var i = 0; i <= 288; ++i) {
|
|
miniTempWebGLIntBuffers[i] = miniTempWebGLIntBuffersStorage.subarray(0, i);
|
|
};
|
|
// End JS library code
|
|
|
|
function checkIncomingModuleAPI() {
|
|
ignoredModuleProp('fetchSettings');
|
|
}
|
|
function slog_js_log(level,c_str) { const str = UTF8ToString(c_str); switch (level) { case 0: console.error(str); break; case 1: console.error(str); break; case 2: console.warn(str); break; default: console.info(str); break; } }
|
|
function sapp_js_add_beforeunload_listener() { Module.sokol_beforeunload = (event) => { if (__sapp_html5_get_ask_leave_site() != 0) { event.preventDefault(); event.returnValue = ' '; } }; window.addEventListener('beforeunload', Module.sokol_beforeunload); }
|
|
function sapp_js_remove_beforeunload_listener() { window.removeEventListener('beforeunload', Module.sokol_beforeunload); }
|
|
function sapp_js_add_clipboard_listener() { Module.sokol_paste = (event) => { const pasted_str = event.clipboardData.getData('text'); withStackSave(() => { const cstr = stringToUTF8OnStack(pasted_str); __sapp_emsc_onpaste(cstr); }); }; window.addEventListener('paste', Module.sokol_paste); }
|
|
function sapp_js_remove_clipboard_listener() { window.removeEventListener('paste', Module.sokol_paste); }
|
|
function sapp_js_write_clipboard(c_str) { const str = UTF8ToString(c_str); const ta = document.createElement('textarea'); ta.setAttribute('autocomplete', 'off'); ta.setAttribute('autocorrect', 'off'); ta.setAttribute('autocapitalize', 'off'); ta.setAttribute('spellcheck', 'false'); ta.style.left = -100 + 'px'; ta.style.top = -100 + 'px'; ta.style.height = 1; ta.style.width = 1; ta.value = str; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); document.body.removeChild(ta); }
|
|
function sapp_js_add_dragndrop_listeners() { Module.sokol_drop_files = []; Module.sokol_dragenter = (event) => { event.stopPropagation(); event.preventDefault(); }; Module.sokol_dragleave = (event) => { event.stopPropagation(); event.preventDefault(); }; Module.sokol_dragover = (event) => { event.stopPropagation(); event.preventDefault(); }; Module.sokol_drop = (event) => { event.stopPropagation(); event.preventDefault(); const files = event.dataTransfer.files; Module.sokol_dropped_files = files; __sapp_emsc_begin_drop(files.length); for (let i = 0; i < files.length; i++) { withStackSave(() => { const cstr = stringToUTF8OnStack(files[i].name); __sapp_emsc_drop(i, cstr); }); } let mods = 0; if (event.shiftKey) { mods |= 1; } if (event.ctrlKey) { mods |= 2; } if (event.altKey) { mods |= 4; } if (event.metaKey) { mods |= 8; } __sapp_emsc_end_drop(event.clientX, event.clientY, mods); }; /** @suppress {missingProperties} */ const canvas = Module.sapp_emsc_target; canvas.addEventListener('dragenter', Module.sokol_dragenter, false); canvas.addEventListener('dragleave', Module.sokol_dragleave, false); canvas.addEventListener('dragover', Module.sokol_dragover, false); canvas.addEventListener('drop', Module.sokol_drop, false); }
|
|
function sapp_js_dropped_file_size(index) { /** @suppress {missingProperties} */ const files = Module.sokol_dropped_files; if ((index < 0) || (index >= files.length)) { return 0; } else { return files[index].size; } }
|
|
function sapp_js_fetch_dropped_file(index,callback,buf_ptr,buf_size,user_data) { const reader = new FileReader(); reader.onload = (loadEvent) => { const content = loadEvent.target.result; if (content.byteLength > buf_size) { __sapp_emsc_invoke_fetch_cb(index, 0, 1, callback, 0, buf_ptr, buf_size, user_data); } else { HEAPU8.set(new Uint8Array(content), buf_ptr); __sapp_emsc_invoke_fetch_cb(index, 1, 0, callback, content.byteLength, buf_ptr, buf_size, user_data); } }; reader.onerror = () => { __sapp_emsc_invoke_fetch_cb(index, 0, 2, callback, 0, buf_ptr, buf_size, user_data); }; /** @suppress {missingProperties} */ const files = Module.sokol_dropped_files; reader.readAsArrayBuffer(files[index]); }
|
|
function sapp_js_remove_dragndrop_listeners() { /** @suppress {missingProperties} */ const canvas = Module.sapp_emsc_target; canvas.removeEventListener('dragenter', Module.sokol_dragenter); canvas.removeEventListener('dragleave', Module.sokol_dragleave); canvas.removeEventListener('dragover', Module.sokol_dragover); canvas.removeEventListener('drop', Module.sokol_drop); }
|
|
function sapp_js_init(c_str_target_selector,c_str_document_title) { if (c_str_document_title !== 0) { document.title = UTF8ToString(c_str_document_title); } const target_selector_str = UTF8ToString(c_str_target_selector); if (Module['canvas'] !== undefined) { if (typeof Module['canvas'] === 'object') { specialHTMLTargets[target_selector_str] = Module['canvas']; } else { console.warn("sokol_app.h: Module['canvas'] is set but is not an object"); } } Module.sapp_emsc_target = findCanvasEventTarget(target_selector_str); if (!Module.sapp_emsc_target) { console.warn("sokol_app.h: can't find html5_canvas_selector ", target_selector_str); } if (!Module.sapp_emsc_target.requestPointerLock) { console.warn("sokol_app.h: target doesn't support requestPointerLock: ", target_selector_str); } }
|
|
function sapp_js_request_pointerlock() { if (Module.sapp_emsc_target) { if (Module.sapp_emsc_target.requestPointerLock) { Module.sapp_emsc_target.requestPointerLock(); } } }
|
|
function sapp_js_exit_pointerlock() { if (document.exitPointerLock) { document.exitPointerLock(); } }
|
|
function sapp_js_set_cursor(cursor_type,shown) { if (Module.sapp_emsc_target) { let cursor; if (shown === 0) { cursor = "none"; } else switch (cursor_type) { case 0: cursor = "auto"; break; case 1: cursor = "default"; break; case 2: cursor = "text"; break; case 3: cursor = "crosshair"; break; case 4: cursor = "pointer"; break; case 5: cursor = "ew-resize"; break; case 6: cursor = "ns-resize"; break; case 7: cursor = "nwse-resize"; break; case 8: cursor = "nesw-resize"; break; case 9: cursor = "all-scroll"; break; case 10: cursor = "not-allowed"; break; default: cursor = "auto"; break; } Module.sapp_emsc_target.style.cursor = cursor; } }
|
|
function sapp_js_clear_favicon() { const link = document.getElementById('sokol-app-favicon'); if (link) { document.head.removeChild(link); } }
|
|
function sapp_js_set_favicon(w,h,pixels) { const canvas = document.createElement('canvas'); canvas.width = w; canvas.height = h; const ctx = canvas.getContext('2d'); const img_data = ctx.createImageData(w, h); img_data.data.set(HEAPU8.subarray(pixels, pixels + w*h*4)); ctx.putImageData(img_data, 0, 0); const new_link = document.createElement('link'); new_link.id = 'sokol-app-favicon'; new_link.rel = 'shortcut icon'; new_link.href = canvas.toDataURL(); document.head.appendChild(new_link); }
|
|
function sfetch_js_send_head_request(slot_id,path_cstr) { const path_str = UTF8ToString(path_cstr); fetch(path_str, { method: 'HEAD' }).then((response) => { if (response.ok) { const content_length = response.headers.get('Content-Length'); if (content_length === null) { console.warn(`sokol_fetch.h: HEAD ${path_str} response has no Content-Length`); __sfetch_emsc_failed_other(slot_id); } else { __sfetch_emsc_head_response(slot_id, Number(content_length)); } } else { __sfetch_emsc_failed_http_status(slot_id, response.status); } }).catch((err) => { console.error(`sokol_fetch.h: HEAD ${path_str} failed with: `, err); __sfetch_emsc_failed_other(slot_id); }); }
|
|
function sfetch_js_send_get_request(slot_id,path_cstr,offset,bytes_to_read,buf_ptr,buf_size) { const path_str = UTF8ToString(path_cstr); const headers = new Headers(); const range_request = bytes_to_read > 0; if (range_request) { headers.append('Range', `bytes=${offset}-${offset+bytes_to_read-1}`); } fetch(path_str, { method: 'GET', headers }).then((response) => { if (response.ok) { response.arrayBuffer().then((data) => { const u8_data = new Uint8Array(data); if (u8_data.length <= buf_size) { HEAPU8.set(u8_data, buf_ptr); __sfetch_emsc_get_response(slot_id, bytes_to_read, u8_data.length); } else { __sfetch_emsc_failed_buffer_too_small(slot_id); } }).catch((err) => { console.error(`sokol_fetch.h: GET ${path_str} failed with: `, err); __sfetch_emsc_failed_other(slot_id); }); } else { __sfetch_emsc_failed_http_status(slot_id, response.status); } }).catch((err) => { console.error(`sokol_fetch.h: GET ${path_str} failed with: `, err); __sfetch_emsc_failed_other(slot_id); }); }
|
|
var wasmImports = {
|
|
/** @export */
|
|
__assert_fail: ___assert_fail,
|
|
/** @export */
|
|
_abort_js: __abort_js,
|
|
/** @export */
|
|
emscripten_cancel_main_loop: _emscripten_cancel_main_loop,
|
|
/** @export */
|
|
emscripten_get_device_pixel_ratio: _emscripten_get_device_pixel_ratio,
|
|
/** @export */
|
|
emscripten_get_element_css_size: _emscripten_get_element_css_size,
|
|
/** @export */
|
|
emscripten_get_now: _emscripten_get_now,
|
|
/** @export */
|
|
emscripten_performance_now: _emscripten_performance_now,
|
|
/** @export */
|
|
emscripten_request_animation_frame_loop: _emscripten_request_animation_frame_loop,
|
|
/** @export */
|
|
emscripten_resize_heap: _emscripten_resize_heap,
|
|
/** @export */
|
|
emscripten_set_blur_callback_on_thread: _emscripten_set_blur_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_canvas_element_size: _emscripten_set_canvas_element_size,
|
|
/** @export */
|
|
emscripten_set_focus_callback_on_thread: _emscripten_set_focus_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_keydown_callback_on_thread: _emscripten_set_keydown_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_keypress_callback_on_thread: _emscripten_set_keypress_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_keyup_callback_on_thread: _emscripten_set_keyup_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_main_loop: _emscripten_set_main_loop,
|
|
/** @export */
|
|
emscripten_set_mousedown_callback_on_thread: _emscripten_set_mousedown_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_mouseenter_callback_on_thread: _emscripten_set_mouseenter_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_mouseleave_callback_on_thread: _emscripten_set_mouseleave_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_mousemove_callback_on_thread: _emscripten_set_mousemove_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_mouseup_callback_on_thread: _emscripten_set_mouseup_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_pointerlockchange_callback_on_thread: _emscripten_set_pointerlockchange_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_pointerlockerror_callback_on_thread: _emscripten_set_pointerlockerror_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_resize_callback_on_thread: _emscripten_set_resize_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_touchcancel_callback_on_thread: _emscripten_set_touchcancel_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_touchend_callback_on_thread: _emscripten_set_touchend_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_touchmove_callback_on_thread: _emscripten_set_touchmove_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_touchstart_callback_on_thread: _emscripten_set_touchstart_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_webglcontextlost_callback_on_thread: _emscripten_set_webglcontextlost_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_webglcontextrestored_callback_on_thread: _emscripten_set_webglcontextrestored_callback_on_thread,
|
|
/** @export */
|
|
emscripten_set_wheel_callback_on_thread: _emscripten_set_wheel_callback_on_thread,
|
|
/** @export */
|
|
emscripten_webgl_create_context: _emscripten_webgl_create_context,
|
|
/** @export */
|
|
emscripten_webgl_make_context_current: _emscripten_webgl_make_context_current,
|
|
/** @export */
|
|
fd_close: _fd_close,
|
|
/** @export */
|
|
fd_seek: _fd_seek,
|
|
/** @export */
|
|
fd_write: _fd_write,
|
|
/** @export */
|
|
glActiveTexture: _glActiveTexture,
|
|
/** @export */
|
|
glAttachShader: _glAttachShader,
|
|
/** @export */
|
|
glBindBuffer: _glBindBuffer,
|
|
/** @export */
|
|
glBindBufferBase: _glBindBufferBase,
|
|
/** @export */
|
|
glBindFramebuffer: _glBindFramebuffer,
|
|
/** @export */
|
|
glBindRenderbuffer: _glBindRenderbuffer,
|
|
/** @export */
|
|
glBindSampler: _glBindSampler,
|
|
/** @export */
|
|
glBindTexture: _glBindTexture,
|
|
/** @export */
|
|
glBindVertexArray: _glBindVertexArray,
|
|
/** @export */
|
|
glBlendColor: _glBlendColor,
|
|
/** @export */
|
|
glBlendEquationSeparate: _glBlendEquationSeparate,
|
|
/** @export */
|
|
glBlendFuncSeparate: _glBlendFuncSeparate,
|
|
/** @export */
|
|
glBlitFramebuffer: _glBlitFramebuffer,
|
|
/** @export */
|
|
glBufferData: _glBufferData,
|
|
/** @export */
|
|
glBufferSubData: _glBufferSubData,
|
|
/** @export */
|
|
glClearBufferfi: _glClearBufferfi,
|
|
/** @export */
|
|
glClearBufferfv: _glClearBufferfv,
|
|
/** @export */
|
|
glClearBufferiv: _glClearBufferiv,
|
|
/** @export */
|
|
glColorMask: _glColorMask,
|
|
/** @export */
|
|
glCompileShader: _glCompileShader,
|
|
/** @export */
|
|
glCompressedTexImage2D: _glCompressedTexImage2D,
|
|
/** @export */
|
|
glCompressedTexImage3D: _glCompressedTexImage3D,
|
|
/** @export */
|
|
glCreateProgram: _glCreateProgram,
|
|
/** @export */
|
|
glCreateShader: _glCreateShader,
|
|
/** @export */
|
|
glCullFace: _glCullFace,
|
|
/** @export */
|
|
glDeleteBuffers: _glDeleteBuffers,
|
|
/** @export */
|
|
glDeleteFramebuffers: _glDeleteFramebuffers,
|
|
/** @export */
|
|
glDeleteProgram: _glDeleteProgram,
|
|
/** @export */
|
|
glDeleteRenderbuffers: _glDeleteRenderbuffers,
|
|
/** @export */
|
|
glDeleteSamplers: _glDeleteSamplers,
|
|
/** @export */
|
|
glDeleteShader: _glDeleteShader,
|
|
/** @export */
|
|
glDeleteTextures: _glDeleteTextures,
|
|
/** @export */
|
|
glDeleteVertexArrays: _glDeleteVertexArrays,
|
|
/** @export */
|
|
glDepthFunc: _glDepthFunc,
|
|
/** @export */
|
|
glDepthMask: _glDepthMask,
|
|
/** @export */
|
|
glDisable: _glDisable,
|
|
/** @export */
|
|
glDisableVertexAttribArray: _glDisableVertexAttribArray,
|
|
/** @export */
|
|
glDrawArrays: _glDrawArrays,
|
|
/** @export */
|
|
glDrawArraysInstanced: _glDrawArraysInstanced,
|
|
/** @export */
|
|
glDrawElements: _glDrawElements,
|
|
/** @export */
|
|
glDrawElementsInstanced: _glDrawElementsInstanced,
|
|
/** @export */
|
|
glEnable: _glEnable,
|
|
/** @export */
|
|
glEnableVertexAttribArray: _glEnableVertexAttribArray,
|
|
/** @export */
|
|
glFrontFace: _glFrontFace,
|
|
/** @export */
|
|
glGenBuffers: _glGenBuffers,
|
|
/** @export */
|
|
glGenRenderbuffers: _glGenRenderbuffers,
|
|
/** @export */
|
|
glGenSamplers: _glGenSamplers,
|
|
/** @export */
|
|
glGenTextures: _glGenTextures,
|
|
/** @export */
|
|
glGenVertexArrays: _glGenVertexArrays,
|
|
/** @export */
|
|
glGetAttribLocation: _glGetAttribLocation,
|
|
/** @export */
|
|
glGetError: _glGetError,
|
|
/** @export */
|
|
glGetIntegerv: _glGetIntegerv,
|
|
/** @export */
|
|
glGetProgramInfoLog: _glGetProgramInfoLog,
|
|
/** @export */
|
|
glGetProgramiv: _glGetProgramiv,
|
|
/** @export */
|
|
glGetShaderInfoLog: _glGetShaderInfoLog,
|
|
/** @export */
|
|
glGetShaderiv: _glGetShaderiv,
|
|
/** @export */
|
|
glGetStringi: _glGetStringi,
|
|
/** @export */
|
|
glGetUniformLocation: _glGetUniformLocation,
|
|
/** @export */
|
|
glInvalidateFramebuffer: _glInvalidateFramebuffer,
|
|
/** @export */
|
|
glLinkProgram: _glLinkProgram,
|
|
/** @export */
|
|
glPixelStorei: _glPixelStorei,
|
|
/** @export */
|
|
glPolygonOffset: _glPolygonOffset,
|
|
/** @export */
|
|
glReadBuffer: _glReadBuffer,
|
|
/** @export */
|
|
glRenderbufferStorageMultisample: _glRenderbufferStorageMultisample,
|
|
/** @export */
|
|
glSamplerParameterf: _glSamplerParameterf,
|
|
/** @export */
|
|
glSamplerParameteri: _glSamplerParameteri,
|
|
/** @export */
|
|
glScissor: _glScissor,
|
|
/** @export */
|
|
glShaderSource: _glShaderSource,
|
|
/** @export */
|
|
glStencilFunc: _glStencilFunc,
|
|
/** @export */
|
|
glStencilFuncSeparate: _glStencilFuncSeparate,
|
|
/** @export */
|
|
glStencilMask: _glStencilMask,
|
|
/** @export */
|
|
glStencilOp: _glStencilOp,
|
|
/** @export */
|
|
glStencilOpSeparate: _glStencilOpSeparate,
|
|
/** @export */
|
|
glTexImage2D: _glTexImage2D,
|
|
/** @export */
|
|
glTexImage3D: _glTexImage3D,
|
|
/** @export */
|
|
glTexParameteri: _glTexParameteri,
|
|
/** @export */
|
|
glTexStorage2D: _glTexStorage2D,
|
|
/** @export */
|
|
glTexStorage3D: _glTexStorage3D,
|
|
/** @export */
|
|
glTexSubImage2D: _glTexSubImage2D,
|
|
/** @export */
|
|
glTexSubImage3D: _glTexSubImage3D,
|
|
/** @export */
|
|
glUniform1fv: _glUniform1fv,
|
|
/** @export */
|
|
glUniform1i: _glUniform1i,
|
|
/** @export */
|
|
glUniform1iv: _glUniform1iv,
|
|
/** @export */
|
|
glUniform2fv: _glUniform2fv,
|
|
/** @export */
|
|
glUniform2iv: _glUniform2iv,
|
|
/** @export */
|
|
glUniform3fv: _glUniform3fv,
|
|
/** @export */
|
|
glUniform3iv: _glUniform3iv,
|
|
/** @export */
|
|
glUniform4fv: _glUniform4fv,
|
|
/** @export */
|
|
glUniform4iv: _glUniform4iv,
|
|
/** @export */
|
|
glUniformMatrix4fv: _glUniformMatrix4fv,
|
|
/** @export */
|
|
glUseProgram: _glUseProgram,
|
|
/** @export */
|
|
glVertexAttribDivisor: _glVertexAttribDivisor,
|
|
/** @export */
|
|
glVertexAttribIPointer: _glVertexAttribIPointer,
|
|
/** @export */
|
|
glVertexAttribPointer: _glVertexAttribPointer,
|
|
/** @export */
|
|
glViewport: _glViewport,
|
|
/** @export */
|
|
sapp_js_add_beforeunload_listener,
|
|
/** @export */
|
|
sapp_js_add_clipboard_listener,
|
|
/** @export */
|
|
sapp_js_add_dragndrop_listeners,
|
|
/** @export */
|
|
sapp_js_clear_favicon,
|
|
/** @export */
|
|
sapp_js_init,
|
|
/** @export */
|
|
sapp_js_remove_beforeunload_listener,
|
|
/** @export */
|
|
sapp_js_remove_clipboard_listener,
|
|
/** @export */
|
|
sapp_js_remove_dragndrop_listeners,
|
|
/** @export */
|
|
sapp_js_request_pointerlock,
|
|
/** @export */
|
|
sapp_js_set_favicon,
|
|
/** @export */
|
|
sfetch_js_send_get_request,
|
|
/** @export */
|
|
sfetch_js_send_head_request,
|
|
/** @export */
|
|
slog_js_log,
|
|
/** @export */
|
|
wasm_debug_break: _wasm_debug_break,
|
|
/** @export */
|
|
wasm_write_string: _wasm_write_string
|
|
};
|
|
var wasmExports;
|
|
createWasm();
|
|
var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors', 0);
|
|
var _main = Module['_main'] = createExportWrapper('main', 2);
|
|
var _malloc = createExportWrapper('malloc', 1);
|
|
var __sapp_emsc_onpaste = Module['__sapp_emsc_onpaste'] = createExportWrapper('_sapp_emsc_onpaste', 1);
|
|
var __sapp_html5_get_ask_leave_site = Module['__sapp_html5_get_ask_leave_site'] = createExportWrapper('_sapp_html5_get_ask_leave_site', 0);
|
|
var __sapp_emsc_begin_drop = Module['__sapp_emsc_begin_drop'] = createExportWrapper('_sapp_emsc_begin_drop', 1);
|
|
var __sapp_emsc_drop = Module['__sapp_emsc_drop'] = createExportWrapper('_sapp_emsc_drop', 2);
|
|
var __sapp_emsc_end_drop = Module['__sapp_emsc_end_drop'] = createExportWrapper('_sapp_emsc_end_drop', 3);
|
|
var __sapp_emsc_invoke_fetch_cb = Module['__sapp_emsc_invoke_fetch_cb'] = createExportWrapper('_sapp_emsc_invoke_fetch_cb', 8);
|
|
var __sfetch_emsc_head_response = Module['__sfetch_emsc_head_response'] = createExportWrapper('_sfetch_emsc_head_response', 2);
|
|
var __sfetch_emsc_get_response = Module['__sfetch_emsc_get_response'] = createExportWrapper('_sfetch_emsc_get_response', 3);
|
|
var __sfetch_emsc_failed_http_status = Module['__sfetch_emsc_failed_http_status'] = createExportWrapper('_sfetch_emsc_failed_http_status', 2);
|
|
var __sfetch_emsc_failed_buffer_too_small = Module['__sfetch_emsc_failed_buffer_too_small'] = createExportWrapper('_sfetch_emsc_failed_buffer_too_small', 1);
|
|
var __sfetch_emsc_failed_other = Module['__sfetch_emsc_failed_other'] = createExportWrapper('_sfetch_emsc_failed_other', 1);
|
|
var _fflush = createExportWrapper('fflush', 1);
|
|
var _strerror = createExportWrapper('strerror', 1);
|
|
var _emscripten_stack_init = () => (_emscripten_stack_init = wasmExports['emscripten_stack_init'])();
|
|
var _emscripten_stack_get_free = () => (_emscripten_stack_get_free = wasmExports['emscripten_stack_get_free'])();
|
|
var _emscripten_stack_get_base = () => (_emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'])();
|
|
var _emscripten_stack_get_end = () => (_emscripten_stack_get_end = wasmExports['emscripten_stack_get_end'])();
|
|
var __emscripten_stack_restore = (a0) => (__emscripten_stack_restore = wasmExports['_emscripten_stack_restore'])(a0);
|
|
var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'])(a0);
|
|
var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
|
|
|
|
// Argument name here must shadow the `wasmExports` global so
|
|
// that it is recognised by metadce and minify-import-export-names
|
|
// passes.
|
|
function applySignatureConversions(wasmExports) {
|
|
// First, make a copy of the incoming exports object
|
|
wasmExports = Object.assign({}, wasmExports);
|
|
var makeWrapper___PP = (f) => (a0, a1, a2) => f(a0, BigInt(a1 ? a1 : 0), BigInt(a2 ? a2 : 0));
|
|
var makeWrapper_pp = (f) => (a0) => Number(f(BigInt(a0)));
|
|
var makeWrapper__p = (f) => (a0) => f(BigInt(a0));
|
|
var makeWrapper_p_ = (f) => (a0) => Number(f(a0));
|
|
var makeWrapper_p = (f) => () => Number(f());
|
|
|
|
wasmExports['main'] = makeWrapper___PP(wasmExports['main']);
|
|
wasmExports['malloc'] = makeWrapper_pp(wasmExports['malloc']);
|
|
wasmExports['fflush'] = makeWrapper__p(wasmExports['fflush']);
|
|
wasmExports['strerror'] = makeWrapper_p_(wasmExports['strerror']);
|
|
wasmExports['emscripten_stack_get_base'] = makeWrapper_p(wasmExports['emscripten_stack_get_base']);
|
|
wasmExports['emscripten_stack_get_end'] = makeWrapper_p(wasmExports['emscripten_stack_get_end']);
|
|
wasmExports['_emscripten_stack_restore'] = makeWrapper__p(wasmExports['_emscripten_stack_restore']);
|
|
wasmExports['_emscripten_stack_alloc'] = makeWrapper_pp(wasmExports['_emscripten_stack_alloc']);
|
|
wasmExports['emscripten_stack_get_current'] = makeWrapper_p(wasmExports['emscripten_stack_get_current']);
|
|
return wasmExports;
|
|
}
|
|
|
|
// include: postamble.js
|
|
// === Auto-generated postamble setup entry stuff ===
|
|
|
|
var missingLibrarySymbols = [
|
|
'writeI53ToI64Clamped',
|
|
'writeI53ToI64Signaling',
|
|
'writeI53ToU64Clamped',
|
|
'writeI53ToU64Signaling',
|
|
'convertI32PairToI53',
|
|
'convertI32PairToI53Checked',
|
|
'convertU32PairToI53',
|
|
'getTempRet0',
|
|
'setTempRet0',
|
|
'zeroMemory',
|
|
'getHeapMax',
|
|
'growMemory',
|
|
'strError',
|
|
'inetPton4',
|
|
'inetNtop4',
|
|
'inetPton6',
|
|
'inetNtop6',
|
|
'readSockaddr',
|
|
'writeSockaddr',
|
|
'emscriptenLog',
|
|
'readEmAsmArgs',
|
|
'getExecutableName',
|
|
'listenOnce',
|
|
'autoResumeAudioContext',
|
|
'getDynCaller',
|
|
'dynCall',
|
|
'runtimeKeepalivePush',
|
|
'runtimeKeepalivePop',
|
|
'asmjsMangle',
|
|
'asyncLoad',
|
|
'alignMemory',
|
|
'mmapAlloc',
|
|
'HandleAllocator',
|
|
'getNativeTypeSize',
|
|
'addOnInit',
|
|
'addOnPostCtor',
|
|
'addOnPreMain',
|
|
'STACK_SIZE',
|
|
'STACK_ALIGN',
|
|
'POINTER_SIZE',
|
|
'ASSERTIONS',
|
|
'getCFunc',
|
|
'ccall',
|
|
'cwrap',
|
|
'uleb128Encode',
|
|
'sigToWasmTypes',
|
|
'generateFuncType',
|
|
'convertJsFunctionToWasm',
|
|
'getEmptyTableSlot',
|
|
'updateTableMap',
|
|
'getFunctionAddress',
|
|
'addFunction',
|
|
'removeFunction',
|
|
'reallyNegative',
|
|
'unSign',
|
|
'strLen',
|
|
'reSign',
|
|
'formatString',
|
|
'intArrayFromString',
|
|
'intArrayToString',
|
|
'AsciiToString',
|
|
'stringToAscii',
|
|
'UTF16ToString',
|
|
'stringToUTF16',
|
|
'lengthBytesUTF16',
|
|
'UTF32ToString',
|
|
'stringToUTF32',
|
|
'lengthBytesUTF32',
|
|
'writeArrayToMemory',
|
|
'fillDeviceOrientationEventData',
|
|
'registerDeviceOrientationEventCallback',
|
|
'fillDeviceMotionEventData',
|
|
'registerDeviceMotionEventCallback',
|
|
'screenOrientation',
|
|
'fillOrientationChangeEventData',
|
|
'registerOrientationChangeEventCallback',
|
|
'fillFullscreenChangeEventData',
|
|
'registerFullscreenChangeEventCallback',
|
|
'JSEvents_requestFullscreen',
|
|
'JSEvents_resizeCanvasForFullscreen',
|
|
'registerRestoreOldStyle',
|
|
'hideEverythingExceptGivenElement',
|
|
'restoreHiddenElements',
|
|
'setLetterbox',
|
|
'softFullscreenResizeWebGLRenderTarget',
|
|
'doRequestFullscreen',
|
|
'requestPointerLock',
|
|
'fillVisibilityChangeEventData',
|
|
'registerVisibilityChangeEventCallback',
|
|
'fillGamepadEventData',
|
|
'registerGamepadEventCallback',
|
|
'registerBeforeUnloadEventCallback',
|
|
'fillBatteryEventData',
|
|
'battery',
|
|
'registerBatteryEventCallback',
|
|
'setCanvasElementSize',
|
|
'getCanvasElementSize',
|
|
'jsStackTrace',
|
|
'getCallstack',
|
|
'convertPCtoSourceLocation',
|
|
'getEnvStrings',
|
|
'checkWasiClock',
|
|
'wasiRightsToMuslOFlags',
|
|
'wasiOFlagsToMuslOFlags',
|
|
'initRandomFill',
|
|
'randomFill',
|
|
'safeSetTimeout',
|
|
'setImmediateWrapped',
|
|
'safeRequestAnimationFrame',
|
|
'clearImmediateWrapped',
|
|
'registerPostMainLoop',
|
|
'registerPreMainLoop',
|
|
'getPromise',
|
|
'makePromise',
|
|
'idsToPromises',
|
|
'makePromiseCallback',
|
|
'ExceptionInfo',
|
|
'findMatchingCatch',
|
|
'Browser_asyncPrepareDataCounter',
|
|
'isLeapYear',
|
|
'ydayFromDate',
|
|
'arraySum',
|
|
'addDays',
|
|
'getSocketFromFD',
|
|
'getSocketAddress',
|
|
'FS_createPreloadedFile',
|
|
'FS_modeStringToFlags',
|
|
'FS_getMode',
|
|
'FS_stdin_getChar',
|
|
'FS_unlink',
|
|
'FS_createDataFile',
|
|
'FS_mkdirTree',
|
|
'_setNetworkCallback',
|
|
'emscriptenWebGLGetUniform',
|
|
'emscriptenWebGLGetVertexAttrib',
|
|
'__glGetActiveAttribOrUniform',
|
|
'writeGLArray',
|
|
'runAndAbortIfError',
|
|
'emscriptenWebGLGetIndexed',
|
|
'ALLOC_NORMAL',
|
|
'ALLOC_STACK',
|
|
'allocate',
|
|
'writeStringToMemory',
|
|
'writeAsciiToMemory',
|
|
'demangle',
|
|
'stackTrace',
|
|
];
|
|
missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
|
|
var unexportedSymbols = [
|
|
'run',
|
|
'addRunDependency',
|
|
'removeRunDependency',
|
|
'out',
|
|
'err',
|
|
'callMain',
|
|
'abort',
|
|
'wasmMemory',
|
|
'wasmExports',
|
|
'writeStackCookie',
|
|
'checkStackCookie',
|
|
'writeI53ToI64',
|
|
'readI53FromI64',
|
|
'readI53FromU64',
|
|
'INT53_MAX',
|
|
'INT53_MIN',
|
|
'bigintToI53Checked',
|
|
'stackSave',
|
|
'stackRestore',
|
|
'stackAlloc',
|
|
'ptrToString',
|
|
'exitJS',
|
|
'abortOnCannotGrowMemory',
|
|
'ENV',
|
|
'ERRNO_CODES',
|
|
'DNS',
|
|
'Protocols',
|
|
'Sockets',
|
|
'timers',
|
|
'warnOnce',
|
|
'readEmAsmArgsArray',
|
|
'jstoi_q',
|
|
'jstoi_s',
|
|
'handleException',
|
|
'keepRuntimeAlive',
|
|
'callUserCallback',
|
|
'maybeExit',
|
|
'wasmTable',
|
|
'noExitRuntime',
|
|
'addOnPreRun',
|
|
'addOnExit',
|
|
'addOnPostRun',
|
|
'freeTableIndexes',
|
|
'functionsInTableMap',
|
|
'setValue',
|
|
'getValue',
|
|
'PATH',
|
|
'PATH_FS',
|
|
'UTF8Decoder',
|
|
'UTF8ArrayToString',
|
|
'UTF8ToString',
|
|
'stringToUTF8Array',
|
|
'stringToUTF8',
|
|
'lengthBytesUTF8',
|
|
'UTF16Decoder',
|
|
'stringToNewUTF8',
|
|
'stringToUTF8OnStack',
|
|
'JSEvents',
|
|
'registerKeyEventCallback',
|
|
'specialHTMLTargets',
|
|
'maybeCStringToJsString',
|
|
'findEventTarget',
|
|
'findCanvasEventTarget',
|
|
'getBoundingClientRect',
|
|
'fillMouseEventData',
|
|
'registerMouseEventCallback',
|
|
'registerWheelEventCallback',
|
|
'registerUiEventCallback',
|
|
'registerFocusEventCallback',
|
|
'currentFullscreenStrategy',
|
|
'restoreOldWindowedStyle',
|
|
'fillPointerlockChangeEventData',
|
|
'registerPointerlockChangeEventCallback',
|
|
'registerPointerlockErrorEventCallback',
|
|
'registerTouchEventCallback',
|
|
'UNWIND_CACHE',
|
|
'ExitStatus',
|
|
'flush_NO_FILESYSTEM',
|
|
'emSetImmediate',
|
|
'emClearImmediate_deps',
|
|
'emClearImmediate',
|
|
'promiseMap',
|
|
'uncaughtExceptionCount',
|
|
'exceptionLast',
|
|
'exceptionCaught',
|
|
'Browser',
|
|
'getPreloadedImageData__data',
|
|
'wget',
|
|
'MONTH_DAYS_REGULAR',
|
|
'MONTH_DAYS_LEAP',
|
|
'MONTH_DAYS_REGULAR_CUMULATIVE',
|
|
'MONTH_DAYS_LEAP_CUMULATIVE',
|
|
'SYSCALLS',
|
|
'preloadPlugins',
|
|
'FS_stdin_getChar_buffer',
|
|
'FS_createPath',
|
|
'FS_createDevice',
|
|
'FS_readFile',
|
|
'FS',
|
|
'FS_createLazyFile',
|
|
'MEMFS',
|
|
'TTY',
|
|
'PIPEFS',
|
|
'SOCKFS',
|
|
'tempFixedLengthArray',
|
|
'miniTempWebGLFloatBuffers',
|
|
'miniTempWebGLIntBuffers',
|
|
'heapObjectForWebGLType',
|
|
'toTypedArrayIndex',
|
|
'webgl_enable_ANGLE_instanced_arrays',
|
|
'webgl_enable_OES_vertex_array_object',
|
|
'webgl_enable_WEBGL_draw_buffers',
|
|
'webgl_enable_WEBGL_multi_draw',
|
|
'webgl_enable_EXT_polygon_offset_clamp',
|
|
'webgl_enable_EXT_clip_control',
|
|
'webgl_enable_WEBGL_polygon_mode',
|
|
'GL',
|
|
'emscriptenWebGLGet',
|
|
'computeUnpackAlignedImageSize',
|
|
'colorChannelsInGlTextureFormat',
|
|
'emscriptenWebGLGetTexPixelData',
|
|
'webglGetUniformLocation',
|
|
'webglPrepareUniformLocationsBeforeFirstUse',
|
|
'webglGetLeftBracePos',
|
|
'registerWebGlEventCallback',
|
|
'AL',
|
|
'GLUT',
|
|
'EGL',
|
|
'GLEW',
|
|
'IDBStore',
|
|
'SDL',
|
|
'SDL_gfx',
|
|
'webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance',
|
|
'webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance',
|
|
'allocateUTF8',
|
|
'allocateUTF8OnStack',
|
|
'print',
|
|
'printErr',
|
|
];
|
|
unexportedSymbols.forEach(unexportedRuntimeSymbol);
|
|
|
|
|
|
|
|
var calledRun;
|
|
|
|
function callMain() {
|
|
assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])');
|
|
assert(typeof onPreRuns === 'undefined' || onPreRuns.length == 0, 'cannot call main when preRun functions remain to be called');
|
|
|
|
var entryFunction = _main;
|
|
|
|
var argc = 0;
|
|
var argv = 0;
|
|
|
|
try {
|
|
|
|
var ret = entryFunction(argc, BigInt(argv));
|
|
|
|
// if we're not running an evented main loop, it's time to exit
|
|
exitJS(ret, /* implicit = */ true);
|
|
return ret;
|
|
} catch (e) {
|
|
return handleException(e);
|
|
}
|
|
}
|
|
|
|
function stackCheckInit() {
|
|
// This is normally called automatically during __wasm_call_ctors but need to
|
|
// get these values before even running any of the ctors so we call it redundantly
|
|
// here.
|
|
_emscripten_stack_init();
|
|
// TODO(sbc): Move writeStackCookie to native to to avoid this.
|
|
writeStackCookie();
|
|
}
|
|
|
|
function run() {
|
|
|
|
if (runDependencies > 0) {
|
|
dependenciesFulfilled = run;
|
|
return;
|
|
}
|
|
|
|
stackCheckInit();
|
|
|
|
preRun();
|
|
|
|
// a preRun added a dependency, run will be called later
|
|
if (runDependencies > 0) {
|
|
dependenciesFulfilled = run;
|
|
return;
|
|
}
|
|
|
|
function doRun() {
|
|
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
// or while the async setStatus time below was happening
|
|
assert(!calledRun);
|
|
calledRun = true;
|
|
Module['calledRun'] = true;
|
|
|
|
if (ABORT) return;
|
|
|
|
initRuntime();
|
|
|
|
preMain();
|
|
|
|
Module['onRuntimeInitialized']?.();
|
|
consumedModuleProp('onRuntimeInitialized');
|
|
|
|
var noInitialRun = Module['noInitialRun'];legacyModuleProp('noInitialRun', 'noInitialRun');
|
|
if (!noInitialRun) callMain();
|
|
|
|
postRun();
|
|
}
|
|
|
|
if (Module['setStatus']) {
|
|
Module['setStatus']('Running...');
|
|
setTimeout(() => {
|
|
setTimeout(() => Module['setStatus'](''), 1);
|
|
doRun();
|
|
}, 1);
|
|
} else
|
|
{
|
|
doRun();
|
|
}
|
|
checkStackCookie();
|
|
}
|
|
|
|
function checkUnflushedContent() {
|
|
// Compiler settings do not allow exiting the runtime, so flushing
|
|
// the streams is not possible. but in ASSERTIONS mode we check
|
|
// if there was something to flush, and if so tell the user they
|
|
// should request that the runtime be exitable.
|
|
// Normally we would not even include flush() at all, but in ASSERTIONS
|
|
// builds we do so just for this check, and here we see if there is any
|
|
// content to flush, that is, we check if there would have been
|
|
// something a non-ASSERTIONS build would have not seen.
|
|
// How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
// mode (which has its own special function for this; otherwise, all
|
|
// the code is inside libc)
|
|
var oldOut = out;
|
|
var oldErr = err;
|
|
var has = false;
|
|
out = err = (x) => {
|
|
has = true;
|
|
}
|
|
try { // it doesn't matter if it fails
|
|
flush_NO_FILESYSTEM();
|
|
} catch(e) {}
|
|
out = oldOut;
|
|
err = oldErr;
|
|
if (has) {
|
|
warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the Emscripten FAQ), or make sure to emit a newline when you printf etc.');
|
|
warnOnce('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)');
|
|
}
|
|
}
|
|
|
|
if (Module['preInit']) {
|
|
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
|
|
while (Module['preInit'].length > 0) {
|
|
Module['preInit'].pop()();
|
|
}
|
|
}
|
|
consumedModuleProp('preInit');
|
|
|
|
run();
|
|
|
|
// end include: postamble.js
|
|
|