Graphics: why immediate mode?

Why is immediate mode so popular in graphics? (imgui, egui)

Why is it more popular than retained mode (iced) ?

This confuses me for the following reason. In my understanding:

  1. retained model only recalculates the location of gui elements on model change

  2. immediate model recalculates the location of all visible gui elements on EVERY FRAME

Given how "wasteful" immediate mode is, why is it so popular in graphics (when high frame rates matter) ?

egui has a section on this GitHub - emilk/egui: egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native TLDR: immediate mode is just simplier to use so where performance doesn't matter that much they're preferred.

It's not a coincidence that both imgui and egui are popular for quick and dirty debug UIs on top of games, where the UI is rather small, with very low styling and customization and thus performance is not a concern.

retained mode GUI is basically a cache invalidation problem, it is actually easier to redraw everything as opposed to cleverly finding out what has changed and trying to do minimal amount of redraw.

that's also one of the reasons behind the "diff two widget tree" idea. there's also attempts to emulate a immediate mode API while under the hood use retained mode widget trees (essentially as caches) to do the rendering.

it's just my personal opinion.

7 Likes

Retained mode GUI is stateful, which means you can mess up the state.

When you display a value of some field in the UI, and something in the program changes the field's value, the GUI has to be made aware of that and update the widget with the new value. If the struct containing the field is deleted, you need to delete GUI widgets for it too. This requires hooking up some sort of observers and event handling to everything exposed to the UI. If you forget to notify the UI after updating some program data, the UI will be out of sync.

With immediate mode UI you just can't make that mistake. You rebuild everything based on the most up-to-date data, and you don't even need to handle events for deletions, because you just won't build UI for things that were deleted.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.