Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
VulkanWindowGraphicsBinding.hpp
1#pragma once
2
3#include <Windows.h>
4#include <Common/Window/Window.hpp>
5#include <Common/Graphics/WindowGraphicsBinding.hpp>
6
7#include "VulkanCore.hpp"
8#include "VulkanRenderTarget.hpp"
9#include <vector>
10
11namespace Grindstone::GraphicsAPI::Vulkan {
12 class Framebuffer;
13 class RenderPass;
14
15 struct ImageSet {
16 Framebuffer* framebuffer;
17 RenderTarget* swapChainTarget;
18 VkFence fence;
19 };
20
22 VkImage image;
23 VkImageView imageView;
24 VkFramebuffer framebuffer;
25 };
26
28 VkSwapchainKHR swapChain;
29 VkRenderPass renderPass;
30 uint32_t width;
31 uint32_t height;
32 uint32_t imageSetCount;
33 VkSurfaceFormatKHR surfaceFormat;
34 ImageSetNative* imageSets;
35 };
36
38 public:
40
41 void CreateSwapChain();
42 virtual VkSurfaceKHR GetSurface();
43 virtual VkSwapchainKHR GetSwapchain();
44 virtual void SubmitWindowObjects(WindowBindingDataNative& windowBindingData);
45 SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice device);
46 void CreateSyncObjects();
47
48 // Inherited via WindowGraphicsBinding
49 virtual bool Initialize(Window *window) override;
50 virtual bool AcquireNextImage() override;
51 virtual void SubmitCommandBuffer(GraphicsAPI::CommandBuffer* buffers) override;
52 virtual bool PresentSwapchain() override;
53 virtual Grindstone::GraphicsAPI::RenderPass* GetRenderPass() override;
54 virtual Grindstone::GraphicsAPI::Framebuffer* GetCurrentFramebuffer() override;
55 virtual uint32_t GetCurrentImageIndex() override;
56 virtual uint32_t GetMaxFramesInFlight() override;
57 virtual void ImmediateSetContext() override;
58 virtual void ImmediateSwapBuffers() override;
59 virtual void Resize(uint32_t width, uint32_t height) override;
60 private:
61 ColorFormat GetDeviceColorFormat() const;
62 VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
63 VkPresentModeKHR ChooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
64 VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
65 void CreateImageSets();
66 void CreateRenderPass();
67 void RecreateSwapchain();
68 private:
69 bool isSwapchainDirty = false;
70 Window* window = nullptr;
71 RenderPass* renderPass = nullptr;
72 std::vector<ImageSet> imageSets;
73
74 ColorFormat swapchainFormat = ColorFormat::Invalid;
75 VkFormat swapchainVulkanFormat;
76
77 VkSurfaceKHR surface = nullptr;
78 VkSwapchainKHR swapChain = nullptr;
79
80 VkExtent2D swapExtent;
81 std::vector<VkSemaphore> imageAvailableSemaphores;
82 std::vector<VkSemaphore> renderFinishedSemaphores;
83 std::vector<VkFence> inFlightFences;
84 uint32_t currentFrame = 0;
85 uint32_t maxFramesInFlight = 0;
86 uint32_t currentSwapchainImageIndex = 0;
87 };
88}
Definition CommandBuffer.hpp:21
Definition Framebuffer.hpp:19
Definition RenderPass.hpp:27
Definition VulkanFramebuffer.hpp:16
Definition VulkanRenderPass.hpp:10
Definition VulkanRenderTarget.hpp:10
Definition VulkanWindowGraphicsBinding.hpp:37
Definition WindowGraphicsBinding.hpp:16
Definition Window.cs:7
Definition VulkanWindowGraphicsBinding.hpp:21
Definition VulkanWindowGraphicsBinding.hpp:15
Definition VulkanWindowGraphicsBinding.hpp:27