aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-01-12 17:16:25 -0500
committerDavid Robillard <d@drobilla.net>2023-01-14 11:53:28 -0500
commit47f0b78734d486c37d52614c748f6ac7d245eb06 (patch)
tree262828f6f6028ad7d4e5eadb18fd8b0ce76a80c5 /examples
parent1e48f8bbfdb0f1ce2f9132d604405fb72d160d9d (diff)
downloadpugl-47f0b78734d486c37d52614c748f6ac7d245eb06.tar.gz
pugl-47f0b78734d486c37d52614c748f6ac7d245eb06.tar.bz2
pugl-47f0b78734d486c37d52614c748f6ac7d245eb06.zip
Windows: Fix drawing while resizing in pugl_vulkan_cpp_demo
Diffstat (limited to 'examples')
-rw-r--r--examples/pugl_vulkan_cpp_demo.cpp61
1 files changed, 44 insertions, 17 deletions
diff --git a/examples/pugl_vulkan_cpp_demo.cpp b/examples/pugl_vulkan_cpp_demo.cpp
index 2cfb1e8..b199277 100644
--- a/examples/pugl_vulkan_cpp_demo.cpp
+++ b/examples/pugl_vulkan_cpp_demo.cpp
@@ -226,6 +226,30 @@ selectSurfaceFormat(const sk::VulkanApi& vk,
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
+template<typename ModeArray>
+VkResult
+chooseBestPresentMode(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& physicalDevice,
+ const sk::SurfaceKHR& surface,
+ const ModeArray& tryModes,
+ VkPresentModeKHR& presentMode)
+{
+ std::vector<VkPresentModeKHR> modes;
+ if (VkResult r = vk.getPhysicalDeviceSurfacePresentModesKHR(
+ physicalDevice, surface, modes)) {
+ return r;
+ }
+
+ for (const auto m : tryModes) {
+ if (std::find(modes.begin(), modes.end(), m) != modes.end()) {
+ presentMode = m;
+ return VK_SUCCESS;
+ }
+ }
+
+ return VK_ERROR_INCOMPATIBLE_DRIVER;
+}
+
VkResult
selectPresentMode(const sk::VulkanApi& vk,
const sk::PhysicalDevice& physicalDevice,
@@ -264,23 +288,26 @@ selectPresentMode(const sk::VulkanApi& vk,
},
};
- std::vector<VkPresentModeKHR> modes;
- if (VkResult r = vk.getPhysicalDeviceSurfacePresentModesKHR(
- physicalDevice, surface, modes)) {
- return r;
- }
+ return chooseBestPresentMode(
+ vk, physicalDevice, surface, priorities[multiBuffer][sync], presentMode);
+}
- const auto& tryModes = priorities[multiBuffer][sync];
- for (const auto m : tryModes) {
- if (std::find(modes.begin(), modes.end(), m) != modes.end()) {
- presentMode = m;
- return VK_SUCCESS;
- }
- }
+VkResult
+selectResizePresentMode(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& physicalDevice,
+ const sk::SurfaceKHR& surface,
+ VkPresentModeKHR& presentMode)
+{
+ static constexpr VkPresentModeKHR priorities[4] = {
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_IMMEDIATE_KHR,
+ VK_PRESENT_MODE_FIFO_KHR,
+ };
- return VK_ERROR_INCOMPATIBLE_DRIVER;
+ return chooseBestPresentMode(
+ vk, physicalDevice, surface, priorities, presentMode);
}
-
VkResult
openDevice(const sk::VulkanApi& vk,
const sk::PhysicalDevice& physicalDevice,
@@ -419,8 +446,8 @@ GraphicsDevice::init(const pugl::VulkanLoader& loader,
surface =
sk::SurfaceKHR{surfaceHandle, {context.instance, vk.vkDestroySurfaceKHR}};
- PhysicalDeviceSelection physicalDeviceSelection = {};
// Select a physical device to use
+ PhysicalDeviceSelection physicalDeviceSelection = {};
if ((r = selectPhysicalDevice(
vk, context.instance, surface, physicalDeviceSelection))) {
return r;
@@ -436,8 +463,8 @@ GraphicsDevice::init(const pugl::VulkanLoader& loader,
opts.doubleBuffer,
opts.sync,
presentMode)) ||
- (r = selectPresentMode(
- vk, physicalDevice, surface, true, false, resizePresentMode)) ||
+ (r = selectResizePresentMode(
+ vk, physicalDevice, surface, resizePresentMode)) ||
(r = openDevice(vk, physicalDevice, graphicsIndex, device))) {
return r;
}