From ecb26e4c0b0e33c82edbdabc2b71c716b5c92bd3 Mon Sep 17 00:00:00 2001 From: Jack Jamison Date: Thu, 19 Mar 2026 10:24:38 -0400 Subject: interactive in this repo --- interactive/glsl-layout-calculator/index.js | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 interactive/glsl-layout-calculator/index.js (limited to 'interactive/glsl-layout-calculator/index.js') diff --git a/interactive/glsl-layout-calculator/index.js b/interactive/glsl-layout-calculator/index.js new file mode 100644 index 0000000..0d416ed --- /dev/null +++ b/interactive/glsl-layout-calculator/index.js @@ -0,0 +1,34 @@ +"use strict"; + +(async () => { + // Create our memory interface. While we don't specify any specific memory + // configuration, we'll use the interface to reference our exported Odin function. + const memInterface = new odin.WasmMemoryInterface(); + await odin.runWasm("index.wasm", null, null, memInterface); + // Now after the WASM module is loaded, we can access our exported functions. + const exports = memInterface.exports; + + const input_field = document.getElementById("input"); + const output_field = document.getElementById("output"); + const version_select = document.getElementById("version_select") + + function update() { + // allocate and store input + const input = input_field.value + const input_size = input.length + memInterface.storeString(exports.alloc_input(input_size), input) + + // call wasm function + const ptr = exports.calculate(version_select.value == "std140" ? 0 : 1) + + // get output + const out_ptr = exports.get_output_ptr() + const out_size = exports.get_output_size() + const out = memInterface.loadString(out_ptr, out_size) + output_field.value = out + } + + input_field.addEventListener("input", update) + version_select.addEventListener("change", update) + update() +})(); -- cgit v1.2.3