-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New platform backend: imgui_impl_emscripten #8178
base: master
Are you sure you want to change the base?
Conversation
Thank you Eugene for the PR! I intuitively agree that a raw Emscripten port may be desirable, but I am not sure we are aligned on the motives.
I believe we need to be clear on the benefits.
On the submitted code:
Thanks! |
Hey Omar, thanks for the initial review! Your thoughts are all valid, I think there are a couple of misunderstandings though - let me address in-line.
Absolutely - in so far as it doesn't not work. What it provides is simply entirely orthogonal to WebGPU. When working on desktop, GLFW creates windows and manages interaction with them, but under Emscripten on the web, none of that applies. When working with WebGL, GLFW is still relevant for creating and managing an GL context. With WebGPU there is no equivalent GLFW functionality (some was recently discussed at glfw/glfw#2333 - tying in WebGPU surface creation - but this is the sum total of interaction GLFW would have with WebGPU). Don't get me wrong, I love GLFW, I've been working with it for about 12 years now. For writing cross-platform code it can't be beaten. But right now I'm writing single-platform code for the web with Emscripten, and in that situation, all GLFW provides is a compatibility layer - creating windows isn't a concept that exists on the web, and when there's no longer a GL context to manage, all it provides is translation between HTML5 inputs via its own input system. The rationale for this PR is just to close that loop, short-circuiting the need for GLFW in this specific situation entirely.
Sure. My point is just that the whole weight of GLFW isn't always necessary.
Sure, absolutely - it was not my intention to make any statements or implications about GLFW vs SDL or anything else. This is intended to be a much lighter weight alternative to those full-service platforms.
I agree it's not a big deal. But some developers, myself included, like to squeeze every drop of performance out of a given frame. For example, the ImGui_ImplGlfw_NewFrame function does quite a lot of work, none of which is actually needed in a callback-driven Emscripten environment - all of this can be omitted in this version.
I didn't mean to imply that this backend wouldn't work with WebGL - I don't think I said anything like that in my description, I'd be happy to revise any misleading wording if you point it out! It just doesn't handle rendering at all. Other rendering backends will interoperate very well with it. It's just that in that situation, GLFW makes (more) sense, because it provides all of the GL context management glue already. Before recently adopting WebGPU, my Emscripten projects all use GLFW for WebGL rendering, and this new backend is my migration path to WebGPU where I no longer need GLFW. I'm not trying to prescribe any specific way of doing things for other developers, this is just something that I wrote for my own utility, that I feel might be useful for others too.
I definitely wouldn't sell it on that basis! The Emscripten features are well established where they're used in those platforms already. But WebGPU is a new way of doing things from a rendering standpoint, which only really makes sense on the web. Whereas Emscripten allows you to write classic OpenGL and execute as WebGL, so a project can support Emscripten as well as native platforms with the same code; with WebGPU on Emscripten you're really going to be writing for the web only. I know there are desktop implementations of WebGPU as well, but the real benefit for me is being able to write code once and have it run on all platforms that support a browser, with near-native performance, and using just one set of APIs without any translation layers.
Agreed. But Emscripten is already supported in several backends such as those for GLFW, the result sometimes producing a complex forest of
As above, I think this is a misunderstanding. This backend simply doesn't attempt to do anything rendering-related.
Absolutely, I expected that - please let me know if there's a style guide somewhere that I've missed, or if you have specific feedback. No problem to adapt this however is required.
Yep, no problem of course, all transferable rights are hereby granted to the project maintainer as per the CLA. I didn't see any copyright statements in the existing backend source, so please let me know how you'd like this to be rephrased, or if you just require it to be deleted entirely. |
What is it?
A new platform back-end, similar to
imgui_impl_glfw
, removing any dependency on GLFW, for use when building with Emscripten running in a web browser. Instead of using Emscripten's GLFW compatibility wrapper for input to imgui, it uses Emscripten's HTML5 API directly.Motivation
The primary motivation for this is the development of WebGPU, and relative obsolescence of GLFW in that context.
Imgui has a rendering backend which allows one to build web applications with Emscripten rendering with WebGPU instead of WebGL. When rendering with WebGPU instead of WebGL, most of GLFW's functionality is no longer required. However, GLFW remains the standard way of processing input for imgui when running on web, building with Emscripten. The version of GLFW shipped with Emscripten is actually a compatibility wrapper around the HTML5 javascript API, so when the
imgui_impl_glfw
platform backend creates its callbacks to pass data to imgui, it adds another layer of translation and indirection from the underlying API itself, which isn't really necessary.This platform backend seeks to replace the GLFW backend when building with Emscripten for the web, in situations where rendering with WebGL is not necessary - either when rendering with WebGPU, or other hypothetical rendering backends.
What's added
The proposed
imgui_impl_emscripten
backend uses Emscripten's HTML5 API to set callbacks directly, to trigger relevant state changes in imgui:What is omitted
imgui_impl_wgpu
.Demo