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:
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by atdunbg on 2026/9/20.
|
||||
//
|
||||
|
||||
#ifndef HELLOVULKAN_LOG_H
|
||||
#define HELLOVULKAN_LOG_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace Engine {
|
||||
|
||||
#define ENGINE_TRACE(...) ::spdlog::trace(__VA_ARGS__)
|
||||
#define ENGINE_INFO(...) ::spdlog::info(__VA_ARGS__)
|
||||
#define ENGINE_WARN(...) ::spdlog::warn(__VA_ARGS__)
|
||||
#define ENGINE_ERROR(...) ::spdlog::error(__VA_ARGS__)
|
||||
#define ENGINE_FATAL(...) ::spdlog::critical(__VA_ARGS__)
|
||||
|
||||
} // namespace Engine
|
||||
|
||||
#endif //HELLOVULKAN_LOG_H
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Created by atdunbg on 2026/9/20.
|
||||
//
|
||||
|
||||
#ifndef HELLOVULKAN_TYPES_H
|
||||
#define HELLOVULKAN_TYPES_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Engine {
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
|
||||
template<typename T>
|
||||
using Scope = std::unique_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
Scope<T> CreateScope(Args&&... args) {
|
||||
return std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
Ref<T> CreateRef(Args&&... args) {
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // namespace Engine
|
||||
|
||||
#endif //HELLOVULKAN_TYPES_H
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// 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"
|
||||
|
||||
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();
|
||||
|
||||
vk::SurfaceKHR CreateSurface(vk::Instance instance);
|
||||
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();
|
||||
|
||||
private:
|
||||
GLFWwindow* m_Window = nullptr;
|
||||
u32 m_Width;
|
||||
u32 m_Height;
|
||||
std::string m_Title;
|
||||
};
|
||||
|
||||
} // namespace Engine
|
||||
|
||||
|
||||
#endif //HELLOVULKAN_WINDOW_H
|
||||
Reference in New Issue
Block a user