Skip to content

Commit

Permalink
Split library_gl.js into library_webgl.js and library_webgl2.js. (#8059)
Browse files Browse the repository at this point in the history
* Split library_gl.js into library_webgl.js and library_webgl2.js.

* Build GL library once for WebGL 1 and once for WebGL 2 because of missing symbols otherwise.

* Update GL emulation function pointer fetching to drop nonexisting GL functions
  • Loading branch information
juj committed Feb 12, 2019
1 parent bacd5ef commit ef230f5
Show file tree
Hide file tree
Showing 18 changed files with 2,307 additions and 2,417 deletions.
2 changes: 1 addition & 1 deletion cmake/Modules/FindOpenGL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SET(OPENGL_XMESA_FOUND FALSE)
# This is the path where <GL/gl.h> is found
SET(OPENGL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include")

# No library to link against for OpenGL, since Emscripten picks it up automatically from library_gl.js,
# No library to link against for OpenGL, since Emscripten picks it up automatically from library_webgl.js,
# but need to report something, or CMake thinks we failed in the search.
SET(OPENGL_LIBRARIES "nul")
SET(OPENGL_gl_LIBRARY "nul")
Expand Down
27 changes: 17 additions & 10 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
libc++abi
gl
gl-mt
gl-emu
gl-mt-emu
gl-webgl2
gl-mt-webgl2
gl-emu-webgl2
gl-mt-emu-webgl2
native_optimizer
binaryen
bullet
Expand Down Expand Up @@ -110,7 +116,8 @@
'''

SYSTEM_TASKS = [
'al', 'compiler-rt', 'gl', 'gl-mt', 'libc', 'libc-mt', 'libc-extras',
'al', 'compiler-rt', 'gl', 'gl-mt', 'gl-emu', 'gl-mt-emu', 'gl-webgl2',
'gl-mt-webgl2', 'gl-emu-webgl2', 'gl-mt-emu-webgl2', 'libc', 'libc-mt', 'libc-extras',
'emmalloc', 'emmalloc_debug', 'dlmalloc', 'dlmalloc_threadsafe', 'pthreads',
'pthreads_stub', 'dlmalloc_debug', 'dlmalloc_threadsafe_debug', 'libc++',
'libc++_noexcept', 'dlmalloc_debug_noerrno', 'dlmalloc_threadsafe_debug_noerrno',
Expand Down Expand Up @@ -239,20 +246,20 @@ def main():
return y->y;
}
''', [static_library_name('libc++abi')])
elif what == 'gl':
elif what == 'gl' or what.startswith('gl-'):
opts = []
if '-mt' in what:
opts += ['-s', 'USE_PTHREADS=1']
if '-emu' in what:
opts += ['-s', 'LEGACY_GL_EMULATION=1']
if '-webgl2' in what:
opts += ['-s', 'USE_WEBGL2=1']
build('''
extern "C" { extern void* emscripten_GetProcAddress(const char *x); }
int main() {
return int(emscripten_GetProcAddress("waka waka"));
}
''', [static_library_name('libgl')])
elif what == 'gl-mt':
build('''
extern "C" { extern void* emscripten_GetProcAddress(const char *x); }
int main() {
return int(emscripten_GetProcAddress("waka waka"));
}
''', [static_library_name('libgl-mt')], ['-s', 'USE_PTHREADS=1'])
''', [static_library_name('lib%s' % what)], opts)
elif what == 'native_optimizer':
build(C_BARE, ['optimizer.2.exe'], ['-O2', '-s', 'WASM=0'])
elif what == 'compiler_rt_wasm':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ See the `library_*.js`_ files for other examples.
``autoAddDeps(myLibrary, name)`` where myLibrary is the object with
all your methods, and ``name`` is the thing they all depend upon.
This is useful when all the implemented methods use a JavaScript
singleton containing helper methods. See ``library_gl.js`` for
singleton containing helper methods. See ``library_webgl.js`` for
an example.
- If a JavaScript library depends on a compiled C library (like most
of *libc*), you must edit `src/deps_info.json`_. Search for
Expand Down
2 changes: 2 additions & 0 deletions src/library_glemu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,9 @@ var LibraryGLEmulation = {
#endif
}
},

glColor4d: 'glColor4f',

glColor4ub__deps: ['glColor4f'],
glColor4ub: function(r, g, b, a) {
_glColor4f((r&255)/255, (g&255)/255, (b&255)/255, (a&255)/255);
Expand Down
Loading

0 comments on commit ef230f5

Please sign in to comment.