mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Merge pull request #2047 from learn-more/sdl3
Fix building love on Windows for SDL3-3.1.0
This commit is contained in:
@@ -26,6 +26,10 @@
|
||||
|
||||
#ifdef LOVE_BUILD_EXE
|
||||
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
#include <SDL_main.h>
|
||||
#endif
|
||||
|
||||
// Lua
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
|
||||
@@ -383,7 +383,11 @@ Message *Event::convert(const SDL_Event &e)
|
||||
// (and SDL doesn't differentiate.) Non-screen touch devices like Mac
|
||||
// trackpads won't give touch coords in the window's coordinate-space.
|
||||
#ifndef LOVE_MACOS
|
||||
touchinfo.id = (int64) e.tfinger.fingerId;
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
touchinfo.id = (int64) e.tfinger.fingerID;
|
||||
#else
|
||||
touchinfo.id = (int64)e.tfinger.fingerId;
|
||||
#endif
|
||||
touchinfo.x = e.tfinger.x;
|
||||
touchinfo.y = e.tfinger.y;
|
||||
touchinfo.dx = e.tfinger.dx;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "Shader.h"
|
||||
#include "Vulkan.h"
|
||||
|
||||
#include <SDL_version.h>
|
||||
#include <SDL_vulkan.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -120,10 +121,18 @@ Graphics::Graphics()
|
||||
// GetInstanceExtensions works with a null window parameter as long as
|
||||
// SDL_Vulkan_LoadLibrary has been called (which we do earlier).
|
||||
unsigned int count;
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
char const* const* extensions_string = SDL_Vulkan_GetInstanceExtensions(&count);
|
||||
if (extensions_string == nullptr)
|
||||
throw love::Exception("couldn't retrieve sdl vulkan extensions");
|
||||
|
||||
std::vector<const char*> extensions(extensions_string, extensions_string + count);
|
||||
#else
|
||||
if (SDL_Vulkan_GetInstanceExtensions(nullptr, &count, nullptr) != SDL_TRUE)
|
||||
throw love::Exception("couldn't retrieve sdl vulkan extensions");
|
||||
|
||||
std::vector<const char*> extensions = {};
|
||||
#endif
|
||||
|
||||
checkOptionalInstanceExtensions(optionalInstanceExtensions);
|
||||
|
||||
@@ -132,11 +141,13 @@ Graphics::Graphics()
|
||||
if (optionalInstanceExtensions.debugInfo)
|
||||
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
size_t additional_extension_count = extensions.size();
|
||||
extensions.resize(additional_extension_count + count);
|
||||
|
||||
if (SDL_Vulkan_GetInstanceExtensions(nullptr, &count, extensions.data() + additional_extension_count) != SDL_TRUE)
|
||||
throw love::Exception("couldn't retrieve sdl vulkan extensions");
|
||||
#endif
|
||||
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
createInfo.ppEnabledExtensionNames = extensions.data();
|
||||
@@ -1769,8 +1780,13 @@ void Graphics::createSurface()
|
||||
{
|
||||
auto window = Module::getInstance<love::window::Window>(M_WINDOW);
|
||||
const void *handle = window->getHandle();
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
if (SDL_Vulkan_CreateSurface((SDL_Window*)handle, instance, nullptr, &surface) != SDL_TRUE)
|
||||
throw love::Exception("failed to create window surface");
|
||||
#else
|
||||
if (SDL_Vulkan_CreateSurface((SDL_Window*)handle, instance, &surface) != SDL_TRUE)
|
||||
throw love::Exception("failed to create window surface");
|
||||
#endif
|
||||
}
|
||||
|
||||
SwapChainSupportDetails Graphics::querySwapChainSupport(VkPhysicalDevice device)
|
||||
|
||||
@@ -1472,15 +1472,27 @@ void Window::swapBuffers()
|
||||
dwmRefreshRate = (double)info.rateRefresh.uiNumerator / (double)info.rateRefresh.uiDenominator;
|
||||
|
||||
SDL_DisplayMode dmode = {};
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
SDL_DisplayID display = SDL_GetDisplayForWindow(window);
|
||||
const SDL_DisplayMode* modePtr = SDL_GetCurrentDisplayMode(display);
|
||||
if (modePtr)
|
||||
dmode = *modePtr;
|
||||
#else
|
||||
int displayindex = SDL_GetWindowDisplayIndex(window);
|
||||
|
||||
if (displayindex >= 0)
|
||||
SDL_GetCurrentDisplayMode(displayindex, &dmode);
|
||||
#endif
|
||||
|
||||
if (dmode.refresh_rate > 0 && dwmRefreshRate > 0 && (fabs(dmode.refresh_rate - dwmRefreshRate) < 2))
|
||||
{
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
int interval = 0;
|
||||
if (SDL_GL_GetSwapInterval(&interval) == 0 && interval == 0)
|
||||
#else
|
||||
if (SDL_GL_GetSwapInterval() == 0)
|
||||
#endif
|
||||
useDwmFlush = true;
|
||||
else
|
||||
SDL_GL_SetSwapInterval(swapInterval);
|
||||
@@ -1735,26 +1747,30 @@ void Window::requestAttention(bool continuous)
|
||||
if (hasFocus())
|
||||
return;
|
||||
|
||||
FLASHWINFO flashinfo = { sizeof(FLASHWINFO) };
|
||||
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
flashinfo.hwnd = (HWND)SDL_GetProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
|
||||
#else
|
||||
SDL_SysWMinfo wminfo = {};
|
||||
SDL_VERSION(&wminfo.version);
|
||||
if (!SDL_GetWindowWMInfo(window, &wminfo))
|
||||
return;
|
||||
|
||||
if (SDL_GetWindowWMInfo(window, &wminfo))
|
||||
flashinfo.hwnd = wminfo.info.win.window;
|
||||
#endif
|
||||
|
||||
flashinfo.uCount = 1;
|
||||
flashinfo.dwFlags = FLASHW_ALL;
|
||||
|
||||
if (continuous)
|
||||
{
|
||||
FLASHWINFO flashinfo = {};
|
||||
flashinfo.cbSize = sizeof(FLASHWINFO);
|
||||
flashinfo.hwnd = wminfo.info.win.window;
|
||||
flashinfo.uCount = 1;
|
||||
flashinfo.dwFlags = FLASHW_ALL;
|
||||
|
||||
if (continuous)
|
||||
{
|
||||
flashinfo.uCount = 0;
|
||||
flashinfo.dwFlags |= FLASHW_TIMERNOFG;
|
||||
}
|
||||
|
||||
FlashWindowEx(&flashinfo);
|
||||
flashinfo.uCount = 0;
|
||||
flashinfo.dwFlags |= FLASHW_TIMERNOFG;
|
||||
}
|
||||
|
||||
FlashWindowEx(&flashinfo);
|
||||
|
||||
#elif defined(LOVE_MACOS)
|
||||
|
||||
love::macos::requestAttention(continuous);
|
||||
|
||||
Reference in New Issue
Block a user