diff options
-rwxr-xr-x | emcc | 394 | ||||
-rw-r--r-- | src/deps_info.json | 7 | ||||
-rw-r--r-- | src/jsifier.js | 10 | ||||
-rw-r--r-- | src/library.js | 2 | ||||
-rw-r--r-- | src/library_egl.js | 2 | ||||
-rw-r--r-- | src/library_gl.js | 190 | ||||
-rw-r--r-- | src/library_sdl.js | 2 | ||||
-rw-r--r-- | src/preamble.js | 4 | ||||
-rw-r--r-- | system/lib/gl.c | 1729 | ||||
-rw-r--r-- | system/lib/gl.symbols | 1 | ||||
-rw-r--r-- | system/lib/sdl.cpp | 13 | ||||
-rw-r--r-- | system/lib/sdl.symbols | 1 | ||||
-rw-r--r-- | tests/cubegeom_proc.c | 331 | ||||
-rwxr-xr-x | tests/runner.py | 9 | ||||
-rw-r--r-- | tests/sdlglshader.c | 5 | ||||
-rw-r--r-- | tests/test_browser.py | 21 | ||||
-rw-r--r-- | tests/test_egl.c | 5 | ||||
-rw-r--r-- | tools/file_packager.py | 3 | ||||
-rw-r--r-- | tools/shared.py | 2 | ||||
-rw-r--r-- | tools/system_libs.py | 397 |
20 files changed, 2609 insertions, 519 deletions
@@ -47,9 +47,9 @@ emcc can be influenced by a few environment variables: EMMAKEN_COMPILER - The compiler to be used, if you don't want the default clang. ''' -import os, sys, shutil, tempfile, subprocess, shlex, time, re, logging +import os, sys, shutil, tempfile, subprocess, shlex, time, re, logging, json from subprocess import PIPE, STDOUT -from tools import shared, jsrun +from tools import shared, jsrun, system_libs from tools.shared import Compression, execute, suffix, unsuffixed, unsuffixed_basename, WINDOWS from tools.response_file import read_response_file @@ -311,6 +311,13 @@ Options that are modified or new in %s include: If a directory is passed here, its entire contents will be embedded. + Note: Embedding files is much less + efficient than preloading them. You + should only use it for small amounts + of small files. Instead, use + --preload-file which emits efficient + binary data. + --preload-file <name> A file to preload before running the compiled code asynchronously. Otherwise similar to --embed-file, except that this @@ -384,6 +391,9 @@ Options that are modified or new in %s include: The main file resides in the base directory and has the suffix ".js". + Note: this option is deprecated (modern JS debuggers + should work ok even on large files) + --bind Compiles the source code using the "embind" bindings approach, which connects C/C++ and JS. @@ -1194,12 +1204,12 @@ try: assert shared.Settings.RESERVED_FUNCTION_POINTERS == 0, 'reserved function pointers not supported in fastcomp' assert shared.Settings.ASM_HEAP_LOG == 0, 'asm heap log not supported in fastcomp' assert shared.Settings.LABEL_DEBUG == 0, 'label debug not supported in fastcomp' - assert shared.Settings.LEGACY_GL_EMULATION == 0, 'legacy gl emulation not supported in fastcomp' assert shared.Settings.EXECUTION_TIMEOUT == -1, 'execution timeout not supported in fastcomp' assert shared.Settings.NAMED_GLOBALS == 0, 'named globals not supported in fastcomp' assert shared.Settings.PGO == 0, 'pgo not supported in fastcomp' assert shared.Settings.TARGET_LE32 == 1, 'fastcomp requires le32' assert shared.Settings.USE_TYPED_ARRAYS == 2, 'fastcomp assumes ta2' + assert not split_js_file, '--split-js is deprecated and not supported in fastcomp' assert not bind, 'embind not supported in fastcomp yet' if jcache: logging.warning('jcache is not supported in fastcomp (you should not need it anyhow), disabling') @@ -1401,382 +1411,12 @@ try: logging.debug('will generate JavaScript') - extra_files_to_link = [] - if not LEAVE_INPUTS_RAW and \ - not shared.Settings.BUILD_AS_SHARED_LIB == 2 and \ + not shared.Settings.BUILD_AS_SHARED_LIB and \ not shared.Settings.SIDE_MODULE: # shared libraries/side modules link no C libraries, need them in parent - - # Check if we need to include some libraries that we compile. (We implement libc ourselves in js, but - # compile a malloc implementation and stdlibc++.) - - def read_symbols(path, exclude=None): - symbols = map(lambda line: line.strip().split(' ')[1], open(path).readlines()) - if exclude: - symbols = filter(lambda symbol: symbol not in exclude, symbols) - return set(symbols) - - lib_opts = ['-O2'] - - # XXX We also need to add libc symbols that use malloc, for example strdup. It's very rare to use just them and not - # a normal malloc symbol (like free, after calling strdup), so we haven't hit this yet, but it is possible. - libc_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libc.symbols')) - sdl_symbols = read_symbols(shared.path_from_root('system', 'lib', 'sdl.symbols')) - libcextra_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libcextra.symbols')) - libcxx_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libcxx', 'symbols'), exclude=libc_symbols) - libcxxabi_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libcxxabi', 'symbols'), exclude=libc_symbols) - - # XXX we should disable EMCC_DEBUG when building libs, just like in the relooper - - def build_libc(lib_filename, files): - o_s = [] - prev_cxx = os.environ.get('EMMAKEN_CXX') - if prev_cxx: os.environ['EMMAKEN_CXX'] = '' - musl_internal_includes = shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal') - for src in files: - o = in_temp(os.path.basename(src) + '.o') - execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', src), '-o', o, '-I', musl_internal_includes] + lib_opts, stdout=stdout, stderr=stderr) - o_s.append(o) - if prev_cxx: os.environ['EMMAKEN_CXX'] = prev_cxx - shared.Building.link(o_s, in_temp(lib_filename)) - return in_temp(lib_filename) - - def build_libcxx(src_dirname, lib_filename, files): - o_s = [] - for src in files: - o = in_temp(src + '.o') - srcfile = shared.path_from_root(src_dirname, src) - execute([shared.PYTHON, shared.EMXX, srcfile, '-o', o, '-std=c++11'] + lib_opts, stdout=stdout, stderr=stderr) - o_s.append(o) - shared.Building.link(o_s, in_temp(lib_filename)) - return in_temp(lib_filename) - - # libc - def create_libc(): - logging.debug(' building libc for cache') - libc_files = [ - 'dlmalloc.c', - os.path.join('libcxx', 'new.cpp'), - ] - musl_files = [ - ['internal', [ - 'floatscan.c', - 'shgetc.c', - ]], - ['math', [ - 'scalbn.c', - 'scalbnl.c', - ]], - ['stdio', [ - '__overflow.c', - '__toread.c', - '__towrite.c', - '__uflow.c', - ]], - ['stdlib', [ - 'atof.c', - 'strtod.c', - ]], - ['string', [ - 'memcmp.c', - 'strcasecmp.c', - 'strcmp.c', - 'strncasecmp.c', - 'strncmp.c', - ]] - ] - for directory, sources in musl_files: - libc_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] - return build_libc('libc.bc', libc_files) - - def apply_libc(need): - # libc needs some sign correction. # If we are in mode 0, switch to 2. We will add our lines - try: - if shared.Settings.CORRECT_SIGNS == 0: raise Exception('we need to change to 2') - except: # we fail if equal to 0 - so we need to switch to 2 - or if CORRECT_SIGNS is not even in Settings - shared.Settings.CORRECT_SIGNS = 2 - if shared.Settings.CORRECT_SIGNS == 2: - shared.Settings.CORRECT_SIGNS_LINES = [shared.path_from_root('src', 'dlmalloc.c') + ':' + str(i+4) for i in [4816, 4191, 4246, 4199, 4205, 4235, 4227]] - # If we are in mode 1, we are correcting everything anyhow. If we are in mode 3, we will be corrected - # so all is well anyhow too. - return True - - # libcextra - def create_libcextra(): - logging.debug('building libcextra for cache') - musl_files = [ - ['ctype', [ - 'iswalnum.c', - 'iswalpha.c', - 'iswblank.c', - 'iswcntrl.c', - 'iswctype.c', - 'iswdigit.c', - 'iswgraph.c', - 'iswlower.c', - 'iswprint.c', - 'iswpunct.c', - 'iswspace.c', - 'iswupper.c', - 'iswxdigit.c', - 'towctrans.c', - 'wcswidth.c', - 'wctrans.c', - 'wcwidth.c', - ]], - ['internal', [ - 'intscan.c', - ]], - ['legacy', [ - 'err.c', - ]], - ['locale', [ - 'iconv.c', - 'iswalnum_l.c', - 'iswalpha_l.c', - 'iswblank_l.c', - 'iswcntrl_l.c', - 'iswctype_l.c', - 'iswdigit_l.c', - 'iswgraph_l.c', - 'iswlower_l.c', - 'iswprint_l.c', - 'iswpunct_l.c', - 'iswspace_l.c', - 'iswupper_l.c', - 'iswxdigit_l.c', - 'strcoll.c', - 'strcasecmp_l.c', - 'strfmon.c', - 'strncasecmp_l.c', - 'strxfrm.c', - 'towctrans_l.c', - 'towlower_l.c', - 'towupper_l.c', - 'wcscoll.c', - 'wcscoll_l.c', - 'wcsxfrm.c', - 'wcsxfrm_l.c', - 'wctrans_l.c', - 'wctype_l.c', - ]], - ['math', [ - '__cos.c', - '__cosdf.c', - '__sin.c', - '__sindf.c', - 'ilogb.c', - 'ilogbf.c', - 'ilogbl.c', - 'ldexp.c', - 'ldexpf.c', - 'ldexpl.c', - 'logb.c', - 'logbf.c', - 'logbl.c', - 'lgamma.c', - 'lgamma_r.c', - 'lgammaf.c', - 'lgammaf_r.c', - 'lgammal.c', - 'scalbnf.c', - 'signgam.c', - 'tgamma.c', - 'tgammaf.c', - 'tgammal.c' - ]], - ['misc', [ - 'getopt.c', - 'getopt_long.c', - ]], - ['multibyte', [ - 'btowc.c', - 'mblen.c', - 'mbrlen.c', - 'mbrtowc.c', - 'mbsinit.c', - 'mbsnrtowcs.c', - 'mbsrtowcs.c', - 'mbstowcs.c', - 'mbtowc.c', - 'wcrtomb.c', - 'wcsnrtombs.c', - 'wcsrtombs.c', - 'wcstombs.c', - 'wctob.c', - 'wctomb.c', - ]], - ['regex', [ - 'fnmatch.c', - 'regcomp.c', - 'regerror.c', - 'regexec.c', - 'tre-mem.c', - ]], - ['stdio', [ - 'fwprintf.c', - 'swprintf.c', - 'vfwprintf.c', - 'vswprintf.c', - 'vwprintf.c', - 'wprintf.c', - 'fputwc.c', - 'fputws.c', - ]], - ['stdlib', [ - 'ecvt.c', - 'fcvt.c', - 'gcvt.c', - 'wcstod.c', - 'wcstol.c', - ]], - ['string', [ - 'memccpy.c', - 'memmem.c', - 'mempcpy.c', - 'memrchr.c', - 'strcasestr.c', - 'strchrnul.c', - 'strlcat.c', - 'strlcpy.c', - 'strsep.c', - 'strverscmp.c', - 'wcpcpy.c', - 'wcpncpy.c', - 'wcscasecmp.c', - 'wcscasecmp_l.c', - 'wcscat.c', - 'wcschr.c', - 'wcscmp.c', - 'wcscpy.c', - 'wcscspn.c', - 'wcsdup.c', - 'wcslen.c', - 'wcsncasecmp.c', - 'wcsncasecmp_l.c', - 'wcsncat.c', - 'wcsncmp.c', - 'wcsncpy.c', - 'wcsnlen.c', - 'wcspbrk.c', - 'wcsrchr.c', - 'wcsspn.c', - 'wcsstr.c', - 'wcstok.c', - 'wcswcs.c', - 'wmemchr.c', - 'wmemcmp.c', - 'wmemcpy.c', - 'wmemmove.c', - 'wmemset.c', - ]] - ] - libcextra_files = [] - for directory, sources in musl_files: - libcextra_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] - return build_libc('libcextra.bc', libcextra_files) - - # libcxx - def create_libcxx(): - logging.debug('building libcxx for cache') - libcxx_files = [ - 'algorithm.cpp', - 'condition_variable.cpp', - 'future.cpp', - 'iostream.cpp', - 'memory.cpp', - 'random.cpp', - 'stdexcept.cpp', - 'system_error.cpp', - 'utility.cpp', - 'bind.cpp', - 'debug.cpp', - 'hash.cpp', - 'mutex.cpp', - 'string.cpp', - 'thread.cpp', - 'valarray.cpp', - 'chrono.cpp', - 'exception.cpp', - 'ios.cpp', - 'locale.cpp', - 'regex.cpp', - 'strstream.cpp' - ] - return build_libcxx(os.path.join('system', 'lib', 'libcxx'), 'libcxx.bc', libcxx_files) - - def apply_libcxx(need): - assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++ with QUANTUM_SIZE == 1' - # libcxx might need corrections, so turn them all on. TODO: check which are actually needed - shared.Settings.CORRECT_SIGNS = shared.Settings.CORRECT_OVERFLOWS = shared.Settings.CORRECT_ROUNDINGS = 1 - #logging.info('using libcxx turns on CORRECT_* options') - return True - - # libcxxabi - just for dynamic_cast for now - def create_libcxxabi(): - logging.debug('building libcxxabi for cache') - libcxxabi_files = [ - 'typeinfo.cpp', - 'private_typeinfo.cpp' - ] - return build_libcxx(os.path.join('system', 'lib', 'libcxxabi', 'src'), 'libcxxabi.bc', libcxxabi_files) - - def apply_libcxxabi(need): - assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++abi with QUANTUM_SIZE == 1' - #logging.info('using libcxxabi, this may need CORRECT_* options') - #shared.Settings.CORRECT_SIGNS = shared.Settings.CORRECT_OVERFLOWS = shared.Settings.CORRECT_ROUNDINGS = 1 - return True - - # SDL. We include code that demands malloc/free if not already required, so we have proper malloc/free from JS SDL code. - # Note that the Force instance here can be optimized out, but we still export malloc/free, so they will be kept alive. - def create_sdl(): - return build_libcxx(os.path.join('system', 'lib'), 'sdl.bc', ['sdl.cpp']) - - def apply_sdl(need): - return 'SDL_Init' in all_needed and ('malloc' not in all_needed or 'free' not in all_needed) - - # Settings this in the environment will avoid checking dependencies and make building big projects a little faster - # 1 means include everything; otherwise it can be the name of a lib (libcxx, etc.) - force = os.environ.get('EMCC_FORCE_STDLIBS') - force_all = force == '1' - - # Scan symbols - all_needed = set() - symbolses = map(lambda temp_file: shared.Building.llvm_nm(temp_file), temp_files) - for symbols in symbolses: - all_needed.update(symbols.undefs) - for symbols in symbolses: - all_needed.difference_update(symbols.defs) - - # Go over libraries to figure out which we must include - # If we have libcxx, we must force inclusion of libc, since libcxx uses new internally. Note: this is kind of hacky. - has = need = None - for name, create, apply_, library_symbols in [('libcxx', create_libcxx, apply_libcxx, libcxx_symbols), - ('libcextra', create_libcextra, lambda x: True, libcextra_symbols), - ('libcxxabi', create_libcxxabi, apply_libcxxabi, libcxxabi_symbols), - ('sdl', create_sdl, apply_sdl, sdl_symbols), - ('libc', create_libc, apply_libc, libc_symbols)]: - force_this = force_all or force == name - if not force_this: - need = set() - has = set() - for symbols in symbolses: - for library_symbol in library_symbols: - if library_symbol in symbols.undefs: - need.add(library_symbol) - if library_symbol in symbols.defs: - has.add(library_symbol) - for haz in has: # remove symbols that are supplied by another of the inputs - if haz in need: - need.remove(haz) - if shared.Settings.VERBOSE: logging.debug('considering %s: we need %s and have %s' % (name, str(need), str(has))) - if force_this or len(need) > 0: - force_all = True - if apply_(need): - # We need to build and link the library in - logging.debug('including %s' % name) - libfile = shared.Cache.get(name, create) - extra_files_to_link.append(libfile) + extra_files_to_link = system_libs.calculate(temp_files, in_temp, stdout, stderr) + else: + extra_files_to_link = [] log_time('calculate system libraries') diff --git a/src/deps_info.json b/src/deps_info.json new file mode 100644 index 00000000..b38ffd00 --- /dev/null +++ b/src/deps_info.json @@ -0,0 +1,7 @@ +{ + "uuid_compare": ["memcmp"], + "SDL_Init": ["malloc", "free"], + "SDL_GL_GetProcAddress": ["emscripten_GetProcAddress"], + "eglGetProcAddress": ["emscripten_GetProcAddress"] +} + diff --git a/src/jsifier.js b/src/jsifier.js index ef15088e..6742f504 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -499,12 +499,8 @@ function JSify(data, functionsOnly) { if (!LINKABLE && !LibraryManager.library.hasOwnProperty(shortident) && !LibraryManager.library.hasOwnProperty(shortident + '__inline')) { if (ERROR_ON_UNDEFINED_SYMBOLS) error('unresolved symbol: ' + shortident); else if (VERBOSE || WARN_ON_UNDEFINED_SYMBOLS) warn('unresolved symbol: ' + shortident); - if (ASM_JS) { - // emit a stub that will fail during runtime. this allows asm validation to succeed. - LibraryManager.library[shortident] = new Function("Module['printErr']('missing function: " + shortident + "'); abort(-1);"); - } else { - cancel = true; // emit nothing, not even var X = undefined; - } + // emit a stub that will fail at runtime + LibraryManager.library[shortident] = new Function("Module['printErr']('missing function: " + shortident + "'); abort(-1);"); } item.JS = cancel ? ';' : addFromLibrary(shortident); } @@ -1852,7 +1848,7 @@ function JSify(data, functionsOnly) { // rest of the output that we started to print out earlier (see comment on the // "Final shape that will be created"). if (PRECISE_I64_MATH && Types.preciseI64MathUsed) { - if (!INCLUDE_FULL_LIBRARY && !SIDE_MODULE) { + if (!INCLUDE_FULL_LIBRARY && !SIDE_MODULE && !BUILD_AS_SHARED_LIB) { // first row are utilities called from generated code, second are needed from fastLong ['i64Add', 'i64Subtract', 'bitshift64Shl', 'bitshift64Lshr', 'bitshift64Ashr', 'llvm_ctlz_i32', 'llvm_cttz_i32'].forEach(function(func) { diff --git a/src/library.js b/src/library.js index a557810c..8f5010ad 100644 --- a/src/library.js +++ b/src/library.js @@ -4613,6 +4613,8 @@ LibraryManager.library = { _ZTIv: [0], // void _ZTIPv: [0], // void* + _ZTISt9exception: [0], // typeinfo for std::exception + llvm_uadd_with_overflow_i8: function(x, y) { x = x & 0xff; y = y & 0xff; diff --git a/src/library_egl.js b/src/library_egl.js index 11cf8951..69dd266d 100644 --- a/src/library_egl.js +++ b/src/library_egl.js @@ -555,7 +555,7 @@ var LibraryEGL = { eglGetProcAddress__deps: ['emscripten_GetProcAddress'], eglGetProcAddress: function(name_) { - return _emscripten_GetProcAddress(Pointer_stringify(name_)); + return _emscripten_GetProcAddress(name_); }, }; diff --git a/src/library_gl.js b/src/library_gl.js index baa0597d..978fb87e 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -1548,9 +1548,7 @@ var LibraryGL = { #endif var log = GLctx.getShaderInfoLog(GL.shaders[shader]); // Work around a bug in Chromium which causes getShaderInfoLog to return null - if (!log) { - log = ""; - } + if (!log) log = '(unknown error)'; log = log.substr(0, maxLength - 1); writeStringToMemory(log, infoLog); if (length) { @@ -1564,7 +1562,10 @@ var LibraryGL = { GL.validateGLObjectID(GL.shaders, shader, 'glGetShaderiv', 'shader'); #endif if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH - {{{ makeSetValue('p', '0', 'GLctx.getShaderInfoLog(GL.shaders[shader]).length + 1', 'i32') }}}; + var log = GLctx.getShaderInfoLog(GL.shaders[shader]); + // Work around a bug in Chromium which causes getShaderInfoLog to return null + if (!log) log = '(unknown error)'; + {{{ makeSetValue('p', '0', 'log.length + 1', 'i32') }}}; } else { {{{ makeSetValue('p', '0', 'GLctx.getShaderParameter(GL.shaders[shader], pname)', 'i32') }}}; } @@ -1853,7 +1854,7 @@ var LibraryGL = { }; var glEnable = _glEnable; - _glEnable = function _glEnable(cap) { + _glEnable = _emscripten_glEnable = function _glEnable(cap) { // Clean up the renderer on any change to the rendering state. The optimization of // skipping renderer setup is aimed at the case of multiple glDraw* right after each other if (GLImmediate.lastRenderer) GLImmediate.lastRenderer.cleanup(); @@ -1878,7 +1879,7 @@ var LibraryGL = { }; var glDisable = _glDisable; - _glDisable = function _glDisable(cap) { + _glDisable = _emscripten_glDisable = function _glDisable(cap) { if (GLImmediate.lastRenderer) GLImmediate.lastRenderer.cleanup(); if (cap == 0x0B60 /* GL_FOG */) { if (GLEmulation.fogEnabled != false) { @@ -1899,7 +1900,7 @@ var LibraryGL = { } glDisable(cap); }; - _glIsEnabled = function _glIsEnabled(cap) { + _glIsEnabled = _emscripten_glIsEnabled = function _glIsEnabled(cap) { if (cap == 0x0B60 /* GL_FOG */) { return GLEmulation.fogEnabled ? 1 : 0; } else if (!(cap in validCapabilities)) { @@ -1909,7 +1910,7 @@ var LibraryGL = { }; var glGetBooleanv = _glGetBooleanv; - _glGetBooleanv = function _glGetBooleanv(pname, p) { + _glGetBooleanv = _emscripten_glGetBooleanv = function _glGetBooleanv(pname, p) { var attrib = GLEmulation.getAttributeFromCapability(pname); if (attrib !== null) { var result = GLImmediate.enabledClientAttributes[attrib]; @@ -1920,7 +1921,7 @@ var LibraryGL = { }; var glGetIntegerv = _glGetIntegerv; - _glGetIntegerv = function _glGetIntegerv(pname, params) { + _glGetIntegerv = _emscripten_glGetIntegerv = function _glGetIntegerv(pname, params) { switch (pname) { case 0x84E2: pname = GLctx.MAX_TEXTURE_IMAGE_UNITS /* fake it */; break; // GL_MAX_TEXTURE_UNITS case 0x8B4A: { // GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB @@ -1989,7 +1990,7 @@ var LibraryGL = { }; var glGetString = _glGetString; - _glGetString = function _glGetString(name_) { + _glGetString = _emscripten_glGetString = function _glGetString(name_) { if (GL.stringCache[name_]) return GL.stringCache[name_]; switch(name_) { case 0x1F03 /* GL_EXTENSIONS */: // Add various extensions that we can support @@ -2013,7 +2014,7 @@ var LibraryGL = { GL.shaderOriginalSources = {}; #endif var glCreateShader = _glCreateShader; - _glCreateShader = function _glCreateShader(shaderType) { + _glCreateShader = _emscripten_glCreateShader = function _glCreateShader(shaderType) { var id = glCreateShader(shaderType); GL.shaderInfos[id] = { type: shaderType, @@ -2030,7 +2031,7 @@ var LibraryGL = { } var glShaderSource = _glShaderSource; - _glShaderSource = function _glShaderSource(shader, count, string, length) { + _glShaderSource = _emscripten_glShaderSource = function _glShaderSource(shader, count, string, length) { var source = GL.getSource(shader, count, string, length); #if GL_DEBUG console.log("glShaderSource: Input: \n" + source); @@ -2144,7 +2145,7 @@ var LibraryGL = { }; var glCompileShader = _glCompileShader; - _glCompileShader = function _glCompileShader(shader) { + _glCompileShader = _emscripten_glCompileShader = function _glCompileShader(shader) { GLctx.compileShader(GL.shaders[shader]); #if GL_DEBUG if (!GLctx.getShaderParameter(GL.shaders[shader], GLctx.COMPILE_STATUS)) { @@ -2159,14 +2160,14 @@ var LibraryGL = { GL.programShaders = {}; var glAttachShader = _glAttachShader; - _glAttachShader = function _glAttachShader(program, shader) { + _glAttachShader = _emscripten_glAttachShader = function _glAttachShader(program, shader) { if (!GL.programShaders[program]) GL.programShaders[program] = []; GL.programShaders[program].push(shader); glAttachShader(program, shader); }; var glDetachShader = _glDetachShader; - _glDetachShader = function _glDetachShader(program, shader) { + _glDetachShader = _emscripten_glDetachShader = function _glDetachShader(program, shader) { var programShader = GL.programShaders[program]; if (!programShader) { Module.printErr('WARNING: _glDetachShader received invalid program: ' + program); @@ -2178,7 +2179,7 @@ var LibraryGL = { }; var glUseProgram = _glUseProgram; - _glUseProgram = function _glUseProgram(program) { + _glUseProgram = _emscripten_glUseProgram = function _glUseProgram(program) { #if GL_DEBUG if (GL.debug) { Module.printErr('[using program with shaders]'); @@ -2199,7 +2200,7 @@ var LibraryGL = { } var glDeleteProgram = _glDeleteProgram; - _glDeleteProgram = function _glDeleteProgram(program) { + _glDeleteProgram = _emscripten_glDeleteProgram = function _glDeleteProgram(program) { glDeleteProgram(program); if (program == GL.currProgram) { GLImmediate.currentRenderer = null; // This changes the FFP emulation shader program, need to recompute that. @@ -2210,12 +2211,12 @@ var LibraryGL = { // If attribute 0 was not bound, bind it to 0 for WebGL performance reasons. Track if 0 is free for that. var zeroUsedPrograms = {}; var glBindAttribLocation = _glBindAttribLocation; - _glBindAttribLocation = function _glBindAttribLocation(program, index, name) { + _glBindAttribLocation = _emscripten_glBindAttribLocation = function _glBindAttribLocation(program, index, name) { if (index == 0) zeroUsedPrograms[program] = true; glBindAttribLocation(program, index, name); }; var glLinkProgram = _glLinkProgram; - _glLinkProgram = function _glLinkProgram(program) { + _glLinkProgram = _emscripten_glLinkProgram = function _glLinkProgram(program) { if (!(program in zeroUsedPrograms)) { GLctx.bindAttribLocation(GL.programs[program], 0, 'a_position'); } @@ -2223,7 +2224,7 @@ var LibraryGL = { }; var glBindBuffer = _glBindBuffer; - _glBindBuffer = function _glBindBuffer(target, buffer) { + _glBindBuffer = _emscripten_glBindBuffer = function _glBindBuffer(target, buffer) { glBindBuffer(target, buffer); if (target == GLctx.ARRAY_BUFFER) { if (GLEmulation.currentVao) { @@ -2238,7 +2239,7 @@ var LibraryGL = { }; var glGetFloatv = _glGetFloatv; - _glGetFloatv = function _glGetFloatv(pname, params) { + _glGetFloatv = _emscripten_glGetFloatv = function _glGetFloatv(pname, params) { if (pname == 0x0BA6) { // GL_MODELVIEW_MATRIX HEAPF32.set(GLImmediate.matrix[0/*m*/], params >> 2); } else if (pname == 0x0BA7) { // GL_PROJECTION_MATRIX @@ -2261,7 +2262,7 @@ var LibraryGL = { }; var glHint = _glHint; - _glHint = function _glHint(target, mode) { + _glHint = _emscripten_glHint = function _glHint(target, mode) { if (target == 0x84EF) { // GL_TEXTURE_COMPRESSION_HINT return; } @@ -2269,21 +2270,21 @@ var LibraryGL = { }; var glEnableVertexAttribArray = _glEnableVertexAttribArray; - _glEnableVertexAttribArray = function _glEnableVertexAttribArray(index) { + _glEnableVertexAttribArray = _emscripten_glEnableVertexAttribArray = function _glEnableVertexAttribArray(index) { glEnableVertexAttribArray(index); GLEmulation.enabledVertexAttribArrays[index] = 1; if (GLEmulation.currentVao) GLEmulation.currentVao.enabledVertexAttribArrays[index] = 1; }; var glDisableVertexAttribArray = _glDisableVertexAttribArray; - _glDisableVertexAttribArray = function _glDisableVertexAttribArray(index) { + _glDisableVertexAttribArray = _emscripten_glDisableVertexAttribArray = function _glDisableVertexAttribArray(index) { glDisableVertexAttribArray(index); delete GLEmulation.enabledVertexAttribArrays[index]; if (GLEmulation.currentVao) delete GLEmulation.currentVao.enabledVertexAttribArrays[index]; }; var glVertexAttribPointer = _glVertexAttribPointer; - _glVertexAttribPointer = function _glVertexAttribPointer(index, size, type, normalized, stride, pointer) { + _glVertexAttribPointer = _emscripten_glVertexAttribPointer = function _glVertexAttribPointer(index, size, type, normalized, stride, pointer) { glVertexAttribPointer(index, size, type, normalized, stride, pointer); if (GLEmulation.currentVao) { // TODO: avoid object creation here? likely not hot though GLEmulation.currentVao.vertexAttribPointers[index] = [index, size, type, normalized, stride, pointer]; @@ -2315,6 +2316,7 @@ var LibraryGL = { glGetShaderPrecisionFormat__sig: 'v', glGetShaderPrecisionFormat: function() { throw 'glGetShaderPrecisionFormat: TODO' }, + glDeleteObject__deps: ['glDeleteProgram', 'glDeleteShader'], glDeleteObject__sig: 'vi', glDeleteObject: function(id) { if (GL.programs[id]) { @@ -2325,8 +2327,10 @@ var LibraryGL = { Module.printErr('WARNING: deleteObject received invalid id: ' + id); } }, + glDeleteObjectARB: 'glDeleteObject', glGetObjectParameteriv__sig: 'viii', + glGetObjectParameteriv__deps: ['glGetProgramiv', 'glGetShaderiv'], glGetObjectParameteriv: function(id, type, result) { if (GL.programs[id]) { if (type == 0x8B84) { // GL_OBJECT_INFO_LOG_LENGTH_ARB @@ -2347,7 +2351,9 @@ var LibraryGL = { Module.printErr('WARNING: getObjectParameteriv received invalid id: ' + id); } }, + glGetObjectParameterivARB: 'glGetObjectParameteriv', + glGetInfoLog__deps: ['glGetProgramInfoLog', 'glGetShaderInfoLog'], glGetInfoLog__sig: 'viiii', glGetInfoLog: function(id, maxLength, length, infoLog) { if (GL.programs[id]) { @@ -2358,6 +2364,7 @@ var LibraryGL = { Module.printErr('WARNING: getObjectParameteriv received invalid id: ' + id); } }, + glGetInfoLogARB: 'glGetInfoLog', glBindProgram__sig: 'vii', glBindProgram: function(type, id) { @@ -2365,6 +2372,7 @@ var LibraryGL = { assert(id == 0); #endif }, + glBindProgramARB: 'glBindProgram', glGetPointerv: function(name, p) { var attribute; @@ -4112,7 +4120,7 @@ var LibraryGL = { // Replace some functions with immediate-mode aware versions. If there are no client // attributes enabled, and we use webgl-friendly modes (no GL_QUADS), then no need // for emulation - _glDrawArrays = function _glDrawArrays(mode, first, count) { + _glDrawArrays = _emscripten_glDrawArrays = function _glDrawArrays(mode, first, count) { if (GLImmediate.totalEnabledClientAttributes == 0 && mode <= 6) { GLctx.drawArrays(mode, first, count); return; @@ -4128,7 +4136,7 @@ var LibraryGL = { GLImmediate.mode = -1; }; - _glDrawElements = function _glDrawElements(mode, count, type, indices, start, end) { // start, end are given if we come from glDrawRangeElements + _glDrawElements = _emscripten_glDrawElements = function _glDrawElements(mode, count, type, indices, start, end) { // start, end are given if we come from glDrawRangeElements if (GLImmediate.totalEnabledClientAttributes == 0 && mode <= 6 && GL.currElementArrayBuffer) { GLctx.drawElements(mode, count, type, indices); return; @@ -4168,36 +4176,36 @@ var LibraryGL = { } var glActiveTexture = _glActiveTexture; - _glActiveTexture = function _glActiveTexture(texture) { + _glActiveTexture = _emscripten_glActiveTexture = function _glActiveTexture(texture) { GLImmediate.TexEnvJIT.hook_activeTexture(texture); glActiveTexture(texture); }; var glEnable = _glEnable; - _glEnable = function _glEnable(cap) { + _glEnable = _emscripten_glEnable = function _glEnable(cap) { GLImmediate.TexEnvJIT.hook_enable(cap); glEnable(cap); }; var |