diff options
-rw-r--r-- | AUTHORS | 3 | ||||
-rwxr-xr-x | emcc | 5 | ||||
-rwxr-xr-x | emmake | 2 | ||||
-rwxr-xr-x | emscripten.py | 66 | ||||
-rw-r--r-- | src/intertyper.js | 25 | ||||
-rw-r--r-- | src/jsifier.js | 28 | ||||
-rw-r--r-- | src/library.js | 101 | ||||
-rw-r--r-- | src/library_browser.js | 4 | ||||
-rw-r--r-- | src/library_gl.js | 837 | ||||
-rw-r--r-- | src/library_sdl.js | 27 | ||||
-rw-r--r-- | src/library_sockfs.js | 2 | ||||
-rw-r--r-- | src/modules.js | 11 | ||||
-rw-r--r-- | src/parseTools.js | 34 | ||||
-rw-r--r-- | src/runtime.js | 5 | ||||
-rw-r--r-- | src/settings.js | 4 | ||||
-rw-r--r-- | src/shell.html | 2 | ||||
-rw-r--r-- | src/simd.js | 1034 | ||||
-rw-r--r-- | src/utility.js | 8 | ||||
-rw-r--r-- | system/include/emscripten/emmintrin.h | 87 | ||||
-rw-r--r-- | system/include/emscripten/vector.h | 20 | ||||
-rw-r--r-- | system/include/emscripten/xmmintrin.h | 131 | ||||
-rw-r--r-- | tests/embind/shell.html | 2 | ||||
-rw-r--r-- | tests/hello_world_worker.cpp | 10 | ||||
-rw-r--r-- | tests/sdl_canvas_size.html | 2 | ||||
-rw-r--r-- | tests/test_browser.py | 21 | ||||
-rw-r--r-- | tests/test_core.py | 517 | ||||
-rw-r--r-- | tests/test_other.py | 19 | ||||
-rw-r--r-- | tools/cache.py | 12 | ||||
-rw-r--r-- | tools/file_packager.py | 8 | ||||
-rw-r--r-- | tools/shared.py | 32 |
30 files changed, 2168 insertions, 891 deletions
@@ -109,4 +109,5 @@ a license to everyone to use it as detailed in LICENSE.) * Bob Roberts <bobroberts177@gmail.com> * John Vilk <jvilk@cs.umass.edu> * Daniel Baulig <dbaulig@fb.com> (copyright owned by Facebook, Inc.) - +* Lu Wang <coolwanglu@gmail.com> +* Heidi Pan <heidi.pan@intel.com> (copyright owned by Intel) @@ -53,8 +53,9 @@ from tools import shared, jsrun from tools.shared import Compression, execute, suffix, unsuffixed, unsuffixed_basename, WINDOWS from tools.response_file import read_response_file -CXX_SUFFIXES = ('.cpp', '.cxx', '.cc') -SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc', '.m', '.mm') +C_SUFFIXES = ('.c', '.C') +CXX_SUFFIXES = ('.cpp', '.cxx', '.cc', '.CPP', '.CXX', '.CC') +SOURCE_SUFFIXES = C_SUFFIXES + CXX_SUFFIXES + ('.m', '.mm') BITCODE_SUFFIXES = ('.bc', '.o', '.obj') DYNAMICLIB_SUFFIXES = ('.dylib', '.so', '.dll') STATICLIB_SUFFIXES = ('.a',) @@ -6,7 +6,7 @@ the environment variables to use emcc and so forth. Usage: emmake make [FLAGS] -Not that if you ran configure with emconfigure, then +Note that if you ran configure with emconfigure, then the environment variables have already been detected and set. This script is useful if you have no configure step, and your Makefile uses the environment vars diff --git a/emscripten.py b/emscripten.py index 40014d2f..ae46ca07 100755 --- a/emscripten.py +++ b/emscripten.py @@ -793,14 +793,30 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, #if DEBUG: print >> sys.stderr, "META", metadata #if DEBUG: print >> sys.stderr, "meminit", mem_init - if DEBUG: logging.debug('emscript: js compiler glue') + # function table masks - # Integrate info from backend - settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE'] = settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE'] + metadata['declares'] + table_sizes = {} + for k, v in metadata['tables'].iteritems(): + table_sizes[k] = str(v.count(',')) # undercounts by one, but that is what we want + funcs = re.sub(r"#FM_(\w+)#", lambda m: table_sizes[m.groups(0)[0]], funcs) + + # js compiler + + if DEBUG: logging.debug('emscript: js compiler glue') # Settings changes assert settings['TARGET_LE32'] == 1 settings['TARGET_LE32'] = 2 + if 'i64Add' in metadata['declares']: # TODO: others, once we split them up + settings['PRECISE_I64_MATH'] = 2 + metadata['declares'] = filter(lambda i64_func: i64_func not in ['getHigh32', 'setHigh32', '__muldi3', '__divdi3', '__remdi3', '__udivdi3', '__uremdi3'], metadata['declares']) # FIXME: do these one by one as normal js lib funcs + + # Integrate info from backend + settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE'] = list( + set(settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE'] + map(shared.JS.to_nice_ident, metadata['declares'])).difference( + map(lambda x: x[1:], metadata['implementedFunctions']) + ) + ) + map(lambda x: x[1:], metadata['externs']) # Save settings to a file to work around v8 issue 1579 settings_file = temp_files.get('.txt').name @@ -823,6 +839,10 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, last_forwarded_json = forwarded_json = json.loads(forwarded_data) + # merge in information from llvm backend + + last_forwarded_json['Functions']['tables'] = metadata['tables'] + '''indexed_functions = set() for key in forwarded_json['Functions']['indexedFunctions'].iterkeys(): indexed_functions.add(key)''' @@ -831,11 +851,13 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, #print >> sys.stderr, 'glue:', pre, '\n\n||||||||||||||||\n\n', post, '...............' - # memory initializer + # memory and global initializers + + global_initializers = ', '.join(map(lambda i: '{ func: function() { %s() } }' % i, metadata['initializers'])) pre = pre.replace('STATICTOP = STATIC_BASE + 0;', '''STATICTOP = STATIC_BASE + Runtime.alignMemory(%d); -// /* global initializers */ __ATINIT__.push({ func: function() { runPostSets() } }); -%s''' % (mem_init.count(',')+1, mem_init)) # XXX wrong size calculation! +/* global initializers */ __ATINIT__.push(%s); +%s''' % (mem_init.count(',')+1, global_initializers, mem_init)) # XXX wrong size calculation! funcs_js = [funcs] if settings.get('ASM_JS'): @@ -848,6 +870,7 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, # merge forwarded data assert settings.get('ASM_JS'), 'fastcomp is asm.js only' + settings['EXPORTED_FUNCTIONS'] = forwarded_json['EXPORTED_FUNCTIONS'] all_exported_functions = set(settings['EXPORTED_FUNCTIONS']) # both asm.js and otherwise for additional_export in settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE']: # additional functions to export from asm, if they are implemented all_exported_functions.add('_' + additional_export) @@ -858,14 +881,6 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, if key in all_exported_functions or export_all or (export_bindings and key.startswith('_emscripten_bind')): exported_implemented_functions.add(key) - if settings.get('ASM_JS'): - # move postsets into the asm module - class PostSets: js = '' - def handle_post_sets(m): - PostSets.js = m.group(0) - return '\n' - pre = re.sub(r'function runPostSets[^}]+}', handle_post_sets, pre) - #if DEBUG: outfile.write('// pre\n') outfile.write(pre) pre = None @@ -873,25 +888,24 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, #if DEBUG: outfile.write('// funcs\n') if settings.get('ASM_JS'): - #print >> sys.stderr, '<<<<<<', post, '>>>>>>' - post_funcs = '' #, post_rest = post.split('// EMSCRIPTEN_END_FUNCS\n') - #post = post_rest - # Move preAsms to their right place def move_preasm(m): contents = m.groups(0)[0] outfile.write(contents + '\n') return '' - post_funcs = re.sub(r'/\* PRE_ASM \*/(.*)\n', lambda m: move_preasm(m), post_funcs) + funcs_js[1] = re.sub(r'/\* PRE_ASM \*/(.*)\n', lambda m: move_preasm(m), funcs_js[1]) - funcs_js += ['\n' + post_funcs + '// EMSCRIPTEN_END_FUNCS\n'] + funcs_js += ['\n// EMSCRIPTEN_END_FUNCS\n'] simple = os.environ.get('EMCC_SIMPLE_ASM') class Counter: i = 0 j = 0 - pre_tables = last_forwarded_json['Functions']['tables']['pre'] - del last_forwarded_json['Functions']['tables']['pre'] + if 'pre' in last_forwarded_json['Functions']['tables']: + pre_tables = last_forwarded_json['Functions']['tables']['pre'] + del last_forwarded_json['Functions']['tables']['pre'] + else: + pre_tables = '' def make_table(sig, raw): i = Counter.i @@ -982,7 +996,7 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, basic_funcs.append('extCall_%s' % sig) # calculate exports - exported_implemented_functions = list(exported_implemented_functions) + exported_implemented_functions = list(exported_implemented_functions) + metadata['initializers'] exported_implemented_functions.append('runPostSets') exports = [] if not simple: @@ -997,8 +1011,8 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, except: pass # If no named globals, only need externals - global_vars = [] - global_funcs = ['_' + key for key, value in forwarded_json['Functions']['libraryFunctions'].iteritems() if value != 2] + global_vars = metadata['externs'] #+ forwarded_json['Variables']['globals'] + global_funcs = list(set(['_' + key for key, value in forwarded_json['Functions']['libraryFunctions'].iteritems() if value != 2]).difference(set(global_vars))) # + metadata['externFuncs']/'declares' def math_fix(g): return g if not g.startswith('Math_') else g.split('_')[1] asm_global_funcs = ''.join([' var ' + g.replace('.', '_') + '=global.' + g + ';\n' for g in maths]) + \ @@ -1101,7 +1115,7 @@ function setTempRet%d(value) { value = value|0; tempRet%d = value; } -''' % (i, i) for i in range(10)])] + [PostSets.js + '\n'] + funcs_js + [''' +''' % (i, i) for i in range(10)])] + funcs_js + [''' %s return %s; diff --git a/src/intertyper.js b/src/intertyper.js index 940c677f..b34d0c08 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -524,6 +524,27 @@ function intertyper(lines, sidePass, baseLineNums) { } }); } + } else if (ident == '_llvm_used') { + var chunk = item.tokens[1].tokens; + var funcs = []; + var part = []; + + for (var i = 0; i < chunk.length; i++) { + if (chunk[i].text == ',') { + var call = parseLLVMFunctionCall(part); + EXPORTED_FUNCTIONS[call.ident] = 0; + part = []; + } else { + part.push(chunk[i]); + } + } + if (part.length > 0) { + var call = parseLLVMFunctionCall(part); + EXPORTED_FUNCTIONS[call.ident] = 0; + } + + ret.type = 'i32'; + ret.value = { intertype: 'value', ident: '0', value: '0', type: ret.type }; } else if (!external) { if (item.tokens[1] && item.tokens[1].text != ';') { if (item.tokens[1].text == 'c') { @@ -538,6 +559,7 @@ function intertyper(lines, sidePass, baseLineNums) { ret.value = { intertype: 'value', ident: '0', value: '0', type: ret.type }; } } + return ret; } } @@ -616,7 +638,8 @@ function intertyper(lines, sidePass, baseLineNums) { // 'bitcast' function bitcastHandler(item) { item.intertype = 'bitcast'; - item.type = item.tokens[4].text; // The final type + var last = getTokenIndexByText(item.tokens, ';'); + item.type = item.tokens[Math.min(last, item.tokens.length-1)].text; // The final type Types.needAnalysis[item.type] = 0; var to = getTokenIndexByText(item.tokens, 'to'); item.params = [parseLLVMSegment(item.tokens.slice(1, to))]; diff --git a/src/jsifier.js b/src/jsifier.js index cb753e57..b5502741 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1373,8 +1373,9 @@ function JSify(data, functionsOnly, givenFunctions) { function insertelementHandler(item) { var base = getVectorBaseType(item.type); var ident = ensureVector(item.ident, base); + var laneOp = ((base == 'float') ? 'SIMD.float32x4.with' : 'SIMD.int32x4.with'); //return ident + '.with' + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + finalizeLLVMParameter(item.value) + ')'; - return 'SIMD.with' + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + ident + ',' + finalizeLLVMParameter(item.value) + ')'; + return laneOp + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + ident + ',' + finalizeLLVMParameter(item.value) + ')'; } function extractelementHandler(item) { var base = getVectorBaseType(item.type); @@ -1603,6 +1604,15 @@ function JSify(data, functionsOnly, givenFunctions) { } } + // we alias llvm memset and such to normal memset. The target has a return value, while the original + // does not, so we need to fix that for the actual call target + if (ASM_JS) { + var sig = LibraryManager.library[simpleIdent + '__sig']; + if (sig && sig[0] !== 'v') { + returnType = Functions.getSignatureType(sig[0]); + } + } + if (byPointer) { var sig = Functions.getSignature(returnType, argsTypes, hasVarArgs); if (ASM_JS) { @@ -1746,11 +1756,13 @@ function JSify(data, functionsOnly, givenFunctions) { print('/* no memory initializer */'); // test purposes } - // Define postsets. These will be run in ATINIT, right before global initializers (which might need the postsets). We cannot - // run them now because the memory initializer might not have been applied yet. - print('function runPostSets() {\n'); - print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n')); - print('}\n'); + if (phase !== 'glue') { + // Define postsets. These will be run in ATINIT, right before global initializers (which might need the postsets). We cannot + // run them now because the memory initializer might not have been applied yet. + print('function runPostSets() {\n'); + print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n')); + print('}\n'); + } if (USE_TYPED_ARRAYS == 2) { if (!BUILD_AS_SHARED_LIB && !SIDE_MODULE) { @@ -1847,10 +1859,10 @@ function JSify(data, functionsOnly, givenFunctions) { // 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) { - if (!Functions.libraryFunctions[func]) { + if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l')) { // TODO: one-by-one in fastcomp glue mode print(processLibraryFunction(LibraryManager.library[func], func)); // must be first to be close to generated code Functions.implementedFunctions['_' + func] = LibraryManager.library[func + '__sig']; - Functions.libraryFunctions[func] = 1; + Functions.libraryFunctions[func] = phase == 'glue' ? 2 : 1; // XXX // limited dependency handling var deps = LibraryManager.library[func + '__deps']; if (deps) { diff --git a/src/library.js b/src/library.js index 4b5fc9ae..bdc0a39e 100644 --- a/src/library.js +++ b/src/library.js @@ -23,6 +23,7 @@ LibraryManager.library = { stdout: 'allocate(1, "i32*", ALLOC_STATIC)', stderr: 'allocate(1, "i32*", ALLOC_STATIC)', _impure_ptr: 'allocate(1, "i32*", ALLOC_STATIC)', + __dso_handle: 'allocate(1, "i32*", ALLOC_STATIC)', // ========================================================================== // dirent.h @@ -471,6 +472,11 @@ LibraryManager.library = { mkstemp: function(template) { return _creat(_mktemp(template), 0600); }, + mkdtemp__deps: ['mktemp', 'mkdir'], + mkdtemp: function(template) { + template = _mktemp(template); + return (_mkdir(template, 0700) === 0) ? template : 0; + }, fcntl__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'], fcntl: function(fildes, cmd, varargs, dup2) { // int fcntl(int fildes, int cmd, ...); @@ -535,7 +541,7 @@ LibraryManager.library = { // Advise as much as you wish. We don't care. return 0; }, - posix_madvise: 'posix_fadvise', + posix_madvise: function(){ return 0 }, // ditto as fadvise posix_fallocate__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'], posix_fallocate: function(fd, offset, len) { // int posix_fallocate(int fd, off_t offset, off_t len); @@ -1862,14 +1868,13 @@ LibraryManager.library = { #endif #if USE_TYPED_ARRAYS == 2 } else if (type == 'i64') { - -#if TARGET_LE32 +#if TARGET_LE32 == 1 ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}}, {{{ makeGetValue('varargs', 'argIndex+8', 'i32', undefined, undefined, true) }}}]; argIndex += {{{ STACK_ALIGN }}}; // each 32-bit chunk is in a 64-bit block #else - ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}}, - {{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true) }}}]; + ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true, 4) }}}, + {{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true, 4) }}}]; #endif #else @@ -2513,6 +2518,10 @@ LibraryManager.library = { } var bytesRead = 0; var streamObj = FS.getStream(stream); + if (!streamObj) { + ___setErrNo(ERRNO_CODES.EBADF); + return 0; + } while (streamObj.ungotten.length && bytesToRead > 0) { {{{ makeSetValue('ptr++', '0', 'streamObj.ungotten.pop()', 'i8') }}} bytesToRead--; @@ -3530,13 +3539,15 @@ LibraryManager.library = { llvm_memcpy_p0i8_p0i8_i32: 'memcpy', llvm_memcpy_p0i8_p0i8_i64: 'memcpy', - memmove__sig: 'viii', + memmove__sig: 'iiii', memmove__asm: true, memmove__deps: ['memcpy'], memmove: function(dest, src, num) { dest = dest|0; src = src|0; num = num|0; + var ret = 0; if (((src|0) < (dest|0)) & ((dest|0) < ((src + num)|0))) { // Unlikely case: Copy backwards in a safe manner + ret = dest; src = (src + num)|0; dest = (dest + num)|0; while ((num|0) > 0) { @@ -3545,9 +3556,11 @@ LibraryManager.library = { num = (num - 1)|0; {{{ makeSetValueAsm('dest', 0, makeGetValueAsm('src', 0, 'i8'), 'i8') }}}; } + dest = ret; } else { _memcpy(dest, src, num) | 0; } + return dest | 0; }, llvm_memmove_i32: 'memmove', llvm_memmove_i64: 'memmove', @@ -3564,7 +3577,7 @@ LibraryManager.library = { memset__inline: function(ptr, value, num, align) { return makeSetValues(ptr, 0, value, 'null', num, align); }, - memset__sig: 'viii', + memset__sig: 'iiii', memset__asm: true, memset: function(ptr, value, num) { #if USE_TYPED_ARRAYS == 2 @@ -3593,8 +3606,10 @@ LibraryManager.library = { {{{ makeSetValueAsm('ptr', 0, 'value', 'i8') }}}; ptr = (ptr+1)|0; } + return (ptr-num)|0; #else {{{ makeSetValues('ptr', '0', 'value', 'null', 'num') }}}; + return ptr; #endif }, llvm_memset_i32: 'memset', @@ -4665,6 +4680,10 @@ LibraryManager.library = { llvm_dbg_declare__inline: function() { throw 'llvm_debug_declare' }, // avoid warning + // llvm-nacl + + llvm_nacl_atomic_store_i32__inline: true, + // ========================================================================== // llvm-mono integration // ========================================================================== @@ -8820,8 +8839,72 @@ LibraryManager.library = { // emscripten vector ops //============================ - emscripten_float32x4_signmask__inline: function(x) { - return x + '.signMask()'; + emscripten_float32x4_signmask__inline: function(a) { + return 'SIMD.float32x4.bitsToInt32x4(' + a + ').signMask'; + }, + + emscripten_float32x4_min__inline: function(a, b) { + return 'SIMD.float32x4.min(' + a + ', ' + b + ')'; + }, + + emscripten_float32x4_max__inline: function(a, b) { + return 'SIMD.float32x4.max(' + a + ', ' + b + ')'; + }, + + emscripten_float32x4_sqrt__inline: function(a) { + return 'SIMD.float32x4.sqrt(' + a + ')'; + }, + + emscripten_float32x4_lessThan__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThan(' + a + ', ' + b + '))'; + }, + + emscripten_float32x4_lessThanOrEqual__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThanOrEqual(' + a + ', ' + b + '))'; + }, + + emscripten_float32x4_equal__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.equal(' + a + ', ' + b + '))'; + }, + + emscripten_float32x4_greaterThanOrEqual__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.greaterThanOrEqual(' + a + ', ' + b + '))'; + }, + + emscripten_float32x4_greaterThan__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.greaterThan(' + a + ', ' + b + '))'; + }, + + emscripten_float32x4_and__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))'; + }, + + emscripten_float32x4_andNot__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.int32x4.not(SIMD.float32x4.bitsToInt32x4(' + a + ')), SIMD.float32x4.bitsToInt32x4(' + b + ')))'; + }, + + emscripten_float32x4_or__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.or(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))'; + }, + + emscripten_float32x4_xor__inline: function(a, b) { + return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.xor(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))'; + }, + + emscripten_int32x4_bitsToFloat32x4__inline: function(a) { + return 'SIMD.int32x4.bitsToFloat32x4(' + a + ')'; + }, + + emscripten_int32x4_toFloat32x4__inline: function(a) { + return 'SIMD.int32x4.toFloat32x4(' + a + ')'; + }, + + emscripten_float32x4_bitsToInt32x4__inline: function(a) { + return 'SIMD.float32x4.bitsToInt32x4(' + a + ')'; + }, + + emscripten_float32x4_toInt32x4__inline: function(a) { + return 'SIMD.float32x4.toInt32x4(' + a + ')'; }, //============================ diff --git a/src/library_browser.js b/src/library_browser.js index fbc609d7..b368c6ac 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -252,7 +252,7 @@ mergeInto(LibraryManager.library, { var errorInfo = '?'; function onContextCreationError(event) { - errorInfo = e.statusMessage || errorInfo; + errorInfo = event.statusMessage || errorInfo; } canvas.addEventListener('webglcontextcreationerror', onContextCreationError, false); try { @@ -863,7 +863,7 @@ mergeInto(LibraryManager.library, { var styleSheet = document.styleSheets[0]; var rules = styleSheet.cssRules; for (var i = 0; i < rules.length; i++) { - if (rules[i].cssText.substr(0, 5) == 'canvas') { + if (rules[i].cssText.substr(0, 6) == 'canvas') { styleSheet.deleteRule(i); i--; } diff --git a/src/library_gl.js b/src/library_gl.js index afd36197..cc39b048 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -209,6 +209,105 @@ var LibraryGL = { ((height - 1) * alignedRowSize + plainRowSize); }, + get: function(name_, p, type) { + var ret = undefined; + switch(name_) { // Handle a few trivial GLES values + case 0x8DFA: // GL_SHADER_COMPILER + ret = 1; + break; + case 0x8DF8: // GL_SHADER_BINARY_FORMATS + if (type === 'Integer') { + // fall through, see gles2_conformance.cpp + } else { + GL.recordError(0x0500); // GL_INVALID_ENUM +#if GL_ASSERTIONS + Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(GL_SHADER_BINARY_FORMATS): Invalid parameter type!'); +#endif + return; + } + 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 = Module.ctx.getParameter(0x86A3 /*GL_COMPRESSED_TEXTURE_FORMATS*/); + ret = formats.length; + break; + case 0x8B9A: // GL_IMPLEMENTATION_COLOR_READ_TYPE + ret = 0x1401; // GL_UNSIGNED_BYTE + break; + case 0x8B9B: // GL_IMPLEMENTATION_COLOR_READ_FORMAT + ret = 0x1908; // GL_RGBA + break; + } + + if (ret === undefined) { + var result = Module.ctx.getParameter(name_); + switch (typeof(result)) { + case "number": + ret = result; + break; + case "boolean": + ret = result ? 1 : 0; + break; + case "string": + GL.recordError(0x0500); // GL_INVALID_ENUM +#if GL_ASSERTIONS + Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(' + name_ + ') on a name which returns a string!'); +#endif + return; + case "object": + if (result === null) { + GL.recordError(0x0500); // GL_INVALID_ENUM +#if GL_ASSERTIONS + Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(' + name_ + ') and it returns null!'); +#endif + return; + } else if (result instanceof Float32Array || + result instanceof Uint32Array || + result instanceof Int32Array || + result instanceof Array) { + for (var i = 0; i < result.length; ++i) { + switch (type) { + case 'Integer': {{{ makeSetValue('p', 'i*4', 'result[i]', 'i32') }}}; break; + case 'Float': {{{ makeSetValue('p', 'i*4', 'result[i]', 'float') }}}; break; + case 'Boolean': {{{ makeSetValue('p', 'i', 'result[i] ? 1 : 0', 'i8') }}}; break; + default: throw 'internal glGet error, bad type: ' + type; + } + } + return; + } else if (result instanceof WebGLBuffer || + result instanceof WebGLProgram || + result instanceof WebGLFramebuffer || + result instanceof WebGLRenderbuffer || + result instanceof WebGLTexture) { + ret = result.name | 0; + } else { + GL.recordError(0x0500); // GL_INVALID_ENUM +#if GL_ASSERTIONS + Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v: Unknown object returned from WebGL getParameter(' + name_ + ')!'); +#endif + return; + } + break; + default: + GL.recordError(0x0500); // GL_INVALID_ENUM +#if GL_ASSERTIONS + Module.printErr('GL_INVALID_ENUM in glGetIntegerv: Native code calling glGet' + type + 'v(' + name_ + ') and it returns ' + result + ' of type ' + typeof(result) + '!'); +#endif + return; + } + } + + switch (type) { + case 'Integer': {{{ makeSetValue('p', '0', 'ret', 'i32') }}}; break; + case 'Float': {{{ makeSetValue('p', '0', 'ret', 'float') }}}; break; + case 'Boolean': {{{ makeSetValue('p', '0', 'ret ? 1 : 0', 'i8') }}}; break; + default: throw 'internal glGet error, bad type: ' + type; + } + }, + getTexPixelData: function(type, format, width, height, pixels, internalFormat) { var sizePerPixel; switch (type) { @@ -288,6 +387,22 @@ var LibraryGL = { } }, +#if GL_FFP_ONLY + enabledClientAttribIndices: [], + enableVertexAttribArray: function enableVertexAttribArray(index) { + if (!GL.enabledClientAttribIndices[index]) { + GL.enabledClientAttribIndices[index] = true; + Module.ctx.enableVertexAttribArray(index); + } + }, + disableVertexAttribArray: function disableVertexAttribArray(index) { + if (GL.enabledClientAttribIndices[index]) { + GL.enabledClientAttribIndices[index] = false; + Module.ctx.disableVertexAttribArray(index); + } + }, +#endif + #if FULL_ES2 calcBufLength: function calcBufLength(size, type, stride, count) { if (stride > 0) { @@ -554,214 +669,17 @@ var LibraryGL = { glGetIntegerv__sig: 'vii', glGetIntegerv: function(name_, p) { - switch(name_) { // Handle a few trivial GLES values - case 0x8DFA: // GL_SHADER_COMPILER - {{{ makeSetValue('p', '0', '1', 'i32') }}}; - return; - case 0x8DF8: // GL_SHADER_BINARY_FORMATS - case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS - {{{ makeSetValue('p', '0', '0', 'i32') }}}; - return; - 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 = Module.ctx.getParameter(0x86A3 /*GL_COMPRESSED_TEXTURE_FORMATS*/); - {{{ makeSetValue('p', '0', 'formats.length', 'i32') }}}; - return; - } - var result = Module.ctx.getParameter(name_); - switch (typeof(result)) { - case "number": - {{{ makeSetValue('p', '0', 'result', 'i32') }}}; - break; - case "boolean": - {{{ makeSetValue('p', '0', 'result ? 1 : 0', 'i8') }}}; - break; - case "string": - GL.recordError(0x0500/*GL_INVALID_ENUM*/); -#if GL_ASSERTIONS - Module.printErr('GL_INVALID_ENUM in glGetIntegerv: Native code calling glGetIntegerv(' + name_ + ') on a name which returns a string!'); -#endif - return; - case "object": - if (result === null) { - {{{ makeSetValue('p', '0', '0', 'i32') }}}; - } else if (result instanceof Float32Array || - result instanceof Uint32Array || - result instanceof Int32Array || - result instanceof Array) { - for (var i = 0; i < result.length; ++i) { - {{{ makeSetValue('p', 'i*4', 'result[i]', 'i32') }}}; - } - } else if (result instanceof WebGLBuffer) { - {{{ makeSetValue('p', '0', 'result.name | 0', 'i32') }}}; - } else if (result instanceof WebGLProgram) { |