Expand description

egui_backend crate primarily provides traits to abstract away Window and Rendering parts of egui backends. this allows us to use any compatible (see WARNING below) window backend with any render backend crate.

this crate can provides 4 traits:

  1. WindowBackend: implemented by window backends
  2. OpenGLWindowContext : specific to Native openGL. Window Backends which support OpengGL can implement this trait
  3. GfxBackend<W: WindowBackend>: implemented by rendering backends for particular or any window backends
  4. UserApp<W: WindowBackend, G: GfxBackend>: implemented by egui users for a particular combination or any combination of Window or Gfx Backends

look at the docs of the relevant trait to learn more.

WARNING: the primary goal was to separate window and rendering completely. It would work for modern graphics api backends like vulkan, metal, dx12 etc.. but for opengl, window parts are often mixed with opengl parts. for example, opengl needs functions like swap_buffers, make_context_current or get_proc_address which are provided by the window crates like sdl2 / glfw / glutin. this is made complicated by multi-threading or the fact that opengl context is often created with a window rather than a separate api etc..

If we remove support for OpenGL, we can simplify this crate A LOT.

TODO: remove OpenGL into a separate crate / trait once webgpu spec is stable

https://developer.chrome.com/en/docs/web-platform/webgpu/ origin trials of webgpu in chrome ends on 1st Feb, 2023.

Re-exports

pub use egui;

Structs

Intended to provide a common struct which all window backends accept as their configuration. a lot of the settings are Option<T>, so that users can let the window backends choose defaults when user doesn’t care.

This is the output from egui that renderer needs. meshes and textures_delta come from egui directly. but window backend needs to also provide screensize in logical coords, scale and physical framebuffer size in pixels.

Native settings for OpenGL creation.

these are settings to be provided to browser when requesting a webgl context

Enums

Different kinds of gfx APIs and their relevant settings.

Traits

This is the trait to implement for Gfx backends. these could be Gfx APIs like opengl or vulkan or wgpu etc.. or higher level renderers like three-d or rend3 or custom renderers etc..

most window backends create the opengl context along with the window (glfw / sdl2) and we need some functions like SwapBuffers or MakeCurrent etc.. which will be called by the renderer. most window backends keep the “OpenGL Window Context” together with the window object itself.

This is the trait most users care about. just implement this trait and you can use any WindowBackend or GfxBackend to run your egui app.

Implement this trait for your windowing backend. the main responsibility of a Windowing Backend is to