Skip to content

Commit

Permalink
Modularize emscripten build.
Browse files Browse the repository at this point in the history
By default, emscripten's generated javascript modules lives in the global object "Module'.

This makes it impossible to load multiple emscripten modules on the same page.

In attempt to avoid namespace collision, this change modularizes the emscripten build so the Module is instead called 'BASIS'.

Many target applications for Basis are likely to already be using other emscripten modules.

Testing:

The existing webgl/(texture|gltf) pages have been updated to use the new name and seem to operate as before
  • Loading branch information
prestomation committed Jun 12, 2019
1 parent f3f7c69 commit 39b5c5b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions webgl/gltf/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<body>
<script>
Module.onRuntimeInitialized = () => {
BASIS().then(Module => {

const { BasisFile, initializeBasis } = Module;

Expand Down Expand Up @@ -97,7 +97,7 @@

}, false );

}
});

function log(s) {

Expand Down
4 changes: 2 additions & 2 deletions webgl/texture/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
<div id='logger'></div>
</body>
<script>
Module.onRuntimeInitialized = () => {
BASIS({onRuntimeInitialized : () => {
var gl = elem('canvas').getContext('webgl');
// Load the DXT extension, and verify it exists.
if (!gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc') && !gl.getExtension('WEBGL_compressed_texture_s3tc')) {
Expand All @@ -275,6 +275,6 @@
}, false);

runLoadFile();
}
}}).then(module => window.Module = module);
</script>
</html>
2 changes: 1 addition & 1 deletion webgl/transcoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ if (EMSCRIPTEN)
set_target_properties(basis_transcoder.js PROPERTIES
OUTPUT_NAME "basis_transcoder"
SUFFIX ".js"
LINK_FLAGS "--bind -s ALLOW_MEMORY_GROWTH=1 -O3 -s ASSERTIONS=0 -s MALLOC=emmalloc")
LINK_FLAGS "--bind -s ALLOW_MEMORY_GROWTH=1 -O3 -s ASSERTIONS=0 -s MALLOC=emmalloc -s MODULARIZE=1 -s EXPORT_NAME=BASIS ")
endif()
22 changes: 21 additions & 1 deletion webgl/transcoder/build/basis_transcoder.js

Large diffs are not rendered by default.

Binary file modified webgl/transcoder/build/basis_transcoder.wasm
Binary file not shown.

0 comments on commit 39b5c5b

Please sign in to comment.