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
typedef struct _SwapChainBuffers {
VkImage image;
VkImageView view;
VkImage image{ VK_NULL_HANDLE };
VkImageView view{ VK_NULL_HANDLE };
} SwapChainBuffer;
class VulkanSwapChain
{
private:
VkInstance instance;
VkDevice device;
VkPhysicalDevice physicalDevice;
VkSurfaceKHR surface;
VkInstance instance{ VK_NULL_HANDLE };
VkDevice device{ VK_NULL_HANDLE };
VkPhysicalDevice physicalDevice{ VK_NULL_HANDLE };
VkSurfaceKHR surface{ VK_NULL_HANDLE };
public:
VkFormat colorFormat;
VkColorSpaceKHR colorSpace;
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
VkFormat colorFormat{};
VkColorSpaceKHR colorSpace{};
VkSwapchainKHR swapChain{ VK_NULL_HANDLE };
uint32_t imageCount;
std::vector<VkImage> images;
std::vector<SwapChainBuffer> buffers;
uint32_t queueNodeIndex = UINT32_MAX;
std::vector<VkImage> images{};
std::vector<SwapChainBuffer> buffers{};
uint32_t queueNodeIndex{ UINT32_MAX };
#if defined(VK_USE_PLATFORM_WIN32_KHR)
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)
*/
@ -18,8 +18,8 @@ namespace vks
{
class Benchmark {
private:
FILE *stream;
VkPhysicalDeviceProperties deviceProps;
FILE* stream{ nullptr };
VkPhysicalDeviceProperties deviceProps{};
public:
bool active = 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)
*/
@ -78,16 +78,16 @@ public:
bool down = false;
} keys;
bool moving()
bool moving() const
{
return keys.left || keys.right || keys.up || keys.down;
}
float getNearClip() {
float getNearClip() const {
return znear;
}
float getFarClip() {
float getFarClip() const {
return zfar;
}

View file

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

View file

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