feat: 搭建 Vulkan 1.4 渲染器骨架,绘制旋转 3D 立方体

使用 Vulkan 1.4 现代路径初始化引擎骨架:
- 用 Shader Object (VK_EXT_shader_object) 替代传统 VkPipeline
- 用 Dynamic Rendering 替代 RenderPass/Framebuffer
- 用 Synchronization2 管理 barrier

核心模块:
- Window:GLFW 封装,GLFW_NO_API 模式,兼容 Wayland
- Log:spdlog 封装
- Types:u32/u64/f32 类型别名

Vulkan 后端:
- Device:Instance、PhysicalDevice、LogicalDevice、Queue 及 feature 查询
- Swapchain:Image、ImageView、DepthBuffer、Recreate
- ShaderManager:SPIR-V 加载与 ShaderEXT 创建
- CommandManager:CommandPool 与主 CommandBuffer
- SyncManager:per-frame Fence 与 ImageAvailable semaphore,per-image RenderFinished semaphore,2 frames in flight
- MemoryAllocator:内存子分配器,256MB block,persistent mapping
- Buffer:VertexBuffer、IndexBuffer、UniformBuffer 封装
- UniformBuffer:每帧上传 MVP 矩阵
- DescriptorManager:DescriptorSetLayout、DescriptorPool、DescriptorSet 及更新

Renderer:
- 协调所有子系统
- 绘制每面不同颜色的旋转 3D 立方体
- 启用 depth test,MVP 矩阵由 GLM 计算

构建:
- CMake 组织 Engine 静态库与 App 可执行文件
- glfw、glm、spdlog 通过 add_subdirectory 引入
This commit is contained in:
2026-09-20 23:09:40 +08:00
parent 706ee2301e
commit 381b7c0aa6
38 changed files with 2423 additions and 12 deletions
+74
View File
@@ -0,0 +1,74 @@
//
// Created by atdunbg on 2026/9/20.
//
#include <Engine/Core/Window.h>
#include <Engine/Core/Log.h>
#include <GLFW/glfw3.h>
namespace Engine {
Window::Window(const std::string& title, u32 width, u32 height)
: m_Width(width), m_Height(height), m_Title(title)
{
if (!glfwInit()) {
ENGINE_FATAL("glfwInit failed");
return;
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
m_Window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
if (!m_Window) {
ENGINE_FATAL("glfwCreateWindow failed");
glfwTerminate();
return;
}
ENGINE_INFO("Window created: {} ({}x{})", title, width, height);
}
Window::~Window()
{
if (m_Window) {
glfwDestroyWindow(m_Window);
}
glfwTerminate();
}
bool Window::ShouldClose() const
{
return glfwWindowShouldClose(m_Window);
}
void Window::PollEvents()
{
glfwPollEvents();
}
vk::SurfaceKHR Window::CreateSurface(vk::Instance instance)
{
VkSurfaceKHR surface;
if (glfwCreateWindowSurface(instance, m_Window, nullptr, &surface) != VK_SUCCESS) {
ENGINE_FATAL("glfwCreateWindowSurface failed");
return nullptr;
}
return surface;
}
void Window::DestroySurface(vk::Instance instance, vk::SurfaceKHR surface)
{
instance.destroySurfaceKHR(surface);
}
std::vector<const char*> Window::GetRequiredExtensions()
{
u32 count = 0;
const char** extensions = glfwGetRequiredInstanceExtensions(&count);
return std::vector<const char*>(extensions, extensions + count);
}
} // namespace Engine