Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Swapchain.hpp
1#pragma once
2
3#include "Common.hpp"
4#include "graphics/GPUObjects.hpp"
5#include "system/Config.hpp"
6#include "resources/Texture.hpp"
7
8// Forward declarations.
9struct GPUContext;
10
16class Swapchain {
17
18public:
19
24 Swapchain(GPUContext & context, const RenderingConfig & config);
25
30 void resize(uint w, uint h);
31
35 bool nextFrame();
36
38 uint count(){ return _imageCount; }
39
41 uint minCount(){ return _minImageCount; }
42
44 ~Swapchain();
45
47 Texture& color(){ return *_backbuffer; }
48
50 Texture& depth(){ return _depth; }
51
57 void getFormats(VkFormat& color, VkFormat& depth, VkFormat& stencil);
58
59private:
60
65 void setup(uint32_t width, uint32_t height);
66
70 bool finishFrame();
71
73 void clean();
74
75 GPUContext* _context = nullptr;
76 VkSwapchainKHR _swapchain = VK_NULL_HANDLE;
77
78 std::vector<Texture> _colors;
80 Texture* _backbuffer = nullptr;
81
82 std::vector<VkSemaphore> _imagesAvailable;
83 std::vector<VkSemaphore> _framesFinished;
84 std::vector<VkFence> _framesInFlight;
85
86 uint _imageCount = 0;
87 uint _minImageCount = 0;
88 bool _vsync = false;
89 uint32_t _imageIndex = 0;
90 bool _frameStarted = false;
91};
Configuration containing parameters for windows and renderers.
Definition: Config.hpp:113
A swapchain handles the creation and presentation of the backbuffer, along with GPU work submission a...
Definition: Swapchain.hpp:16
void clean()
Definition: Swapchain.cpp:374
uint count()
Definition: Swapchain.hpp:38
Texture & depth()
Definition: Swapchain.hpp:50
VkSwapchainKHR _swapchain
Native handle.
Definition: Swapchain.hpp:76
bool nextFrame()
Definition: Swapchain.cpp:312
~Swapchain()
Definition: Swapchain.cpp:364
bool _vsync
Is V-sync enabled.
Definition: Swapchain.hpp:88
bool finishFrame()
Definition: Swapchain.cpp:258
uint _minImageCount
Minimum number of images required by the swapchain.
Definition: Swapchain.hpp:87
std::vector< VkSemaphore > _imagesAvailable
Semaphores signaling when swapchain images are available for a new frame.
Definition: Swapchain.hpp:82
std::vector< VkSemaphore > _framesFinished
Semaphores signaling when a frame has been completed.
Definition: Swapchain.hpp:83
uint minCount()
Definition: Swapchain.hpp:41
std::vector< VkFence > _framesInFlight
Fences ensuring that frames are properly ordered.
Definition: Swapchain.hpp:84
Texture * _backbuffer
The current backbuffer.
Definition: Swapchain.hpp:80
Texture _depth
The shared depth texture.
Definition: Swapchain.hpp:79
uint32_t _imageIndex
Current image index.
Definition: Swapchain.hpp:89
void setup(uint32_t width, uint32_t height)
Definition: Swapchain.cpp:15
bool _frameStarted
Has a frame been previously submitted.
Definition: Swapchain.hpp:90
GPUContext * _context
The GPU internal context.
Definition: Swapchain.hpp:75
Texture & color()
Definition: Swapchain.hpp:47
void resize(uint w, uint h)
Definition: Swapchain.cpp:239
void getFormats(VkFormat &color, VkFormat &depth, VkFormat &stencil)
Definition: Swapchain.cpp:248
std::vector< Texture > _colors
Backbuffers.
Definition: Swapchain.hpp:78
uint _imageCount
Number of images in the swapchain.
Definition: Swapchain.hpp:86
Represents a texture containing one or more images, stored on the CPU and/or GPU.
Definition: Texture.hpp:12
Global GPU context, storing all structures used for resource allocation and tracking,...
Definition: GPUInternal.hpp:72