zengine/engine/modules/render/vulkan/include/vkn/vulkan_window.h

56 lines
1.6 KiB
C
Raw Normal View History

2024-08-17 18:01:21 +08:00
#pragma once
#include "type.h"
#include "render/window.h"
2024-09-01 22:32:29 +08:00
#include <SDL2/SDL_vulkan.h>
2024-08-17 18:01:21 +08:00
namespace vkn {
2024-08-30 22:09:05 +08:00
class Device;
2024-09-07 17:48:12 +08:00
struct VulkanContext;
2024-09-22 20:26:49 +08:00
using api::TextureDesc;
2024-09-01 22:32:29 +08:00
struct VULKAN_API VulkanWindowArgs {
2024-08-30 22:09:05 +08:00
uint32_t frames;
uint32_t width;
uint32_t height;
VkFormat imageFormat;
VkColorSpaceKHR imageColorSpace;
VkPresentModeKHR presentMode;
VkImageUsageFlags imageUsage;
uint32_t maxFrameInFlightCount;
VkExtent2D EnableImageExtent2D(VkSurfaceCapabilitiesKHR& capabilities);
2024-12-23 17:44:32 +08:00
static VulkanWindowArgs Default(uint32_t frames);
2024-08-30 22:09:05 +08:00
};
class VulkanSwapchain {
private:
2024-10-21 16:31:02 +08:00
friend class VulkanWindow;
2024-08-30 22:09:05 +08:00
Device& mDevice;
VkSwapchainKHR mPtr;
2024-12-15 17:24:35 +08:00
uint32_t mFrames;
2024-10-21 16:31:02 +08:00
pmr::vector<TextureDesc> mSurfaces{ GlobalPool() };
2024-09-22 20:26:49 +08:00
pmr::vector<VkCommandBuffer> mCommands{ GlobalPool() };
2024-10-21 16:31:02 +08:00
pmr::vector<VkFence> mFences{ GlobalPool() };
pmr::vector<VkSemaphore> mSemaphores{ GlobalPool() };
2024-08-30 22:09:05 +08:00
public:
VulkanSwapchain(Device& device, VkSurfaceKHR surface, VulkanWindowArgs& args);
2024-09-07 17:48:12 +08:00
void Aquire(VulkanContext& ctx);
void Present(VulkanContext& ctx);
2024-08-30 22:09:05 +08:00
};
2024-09-01 22:32:29 +08:00
class VULKAN_API VulkanWindow : public api::Window {
2024-08-17 18:01:21 +08:00
private:
2024-08-30 22:09:05 +08:00
VulkanSwapchain* mSwapchain;
2024-08-23 22:13:05 +08:00
public:
void* operator new(size_t size) {
return ::operator new(size, GlobalPool());
}
void operator delete(void* p) {}
2024-08-17 18:01:21 +08:00
public:
using api::Window::Window;
2024-12-23 17:44:32 +08:00
bool CreateRender(VulkanWindowArgs& args);
2024-08-23 22:13:05 +08:00
static VulkanWindow* Ptr() {
return (VulkanWindow*)api::Window::Ptr();
}
2024-09-07 17:48:12 +08:00
void Aquire(VulkanContext& ctx) { mSwapchain->Aquire(ctx); };
void Present(VulkanContext& ctx) { mSwapchain->Present(ctx); };
2024-12-12 22:20:56 +08:00
VulkanSwapchain* Swapchain() {
return mSwapchain;
}
2024-08-17 18:01:21 +08:00
};
}