aboutsummaryrefslogtreecommitdiff
path: root/interactive/glsl-layout-calculator/index.js
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2026-03-19 10:24:38 -0400
committerJack Jamison <jackqjamison@gmail.com>2026-03-19 10:24:38 -0400
commitecb26e4c0b0e33c82edbdabc2b71c716b5c92bd3 (patch)
tree7b3cd3d1ae518f660b157ef0ac8d0a6e26c1ebef /interactive/glsl-layout-calculator/index.js
parent9e248eeb4f9a954d129c9fddd710b99abfc4106a (diff)
interactive in this repo
Diffstat (limited to 'interactive/glsl-layout-calculator/index.js')
-rw-r--r--interactive/glsl-layout-calculator/index.js34
1 files changed, 34 insertions, 0 deletions
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()
+})();