diff --git a/src/love.cpp b/src/love.cpp index a94779753..edd0e8eec 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -26,6 +26,10 @@ #ifdef LOVE_BUILD_EXE +#if SDL_VERSION_ATLEAST(3, 0, 0) +#include +#endif + // Lua extern "C" { #include diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index 08977f354..d8a9a59b5 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -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; diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index b28ed9c40..e8c4c6785 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -29,6 +29,7 @@ #include "Shader.h" #include "Vulkan.h" +#include #include #include @@ -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 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 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(extensions.size()); createInfo.ppEnabledExtensionNames = extensions.data(); @@ -1769,8 +1780,13 @@ void Graphics::createSurface() { auto window = Module::getInstance(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) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 2c4e69cb7..424d14d36 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -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);