Skip to content

Commit

Permalink
merge shell file
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Oct 20, 2024
1 parent b4db5d2 commit 6dabf77
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ endif

examples/webgpu/webgpu: examples/webgpu/webgpu.c RGFW.h
ifeq ($(CC),emcc) # web ASM
emcc $< -I. --shell-file ./webasm/shell.html -s USE_WEBGPU=1 -o $@$(EXT)
emcc $< -I. -s USE_WEBGPU=1 -o $@$(EXT)
else
@echo webgpu is not supported on $(detected_OS)
endif
Expand Down
72 changes: 0 additions & 72 deletions webasm/shell.html

This file was deleted.

56 changes: 56 additions & 0 deletions webasm/webgpu.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,62 @@ <h1>RGFW WebASM Example &nbsp;&nbsp;&nbsp;&nbsp;
};
})();
</script>

<script type='text/javascript'>
var Module = {
print: (function() {
return (text) => {console.log(text);
};
})(),
canvas: (function() {
return document.getElementById('canvas');
})(),
};

initWebGPU = async () => {
// Check to ensure the user agent supports WebGPU
if (!('gpu' in navigator)) {
const msg = '⚠️ WebGPU is not available on this browser.';

const pre = document.createElement('pre');
pre.style.color = '#f00';
pre.style.textAlign = 'center';
pre.textContent = msg;
document.body.appendChild(pre);

console.error(msg);

return false;
}

// Request an adapter
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
console.error('No WebGPU adapters found.');
return false;
}

// Request a device
const device = await adapter.requestDevice();
device.lost.then((info) => {
console.error(`WebGPU device was lost: ${info.message}`);
device = null;

if (info.reason != 'destroyed') {
initWebGPU();
}
});

// Set WebGPU device in Module
Module.preinitializedWebGPUDevice = device;

return true;
}

initWebGPU();
</script>
{{{ SCRIPT }}}

</body>

</html>

0 comments on commit 6dabf77

Please sign in to comment.