Files
HelloVulkan/Engine/include/Engine/Core/Window.h
T
atdunbg dd7c67a116 feat: ImGui docking Editor + 显示链/帧同步/输入语义重构
- App/editor: Hierarchy/Inspector/Viewport/Stats 四面板 + DockBuilder 默认布局,main.cpp 瘦身为场景搭建与生命周期
- 显示链: Tonemap→PresentTarget 经 ImGui::Image 呈现(零色偏),backbuffer 仅承载 ImGui;Direct/Viewport 双显示模式 + 面板分辨率上报
- 帧首同步 BeginFrameSync: resize/vsync/尺寸/模式意图统一帧首落定(修描述符悬垂);修复 vsync 意图未落 swapchain 导致的每帧重建交换链
- 输入: Editor 每帧判定键盘/鼠标归属(打字让位、Viewport hover/focus 放行、Fullscreen 全放行)
- 材质: roughness 独立槽位 + 非 glTF 金属/粗糙贴图映射;透明队列 depthWrite=FALSE + translucent 独立 shader + scratch 清帧
- FBX: 非蒙皮网格烘焙节点链全局变换(Z-up 旋转/单位换算落顶点)
- Hierarchy 行 ImGui ID 以 UUID 作用域(重名不冲突、改名不丢选中)
2026-09-30 00:24:53 +08:00

111 lines
3.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// Created by atdunbg on 2026/9/20.
//
#ifndef HELLOVULKAN_WINDOW_H
#define HELLOVULKAN_WINDOW_H
#include <vulkan/vulkan.hpp>
#include <string>
#include <functional>
#include "Types.h"
#include "Event.h"
struct GLFWwindow;
namespace Engine {
class Window {
public:
Window(const std::string& title, u32 width, u32 height);
~Window();
Window(const Window&) = delete;
Window& operator=(const Window&) = delete;
bool ShouldClose() const;
void PollEvents();
// 事件出口:GLFW 回调 → Event → 上层回调(由 Application 注册)。
// 未注册时事件直接丢弃。
using EventCallbackFn = std::function<void(const Event&)>;
void SetEventCallback(EventCallbackFn callback) { m_EventCallback = std::move(callback); }
// 输入捕获:返回 true = 该类输入被 UI 占用(如 ImGui 窗口交互)。
// 生效范围:类型化事件回调(Key/Mouse*)+ 轮询接口
//(IsKeyPressed/GetMouseDelta)。窗口类事件(Resize/Close/Focus)不受影响。
// 未设置时全部放行(行为与无 UI 时一致)。
using CaptureFn = std::function<bool()>;
void SetInputCapture(CaptureFn keyboard, CaptureFn mouse)
{
m_KeyboardCapture = std::move(keyboard);
m_MouseCapture = std::move(mouse);
}
vk::SurfaceKHR CreateSurface(vk::Instance instance) const;
void DestroySurface(vk::Instance instance, vk::SurfaceKHR surface);
u32 GetWidth() const { return m_Width; }
u32 GetHeight() const { return m_Height; }
GLFWwindow* GetHandle() const { return m_Window; }
// 需要的 Vulkan 扩展(GLFW 提供)
static std::vector<const char*> GetRequiredExtensions();
// 窗口事件
void GetFramebufferSize(int& width, int& height) const;
bool WasResized() const { return m_FramebufferResized; }
void ResetResizedFlag() { m_FramebufferResized = false; }
// 输入事件系统
bool IsKeyPressed(int key) const;
// UI 捕获鼠标(ImGui 悬停)时返回 false——面板上的按键归 ImGui
bool IsMouseButtonPressed(int button) const;
void GetMouseDelta(float& dx, float& dy) const;
// 光标捕获(自由视角):DISABLED 隐藏光标出无界增量,NORMAL 恢复。
// 重复设置同值无操作;切换后鼠标增量参考点重置(防跳变)
void SetCursorCaptured(bool captured);
bool IsCursorCaptured() const { return m_CursorCaptured; }
private:
GLFWwindow* m_Window = nullptr;
u32 m_Width;
u32 m_Height;
std::string m_Title;
bool m_FramebufferResized = false;
EventCallbackFn m_EventCallback;
// UI 输入捕获(ImGui 接管时置位)
CaptureFn m_KeyboardCapture;
CaptureFn m_MouseCapture;
// 光标捕获状态与鼠标增量参考点(GetMouseDelta 为 const,用 mutable)
bool m_CursorCaptured = false;
mutable bool m_FirstMouse = true;
mutable double m_LastMouseX = 0.0;
mutable double m_LastMouseY = 0.0;
// GLFW 静态回调(通过 window user pointer 找回 this)
static void FramebufferResizeCallback(GLFWwindow* window, int width, int height);
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
static void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
static void CursorPosCallback(GLFWwindow* window, double xpos, double ypos);
static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
static void WindowFocusCallback(GLFWwindow* window, int focused);
static void WindowCloseCallback(GLFWwindow* window);
};
} // namespace Engine
#endif //HELLOVULKAN_WINDOW_H