#ifndef GAMINGCORE_VULKAN_WRAPPER_HPP #define GAMINGCORE_VULKAN_WRAPPER_HPP #include #include #include #include #include "core/VulkanBase.hpp" namespace Core::Vulkan { bool init(); void render(); void destroy(); template struct BaseWrapper { VkDevice device = VK_NULL_HANDLE; T handle = VK_NULL_HANDLE; BaseWrapper() = default; BaseWrapper(const BaseWrapper&) = delete; BaseWrapper(BaseWrapper&& o) : BaseWrapper() { swap(o); } BaseWrapper& operator=(const BaseWrapper&) = delete; BaseWrapper& operator=(BaseWrapper&& o) { swap(o); o = BaseWrapper(); } void swap(BaseWrapper& o) { Core::swap(device, o.device); Core::swap(handle, o.handle); } operator T() { return handle; } operator T*() { return &handle; } operator const T*() const { return &handle; } }; struct ImageView : public BaseWrapper { ImageView() = default; ImageView(ImageView&&) = default; ~ImageView(); bool init(VkDevice d, VkImage image, VkFormat format); }; struct Framebuffer : public BaseWrapper { Framebuffer() = default; Framebuffer(Framebuffer&&) = default; ~Framebuffer(); bool init(const ImageView& iv, VkRenderPass rp, u32 width, u32 height); }; struct Semaphore : public BaseWrapper { Semaphore() = default; Semaphore(Semaphore&&) = default; ~Semaphore(); bool init(VkDevice d); }; struct Fence : public BaseWrapper { Fence() = default; Fence(Fence&&) = default; ~Fence(); bool init(VkDevice d); void reset(); void waitFor(u64 timeout = UINT64_MAX); }; struct Swapchain : public BaseWrapper { Swapchain() = default; Swapchain(Swapchain&&) = default; ~Swapchain(); struct Data { Base& base; VkExtent2D size{}; VkSurfaceFormatKHR surfaceFormat{}; VkPresentModeKHR presentMode{}; VkSharingMode sharingMode{}; List queueFamilies{}; }; bool init(Data& d); bool nextImage(u32& imageIndex, Semaphore& s, u64 timeout = UINT64_MAX); }; struct ShaderModule : public BaseWrapper { ShaderModule() = default; ShaderModule(ShaderModule&&) = default; ~ShaderModule(); bool init(VkDevice d, const char* path); }; struct PipelineLayout : public BaseWrapper { PipelineLayout() = default; PipelineLayout(PipelineLayout&&) = default; ~PipelineLayout(); bool init(VkDevice d); }; struct SwapchainImages { List images{}; List imageViews{}; bool init(const Swapchain& s, VkFormat format); }; struct RenderPass : public BaseWrapper { RenderPass() = default; RenderPass(RenderPass&&) = default; ~RenderPass(); bool init(VkDevice d, VkFormat format); }; struct Pipeline : public BaseWrapper { VkViewport viewport; VkRect2D scissor; Pipeline(); Pipeline(Pipeline&&) = default; ~Pipeline(); void updateSize(u32 width, u32 height); bool init(PipelineLayout& pl, RenderPass& rp); }; struct CommandPool : public BaseWrapper { CommandPool() = default; CommandPool(CommandPool&&) = default; ~CommandPool(); bool init(VkDevice d, u32 queueFamily); }; struct CommandBuffer : public BaseWrapper { CommandBuffer() = default; CommandBuffer(CommandBuffer&&) = default; bool init(CommandPool& cp); void reset(); void begin(); void end(); void beginRenderPass( RenderPass& rp, Framebuffer& f, const VkExtent2D& size); void endRenderPass(); void bindPipeline(Pipeline& p); void draw(u32 vertices); }; struct Queue : public BaseWrapper { Queue() = default; Queue(Queue&&) = default; bool init(VkDevice d, u32 queueFamily); void submit( CommandBuffer& cb, Fence& f, Semaphore& wait, Semaphore& signal, VkPipelineStageFlags flags); void present(Semaphore& signal, Swapchain& s, u32 index); }; } #endif