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