mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
vulkan: implement vsync setting
This commit is contained in:
@@ -178,14 +178,6 @@ public:
|
||||
Vector4 normalMatrix[3]; // 3x3 matrix padded to an array of 3 vector4s.
|
||||
Vector4 screenSizeParams;
|
||||
Colorf constantColor;
|
||||
|
||||
bool operator==(const BuiltinUniformData& other) {
|
||||
auto first = *this;
|
||||
return first.transformMatrix == other.transformMatrix && first.projectionMatrix == other.projectionMatrix
|
||||
&& first.normalMatrix[0] == other.normalMatrix[0] && first.normalMatrix[1] == other.normalMatrix[1]
|
||||
&& first.normalMatrix[2] == other.normalMatrix[2] && first.screenSizeParams == other.screenSizeParams
|
||||
&& first.constantColor == other.constantColor;
|
||||
}
|
||||
};
|
||||
|
||||
// Pointer to currently active Shader.
|
||||
|
||||
@@ -972,14 +972,30 @@ VkSurfaceFormatKHR Graphics::chooseSwapSurfaceFormat(const std::vector<VkSurface
|
||||
}
|
||||
|
||||
VkPresentModeKHR Graphics::chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes) {
|
||||
// needed ?
|
||||
for (const auto& availablePresentMode : availablePresentModes) {
|
||||
if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
|
||||
return availablePresentMode;
|
||||
int vsync = Vulkan::getVsync();
|
||||
|
||||
switch (vsync) {
|
||||
case -1: {
|
||||
auto it = std::find(availablePresentModes.begin(), availablePresentModes.end(), VK_PRESENT_MODE_FIFO_RELAXED_KHR);
|
||||
if (it != availablePresentModes.end()) {
|
||||
return VK_PRESENT_MODE_FIFO_RELAXED_KHR;
|
||||
}
|
||||
}
|
||||
|
||||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
case 1: {
|
||||
auto it = std::find(availablePresentModes.begin(), availablePresentModes.end(), VK_PRESENT_MODE_MAILBOX_KHR);
|
||||
if (it != availablePresentModes.end()) {
|
||||
return VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
}
|
||||
}
|
||||
case 0: {
|
||||
auto it = std::find(availablePresentModes.begin(), availablePresentModes.end(), VK_PRESENT_MODE_IMMEDIATE_KHR);
|
||||
if (it != availablePresentModes.end()) {
|
||||
return VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
}
|
||||
}
|
||||
|
||||
VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace love {
|
||||
namespace graphics {
|
||||
namespace vulkan {
|
||||
static uint32_t numShaderSwitches;
|
||||
static int vsync = 1;
|
||||
|
||||
void Vulkan::shaderSwitch() {
|
||||
numShaderSwitches++;
|
||||
@@ -20,6 +21,14 @@ void Vulkan::resetShaderSwitches() {
|
||||
numShaderSwitches = 0;
|
||||
}
|
||||
|
||||
void Vulkan::setVsync(int value) {
|
||||
vsync = value;
|
||||
}
|
||||
|
||||
int Vulkan::getVsync() {
|
||||
return vsync;
|
||||
}
|
||||
|
||||
VkFormat Vulkan::getVulkanVertexFormat(DataFormat format) {
|
||||
switch (format) {
|
||||
case DATAFORMAT_FLOAT:
|
||||
|
||||
@@ -30,6 +30,9 @@ public:
|
||||
static uint32_t getNumShaderSwitches();
|
||||
static void resetShaderSwitches();
|
||||
|
||||
static void setVsync(int vsync);
|
||||
static int getVsync();
|
||||
|
||||
static VkFormat getVulkanVertexFormat(DataFormat format);
|
||||
static TextureFormat getTextureFormat(PixelFormat);
|
||||
static std::string getVendorName(uint32_t vendorId);
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "graphics/Graphics.h"
|
||||
#include "graphics/vulkan/Graphics.h"
|
||||
#ifdef LOVE_GRAPHICS_VULKAN
|
||||
# include "graphics/vulkan/Graphics.h"
|
||||
# include "graphics/vulkan/Vulkan.h"
|
||||
#endif
|
||||
#include "Window.h"
|
||||
|
||||
#ifdef LOVE_ANDROID
|
||||
@@ -1116,6 +1119,9 @@ void Window::setVSync(int vsync)
|
||||
}
|
||||
|
||||
// fixme: doesn't work for vulkan yet.
|
||||
#ifdef LOVE_GRAPHICS_VULKAN
|
||||
love::graphics::vulkan::Vulkan::setVsync(vsync);
|
||||
#endif
|
||||
|
||||
#if defined(LOVE_GRAPHICS_METAL) && defined(LOVE_MACOS)
|
||||
if (metalView != nullptr)
|
||||
|
||||
Reference in New Issue
Block a user