Skip to content

[codex] Fix ImGui window framebuffer clearing#3

Merged
Sunrisepeak merged 6 commits into
mainfrom
codex/fix-imgui-window-clear
Jun 3, 2026
Merged

[codex] Fix ImGui window framebuffer clearing#3
Sunrisepeak merged 6 commits into
mainfrom
codex/fix-imgui-window-clear

Conversation

@Sunrisepeak
Copy link
Copy Markdown
Member

Summary

  • expose explicit framebuffer helpers from the GLFW/OpenGL3 backend modules
  • clear the color framebuffer in the GLFW/OpenGL3 examples before rendering ImGui draw data
  • extend backend API tests to cover the new helpers

Root Cause

The examples rendered ImGui draw data directly into the back buffer and swapped buffers without clearing the framebuffer each frame. Moving an ImGui window could leave stale pixels behind. The renderer backend itself should not implicitly clear because many applications render their own scene before drawing ImGui as an overlay.

Validation

  • mcpp test
  • cd examples/basic && mcpp run
  • cd examples/minimal_window && mcpp build
  • cd examples/glfw_opengl3 && mcpp build

This PR is intentionally left unmerged.

Split the package into imgui.core + a generic backend abstraction layer
(imgui.backend) plus reusable platform/renderer pieces composed into a
single Backend type per backend.

- imgui.backend: shared types (GlConfig/Error/FbSize), RecommendedGlConfig()
  cross-platform defaults, and a compile-time BackendApi concept.
- imgui.backend.platform.glfw / imgui.backend.renderer.opengl3: reusable
  assembly pieces (window/events vs GL/renderer).
- imgui.backend.glfw_opengl3: assembles them into ImGui::Backend::GlfwOpenGL3,
  static_assert(BackendApi<...>) enforced. Re-exports imgui.backend but not
  imgui.core; consumers import imgui.core themselves.
- Uniform usage: swapping backend is a different import + one-line alias.
- Cross-platform: macos/windows toolchain entries, CI matrix (ubuntu/macos/
  windows), RecommendedGlConfig() handles macOS forward-compat; examples drop
  hard-coded GL hints.
- core: export ImVec4.
- Remove per-function hand-forwarding composite module.

Design: .agents/docs/2026-06-03-imgui-backend-abstraction-design.md

Verified: mcpp build/test, all examples build, minimal_window runs a real
window (clean framebuffer clear, no artifacts) under both clang and gcc.
@Sunrisepeak
Copy link
Copy Markdown
Member Author

追加:backend 抽象层 + 跨平台重构 (e2a5c0f)

在原 framebuffer-clear 修复之上,按设计文档把架构重构为 imgui.core + 通用 backend 抽象层。

模块分层

  • imgui.backend —— 抽象层:共享类型 GlConfig/Error/FbSizeRecommendedGlConfig() 跨平台默认值、编译期 BackendApi concept(无平台代码)。
  • imgui.backend.platform.glfw / imgui.backend.renderer.opengl3 —— 可复用的 platform/renderer 拼装片。
  • imgui.backend.glfw_opengl3 —— 装配成单一 ImGui::Backend::GlfwOpenGL3 类型,static_assert(BackendApi<...>) 强制契约。re-export imgui.backend,但不 re-export imgui.core

用法一致:换后端 = 改 import + 一行 using Backend = ...,业务循环逐字不变。取消了旧组合模块的逐函数手工转发。

跨平台:mcpp.toml 增加 macos/windows toolchain;CI 改为 ubuntu/macos/windows 矩阵;RecommendedGlConfig() 自动处理 macOS forward-compat + GLSL 版本;示例移除硬编码 (3,3,true,false)

验证

  • mcpp build / mcpp test 通过(含契约 static_assert)
  • 三个 examples 全部 build 通过,examples/basic headless 运行 OK
  • examples/minimal_window 在真实显示(DISPLAY)下运行:窗口正常、framebuffer 清屏无残影;clang 与 gcc 16 均通过

设计文档:.agents/docs/2026-06-03-imgui-backend-abstraction-design.md

- Windows uses the PowerShell xlings installer (the bash one-liner only
  supports Linux/macOS); Linux/macOS keep curl|bash.
- All mcpp steps run under bash (Git Bash on Windows) for consistent syntax.
- Linux is the required must-pass leg; macOS/Windows are continue-on-error
  while mcpp-index toolchain/runtime support for them settles, so they do not
  block CI.
- mcpp.toml: use portable [toolchain] default = "llvm@20.1.7" instead of
  per-OS keys.
The minimal_window example lost its [toolchain] pin, so a fresh CI machine
fell back to installing gcc-musl (static) as default, which cannot link the
X11/GL window example. Pin all examples to default = "llvm@20.1.7" for
portable, deterministic toolchain selection across platforms.
@Sunrisepeak
Copy link
Copy Markdown
Member Author

CI 全绿 ✅ (run 26887174718)

三平台全部通过(build + test + 三个 examples 构建):

  • mcpp (ubuntu-latest) — success(必过主 job)
  • mcpp (macos-latest) — success
  • mcpp (windows-latest) — success

修复要点:

  • Windows 改用 PowerShell 安装 xlings(curl|bash 只支持 Linux/macOS);所有 mcpp 步骤统一走 bash(Windows 用 Git Bash)。
  • examples/minimal_window 此前丢了 [toolchain] pin,fresh CI 机器会回退到 gcc-musl(静态,808MB,链不了 X11/GL)而失败 —— 已为所有 example 与根包统一 [toolchain] default = "llvm@20.1.7"
  • macOS/Windows 仍保留 continue-on-error 作为安全网,Linux 为必过 job。

A pin is still required (an unpinned package falls back to gcc-musl static,
which cannot link X11/GL), but it does not have to be llvm. Linux now builds
with gcc 16; macOS/Windows keep llvm@20.1.7. Applied to the root package and
all examples. Verified: gcc 16 builds the library, both test binaries, and all
three examples on Linux.
A library should not dictate the consumer's toolchain. Remove [toolchain]
from the package and all examples; mcpp resolves the environment/default
toolchain instead. Verified locally (resolves gcc 16.1.0, lib + tests pass).
@Sunrisepeak Sunrisepeak marked this pull request as ready for review June 3, 2026 13:43
@Sunrisepeak Sunrisepeak merged commit 7e241fa into main Jun 3, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant