From 19f28e3c2d032699eddb134d24a9747cb45d2ea3 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Wed, 9 Oct 2024 00:23:52 +0200 Subject: [PATCH] Fix more SDL3 compatibility problems - use SDL_SetHint() to set the video driver to "dummy" for the dedicated server - adjustments for some more functions that now return bool instead of int. I hope I found all cases of that now, at least in the generic and Linux code, may have to take a closer look at Windows- and Mac- specific code --- neo/framework/Common.cpp | 4 +++- neo/sys/glimp.cpp | 30 ++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index fb0cdaf1..e4d5d07c 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -2949,7 +2949,9 @@ void idCommonLocal::Init( int argc, char **argv ) { // we want to use the SDL event queue for dedicated servers. That // requires video to be initialized, so we just use the dummy // driver for headless boxen -#if SDL_VERSION_ATLEAST(2, 0, 0) +#if SDL_VERSION_ATLEAST(3, 0, 0) + SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "dummy"); +#elif SDL_VERSION_ATLEAST(2, 0, 0) SDL_setenv("SDL_VIDEODRIVER", "dummy", 1); #else char dummy[] = "SDL_VIDEODRIVER=dummy\0"; diff --git a/neo/sys/glimp.cpp b/neo/sys/glimp.cpp index 0e1babb8..be1e4197 100644 --- a/neo/sys/glimp.cpp +++ b/neo/sys/glimp.cpp @@ -749,7 +749,11 @@ try_again: glConfig.haveDebugContext = false; #if SDL_VERSION_ATLEAST(2, 0, 0) int cflags = 0; + #if SDL_VERSION_ATLEAST(3, 0, 0) + if ( SDL_GL_GetAttribute( SDL_GL_CONTEXT_FLAGS, &cflags ) ) { + #else // SDL2 if ( SDL_GL_GetAttribute( SDL_GL_CONTEXT_FLAGS, &cflags ) == 0 ) { + #endif glConfig.haveDebugContext = (cflags & SDL_GL_CONTEXT_DEBUG_FLAG) != 0; if ( glConfig.haveDebugContext ) common->Printf( "Got a debug context!\n" ); @@ -935,19 +939,19 @@ glimpParms_t GLimp_GetCurState() glimpParms_t ret = {}; #if SDL_VERSION_ATLEAST(2, 0, 0) + My_SDL_WindowFlags winFlags = SDL_GetWindowFlags( window ); + ret.fullScreen = (winFlags & SDL_WINDOW_FULLSCREEN) != 0; int curMultiSamples = 0; - if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &curMultiSamples ) == 0 && curMultiSamples > 0 ) { - if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &curMultiSamples ) != 0 ) { + + #if SDL_VERSION_ATLEAST(3, 0, 0) + if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &curMultiSamples ) && curMultiSamples > 0 ) { + if ( ! SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &curMultiSamples ) ) { curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA } } else { curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA } - ret.multiSamples = curMultiSamples; - My_SDL_WindowFlags winFlags = SDL_GetWindowFlags( window ); - ret.fullScreen = (winFlags & SDL_WINDOW_FULLSCREEN) != 0; -#if SDL_VERSION_ATLEAST(3, 0, 0) if (ret.fullScreen) { const SDL_DisplayMode* fullscreenMode = SDL_GetWindowFullscreenMode( window ); if (fullscreenMode != NULL) { @@ -960,7 +964,15 @@ glimpParms_t GLimp_GetCurState() ret.fullScreenDesktop = true; } } -#else // SDL2 + #else // SDL2 + if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &curMultiSamples ) == 0 && curMultiSamples > 0 ) { + if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &curMultiSamples ) != 0 ) { + curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA + } + } else { + curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA + } + ret.fullScreenDesktop = (winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP; if ( ret.fullScreen && !ret.fullScreenDesktop ) { // I think SDL_GetWindowDisplayMode() is only for "real" fullscreen? SDL_DisplayMode real_mode = {}; @@ -972,7 +984,9 @@ glimpParms_t GLimp_GetCurState() common->Warning( "GLimp_GetCurState(): Can't get display mode: %s\n", SDL_GetError() ); } } -#endif + #endif + + ret.multiSamples = curMultiSamples; if ( ret.width == 0 && ret.height == 0 ) { // windowed mode, fullscreen-desktop mode or SDL_GetWindowDisplayMode() failed SDL_GetWindowSize( window, &ret.width, &ret.height );