feat: 透明窗口支持 + 退出确认流程 + ImGui 总开关
用户自主改进批次: - 透明窗口:GLFW_TRANSPARENT_FRAMEBUFFER + 窗口 opacity 0.5, swapchain composite alpha 按能力自适应(Opaque/Pre/PostMultiplied), Forward 清屏 alpha=0,tonemap 透传 HDR alpha——物体实体、背景透明 - 退出确认:Window 挂 WindowCloseCallback 发事件,App 侧 OnWindowClose 置确认标记,OnRenderOverlay 弹 ImGui 确认框后 Close(); 主循环退出条件改为 m_Running(close 事件驱动) - ImGui 总开关:` 键切换 ImGuiLayer::SetEnabled,禁用时跳过 NewFrame/OnRenderOverlay/BuildDrawData 整段 - 帧率控制简化:去掉 LimitFps 开关,非 vsync 时恒按 target 限帧 (默认 60,可调 ≥24);m_VSync 默认 false(Mailbox 不限速) - 清理:Model.cpp const 修正,swapchain 日志带 present mode, GPU 遥测暂时注释 验证:0 error 0 warning,composite alpha 实测选 PreMultiplied(0x2), present=Mailbox
This commit is contained in:
@@ -84,7 +84,7 @@ namespace Engine {
|
||||
|
||||
OnInit();
|
||||
|
||||
while (m_Running && !m_Window->ShouldClose()) {
|
||||
while (m_Running) {
|
||||
const auto frameStart = std::chrono::steady_clock::now();
|
||||
|
||||
m_Window->PollEvents();
|
||||
@@ -103,13 +103,10 @@ namespace Engine {
|
||||
const auto uiStart = std::chrono::steady_clock::now();
|
||||
|
||||
// ---- UI 构建段:OnRenderOverlay 只"声明"控件,不直接碰 GPU ----
|
||||
if (m_ImGuiLayer) {
|
||||
if (m_ImGuiLayer && m_ImGuiLayer->IsEnabled())
|
||||
{
|
||||
m_ImGuiLayer->NewFrame();
|
||||
}
|
||||
|
||||
OnRenderOverlay();
|
||||
|
||||
if (m_ImGuiLayer) {
|
||||
OnRenderOverlay();
|
||||
m_ImGuiLayer->BuildDrawData();
|
||||
}
|
||||
const auto uiEnd = std::chrono::steady_clock::now();
|
||||
@@ -120,7 +117,7 @@ namespace Engine {
|
||||
|
||||
// ---- 帧率控制:vsync 开启时 present 自带节奏;否则按目标限帧 ----
|
||||
// 策略:先 sleep 到剩 ~2ms,再自旋——精度高且不烧 CPU
|
||||
if (!m_VSync && m_LimitFps) {
|
||||
if (!m_VSync) {
|
||||
const auto deadline = frameStart +
|
||||
std::chrono::microseconds(static_cast<long long>(
|
||||
1e6 / m_TargetFps));
|
||||
@@ -137,23 +134,6 @@ namespace Engine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CPU 侧遥测(每 120 帧一行):定位帧耗时的 CPU 归属
|
||||
const auto frameEnd = std::chrono::steady_clock::now();
|
||||
static u32 cpuTelemetryCount = 0;
|
||||
if (++cpuTelemetryCount % 120 == 1) {
|
||||
const f32 uiMs = std::chrono::duration<f32, std::milli>(
|
||||
uiEnd - uiStart).count();
|
||||
const f32 renderMs = std::chrono::duration<f32, std::milli>(
|
||||
frameEnd - uiEnd).count();
|
||||
const f32 updateMs = std::chrono::duration<f32, std::milli>(
|
||||
uiStart - frameStart).count();
|
||||
const f32 totalMs = std::chrono::duration<f32, std::milli>(
|
||||
frameEnd - frameStart).count();
|
||||
ENGINE_INFO("CPU times: update={:.2f}ms ui={:.2f}ms render={:.2f}ms total={:.2f}ms",
|
||||
updateMs, uiMs, renderMs, totalMs);
|
||||
}
|
||||
|
||||
++m_FrameCount;
|
||||
}
|
||||
|
||||
@@ -182,7 +162,6 @@ namespace Engine {
|
||||
|
||||
void Application::OnWindowClose(const Event& event)
|
||||
{
|
||||
// 默认行为:直接退出。需要"退出确认"的程序覆写本钩子。
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user