Add refresh rate to window/mode info

This commit is contained in:
Connor McLaughlin 2021-02-13 21:24:58 +10:00
parent 935c73fb6c
commit b811b78c09
2 changed files with 8 additions and 3 deletions

View file

@ -10,6 +10,7 @@
#include "util.h" #include "util.h"
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cmath>
Log_SetChannel(Vulkan::SwapChain); Log_SetChannel(Vulkan::SwapChain);
#if defined(VK_USE_PLATFORM_XLIB_KHR) #if defined(VK_USE_PLATFORM_XLIB_KHR)
@ -131,11 +132,14 @@ static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice p
const VkDisplayModePropertiesKHR* matched_mode = nullptr; const VkDisplayModePropertiesKHR* matched_mode = nullptr;
for (const VkDisplayModePropertiesKHR& mode : modes) for (const VkDisplayModePropertiesKHR& mode : modes)
{ {
Log_DevPrintf(" Mode %ux%u @ %u", mode.parameters.visibleRegion.width, mode.parameters.visibleRegion.height, const float refresh_rate = static_cast<float>(mode.parameters.refreshRate) * 1000.0f;
mode.parameters.refreshRate); Log_DevPrintf(" Mode %ux%u @ %f", mode.parameters.visibleRegion.width, mode.parameters.visibleRegion.height,
refresh_rate);
if (!matched_mode && if (!matched_mode &&
((wi.surface_width == 0 && wi.surface_height == 0) || ((wi.surface_width == 0 && wi.surface_height == 0) ||
(mode.parameters.visibleRegion.width == wi.surface_width && mode.parameters.visibleRegion.height))) (mode.parameters.visibleRegion.width == wi.surface_width && mode.parameters.visibleRegion.height &&
(wi.surface_refresh_rate == 0.0f || std::abs(refresh_rate - wi.surface_refresh_rate) < 0.1f))))
{ {
matched_mode = &mode; matched_mode = &mode;
} }

View file

@ -30,6 +30,7 @@ struct WindowInfo
void* window_handle = nullptr; void* window_handle = nullptr;
u32 surface_width = 0; u32 surface_width = 0;
u32 surface_height = 0; u32 surface_height = 0;
float surface_refresh_rate = 0.0f;
float surface_scale = 1.0f; float surface_scale = 1.0f;
SurfaceFormat surface_format = SurfaceFormat::RGB8; SurfaceFormat surface_format = SurfaceFormat::RGB8;