Skip to content

Commit fda8dd1

Browse files
authored
Use normal JS library aliases for GL symbols. NFC (#19033)
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; ```
1 parent 13b1f81 commit fda8dd1

File tree

2 files changed

+15
-41
lines changed

2 files changed

+15
-41
lines changed

src/library_glemu.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,16 +3881,16 @@ var LibraryGLEmulation = {
38813881

38823882
// Open GLES1.1 compatibility
38833883

3884-
glGenFramebuffersOES : 'glGenFramebuffers',
3885-
glGenRenderbuffersOES : 'glGenRenderbuffers',
3886-
glBindFramebufferOES : 'glBindFramebuffer',
3887-
glBindRenderbufferOES : 'glBindRenderbuffer',
3888-
glGetRenderbufferParameterivOES : 'glGetRenderbufferParameteriv',
3889-
glFramebufferRenderbufferOES : 'glFramebufferRenderbuffer',
3890-
glRenderbufferStorageOES : 'glRenderbufferStorage',
3891-
glCheckFramebufferStatusOES : 'glCheckFramebufferStatus',
3892-
glDeleteFramebuffersOES : 'glDeleteFramebuffers',
3893-
glDeleteRenderbuffersOES : 'glDeleteRenderbuffers',
3884+
glGenFramebuffersOES: 'glGenFramebuffers',
3885+
glGenRenderbuffersOES: 'glGenRenderbuffers',
3886+
glBindFramebufferOES: 'glBindFramebuffer',
3887+
glBindRenderbufferOES: 'glBindRenderbuffer',
3888+
glGetRenderbufferParameterivOES: 'glGetRenderbufferParameteriv',
3889+
glFramebufferRenderbufferOES: 'glFramebufferRenderbuffer',
3890+
glRenderbufferStorageOES: 'glRenderbufferStorage',
3891+
glCheckFramebufferStatusOES: 'glCheckFramebufferStatus',
3892+
glDeleteFramebuffersOES: 'glDeleteFramebuffers',
3893+
glDeleteRenderbuffersOES: 'glDeleteRenderbuffers',
38943894
glFramebufferTexture2DOES: 'glFramebufferTexture2D',
38953895

38963896
// GLU

src/library_webgl.js

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4220,40 +4220,14 @@ createGLPassthroughFunctions(LibraryGL, glPassthroughFuncs);
42204220

42214221
autoAddDeps(LibraryGL, '$GL');
42224222

4223-
function copyLibEntry(lib, a, b) {
4224-
lib[a] = lib[b];
4225-
lib[a + '__postset'] = lib[b + '__postset'];
4226-
lib[a + '__proxy'] = lib[b + '__proxy'];
4227-
lib[a + '__sig'] = lib[b + '__sig'];
4228-
lib[a + '__deps'] = (lib[b + '__deps'] || []).slice(0);
4229-
}
4230-
42314223
function recordGLProcAddressGet(lib) {
4232-
// 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)
4224+
// GL proc address retrieval - allow access through glX and emscripten_glX, to
4225+
// allow name collisions with user-implemented things having the same name
4226+
// (see gl.c)
42334227
Object.keys(lib).forEach((x) => {
4234-
if (isJsLibraryConfigIdentifier(x)) return;
4235-
if (x.substr(0, 2) != 'gl') return;
4236-
while (typeof lib[x] == 'string') {
4237-
// resolve aliases right here, simpler for fastcomp
4238-
copyLibEntry(lib, x, lib[x]);
4228+
if (x.startsWith('gl') && !isJsLibraryConfigIdentifier(x)) {
4229+
lib['emscripten_' + x] = x;
42394230
}
4240-
const y = 'emscripten_' + x;
4241-
lib[x + '__deps'] = (lib[x + '__deps'] || []).map((dep) => {
4242-
// prefix dependencies as well
4243-
if (typeof dep == 'string' && dep[0] == 'g' && dep[1] == 'l' && lib[dep]) {
4244-
const orig = dep;
4245-
dep = 'emscripten_' + dep;
4246-
let fixed = lib[x].toString().replace(new RegExp('_' + orig + '\\(', 'g'), '_' + dep + '(');
4247-
// `function` is 8 characters, add space and an explicit name after if there isn't one already
4248-
if (fixed.startsWith('function(') || fixed.startsWith('function (')) {
4249-
fixed = fixed.substr(0, 8) + ' _' + y + fixed.substr(8);
4250-
}
4251-
lib[x] = eval('(function() { return ' + fixed + ' })()');
4252-
}
4253-
return dep;
4254-
});
4255-
// copy it
4256-
copyLibEntry(lib, y, x);
42574231
});
42584232
}
42594233

0 commit comments

Comments
 (0)