Code cleanup, better naming, moved comments to header
This commit is contained in:
parent
0b5281d087
commit
4a0c8b8f23
3 changed files with 37 additions and 42 deletions
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* A swap chain is a collection of framebuffers used for rendering and presentation to the windowing system
|
||||
*
|
||||
* 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)
|
||||
*/
|
||||
|
|
@ -192,30 +192,19 @@ void VulkanSwapChain::initSurface(screen_context_t screen_context, screen_window
|
|||
colorSpace = selectedFormat.colorSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set instance, physical and logical device to use for the swapchain and get all required function pointers
|
||||
*
|
||||
* @param instance Vulkan instance to use
|
||||
* @param physicalDevice Physical device used to query properties and formats relevant to the swapchain
|
||||
* @param device Logical representation of the device to create the swapchain for
|
||||
*
|
||||
*/
|
||||
void VulkanSwapChain::connect(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device)
|
||||
void VulkanSwapChain::setContext(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device)
|
||||
{
|
||||
this->instance = instance;
|
||||
this->physicalDevice = physicalDevice;
|
||||
this->device = device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the swapchain and get its images with given width and height
|
||||
*
|
||||
* @param width Pointer to the width of the swapchain (may be adjusted to fit the requirements of the swapchain)
|
||||
* @param height Pointer to the height of the swapchain (may be adjusted to fit the requirements of the swapchain)
|
||||
* @param vsync (Optional) Can be used to force vsync-ed rendering (by using VK_PRESENT_MODE_FIFO_KHR as presentation mode)
|
||||
*/
|
||||
void VulkanSwapChain::create(uint32_t *width, uint32_t *height, bool vsync, bool fullscreen)
|
||||
{
|
||||
assert(physicalDevice);
|
||||
assert(device);
|
||||
assert(instance);
|
||||
|
||||
// Store the current swap chain handle so we can use it later on to ease up recreation
|
||||
VkSwapchainKHR oldSwapchain = swapChain;
|
||||
|
||||
|
|
@ -396,16 +385,6 @@ void VulkanSwapChain::create(uint32_t *width, uint32_t *height, bool vsync, bool
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires the next image in the swap chain
|
||||
*
|
||||
* @param presentCompleteSemaphore (Optional) Semaphore that is signaled when the image is ready for use
|
||||
* @param imageIndex Pointer to the image index that will be increased if the next image could be acquired
|
||||
*
|
||||
* @note The function will always wait until the next image has been acquired by setting timeout to UINT64_MAX
|
||||
*
|
||||
* @return VkResult of the image acquisition
|
||||
*/
|
||||
VkResult VulkanSwapChain::acquireNextImage(VkSemaphore presentCompleteSemaphore, uint32_t *imageIndex)
|
||||
{
|
||||
// By setting timeout to UINT64_MAX we will always wait until the next image has been acquired or an actual error is thrown
|
||||
|
|
@ -413,15 +392,6 @@ VkResult VulkanSwapChain::acquireNextImage(VkSemaphore presentCompleteSemaphore,
|
|||
return vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, presentCompleteSemaphore, (VkFence)nullptr, imageIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue an image for presentation
|
||||
*
|
||||
* @param queue Presentation queue for presenting the image
|
||||
* @param imageIndex Index of the swapchain image to queue for presentation
|
||||
* @param waitSemaphore (Optional) Semaphore that is waited on before the image is presented (only used if != VK_NULL_HANDLE)
|
||||
*
|
||||
* @return VkResult of the queue presentation
|
||||
*/
|
||||
VkResult VulkanSwapChain::queuePresent(VkQueue queue, uint32_t imageIndex, VkSemaphore waitSemaphore)
|
||||
{
|
||||
VkPresentInfoKHR presentInfo = {};
|
||||
|
|
@ -440,9 +410,6 @@ VkResult VulkanSwapChain::queuePresent(VkQueue queue, uint32_t imageIndex, VkSem
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroy and free Vulkan resources used for the swapchain
|
||||
*/
|
||||
void VulkanSwapChain::cleanup()
|
||||
{
|
||||
if (swapChain != VK_NULL_HANDLE)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* A swap chain is a collection of framebuffers used for rendering and presentation to the windowing system
|
||||
*
|
||||
* 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)
|
||||
*/
|
||||
|
|
@ -68,9 +68,37 @@ public:
|
|||
#elif defined(VK_USE_PLATFORM_SCREEN_QNX)
|
||||
void initSurface(screen_context_t screen_context, screen_window_t screen_window);
|
||||
#endif
|
||||
void connect(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device);
|
||||
/* Set the Vulkan objects required for swapchain creation and management, must be called before swapchain creation */
|
||||
void setContext(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device);
|
||||
/**
|
||||
* Create the swapchain and get its images with given width and height
|
||||
*
|
||||
* @param width Pointer to the width of the swapchain (may be adjusted to fit the requirements of the swapchain)
|
||||
* @param height Pointer to the height of the swapchain (may be adjusted to fit the requirements of the swapchain)
|
||||
* @param vsync (Optional, default = false) Can be used to force vsync-ed rendering (by using VK_PRESENT_MODE_FIFO_KHR as presentation mode)
|
||||
*/
|
||||
void create(uint32_t* width, uint32_t* height, bool vsync = false, bool fullscreen = false);
|
||||
/**
|
||||
* Acquires the next image in the swap chain
|
||||
*
|
||||
* @param presentCompleteSemaphore (Optional) Semaphore that is signaled when the image is ready for use
|
||||
* @param imageIndex Pointer to the image index that will be increased if the next image could be acquired
|
||||
*
|
||||
* @note The function will always wait until the next image has been acquired by setting timeout to UINT64_MAX
|
||||
*
|
||||
* @return VkResult of the image acquisition
|
||||
*/
|
||||
VkResult acquireNextImage(VkSemaphore presentCompleteSemaphore, uint32_t* imageIndex);
|
||||
/**
|
||||
* Queue an image for presentation
|
||||
*
|
||||
* @param queue Presentation queue for presenting the image
|
||||
* @param imageIndex Index of the swapchain image to queue for presentation
|
||||
* @param waitSemaphore (Optional) Semaphore that is waited on before the image is presented (only used if != VK_NULL_HANDLE)
|
||||
*
|
||||
* @return VkResult of the queue presentation
|
||||
*/
|
||||
VkResult queuePresent(VkQueue queue, uint32_t imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE);
|
||||
/* Free all Vulkan resources acquired by the swapchain */
|
||||
void cleanup();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1077,7 +1077,7 @@ bool VulkanExampleBase::initVulkan()
|
|||
}
|
||||
assert(validFormat);
|
||||
|
||||
swapChain.connect(instance, physicalDevice, device);
|
||||
swapChain.setContext(instance, physicalDevice, device);
|
||||
|
||||
// Create synchronization objects
|
||||
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue