From 6c39c7dc359cf957e466596dab4e4b50888dc6ef Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 21 Mar 2023 22:22:08 -0700 Subject: [PATCH] Use normal JS library aliases for GL symbols. NFC The `recordGLProcAddressGet` helper was attempt to resolve and create aliases using `copyLibEntry`, but this function doesn't work when the target of the alias exists in a different library file. This was resulting `undefined` being set for these aliases and the resulting JS code would contains, for example: ``` var glGenFramebuffersOES = undefined; ``` Completely removing the aliasing resolution and the symbol copying from `recordGLProcAddressGet` seems to do the right thing, and should save on code size too: ``` var _glGenFramebuffersOES = _glGenFramebuffers; ``` --- src/library_glemu.js | 20 ++++++++++---------- src/library_webgl.js | 36 +++++------------------------------- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/library_glemu.js b/src/library_glemu.js index c70ec55bb3652..d9914cd0882bd 100644 --- a/src/library_glemu.js +++ b/src/library_glemu.js @@ -3881,16 +3881,16 @@ var LibraryGLEmulation = { // Open GLES1.1 compatibility - glGenFramebuffersOES : 'glGenFramebuffers', - glGenRenderbuffersOES : 'glGenRenderbuffers', - glBindFramebufferOES : 'glBindFramebuffer', - glBindRenderbufferOES : 'glBindRenderbuffer', - glGetRenderbufferParameterivOES : 'glGetRenderbufferParameteriv', - glFramebufferRenderbufferOES : 'glFramebufferRenderbuffer', - glRenderbufferStorageOES : 'glRenderbufferStorage', - glCheckFramebufferStatusOES : 'glCheckFramebufferStatus', - glDeleteFramebuffersOES : 'glDeleteFramebuffers', - glDeleteRenderbuffersOES : 'glDeleteRenderbuffers', + glGenFramebuffersOES: 'glGenFramebuffers', + glGenRenderbuffersOES: 'glGenRenderbuffers', + glBindFramebufferOES: 'glBindFramebuffer', + glBindRenderbufferOES: 'glBindRenderbuffer', + glGetRenderbufferParameterivOES: 'glGetRenderbufferParameteriv', + glFramebufferRenderbufferOES: 'glFramebufferRenderbuffer', + glRenderbufferStorageOES: 'glRenderbufferStorage', + glCheckFramebufferStatusOES: 'glCheckFramebufferStatus', + glDeleteFramebuffersOES: 'glDeleteFramebuffers', + glDeleteRenderbuffersOES: 'glDeleteRenderbuffers', glFramebufferTexture2DOES: 'glFramebufferTexture2D', // GLU diff --git a/src/library_webgl.js b/src/library_webgl.js index a10a44cfab989..1f7ec630abd43 100644 --- a/src/library_webgl.js +++ b/src/library_webgl.js @@ -4220,40 +4220,14 @@ createGLPassthroughFunctions(LibraryGL, glPassthroughFuncs); autoAddDeps(LibraryGL, '$GL'); -function copyLibEntry(lib, a, b) { - lib[a] = lib[b]; - lib[a + '__postset'] = lib[b + '__postset']; - lib[a + '__proxy'] = lib[b + '__proxy']; - lib[a + '__sig'] = lib[b + '__sig']; - lib[a + '__deps'] = (lib[b + '__deps'] || []).slice(0); -} - function recordGLProcAddressGet(lib) { - // GL proc address retrieval - allow access through glX and emscripten_glX, to allow name collisions with user-implemented things having the same name (see gl.c) + // GL proc address retrieval - allow access through glX and emscripten_glX, to + // allow name collisions with user-implemented things having the same name + // (see gl.c) Object.keys(lib).forEach((x) => { - if (isJsLibraryConfigIdentifier(x)) return; - if (x.substr(0, 2) != 'gl') return; - while (typeof lib[x] == 'string') { - // resolve aliases right here, simpler for fastcomp - copyLibEntry(lib, x, lib[x]); + if (x.startsWith('gl') && !isJsLibraryConfigIdentifier(x)) { + lib['emscripten_' + x] = x; } - const y = 'emscripten_' + x; - lib[x + '__deps'] = (lib[x + '__deps'] || []).map((dep) => { - // prefix dependencies as well - if (typeof dep == 'string' && dep[0] == 'g' && dep[1] == 'l' && lib[dep]) { - const orig = dep; - dep = 'emscripten_' + dep; - let fixed = lib[x].toString().replace(new RegExp('_' + orig + '\\(', 'g'), '_' + dep + '('); - // `function` is 8 characters, add space and an explicit name after if there isn't one already - if (fixed.startsWith('function(') || fixed.startsWith('function (')) { - fixed = fixed.substr(0, 8) + ' _' + y + fixed.substr(8); - } - lib[x] = eval('(function() { return ' + fixed + ' })()'); - } - return dep; - }); - // copy it - copyLibEntry(lib, y, x); }); }