flyover / imgui-js

JavaScript bindings for Dear ImGui using Emscripten and TypeScript
https://flyover.github.io/imgui-js/example/
MIT License
951 stars 99 forks source link

Add WebGPU implementation #35

Open sh54 opened 3 years ago

sh54 commented 3 years ago

It would be nice to target WebGPU too. That should eventually be replacing WebGL. Its api is starting to settle down so any breaking changes will probably just be name stuff and petty argument changes rather than anything big.

I don't mind implementing it. I am using this library with clojurescript and I have it rendering via WebGPU there. Porting it over should not be much of a hassle.

One question I have is structuring related. All the HTML platform stuff (canvas_on_keydown etc) is the same so really should be shared. In my own implementation I keep the platform and renderer stuff separate. This maps up to the imgui concept that there is a io.BackendPlatformName and a io.BackendRendererName.

I propose splitting out the html platform stuff into its own file. Then add a WebGL renderer file, a new WebGPU renderer file, and perhaps split out the canvas fallback renderer into its own file. To maintain backwards compatibility keep imgui_impl.ts (and thus imgui_impl.umd.js) but it would just import in the html platform implementation and the webgl renderer plus the canvas renderer as fallback.