Code cleanup

This commit is contained in:
Sascha Willems 2024-11-23 15:37:57 +01:00
parent 4d91720ccc
commit 0f56b8270d
5 changed files with 38 additions and 41 deletions

View file

@ -28,25 +28,25 @@
#endif #endif
typedef struct _SwapChainBuffers { typedef struct _SwapChainBuffers {
VkImage image; VkImage image{ VK_NULL_HANDLE };
VkImageView view; VkImageView view{ VK_NULL_HANDLE };
} SwapChainBuffer; } SwapChainBuffer;
class VulkanSwapChain class VulkanSwapChain
{ {
private: private:
VkInstance instance; VkInstance instance{ VK_NULL_HANDLE };
VkDevice device; VkDevice device{ VK_NULL_HANDLE };
VkPhysicalDevice physicalDevice; VkPhysicalDevice physicalDevice{ VK_NULL_HANDLE };
VkSurfaceKHR surface; VkSurfaceKHR surface{ VK_NULL_HANDLE };
public: public:
VkFormat colorFormat; VkFormat colorFormat{};
VkColorSpaceKHR colorSpace; VkColorSpaceKHR colorSpace{};
VkSwapchainKHR swapChain = VK_NULL_HANDLE; VkSwapchainKHR swapChain{ VK_NULL_HANDLE };
uint32_t imageCount; uint32_t imageCount;
std::vector<VkImage> images; std::vector<VkImage> images{};
std::vector<SwapChainBuffer> buffers; std::vector<SwapChainBuffer> buffers{};
uint32_t queueNodeIndex = UINT32_MAX; uint32_t queueNodeIndex{ UINT32_MAX };
#if defined(VK_USE_PLATFORM_WIN32_KHR) #if defined(VK_USE_PLATFORM_WIN32_KHR)
void initSurface(void* platformHandle, void* platformWindow); void initSurface(void* platformHandle, void* platformWindow);

View file

@ -1,7 +1,7 @@
/* /*
* Benchmark class * Benchmark class - Can be used for automated benchmarks
* *
* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -18,8 +18,8 @@ namespace vks
{ {
class Benchmark { class Benchmark {
private: private:
FILE *stream; FILE* stream{ nullptr };
VkPhysicalDeviceProperties deviceProps; VkPhysicalDeviceProperties deviceProps{};
public: public:
bool active = false; bool active = false;
bool outputFrameTimes = false; bool outputFrameTimes = false;

View file

@ -1,7 +1,7 @@
/* /*
* Basic camera class * Basic camera class providing a look-at and first-person camera
* *
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -78,16 +78,16 @@ public:
bool down = false; bool down = false;
} keys; } keys;
bool moving() bool moving() const
{ {
return keys.left || keys.right || keys.up || keys.down; return keys.left || keys.right || keys.up || keys.down;
} }
float getNearClip() { float getNearClip() const {
return znear; return znear;
} }
float getFarClip() { float getFarClip() const {
return zfar; return zfar;
} }

View file

@ -167,7 +167,7 @@ void VulkanExampleBase::renderFrame()
VulkanExampleBase::submitFrame(); VulkanExampleBase::submitFrame();
} }
std::string VulkanExampleBase::getWindowTitle() std::string VulkanExampleBase::getWindowTitle() const
{ {
std::string windowTitle{ title + " - " + deviceProperties.deviceName }; std::string windowTitle{ title + " - " + deviceProperties.deviceName };
if (!settings.overlay) { if (!settings.overlay) {
@ -1160,7 +1160,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
{ {
this->windowInstance = hinstance; this->windowInstance = hinstance;
WNDCLASSEX wndClass; WNDCLASSEX wndClass{};
wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.style = CS_HREDRAW | CS_VREDRAW;
@ -3076,26 +3076,23 @@ void VulkanExampleBase::setupDepthStencil()
void VulkanExampleBase::setupFrameBuffer() void VulkanExampleBase::setupFrameBuffer()
{ {
VkImageView attachments[2];
// Depth/Stencil attachment is the same for all frame buffers
attachments[1] = depthStencil.view;
VkFramebufferCreateInfo frameBufferCreateInfo = {};
frameBufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
frameBufferCreateInfo.pNext = NULL;
frameBufferCreateInfo.renderPass = renderPass;
frameBufferCreateInfo.attachmentCount = 2;
frameBufferCreateInfo.pAttachments = attachments;
frameBufferCreateInfo.width = width;
frameBufferCreateInfo.height = height;
frameBufferCreateInfo.layers = 1;
// Create frame buffers for every swap chain image // Create frame buffers for every swap chain image
frameBuffers.resize(swapChain.imageCount); frameBuffers.resize(swapChain.imageCount);
for (uint32_t i = 0; i < frameBuffers.size(); i++) for (uint32_t i = 0; i < frameBuffers.size(); i++)
{ {
attachments[0] = swapChain.buffers[i].view; const VkImageView attachments[2] = {
swapChain.buffers[i].view,
// Depth/Stencil attachment is the same for all frame buffers
depthStencil.view
};
VkFramebufferCreateInfo frameBufferCreateInfo{};
frameBufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
frameBufferCreateInfo.renderPass = renderPass;
frameBufferCreateInfo.attachmentCount = 2;
frameBufferCreateInfo.pAttachments = attachments;
frameBufferCreateInfo.width = width;
frameBufferCreateInfo.height = height;
frameBufferCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCreateInfo, nullptr, &frameBuffers[i])); VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCreateInfo, nullptr, &frameBuffers[i]));
} }
} }
@ -3142,7 +3139,7 @@ void VulkanExampleBase::setupRenderPass()
subpassDescription.pResolveAttachments = nullptr; subpassDescription.pResolveAttachments = nullptr;
// Subpass dependencies for layout transitions // Subpass dependencies for layout transitions
std::array<VkSubpassDependency, 2> dependencies; std::array<VkSubpassDependency, 2> dependencies{};
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
dependencies[0].dstSubpass = 0; dependencies[0].dstSubpass = 0;

View file

@ -76,7 +76,7 @@
class VulkanExampleBase class VulkanExampleBase
{ {
private: private:
std::string getWindowTitle(); std::string getWindowTitle() const;
uint32_t destWidth; uint32_t destWidth;
uint32_t destHeight; uint32_t destHeight;
bool resizing = false; bool resizing = false;