-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
SwapChain.h
94 lines (73 loc) · 2.5 KB
/
SwapChain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <vector>
#include "Common/CommonTypes.h"
#include "VideoBackends/Vulkan/Constants.h"
#include "VideoBackends/Vulkan/Texture2D.h"
namespace Vulkan
{
class CommandBufferManager;
class ObjectCache;
class SwapChain
{
public:
SwapChain(void* native_handle, VkSurfaceKHR surface);
~SwapChain();
// Creates a vulkan-renderable surface for the specified window handle.
static VkSurfaceKHR CreateVulkanSurface(VkInstance instance, void* hwnd);
// Create a new swap chain from a pre-existing surface.
static std::unique_ptr<SwapChain> Create(void* native_handle, VkSurfaceKHR surface);
void* GetNativeHandle() const { return m_native_handle; }
VkSurfaceKHR GetSurface() const { return m_surface; }
VkSurfaceFormatKHR GetSurfaceFormat() const { return m_surface_format; }
VkSwapchainKHR GetSwapChain() const { return m_swap_chain; }
VkRenderPass GetRenderPass() const { return m_render_pass; }
u32 GetWidth() const { return m_width; }
u32 GetHeight() const { return m_height; }
u32 GetCurrentImageIndex() const { return m_current_swap_chain_image_index; }
VkImage GetCurrentImage() const
{
return m_swap_chain_images[m_current_swap_chain_image_index].image;
}
Texture2D* GetCurrentTexture() const
{
return m_swap_chain_images[m_current_swap_chain_image_index].texture.get();
}
VkFramebuffer GetCurrentFramebuffer() const
{
return m_swap_chain_images[m_current_swap_chain_image_index].framebuffer;
}
VkResult AcquireNextImage(VkSemaphore available_semaphore);
bool RecreateSurface(void* native_handle);
bool ResizeSwapChain();
private:
bool SelectSurfaceFormat();
bool SelectPresentMode();
bool CreateSwapChain();
void DestroySwapChain();
bool CreateRenderPass();
void DestroyRenderPass();
bool SetupSwapChainImages();
void DestroySwapChainImages();
void DestroySurface();
struct SwapChainImage
{
VkImage image;
std::unique_ptr<Texture2D> texture;
VkFramebuffer framebuffer;
};
void* m_native_handle = nullptr;
VkSurfaceKHR m_surface = nullptr;
VkSurfaceFormatKHR m_surface_format = {};
VkPresentModeKHR m_present_mode = VK_PRESENT_MODE_RANGE_SIZE_KHR;
VkSwapchainKHR m_swap_chain = nullptr;
std::vector<SwapChainImage> m_swap_chain_images;
u32 m_current_swap_chain_image_index = 0;
VkRenderPass m_render_pass = nullptr;
u32 m_width = 0;
u32 m_height = 0;
};
} // namespace Vulkan