imgui-mirror/examples/example_apple_metal4
Ahmidou Lyazidi 6555153b21 Backends + Examples: Metal4: robust CAMetalLayer multi-viewport on macOS
Rework the Metal 4 backend and example for correct, glitch-free multi-viewport
rendering on macOS, and convert example_apple_metal4 off MTKView.

Backend (imgui_impl_metal4.mm):
- Per-window argument tables so overlapping per-window GPU work within a frame can't
  corrupt each other's bindings (multi-viewport flicker).
- Hold per-slot vertex/index buffers until their frame completes, so a second viewport
  rendered later in the same frame can't overwrite a buffer still in flight (blink).
- Make hand-built render-pass drawables resident, and evict stale (resized-away)
  drawables from the residency set so it can't grow without bound during a live resize.
- Present secondary viewports in-transaction on the frame they were resized so content
  stays glued to the new size (no stutter).

Example (example_apple_metal4/main.mm):
- Replace MTKView with a custom NSView/UIView + CAMetalLayer driven by a display link.
- Proper frames-in-flight: per-slot command allocators, rotating slots, and a semaphore
  gate released on GPU completion via an MTLSharedEvent listener.
- Glitch-free main-window resize: present in-transaction during a live resize, driven by
  AppKit (the display link steps aside) so the transaction commits and drawables aren't
  starved; async present otherwise (avoids a ~1s nextDrawable stall / freeze).
- Idle CPU throttling: only redraw on input/activity plus a slow heartbeat, so the main
  thread sleeps when nothing changes.
2026-09-18 14:35:49 -07:00
..

iOS / OSX Metal4 example

Introduction

This example shows how to integrate Dear ImGui with Metal4. It is based on the "cross-platform" game template provided with Xcode as of Xcode 9.

Consider basing your work off the example_glfw_metal/ or example_sdl2_metal/ examples. They are better supported and will be portable unlike this one.