Remove support for SDL2 2.0.5 and earlier

This commit is contained in:
Cacodemon345 2021-05-02 15:59:38 +06:00 committed by GitHub
parent f676cd81d2
commit e4ada10e78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 44 deletions

View file

@ -179,6 +179,19 @@ else()
if( NOT APPLE OR NOT OSX_COCOA_BACKEND ) if( NOT APPLE OR NOT OSX_COCOA_BACKEND )
find_package( SDL2 REQUIRED CONFIG ) find_package( SDL2 REQUIRED CONFIG )
include_directories( "${SDL2_INCLUDE_DIRS}" ) include_directories( "${SDL2_INCLUDE_DIRS}" )
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}" "${SDL2_INCLUDE_DIRS}")
CHECK_CXX_SOURCE_COMPILES("#include <SDL_version.h>
int main()
{
#if !SDL_VERSION_ATLEAST(2, 0, 6)
#error \"Only SDL 2.0.6 or later is supported.\"
#endif
return 0;
}" SDL2_MIN_VERSION )
if (NOT SDL2_MIN_VERSION)
message(SEND_ERROR "Only SDL 2.0.6 or later is supported.")
endif()
set( ZDOOM_LIBS ${ZDOOM_LIBS} "${SDL2_LIBRARIES}" ) set( ZDOOM_LIBS ${ZDOOM_LIBS} "${SDL2_LIBRARIES}" )
endif() endif()

View file

@ -61,12 +61,9 @@
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
// Requires SDL 2.0.6 or newer #if defined HAVE_VULKAN
//#define SDL2_STATIC_LIBRARY
#if defined SDL2_STATIC_LIBRARY && defined HAVE_VULKAN
#include <SDL_vulkan.h> #include <SDL_vulkan.h>
#endif // SDL2_STATIC_LIBRARY && HAVE_VULKAN #endif // HAVE_VULKAN
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
@ -118,30 +115,7 @@ CCMD(vid_list_sdl_render_drivers)
namespace Priv namespace Priv
{ {
#ifdef SDL2_STATIC_LIBRARY static const uint32_t VulkanWindowFlag = SDL_WINDOW_VULKAN;
#define SDL2_OPTIONAL_FUNCTION(RESULT, NAME, ...) \
RESULT(*NAME)(__VA_ARGS__) = SDL_ ## NAME
#else // !SDL2_STATIC_LIBRARY
FModule library("SDL2");
#define SDL2_OPTIONAL_FUNCTION(RESULT, NAME, ...) \
static TOptProc<library, RESULT(*)(__VA_ARGS__)> NAME("SDL_" #NAME)
#endif // SDL2_STATIC_LIBRARY
SDL2_OPTIONAL_FUNCTION(int, GetWindowBordersSize, SDL_Window *window, int *top, int *left, int *bottom, int *right);
#ifdef HAVE_VULKAN
SDL2_OPTIONAL_FUNCTION(void, Vulkan_GetDrawableSize, SDL_Window *window, int *width, int *height);
SDL2_OPTIONAL_FUNCTION(SDL_bool, Vulkan_GetInstanceExtensions, SDL_Window *window, unsigned int *count, const char **names);
SDL2_OPTIONAL_FUNCTION(SDL_bool, Vulkan_CreateSurface, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface);
#endif
#undef SDL2_OPTIONAL_FUNCTION
static const uint32_t VulkanWindowFlag = 0x1000'0000;
SDL_Window *window; SDL_Window *window;
bool vulkanEnabled; bool vulkanEnabled;
@ -240,22 +214,21 @@ void I_GetVulkanDrawableSize(int *width, int *height)
{ {
assert(Priv::vulkanEnabled); assert(Priv::vulkanEnabled);
assert(Priv::window != nullptr); assert(Priv::window != nullptr);
assert(Priv::Vulkan_GetDrawableSize); SDL_Vulkan_GetDrawableSize(Priv::window, width, height);
Priv::Vulkan_GetDrawableSize(Priv::window, width, height);
} }
bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names) bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names)
{ {
assert(Priv::vulkanEnabled); assert(Priv::vulkanEnabled);
assert(Priv::window != nullptr); assert(Priv::window != nullptr);
return Priv::Vulkan_GetInstanceExtensions(Priv::window, count, names) == SDL_TRUE; return SDL_Vulkan_GetInstanceExtensions(Priv::window, count, names) == SDL_TRUE;
} }
bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface) bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
{ {
assert(Priv::vulkanEnabled); assert(Priv::vulkanEnabled);
assert(Priv::window != nullptr); assert(Priv::window != nullptr);
return Priv::Vulkan_CreateSurface(Priv::window, instance, surface) == SDL_TRUE; return SDL_Vulkan_CreateSurface(Priv::window, instance, surface) == SDL_TRUE;
} }
#endif #endif
@ -419,20 +392,19 @@ SDLVideo::SDLVideo ()
return; return;
} }
#ifndef SDL2_STATIC_LIBRARY // Fail gracefully if we somehow reach here after linking against a SDL2 library older than 2.0.6.
// Load optional SDL functions SDL_version sdlver;
if (!Priv::library.IsLoaded()) SDL_GetVersion(&sdlver);
if (!(sdlver.patch >= 6))
{ {
Priv::library.Load({ "libSDL2-2.0.so.0", "libSDL2-2.0.so", "libSDL2.so" }); I_FatalError("Only SDL 2.0.6 or later is supported.");
} }
#endif // !SDL2_STATIC_LIBRARY
#ifdef HAVE_SOFTPOLY #ifdef HAVE_SOFTPOLY
Priv::softpolyEnabled = vid_preferbackend == 2; Priv::softpolyEnabled = vid_preferbackend == 2;
#endif #endif
#ifdef HAVE_VULKAN #ifdef HAVE_VULKAN
Priv::vulkanEnabled = vid_preferbackend == 1 Priv::vulkanEnabled = vid_preferbackend == 1;
&& Priv::Vulkan_GetDrawableSize && Priv::Vulkan_GetInstanceExtensions && Priv::Vulkan_CreateSurface;
if (Priv::vulkanEnabled) if (Priv::vulkanEnabled)
{ {
@ -539,7 +511,7 @@ int SystemBaseFrameBuffer::GetClientWidth()
#ifdef HAVE_VULKAN #ifdef HAVE_VULKAN
assert(Priv::vulkanEnabled); assert(Priv::vulkanEnabled);
Priv::Vulkan_GetDrawableSize(Priv::window, &width, nullptr); SDL_Vulkan_GetDrawableSize(Priv::window, &width, nullptr);
#endif #endif
return width; return width;
@ -562,7 +534,7 @@ int SystemBaseFrameBuffer::GetClientHeight()
#ifdef HAVE_VULKAN #ifdef HAVE_VULKAN
assert(Priv::vulkanEnabled); assert(Priv::vulkanEnabled);
Priv::Vulkan_GetDrawableSize(Priv::window, nullptr, &height); SDL_Vulkan_GetDrawableSize(Priv::window, nullptr, &height);
#endif #endif
return height; return height;
@ -745,10 +717,10 @@ void ProcessSDLWindowEvent(const SDL_WindowEvent &event)
break; break;
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
if (!vid_fullscreen && Priv::GetWindowBordersSize) if (!vid_fullscreen)
{ {
int top = 0, left = 0; int top = 0, left = 0;
Priv::GetWindowBordersSize(Priv::window, &top, &left, nullptr, nullptr); SDL_GetWindowBordersSize(Priv::window, &top, &left, nullptr, nullptr);
win_x = event.data1-left; win_x = event.data1-left;
win_y = event.data2-top; win_y = event.data2-top;
} }