Set up a basic "front-end" for the webassembly module to be tested locally from a data folder (I use python -m http.server). The WebAssembly application is now responsible for all setup/rendering through the WebGL2 context.

This commit is contained in:
2025-09-01 12:13:56 -07:00
parent cca61ea163
commit b548b7bb26
14 changed files with 1416 additions and 14 deletions

42
data/wasm_functions.js Normal file
View File

@@ -0,0 +1,42 @@
import { appGlobals } from './globals.js'
export async function loadWasmModule(filePath, environment)
{
let result = null;
try
{
const fetchPromise = fetch(filePath);
const wasmModule = await WebAssembly.instantiateStreaming(
fetchPromise,
{ env: environment }
);
result = wasmModule.instance;
}
catch (exception)
{
console.error("Failed to load WASM module from \"" + filePath + "\":", exception);
}
return result;
}
//TODO: We should do some performance measurements of wasmPntrToJsString vs wasmPntrAndLengthToJsString!
export function wasmPntrToJsString(ptr)
{
let cIndex = ptr;
while (cIndex < appGlobals.memDataView.byteLength)
{
let byteValue = appGlobals.memDataView.getUint8(cIndex, true);
if (byteValue == 0) { break; }
cIndex++;
}
return appGlobals.textDecoder.decode(
appGlobals.memDataView.buffer.slice(ptr, cIndex)
);
}
export function wasmPntrAndLengthToJsString(ptr, length)
{
return appGlobals.textDecoder.decode(
appGlobals.memDataView.buffer.slice(ptr, ptr + length)
);
}