Skip to content

Commit 475548d

Browse files
committed
move emscripten_GetProcAddress to a C library, so that it is less hackish and can work in fastcomp
1 parent b3ab733 commit 475548d

File tree

8 files changed

+1767
-83
lines changed

8 files changed

+1767
-83
lines changed

src/deps_info.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"uuid_compare": ["memcmp"],
3-
"SDL_Init": ["malloc", "free"]
3+
"SDL_Init": ["malloc", "free"],
4+
"SDL_GL_GetProcAddress": ["emscripten_GetProcAddress"],
5+
"eglGetProcAddress": ["emscripten_GetProcAddress"]
46
}
57

src/library_egl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ var LibraryEGL = {
555555

556556
eglGetProcAddress__deps: ['emscripten_GetProcAddress'],
557557
eglGetProcAddress: function(name_) {
558-
return _emscripten_GetProcAddress(Pointer_stringify(name_));
558+
return _emscripten_GetProcAddress(name_);
559559
},
560560
};
561561

src/library_gl.js

+20-79
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,7 @@ var LibraryGL = {
23252325
Module.printErr('WARNING: deleteObject received invalid id: ' + id);
23262326
}
23272327
},
2328+
glDeleteObjectARB: 'glDeleteObject',
23282329

23292330
glGetObjectParameteriv__sig: 'viii',
23302331
glGetObjectParameteriv: function(id, type, result) {
@@ -2347,6 +2348,7 @@ var LibraryGL = {
23472348
Module.printErr('WARNING: getObjectParameteriv received invalid id: ' + id);
23482349
}
23492350
},
2351+
glGetObjectParameterivARB: 'glGetObjectParameteriv',
23502352

23512353
glGetInfoLog__sig: 'viiii',
23522354
glGetInfoLog: function(id, maxLength, length, infoLog) {
@@ -2358,13 +2360,15 @@ var LibraryGL = {
23582360
Module.printErr('WARNING: getObjectParameteriv received invalid id: ' + id);
23592361
}
23602362
},
2363+
glGetInfoLogARB: 'glGetInfoLog',
23612364

23622365
glBindProgram__sig: 'vii',
23632366
glBindProgram: function(type, id) {
23642367
#if ASSERTIONS
23652368
assert(id == 0);
23662369
#endif
23672370
},
2371+
glBindProgramARB: 'glBindProgram',
23682372

23692373
glGetPointerv: function(name, p) {
23702374
var attribute;
@@ -5031,39 +5035,11 @@ var LibraryGL = {
50315035

50325036
#else // LEGACY_GL_EMULATION
50335037

5034-
// Warn if code tries to use various emulation stuff, when emulation is disabled
5035-
// (do not warn if INCLUDE_FULL_LIBRARY is one, because then likely the gl code will
5036-
// not be called anyhow, leave only the runtime aborts)
5037-
glVertexPointer__deps: [function() {
5038-
#if INCLUDE_FULL_LIBRARY == 0
5039-
warn('Legacy GL function (glVertexPointer) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.');
5040-
#endif
5041-
}],
5042-
glVertexPointer: function(){ throw 'Legacy GL function (glVertexPointer) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5043-
glGenVertexArrays__deps: [function() {
5044-
#if INCLUDE_FULL_LIBRARY == 0
5045-
warn('Legacy GL function (glGenVertexArrays) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.');
5046-
#endif
5047-
}],
5048-
glGenVertexArrays: function(){ throw 'Legacy GL function (glGenVertexArrays) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5049-
glMatrixMode__deps: [function() {
5050-
#if INCLUDE_FULL_LIBRARY == 0
5051-
warn('Legacy GL function (glMatrixMode) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.');
5052-
#endif
5053-
}],
5054-
glMatrixMode: function(){ throw 'Legacy GL function (glMatrixMode) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5055-
glBegin__deps: [function() {
5056-
#if INCLUDE_FULL_LIBRARY == 0
5057-
warn('Legacy GL function (glBegin) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.');
5058-
#endif
5059-
}],
5060-
glBegin: function(){ throw 'Legacy GL function (glBegin) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5061-
glLoadIdentity__deps: [function() {
5062-
#if INCLUDE_FULL_LIBRARY == 0
5063-
warn('Legacy GL function (glLoadIdentity) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.');
5064-
#endif
5065-
}],
5066-
glLoadIdentity: function(){ throw 'Legacy GL function (glLoadIdentity) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5038+
glVertexPointer: function(){ throw 'Legacy GL function (glVertexPointer) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5039+
glGenVertexArrays: function(){ throw 'Legacy GL function (glGenVertexArrays) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5040+
glMatrixMode: function(){ throw 'Legacy GL function (glMatrixMode) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5041+
glBegin: function(){ throw 'Legacy GL function (glBegin) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
5042+
glLoadIdentity: function(){ throw 'Legacy GL function (glLoadIdentity) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
50675043

50685044
#endif // LEGACY_GL_EMULATION
50695045

@@ -5374,52 +5350,17 @@ if (LEGACY_GL_EMULATION) {
53745350
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$GLEmulation');
53755351
}
53765352

5377-
// GL proc address retrieval
5378-
LibraryGL.emscripten_GetProcAddress__deps = [function() {
5379-
// ProcAddress is used, so include everything in GL. This runs before we go to the $ProcAddressTable object,
5380-
// and we fill its deps just in time, and create the lookup table
5381-
var table = {};
5382-
LibraryManager.library.emscripten_procAddressTable__deps = keys(LibraryGL).map(function(x) {
5383-
if (x.substr(-6) == '__deps' || x.substr(-9) == '__postset' || x.substr(-5) == '__sig' || x.substr(-5) == '__asm' || x.substr(0, 2) != 'gl') return null;
5384-
var original = x;
5385-
if (('_' + x) in Functions.implementedFunctions) {
5386-
// a user-implemented function aliases this one, but we still want it to be accessible by name, so rename it
5387-
var y = x + '__procTable';
5388-
LibraryManager.library[y] = LibraryManager.library[x];
5389-
LibraryManager.library[y + '__deps'] = LibraryManager.library[x + '__deps'];
5390-
LibraryManager.library[y + '__postset'] = LibraryManager.library[x + '__postset'];
5391-
LibraryManager.library[y + '__sig'] = LibraryManager.library[x + '__sig'];//|| Functions.implementedFunctions['_' + x];
5392-
LibraryManager.library[y + '__asm'] = LibraryManager.library[x + '__asm'];
5393-
x = y;
5394-
assert(!(y in Functions.implementedFunctions) && !Functions.unimplementedFunctions['_' + y]);
5395-
}
5396-
var longX = '_' + x;
5397-
var sig = LibraryManager.library[x + '__sig'] || functionStubSigs[longX];
5398-
if (sig) {
5399-
table[original] = Functions.getIndex(longX, sig);
5400-
if (!(longX in Functions.implementedFunctions)) Functions.unimplementedFunctions[longX] = sig;
5401-
}
5402-
return x;
5403-
}).filter(function(x) { return x !== null });
5404-
// convert table into function with switch, to not confuse closure compiler
5405-
var tableImpl = 'switch(name) {\n';
5406-
for (var x in table) tableImpl += 'case "' + x + '": return ' + table[x] + '; break;\n';
5407-
tableImpl += '}\nreturn 0;';
5408-
LibraryManager.library.emscripten_procAddressTable = new Function('name', tableImpl);
5409-
}, 'emscripten_procAddressTable'];
5410-
LibraryGL.emscripten_GetProcAddress = function _LibraryGL_emscripten_GetProcAddress(name) {
5411-
name = name.replace('EXT', '').replace('ARB', '');
5412-
switch(name) { // misc renamings
5413-
case 'glCreateProgramObject': name = 'glCreateProgram'; break;
5414-
case 'glUseProgramObject': name = 'glUseProgram'; break;
5415-
case 'glCreateShaderObject': name = 'glCreateShader'; break;
5416-
case 'glAttachObject': name = 'glAttachShader'; break;
5417-
case 'glDetachObject': name = 'glDetachShader'; break;
5418-
}
5419-
var ret = _emscripten_procAddressTable(name);
5420-
if (!ret) Module.printErr('WARNING: getProcAddress failed for ' + name);
5421-
return ret;
5422-
}
5353+
// 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)
5354+
keys(LibraryGL).forEach(function(x) {
5355+
if (x.substr(-6) == '__deps' || x.substr(-9) == '__postset' || x.substr(-5) == '__sig' || x.substr(-5) == '__asm' || x.substr(0, 2) != 'gl') return;
5356+
var original = x;
5357+
var y = 'emscripten_' + x;
5358+
LibraryGL[y] = LibraryGL[x];
5359+
LibraryGL[y + '__deps'] = LibraryGL[x + '__deps']; // note that we might want to rename in the deps as well
5360+
LibraryGL[y + '__postset'] = LibraryGL[x + '__postset'];
5361+
LibraryGL[y + '__sig'] = LibraryGL[x + '__sig'];
5362+
LibraryGL[y + '__asm'] = LibraryGL[x + '__asm'];
5363+
});
54235364

54245365
// Final merge
54255366
mergeInto(LibraryManager.library, LibraryGL);

src/library_sdl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,7 @@ var LibrarySDL = {
24872487

24882488
SDL_GL_GetProcAddress__deps: ['emscripten_GetProcAddress'],
24892489
SDL_GL_GetProcAddress: function(name_) {
2490-
return _emscripten_GetProcAddress(Pointer_stringify(name_));
2490+
return _emscripten_GetProcAddress(name_);
24912491
},
24922492

24932493
SDL_GL_SwapBuffers: function() {},

0 commit comments

Comments
 (0)