Skip to content

Commit 46c3078

Browse files
committed
[code] Cleanup.
1 parent 730adb2 commit 46c3078

File tree

7 files changed

+31
-45
lines changed

7 files changed

+31
-45
lines changed

include/inexor/vulkan-renderer/renderer.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,9 @@ class VulkanRenderer {
163163
/// @param graphics_card The regarded graphics card.
164164
VkResult create_physical_device(const VkPhysicalDevice &graphics_card, const bool enable_debug_markers = true);
165165

166-
/// @brief Creates an instance of VulkanDebugMarkerManager
166+
/// @brief Creates an instance of VulkanDebugMarkerManager.
167167
VkResult initialise_debug_marker_manager(const bool enable_debug_markers = true);
168168

169-
/// @brief Initialises glTF 2.0 model manager.
170-
VkResult initialise_glTF2_model_manager();
171-
172169
VkResult update_cameras();
173170

174171
/// @brief Create depth image.
@@ -183,9 +180,6 @@ class VulkanRenderer {
183180
/// @brief Creates the semaphores neccesary for synchronisation.
184181
VkResult create_synchronisation_objects();
185182

186-
/// @brief Creates the swapchain.
187-
VkResult create_swapchain();
188-
189183
/// @brief Cleans the swapchain.
190184
VkResult cleanup_swapchain();
191185

include/inexor/vulkan-renderer/wrapper/swapchain.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@ class Swapchain {
1818
VkPhysicalDevice graphics_card;
1919
VkSurfaceKHR surface;
2020
VkSwapchainKHR swapchain;
21-
VkSwapchainKHR old_swapchain;
2221
VkSurfaceFormatKHR surface_format;
2322
VkExtent2D extent;
2423

2524
std::vector<VkImage> swapchain_images;
2625
std::vector<VkImageView> swapchain_image_views;
27-
std::uint32_t images_in_swapchain_count;
26+
std::uint32_t swapchain_image_count;
2827
bool vsync_enabled;
2928

3029
/// @brief (Re)creates the swapchain.
3130
/// @param window_width [in] The requested width of the window.
3231
/// @param window_height [in] The requested height of the window.
3332
/// @note We are passing width and height of the window as reference since the API
3433
/// needs to check if the swapchain can support the requested resolution.
35-
void setup_swapchain(std::uint32_t &window_width, std::uint32_t &window_height);
34+
void setup_swapchain(const VkSwapchainKHR old_swapchain, std::uint32_t window_width, std::uint32_t window_height);
3635

3736
public:
3837
/// Delete the copy constructor so swapchains are move-only objects.
@@ -45,17 +44,17 @@ class Swapchain {
4544

4645
/// @brief
4746
/// @note We must pass width and height as call by reference!
48-
Swapchain(const VkDevice device, const VkPhysicalDevice graphics_card, const VkSurfaceKHR surface, std::uint32_t &window_width,
49-
std::uint32_t &window_height, const bool enable_vsync);
47+
Swapchain(const VkDevice device, const VkPhysicalDevice graphics_card, const VkSurfaceKHR surface, std::uint32_t window_width, std::uint32_t window_height,
48+
const bool enable_vsync);
5049

5150
~Swapchain();
5251

5352
/// @brief The swapchain needs to be recreated if it has been invalidated.
5453
/// @note We must pass width and height as call by reference!
5554
/// This happens for example when the window gets resized.
56-
void recreate(std::uint32_t &window_width, std::uint32_t &window_height);
55+
void recreate(std::uint32_t window_width, std::uint32_t window_height);
5756

58-
[[nodiscard]] const VkSwapchainKHR* get_swapchain_ptr() const {
57+
[[nodiscard]] const VkSwapchainKHR *get_swapchain_ptr() const {
5958
return &swapchain;
6059
}
6160

@@ -64,7 +63,7 @@ class Swapchain {
6463
}
6564

6665
[[nodiscard]] std::uint32_t get_image_count() const {
67-
return images_in_swapchain_count;
66+
return swapchain_image_count;
6867
}
6968

7069
[[nodiscard]] VkFormat get_image_format() const {

include/inexor/vulkan-renderer/wrapper/window.hpp

Whitespace-only changes.

src/vulkan-renderer/bezier_curve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "inexor/vulkan-renderer/bezier_curve.h"
1+
#include "inexor/vulkan-renderer/bezier_curve.hpp"
22

33
namespace inexor::vulkan_renderer {
44

src/vulkan-renderer/wrapper/swapchain.cpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace inexor::vulkan_renderer::wrapper {
44

55
Swapchain::Swapchain(Swapchain &&other) noexcept
66
: device(other.device), graphics_card(std::exchange(other.graphics_card, nullptr)), surface(std::exchange(other.surface, nullptr)),
7-
swapchain(std::exchange(other.swapchain, nullptr)), old_swapchain(std::exchange(other.old_swapchain, nullptr)), surface_format(other.surface_format),
8-
extent(other.extent), swapchain_images(std::move(other.swapchain_images)), swapchain_image_views(std::move(other.swapchain_image_views)),
9-
images_in_swapchain_count(other.images_in_swapchain_count), vsync_enabled(other.vsync_enabled) {}
7+
swapchain(std::exchange(other.swapchain, nullptr)), surface_format(other.surface_format), extent(other.extent),
8+
swapchain_images(std::move(other.swapchain_images)), swapchain_image_views(std::move(other.swapchain_image_views)),
9+
swapchain_image_count(other.swapchain_image_count), vsync_enabled(other.vsync_enabled) {}
1010

11-
void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &window_height) {
11+
void Swapchain::setup_swapchain(const VkSwapchainKHR old_swapchain, std::uint32_t window_width, std::uint32_t window_height) {
1212
VulkanSettingsDecisionMaker settings_decision_maker;
1313

1414
settings_decision_maker.decide_width_and_height_of_swapchain_extent(graphics_card, surface, window_width, window_height, extent);
@@ -19,13 +19,7 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
1919
throw std::runtime_error("Error: Could not find a suitable present mode!");
2020
}
2121

22-
images_in_swapchain_count = settings_decision_maker.decide_how_many_images_in_swapchain_to_use(graphics_card, surface);
23-
24-
// Find the transformation of the surface.
25-
auto pre_transform = settings_decision_maker.decide_which_image_transformation_to_use(graphics_card, surface);
26-
27-
// Find a supported composite alpha format (not all devices support alpha opaque).
28-
auto composite_alpha_format = settings_decision_maker.find_composite_alpha_format(graphics_card, surface);
22+
swapchain_image_count = settings_decision_maker.decide_how_many_images_in_swapchain_to_use(graphics_card, surface);
2923

3024
auto surface_format_candidate = settings_decision_maker.decide_which_surface_color_format_in_swapchain_to_use(graphics_card, surface);
3125

@@ -38,13 +32,14 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
3832
VkSwapchainCreateInfoKHR swapchain_create_info = {};
3933
swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
4034
swapchain_create_info.surface = surface;
41-
swapchain_create_info.minImageCount = images_in_swapchain_count;
35+
swapchain_create_info.minImageCount = swapchain_image_count;
4236
swapchain_create_info.imageFormat = surface_format.format;
4337
swapchain_create_info.imageColorSpace = surface_format.colorSpace;
4438
swapchain_create_info.imageExtent.width = extent.width;
4539
swapchain_create_info.imageExtent.height = extent.height;
4640
swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
47-
swapchain_create_info.preTransform = (VkSurfaceTransformFlagBitsKHR)pre_transform;
41+
swapchain_create_info.preTransform =
42+
(VkSurfaceTransformFlagBitsKHR)settings_decision_maker.decide_which_image_transformation_to_use(graphics_card, surface);
4843
swapchain_create_info.imageArrayLayers = 1;
4944
swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
5045
swapchain_create_info.queueFamilyIndexCount = 0;
@@ -57,7 +52,7 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
5752

5853
// Setting clipped to VK_TRUE allows the implementation to discard rendering outside of the surface area.
5954
swapchain_create_info.clipped = VK_TRUE;
60-
swapchain_create_info.compositeAlpha = composite_alpha_format;
55+
swapchain_create_info.compositeAlpha = settings_decision_maker.find_composite_alpha_format(graphics_card, surface);
6156

6257
// Set additional usage flag for blitting from the swapchain images if supported.
6358
VkFormatProperties formatProps;
@@ -72,21 +67,21 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
7267
throw std::runtime_error("Error: vkCreateSwapchainKHR failed!");
7368
}
7469

75-
if (vkGetSwapchainImagesKHR(device, swapchain, &images_in_swapchain_count, nullptr) != VK_SUCCESS) {
70+
if (vkGetSwapchainImagesKHR(device, swapchain, &swapchain_image_count, nullptr) != VK_SUCCESS) {
7671
throw std::runtime_error("Error: vkGetSwapchainImagesKHR failed!");
7772
}
7873

79-
swapchain_images.resize(images_in_swapchain_count);
74+
swapchain_images.resize(swapchain_image_count);
8075

81-
if (vkGetSwapchainImagesKHR(device, swapchain, &images_in_swapchain_count, swapchain_images.data())) {
76+
if (vkGetSwapchainImagesKHR(device, swapchain, &swapchain_image_count, swapchain_images.data())) {
8277
throw std::runtime_error("Error: vkGetSwapchainImagesKHR failed!");
8378
}
8479

8580
// TODO: Assign an appropriate debug marker name to the swapchain images.
8681

87-
spdlog::debug("Creating {} swapchain image views.", images_in_swapchain_count);
82+
spdlog::debug("Creating {} swapchain image views.", swapchain_image_count);
8883

89-
swapchain_image_views.resize(images_in_swapchain_count);
84+
swapchain_image_views.resize(swapchain_image_count);
9085

9186
VkImageViewCreateInfo image_view_create_info = {};
9287
image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
@@ -102,7 +97,7 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
10297
image_view_create_info.subresourceRange.baseArrayLayer = 0;
10398
image_view_create_info.subresourceRange.layerCount = 1;
10499

105-
for (std::size_t i = 0; i < images_in_swapchain_count; i++) {
100+
for (std::size_t i = 0; i < swapchain_image_count; i++) {
106101
spdlog::debug("Creating swapchain image #{}.", i);
107102

108103
image_view_create_info.image = swapchain_images[i];
@@ -114,25 +109,23 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
114109
// TODO: Use Vulkan debug markers to assign an appropriate name to this swapchain image view.
115110
}
116111

117-
spdlog::debug("Created {} swapchain image views successfully.", images_in_swapchain_count);
112+
spdlog::debug("Created {} swapchain image views successfully.", swapchain_image_count);
118113
}
119114

120-
Swapchain::Swapchain(const VkDevice device, const VkPhysicalDevice graphics_card, const VkSurfaceKHR surface, std::uint32_t &window_width,
121-
std::uint32_t &window_height, const bool enable_vsync)
115+
Swapchain::Swapchain(const VkDevice device, const VkPhysicalDevice graphics_card, const VkSurfaceKHR surface, std::uint32_t window_width,
116+
std::uint32_t window_height, const bool enable_vsync)
122117
: device(device), graphics_card(graphics_card), surface(surface), vsync_enabled(enable_vsync) {
123118

124119
assert(device);
125120
assert(graphics_card);
126121
assert(surface);
127122

128-
old_swapchain = VK_NULL_HANDLE;
129-
130-
setup_swapchain(window_width, window_height);
123+
setup_swapchain(VK_NULL_HANDLE, window_width, window_height);
131124
}
132125

133-
void Swapchain::recreate(std::uint32_t &window_width, std::uint32_t &window_height) {
126+
void Swapchain::recreate(std::uint32_t window_width, std::uint32_t window_height) {
134127
// Store the old swapchain. This allows us to pass it to VkSwapchainCreateInfoKHR::oldSwapchain to speed up swapchain recreation.
135-
old_swapchain = swapchain;
128+
VkSwapchainKHR old_swapchain = swapchain;
136129

137130
// When swapchain needs to be recreated, all the old swapchain images need to be destroyed.
138131

@@ -146,7 +139,7 @@ void Swapchain::recreate(std::uint32_t &window_width, std::uint32_t &window_heig
146139

147140
swapchain_images.clear();
148141

149-
setup_swapchain(window_width, window_height);
142+
setup_swapchain(old_swapchain, window_width, window_height);
150143
}
151144

152145
Swapchain::~Swapchain() {

src/vulkan-renderer/wrapper/window.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)