ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.38k stars 10.33k forks source link

New platform backend: imgui_impl_emscripten #8178

Open slowriot opened 2 days ago

slowriot commented 2 days ago

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

Demo