move some options from swap chain to engine configuration and fix not working VSync

This commit is contained in:
ohyzha
2024-07-22 11:07:33 +03:00
parent bc02c0e937
commit 6ed4136393
5 changed files with 55 additions and 29 deletions

View File

@@ -81,10 +81,13 @@ namespace OpenVulkano::Vulkan
{ preTransform = vk::SurfaceTransformFlagBitsKHR::eIdentity; }
else { preTransform = surfaceCapabilities.currentTransform; }
uint32_t usingImages = std::max(preferredImageCount, surfaceCapabilities.minImageCount);
EngineConfiguration* config = EngineConfiguration::GetEngineConfiguration();
uint32_t usingImages = std::max(config->GetPrefferedSwapChainImageCount(), surfaceCapabilities.minImageCount);
if (surfaceCapabilities.maxImageCount > 0) //GPU has limit of swap chain images
usingImages = std::min(usingImages, surfaceCapabilities.maxImageCount);
Logger::RENDER->debug("GPU supports {0} to {1} swap chain images. Preferred: {2}, Using: {3}", surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount, preferredImageCount, usingImages);
Logger::RENDER->debug("GPU supports {0} to {1} swap chain images. Preferred: {2}, Using: {3}",
surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount,
config->GetPrefferedSwapChainImageCount(), usingImages);
const vk::SwapchainCreateInfoKHR createInfo({}, surface, usingImages, surfaceFormat.format,
surfaceFormat.colorSpace, size, 1,
@@ -151,6 +154,9 @@ namespace OpenVulkano::Vulkan
vk::PresentModeKHR SwapChain::ChosePresentMode()
{
std::vector<vk::PresentModeKHR> presentModes = device->physicalDevice.getSurfacePresentModesKHR(surface);
EngineConfiguration* config = EngineConfiguration::GetEngineConfiguration();
const bool useVSync = config->GetVSync();
const int32_t fpsCap = config->GetFpsCap();
#ifdef DEBUG
std::string availableModes = "";
for (const auto& presentMode : presentModes)
@@ -158,12 +164,13 @@ namespace OpenVulkano::Vulkan
if (availableModes.length() > 0) availableModes += ", ";
availableModes += vk::to_string(presentMode);
}
Logger::RENDER->debug("Available swap chain present modes {0}. Searching best mode for: vsync={1}", availableModes, useVsync);
Logger::RENDER->debug("Available swap chain present modes {0}. Searching best mode for: vsync={1}", availableModes, useVSync);
#endif
vk::PresentModeKHR mode = vk::PresentModeKHR::eFifo;
if (useVsync)
if (useVSync)
{
if (Utils::Contains(presentModes, vk::PresentModeKHR::eMailbox)) mode = vk::PresentModeKHR::eMailbox;
if (fpsCap != 0 && Utils::Contains(presentModes, vk::PresentModeKHR::eMailbox))
mode = vk::PresentModeKHR::eMailbox;
}
else
{

View File

@@ -10,6 +10,7 @@
#include "Image.hpp"
#include "FrameBuffer.hpp"
#include "Base/UI/IWindow.hpp"
#include "Base/EngineConfiguration.hpp"
#include "Base/Logger.hpp"
#include <vulkan/vulkan.hpp>
@@ -46,13 +47,6 @@ namespace OpenVulkano
vk::Rect2D fullscreenScissor;
std::vector<vk::Semaphore> imageAvailableSemaphores;
uint32_t currentSemaphoreId = 0;
bool useVsync = false;
#ifdef __APPLE__
uint32_t preferredImageCount = 3; //TODO add option
#else
uint32_t preferredImageCount = 2; //TODO add option
#endif
vk::Extent2D size{0,0};
public:
@@ -99,13 +93,6 @@ namespace OpenVulkano
}
}
[[nodiscard]] bool UseVsync() const { return useVsync; }
void SetVsync(bool vsync)
{ //TODO change swap chain
this->useVsync = vsync;
}
[[nodiscard]] uint32_t GetImageCount() const
{
return images.size();