From 64772ca49f44671a2564b2c0811863da174b54a2 Mon Sep 17 00:00:00 2001 From: Er2 Date: Wed, 5 Mar 2025 16:44:41 +0300 Subject: [PATCH] SDL3: Add port --- engine/client/cl_game.c | 21 ++- engine/client/input.c | 23 ++- engine/common/filesystem_engine.c | 9 +- engine/common/host.c | 6 +- engine/common/soundlib/snd_utils.c | 4 +- engine/common/system.c | 22 ++- engine/platform/sdl/events.c | 169 +++++++++++------ engine/platform/sdl/in_sdl.c | 84 +++++++-- engine/platform/sdl/joy_sdl.c | 48 ++++- engine/platform/sdl/s_sdl.c | 141 ++++++++++++-- engine/platform/sdl/sys_sdl.c | 35 +++- engine/platform/sdl/vid_sdl.c | 284 +++++++++++++++++++++++++---- engine/platform/stub/s_stub.c | 2 +- 13 files changed, 713 insertions(+), 135 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index a2109de8cc..0258b14f7e 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -13,8 +13,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -#if XASH_SDL -#include // SDL_GetWindowPosition +#if XASH_SDL // SDL_GetWindowPosition +#if XASH_SDL == 3 +// Officially recommended method of using SDL3 +#include +#else +#include +#endif #endif // XASH_SDL #include "common.h" @@ -2092,7 +2097,7 @@ static int GAME_EXPORT pfnGetWindowCenterX( void ) } #endif -#if XASH_SDL == 2 +#if XASH_SDL == 2 || XASH_SDL == 3 SDL_GetWindowPosition( host.hWnd, &x, NULL ); #endif @@ -2117,7 +2122,7 @@ static int GAME_EXPORT pfnGetWindowCenterY( void ) } #endif -#if XASH_SDL == 2 +#if XASH_SDL == 2 || XASH_SDL == 3 SDL_GetWindowPosition( host.hWnd, NULL, &y ); #endif @@ -3970,7 +3975,13 @@ qboolean CL_LoadProgs( const char *name ) // and if so, disable relative mouse mode #if XASH_WIN32 && !XASH_64BIT clgame.client_dll_uses_sdl = COM_CheckLibraryDirectDependency( name, OS_LIB_PREFIX "SDL2." OS_LIB_EXT, false ); - Con_Printf( S_NOTE "%s uses %s for mouse input\n", name, clgame.client_dll_uses_sdl ? "SDL2" : "Windows API" ); + if (clgame.client_dll_uses_sdl) + Con_Printf( S_NOTE "%s uses %s for mouse input\n", name, "SDL2" ); + else + { + clgame.client_dll_uses_sdl = COM_CheckLibraryDirectDependency( name, OS_LIB_PREFIX "SDL3." OS_LIB_EXT, false ); + Con_Printf( S_NOTE "%s uses %s for mouse input\n", name, clgame.client_dll_uses_sdl ? "SDL3" : "Windows API" ); + } #endif // NOTE: important stuff! diff --git a/engine/client/input.c b/engine/client/input.c index 98886052bc..02ab4f74c8 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -20,8 +20,13 @@ GNU General Public License for more details. #include "cursor_type.h" #if XASH_SDL +#if XASH_SDL == 3 +// Officially recommended method of using SDL3 +#include +#else #include #endif +#endif #include "platform/platform.h" @@ -212,7 +217,10 @@ void IN_SetRelativeMouseMode( qboolean set ) if( set && !s_bRawInput ) { -#if XASH_SDL == 2 +#if XASH_SDL == 3 + SDL_GetRelativeMouseState(NULL, NULL); + SDL_SetWindowRelativeMouseMode(host.hWnd, true); +#elif XASH_SDL == 2 SDL_GetRelativeMouseState( NULL, NULL ); SDL_SetRelativeMouseMode( SDL_TRUE ); #endif @@ -222,7 +230,10 @@ void IN_SetRelativeMouseMode( qboolean set ) } else if( !set && s_bRawInput ) { -#if XASH_SDL == 2 +#if XASH_SDL == 3 + SDL_GetRelativeMouseState(NULL, NULL); + SDL_SetWindowRelativeMouseMode(host.hWnd, false); +#elif XASH_SDL == 2 SDL_GetRelativeMouseState( NULL, NULL ); SDL_SetRelativeMouseMode( SDL_FALSE ); #endif @@ -240,7 +251,11 @@ void IN_SetMouseGrab( qboolean set ) if( set && !s_bMouseGrab ) { #if XASH_SDL +#if XASH_SDL == 3 + SDL_SetWindowMouseGrab( host.hWnd, true ); +#else SDL_SetWindowGrab( host.hWnd, SDL_TRUE ); +#endif #endif s_bMouseGrab = true; if( verbose ) @@ -249,7 +264,11 @@ void IN_SetMouseGrab( qboolean set ) else if( !set && s_bMouseGrab ) { #if XASH_SDL +#if XASH_SDL == 3 + SDL_SetWindowMouseGrab( host.hWnd, false ); +#else SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); +#endif #endif s_bMouseGrab = false; diff --git a/engine/common/filesystem_engine.c b/engine/common/filesystem_engine.c index ef77619933..da4f53ec69 100644 --- a/engine/common/filesystem_engine.c +++ b/engine/common/filesystem_engine.c @@ -17,7 +17,12 @@ GNU General Public License for more details. */ #if XASH_SDL -#include // SDL_GetBasePath +// SDL_GetBasePath +#if XASH_SDL == 3 +#include +#else +#include +#endif #endif #include @@ -209,7 +214,7 @@ static qboolean FS_DetermineRootDirectory( char *out, size_t size ) return true; Sys_Error( "couldn't find %s data directory", XASH_ENGINE_NAME ); return false; -#elif ( XASH_SDL == 2 ) && !XASH_NSWITCH // GetBasePath not impl'd in switch-sdl2 +#elif ( XASH_SDL == 2 || XASH_SDL == 3 ) && !XASH_NSWITCH // GetBasePath not impl'd in switch-sdl2 path = SDL_GetBasePath(); #if XASH_APPLE diff --git a/engine/common/host.c b/engine/common/host.c index c2f7e4535d..51c959546d 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -15,7 +15,11 @@ GNU General Public License for more details. #include "build.h" #ifdef XASH_SDL +#if XASH_SDL == 3 +#include +#else #include +#endif #endif // XASH_SDL #include // va_args #if !XASH_WIN32 @@ -201,7 +205,7 @@ static void Sys_PrintUsage( const char *exename ) #if !XASH_MOBILE_PLATFORM O("-daemonize ", "run engine as a daemon") #endif -#if XASH_SDL == 2 +#if XASH_SDL == 2 || XASH_SDL == 3 O("-sdl_renderer ","use alternative SDL_Renderer for software") #endif // XASH_SDL #if XASH_ANDROID && !XASH_SDL diff --git a/engine/common/soundlib/snd_utils.c b/engine/common/soundlib/snd_utils.c index d9930ba9fe..4784617646 100644 --- a/engine/common/soundlib/snd_utils.c +++ b/engine/common/soundlib/snd_utils.c @@ -14,7 +14,9 @@ GNU General Public License for more details. */ #include "soundlib.h" -#if XASH_SDL +#if XASH_SDL == 3 +#include +#elif XASH_SDL #include #endif // XASH_SDL diff --git a/engine/common/system.c b/engine/common/system.c index 765a4d260b..9a100bc0dc 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -24,8 +24,12 @@ GNU General Public License for more details. #endif #ifdef XASH_SDL +#if XASH_SDL == 3 +#include +#else #include #endif +#endif #if XASH_POSIX #include @@ -72,7 +76,9 @@ Sys_DebugBreak */ void Sys_DebugBreak( void ) { -#if XASH_SDL +#if XASH_SDL == 3 + int was_grabbed = host.hWnd != NULL && SDL_GetWindowMouseGrab( host.hWnd ); +#elif XASH_SDL int was_grabbed = host.hWnd != NULL && SDL_GetWindowGrab( host.hWnd ); #endif @@ -81,7 +87,13 @@ void Sys_DebugBreak( void ) #if XASH_SDL if( was_grabbed ) // so annoying... + { +#if XASH_SDL == 3 + SDL_SetWindowMouseGrab( host.hWnd, false ); +#else SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); +#endif + } #endif // XASH_SDL #if _MSC_VER @@ -93,7 +105,13 @@ void Sys_DebugBreak( void ) #if XASH_SDL if( was_grabbed ) + { +#if XASH_SDL == 3 + SDL_SetWindowMouseGrab( host.hWnd, true ); +#else SDL_SetWindowGrab( host.hWnd, SDL_TRUE ); +#endif + } #endif } @@ -393,7 +411,7 @@ void Sys_Error( const char *error, ... ) if( !Host_IsDedicated() ) { -#if XASH_SDL == 2 +#if XASH_SDL == 2 || XASH_SDL == 3 if( host.hWnd ) SDL_HideWindow( host.hWnd ); #endif #if XASH_WIN32 diff --git a/engine/platform/sdl/events.c b/engine/platform/sdl/events.c index 4bf58c7143..2380d9e62e 100644 --- a/engine/platform/sdl/events.c +++ b/engine/platform/sdl/events.c @@ -13,7 +13,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #if defined( XASH_SDL ) && !XASH_DEDICATED +#if XASH_SDL == 3 +// Officially recommended method of using SDL3 +#define SDL_ENABLE_OLD_NAMES // To reduce ifdefs count, TODO(Er2): Remove old names support +#include +#else #include +#endif #include #include "common.h" @@ -98,12 +104,17 @@ SDLash_KeyEvent */ static void SDLash_KeyEvent( SDL_KeyboardEvent key ) { +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + bool down = key.down; + int keynum = key.scancode; +#else int down = key.state != SDL_RELEASED; #if SDL_VERSION_ATLEAST( 2, 0, 0 ) int keynum = key.keysym.scancode; #else int keynum = key.keysym.sym; #endif +#endif #if XASH_ANDROID if( keynum == SDL_SCANCODE_VOLUMEUP || keynum == SDL_SCANCODE_VOLUMEDOWN ) @@ -112,7 +123,11 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key ) } #endif +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + if( SDL_IsTextInputActive(host.hWnd) && down ) +#else if( SDL_IsTextInputActive( ) && down ) +#endif { // this is how engine understands ctrl+c, ctrl+v and other hotkeys if( cls.key_dest != key_game && FBitSet( SDL_GetModState(), KMOD_CTRL )) @@ -228,8 +243,10 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key ) case SDL_SCANCODE_MUTE: case SDL_SCANCODE_VOLUMEUP: case SDL_SCANCODE_VOLUMEDOWN: +#if !SDL_VERSION_ATLEAST( 3, 2, 0 ) case SDL_SCANCODE_BRIGHTNESSDOWN: case SDL_SCANCODE_BRIGHTNESSUP: +#endif case SDL_SCANCODE_SELECT: return; #endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) @@ -264,7 +281,11 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) return; #endif +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + if( !button.down ) +#else if( button.state == SDL_RELEASED ) +#endif down = 0; else if( button.clicks >= 2 ) down = 2; // special state for double-click in UI @@ -366,7 +387,79 @@ static void SDLash_ActiveEvent( int gain ) /* ============= -SDLash_EventFilter +SDLash_WindowEventHandler + +============= +*/ +#if SDL_VERSION_ATLEAST( 2, 0, 0 ) +static void SDLash3D_WindowEventHandler( SDL_Event *event ) +{ + if( event->window.windowID != SDL_GetWindowID( host.hWnd ) ) + return; + + if( host.status == HOST_SHUTDOWN || Host_IsDedicated() ) + return; // no need to activate + +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + switch( event->type ) +#else + switch( event->window.event ) +#endif + { + case SDL_WINDOWEVENT_MOVED: + { + char val[32]; + + Q_snprintf( val, sizeof( val ), "%d", event->window.data1 ); + Cvar_DirectSet( &window_xpos, val ); + + Q_snprintf( val, sizeof( val ), "%d", event->window.data2 ); + Cvar_DirectSet( &window_ypos, val ); + + if ( vid_fullscreen.value == WINDOW_MODE_WINDOWED ) + Cvar_DirectSet( &vid_maximized, "0" ); + break; + } + case SDL_WINDOWEVENT_MINIMIZED: + host.status = HOST_SLEEP; + Cvar_DirectSet( &vid_maximized, "0" ); + VID_RestoreScreenResolution( ); + break; + case SDL_WINDOWEVENT_RESTORED: + host.status = HOST_FRAME; + host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; + Cvar_DirectSet( &vid_maximized, "0" ); + if( vid_fullscreen.value == WINDOW_MODE_FULLSCREEN ) + VID_SetMode(); + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + SDLash_ActiveEvent( true ); + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + SDLash_ActiveEvent( false ); + break; + case SDL_WINDOWEVENT_RESIZED: +#if !XASH_MOBILE_PLATFORM + if( vid_fullscreen.value == WINDOW_MODE_WINDOWED ) +#endif + { + SDL_Window *wnd = SDL_GetWindowFromID( event->window.windowID ); + VID_SaveWindowSize( event->window.data1, event->window.data2, + FBitSet( SDL_GetWindowFlags( wnd ), SDL_WINDOW_MAXIMIZED ) != 0 ); + } + break; + case SDL_WINDOWEVENT_MAXIMIZED: + Cvar_DirectSet( &vid_maximized, "1" ); + break; + default: + break; + } +} +#endif + +/* +============= +SDLash_EventHandler ============= */ @@ -449,7 +542,11 @@ static void SDLash_EventHandler( SDL_Event *event ) dy /= (float)refState.height; } +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + IN_TouchEvent( type, event->tfinger.fingerID, x, y, dx, dy ); +#else IN_TouchEvent( type, event->tfinger.fingerId, x, y, dx, dy ); +#endif break; } @@ -471,63 +568,19 @@ static void SDLash_EventHandler( SDL_Event *event ) SDLash_HandleGameControllerEvent( event ); break; +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + case SDL_EVENT_WINDOW_MOVED: + case SDL_EVENT_WINDOW_MINIMIZED: + case SDL_EVENT_WINDOW_RESTORED: + case SDL_EVENT_WINDOW_FOCUS_GAINED: + case SDL_EVENT_WINDOW_FOCUS_LOST: + case SDL_EVENT_WINDOW_RESIZED: + case SDL_EVENT_WINDOW_MAXIMIZED: +#else case SDL_WINDOWEVENT: - if( event->window.windowID != SDL_GetWindowID( host.hWnd ) ) - return; - - if( host.status == HOST_SHUTDOWN || Host_IsDedicated() ) - break; // no need to activate - - switch( event->window.event ) - { - case SDL_WINDOWEVENT_MOVED: - { - char val[32]; - - Q_snprintf( val, sizeof( val ), "%d", event->window.data1 ); - Cvar_DirectSet( &window_xpos, val ); - - Q_snprintf( val, sizeof( val ), "%d", event->window.data2 ); - Cvar_DirectSet( &window_ypos, val ); - - if ( vid_fullscreen.value == WINDOW_MODE_WINDOWED ) - Cvar_DirectSet( &vid_maximized, "0" ); - break; - } - case SDL_WINDOWEVENT_MINIMIZED: - host.status = HOST_SLEEP; - Cvar_DirectSet( &vid_maximized, "0" ); - VID_RestoreScreenResolution( ); - break; - case SDL_WINDOWEVENT_RESTORED: - host.status = HOST_FRAME; - host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; - Cvar_DirectSet( &vid_maximized, "0" ); - if( vid_fullscreen.value == WINDOW_MODE_FULLSCREEN ) - VID_SetMode(); - break; - case SDL_WINDOWEVENT_FOCUS_GAINED: - SDLash_ActiveEvent( true ); - break; - case SDL_WINDOWEVENT_FOCUS_LOST: - SDLash_ActiveEvent( false ); - break; - case SDL_WINDOWEVENT_RESIZED: -#if !XASH_MOBILE_PLATFORM - if( vid_fullscreen.value == WINDOW_MODE_WINDOWED ) #endif - { - SDL_Window *wnd = SDL_GetWindowFromID( event->window.windowID ); - VID_SaveWindowSize( event->window.data1, event->window.data2, - FBitSet( SDL_GetWindowFlags( wnd ), SDL_WINDOW_MAXIMIZED ) != 0 ); - } - break; - case SDL_WINDOWEVENT_MAXIMIZED: - Cvar_DirectSet( &vid_maximized, "1" ); - break; - default: - break; - } + SDLash3D_WindowEventHandler(event); + break; #else case SDL_VIDEORESIZE: VID_SaveWindowSize( event->resize.w, event->resize.h ); @@ -570,7 +623,11 @@ void Platform_PreCreateMove( void ) if( m_ignore.value ) { SDL_GetRelativeMouseState( NULL, NULL ); +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDL_ShowCursor(); +#else SDL_ShowCursor( SDL_TRUE ); +#endif } } diff --git a/engine/platform/sdl/in_sdl.c b/engine/platform/sdl/in_sdl.c index 1e94b58249..44861c87ec 100644 --- a/engine/platform/sdl/in_sdl.c +++ b/engine/platform/sdl/in_sdl.c @@ -12,7 +12,12 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#if XASH_SDL == 3 +// Officially recommended method of using SDL3 +#include +#else #include +#endif #include "common.h" #include "keydefs.h" @@ -35,7 +40,11 @@ static struct static struct { +#if SDL_MAJOR_VERSION >= 3 + float x, y; +#else int x, y; +#endif qboolean pushed; } in_visible_cursor_pos; @@ -47,6 +56,12 @@ Platform_GetMousePos */ void GAME_EXPORT Platform_GetMousePos( int *x, int *y ) { +#if SDL_MAJOR_VERSION >= 3 + float m_x, m_y; + SDL_GetMouseState( &m_x, &m_y ); + *x = m_x; + *y = m_y; +#else SDL_GetMouseState( x, y ); if( x && window_width.value && window_width.value != refState.width ) @@ -60,6 +75,7 @@ void GAME_EXPORT Platform_GetMousePos( int *x, int *y ) float factor = refState.height / window_height.value; *y = *y * factor; } +#endif } /* @@ -81,7 +97,11 @@ Platform_MouseMove */ void Platform_MouseMove( float *x, float *y ) { +#if SDL_MAJOR_VERSION >= 3 + float m_x, m_y; +#else int m_x, m_y; +#endif SDL_GetRelativeMouseState( &m_x, &m_y ); *x = (float)m_x; *y = (float)m_y; @@ -140,7 +160,9 @@ SDLash_EnableTextInput */ void Platform_EnableTextInput( qboolean enable ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + enable ? SDL_StartTextInput(host.hWnd) : SDL_StopTextInput(host.hWnd); +#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) enable ? SDL_StartTextInput() : SDL_StopTextInput(); #endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) } @@ -155,7 +177,26 @@ SDLash_InitCursors */ void SDLash_InitCursors( void ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + if( cursors.initialized ) + SDLash_FreeCursors(); + + // load up all default cursors + cursors.cursors[dc_none] = NULL; + cursors.cursors[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT); + cursors.cursors[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT); + cursors.cursors[dc_hourglass] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT); + cursors.cursors[dc_crosshair] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR); + cursors.cursors[dc_up] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT); + cursors.cursors[dc_sizenwse] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NWSE_RESIZE); + cursors.cursors[dc_sizenesw] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NESW_RESIZE); + cursors.cursors[dc_sizewe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_EW_RESIZE); + cursors.cursors[dc_sizens] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NS_RESIZE); + cursors.cursors[dc_sizeall] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_MOVE); + cursors.cursors[dc_no] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED); + cursors.cursors[dc_hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER); + cursors.initialized = true; +#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) if( cursors.initialized ) SDLash_FreeCursors(); @@ -191,7 +232,13 @@ void SDLash_FreeCursors( void ) for( ; i < ARRAYSIZE( cursors.cursors ); i++ ) { if( cursors.cursors[i] ) + { +#if SDL_MAJOR_VERSION >= 3 + SDL_DestroyCursor( cursors.cursors[i] ); +#else SDL_FreeCursor( cursors.cursors[i] ); +#endif + } cursors.cursors[i] = NULL; } @@ -233,7 +280,11 @@ void Platform_SetCursorType( VGUI_DefaultCursor type ) if( cursors.initialized ) SDL_SetCursor( cursors.cursors[type] ); +#if SDL_MAJOR_VERSION >= 3 + SDL_ShowCursor(); +#else SDL_ShowCursor( true ); +#endif // restore the last mouse position if( in_visible_cursor_pos.pushed ) @@ -252,7 +303,11 @@ void Platform_SetCursorType( VGUI_DefaultCursor type ) in_visible_cursor_pos.pushed = true; } +#if SDL_MAJOR_VERSION >= 3 + SDL_HideCursor(); +#else SDL_ShowCursor( false ); +#endif } #else if( host.mouse_visible ) @@ -275,30 +330,35 @@ Platform_GetKeyModifiers key_modifier_t Platform_GetKeyModifiers( void ) { #if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_MAJOR_VERSION >= 3 +#define SDL_KMOD(kmod) SDL_KMOD_##kmod +#else +#define SDL_KMOD(kmod) KMOD_##kmod +#endif SDL_Keymod modFlags; key_modifier_t resultFlags; resultFlags = KeyModifier_None; modFlags = SDL_GetModState(); - if( FBitSet( modFlags, KMOD_LCTRL )) + if( FBitSet( modFlags, SDL_KMOD(LCTRL) )) SetBits( resultFlags, KeyModifier_LeftCtrl ); - if( FBitSet( modFlags, KMOD_RCTRL )) + if( FBitSet( modFlags, SDL_KMOD(RCTRL) )) SetBits( resultFlags, KeyModifier_RightCtrl ); - if( FBitSet( modFlags, KMOD_RSHIFT )) + if( FBitSet( modFlags, SDL_KMOD(RSHIFT) )) SetBits( resultFlags, KeyModifier_RightShift ); - if( FBitSet( modFlags, KMOD_LSHIFT )) + if( FBitSet( modFlags, SDL_KMOD(LSHIFT) )) SetBits( resultFlags, KeyModifier_LeftShift ); - if( FBitSet( modFlags, KMOD_LALT )) + if( FBitSet( modFlags, SDL_KMOD(LALT) )) SetBits( resultFlags, KeyModifier_LeftAlt ); - if( FBitSet( modFlags, KMOD_RALT )) + if( FBitSet( modFlags, SDL_KMOD(RALT) )) SetBits( resultFlags, KeyModifier_RightAlt ); - if( FBitSet( modFlags, KMOD_NUM )) + if( FBitSet( modFlags, SDL_KMOD(NUM) )) SetBits( resultFlags, KeyModifier_NumLock ); - if( FBitSet( modFlags, KMOD_CAPS )) + if( FBitSet( modFlags, SDL_KMOD(CAPS) )) SetBits( resultFlags, KeyModifier_CapsLock ); - if( FBitSet( modFlags, KMOD_RGUI )) + if( FBitSet( modFlags, SDL_KMOD(RGUI) )) SetBits( resultFlags, KeyModifier_RightSuper ); - if( FBitSet( modFlags, KMOD_LGUI )) + if( FBitSet( modFlags, SDL_KMOD(LGUI) )) SetBits( resultFlags, KeyModifier_LeftSuper ); return resultFlags; diff --git a/engine/platform/sdl/joy_sdl.c b/engine/platform/sdl/joy_sdl.c index d593963e13..9bdef2612f 100644 --- a/engine/platform/sdl/joy_sdl.c +++ b/engine/platform/sdl/joy_sdl.c @@ -12,7 +12,13 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#if XASH_SDL == 3 +// Officially recommended method of using SDL3 +#define SDL_ENABLE_OLD_NAMES // To reduce ifdefs count, TODO(Er2): Remove old names support +#include +#else #include +#endif #if SDL_VERSION_ATLEAST( 2, 0, 0 ) #include "common.h" @@ -21,6 +27,13 @@ GNU General Public License for more details. #include "client.h" #include "events.h" +#if SDL_MAJOR_VERSION >= 3 +// SDL3 moved to booleans, no more weird code with != 0 or < 0 +#define SDL_SUCCESS(expr) (expr) +#else +#define SDL_SUCCESS(expr) ((expr) == 0) +#endif + static const int g_button_mapping[] = { #if XASH_NSWITCH // devkitPro/SDL has inverted Nintendo layout for SDL_GameController @@ -264,17 +277,31 @@ void SDLash_HandleGameControllerEvent( SDL_Event *ev ) switch( ev->type ) { case SDL_CONTROLLERAXISMOTION: +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDLash_SetActiveGameController( ev->gaxis.which ); + x = ev->gaxis.axis; + if( x >= 0 && x < ARRAYSIZE( g_axis_mapping )) + Joy_AxisMotionEvent( g_axis_mapping[x], ev->gaxis.value ); +#else SDLash_SetActiveGameController( ev->caxis.which ); x = ev->caxis.axis; if( x >= 0 && x < ARRAYSIZE( g_axis_mapping )) Joy_AxisMotionEvent( g_axis_mapping[x], ev->caxis.value ); +#endif break; case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDLash_SetActiveGameController( ev->gbutton.which ); + x = ev->gbutton.button; + if( x >= 0 && x < ARRAYSIZE( g_button_mapping )) + Key_Event( g_button_mapping[x], ev->gbutton.down ); +#else SDLash_SetActiveGameController( ev->cbutton.which ); x = ev->cbutton.button; if( x >= 0 && x < ARRAYSIZE( g_button_mapping )) Key_Event( g_button_mapping[x], ev->cbutton.state ); +#endif break; case SDL_CONTROLLERDEVICEREMOVED: SDLash_GameControllerRemoved( ev->cdevice.which ); @@ -282,7 +309,11 @@ void SDLash_HandleGameControllerEvent( SDL_Event *ev ) case SDL_CONTROLLERDEVICEADDED: SDLash_GameControllerAdded( ev->cdevice.which ); break; -#if SDL_VERSION_ATLEAST( 2, 0, 14 ) +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + case SDL_EVENT_GAMEPAD_SENSOR_UPDATE: + SDLash_GameControllerSensorUpdate( ev->gsensor ); + break; +#elif SDL_VERSION_ATLEAST( 2, 0, 14 ) case SDL_CONTROLLERSENSORUPDATE: SDLash_GameControllerSensorUpdate( ev->csensor ); break; @@ -335,10 +366,13 @@ Platform_JoyInit int Platform_JoyInit( void ) { int count, numJoysticks, i; +#if SDL_MAJOR_VERSION >= 3 + SDL_JoystickID *joysticks; +#endif Con_Reportf( "Joystick: SDL GameController API\n" ); if( SDL_WasInit( SDL_INIT_GAMECONTROLLER ) != SDL_INIT_GAMECONTROLLER && - SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER )) + !SDL_SUCCESS(SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER ))) { Con_Reportf( "Failed to initialize SDL GameController API: %s\n", SDL_GetError( )); return 0; @@ -348,12 +382,22 @@ int Platform_JoyInit( void ) SDLash_GameControllerAddMappings( "controllermappings.txt" ); count = 0; +#if SDL_MAJOR_VERSION >= 3 + joysticks = SDL_GetJoysticks(&numJoysticks); + for ( i = 0; i < numJoysticks; i++ ) + { + if( SDL_IsGamepad( i )) + ++count; + } + SDL_free(joysticks); +#else numJoysticks = SDL_NumJoysticks(); for ( i = 0; i < numJoysticks; i++ ) { if( SDL_IsGameController( i )) ++count; } +#endif return count; } diff --git a/engine/platform/sdl/s_sdl.c b/engine/platform/sdl/s_sdl.c index e763863be4..979111f771 100644 --- a/engine/platform/sdl/s_sdl.c +++ b/engine/platform/sdl/s_sdl.c @@ -20,7 +20,11 @@ GNU General Public License for more details. #include "sound.h" #include "voice.h" +#if XASH_SDL == 3 +#include +#else #include +#endif #include #define SAMPLE_16BIT_SHIFT 1 @@ -34,22 +38,40 @@ GNU General Public License for more details. #define SDL_LockAudioDevice( x ) SDL_LockAudio() #define SDL_UnlockAudioDevice( x ) SDL_UnlockAudio() #define SDLash_IsAudioError( x ) (( x ) != 0) +#elif SDL_VERSION_ATLEAST( 3, 2, 0 ) +#define SDLash_IsAudioError( x ) (!(x)) #else #define SDLash_IsAudioError( x ) (( x ) == 0) #endif +#if SDL_MAJOR_VERSION >= 3 +// SDL3 moved to booleans, no more weird code with != 0 or < 0 +#define SDL_SUCCESS(expr) (expr) +#else +#define SDL_SUCCESS(expr) ((expr) == 0) +#endif + /* ======================================================================= Global variables. Must be visible to window-procedure function so it can unlock and free the data block after it has been played. ======================================================================= */ -static int sdl_dev; +#if SDL_MAJOR_VERSION >= 3 +static SDL_AudioStream *sdl_dev = NULL; +static SDL_AudioStream *in_dev = NULL; +#else +static SDL_AudioDeviceID sdl_dev = 0; static SDL_AudioDeviceID in_dev = 0; +#endif static SDL_AudioFormat sdl_format; static char sdl_backend_name[32]; +#if SDL_MAJOR_VERSION >= 3 +static void SDL_SoundCallback( void *userdata, SDL_AudioStream *stream, int len, int totalAmount ) +#else static void SDL_SoundCallback( void *userdata, Uint8 *stream, int len ) +#endif { const int size = dma.samples << 1; int pos; @@ -58,7 +80,9 @@ static void SDL_SoundCallback( void *userdata, Uint8 *stream, int len ) #if ! SDL_VERSION_ATLEAST( 2, 0, 0 ) if( !dma.buffer ) { +#if !SDL_VERSION_ATLEAST(3, 2, 0) memset( stream, 0, len ); +#endif return; } #endif @@ -71,15 +95,24 @@ static void SDL_SoundCallback( void *userdata, Uint8 *stream, int len ) if( wrapped < 0 ) { +#if SDL_VERSION_ATLEAST(3, 2, 0) + SDL_PutAudioStreamData(stream, dma.buffer + pos, len); +#else memcpy( stream, dma.buffer + pos, len ); +#endif dma.samplepos += len >> 1; } else { int remaining = size - pos; +#if SDL_VERSION_ATLEAST(3, 2, 0) + SDL_PutAudioStreamData(stream, dma.buffer + pos, remaining); + SDL_PutAudioStreamData(stream, dma.buffer, wrapped); +#else memcpy( stream, dma.buffer + pos, remaining ); memcpy( stream + remaining, dma.buffer, wrapped ); +#endif dma.samplepos = wrapped >> 1; } @@ -97,9 +130,14 @@ Returns false if nothing is found. */ qboolean SNDDMA_Init( void ) { - SDL_AudioSpec desired, obtained; + SDL_AudioSpec desired; +#if !SDL_VERSION_ATLEAST(3, 2, 0) + SDL_AudioSpec obtained; +#endif int samplecount; +#if XASH_WIN32 const char *driver = NULL; +#endif // Modders often tend to use proprietary crappy solutions // like FMOD to play music, sometimes even with versions outdated by a few decades! @@ -128,14 +166,20 @@ qboolean SNDDMA_Init( void ) // even if we don't have PA // we still can safely set env variables +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + // Er2: Should be this removed? + SDL_setenv_unsafe( "PULSE_PROP_application.name", GI->title, 1 ); + SDL_setenv_unsafe( "PULSE_PROP_media.role", "game", 1 ); +#else SDL_setenv( "PULSE_PROP_application.name", GI->title, 1 ); SDL_setenv( "PULSE_PROP_media.role", "game", 1 ); +#endif // reinitialize SDL with our driver just in case if( SDL_WasInit( SDL_INIT_AUDIO )) SDL_QuitSubSystem( SDL_INIT_AUDIO ); - if( SDL_InitSubSystem( SDL_INIT_AUDIO )) + if( !SDL_SUCCESS(SDL_InitSubSystem( SDL_INIT_AUDIO )) ) { Con_Reportf( S_ERROR "Audio: SDL: %s \n", SDL_GetError( ) ); return false; @@ -143,12 +187,20 @@ qboolean SNDDMA_Init( void ) memset( &desired, 0, sizeof( desired ) ); desired.freq = SOUND_DMA_SPEED; + desired.channels = 2; +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + desired.format = SDL_AUDIO_S16LE; +#else desired.format = AUDIO_S16LSB; desired.samples = 1024; - desired.channels = 2; desired.callback = SDL_SoundCallback; +#endif +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + sdl_dev = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired, SDL_SoundCallback, NULL); +#else sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 ); +#endif if( SDLash_IsAudioError( sdl_dev )) { @@ -156,6 +208,7 @@ qboolean SNDDMA_Init( void ) return false; } +#if !SDL_VERSION_ATLEAST( 3, 2, 0 ) if( obtained.format != AUDIO_S16LSB ) { Con_Printf( "SDL audio format %d unsupported.\n", obtained.format ); @@ -167,20 +220,30 @@ qboolean SNDDMA_Init( void ) Con_Printf( "SDL audio channels %d unsupported.\n", obtained.channels ); goto fail; } +#endif - dma.format.speed = obtained.freq; - dma.format.channels = obtained.channels; - dma.format.width = 2; samplecount = s_samplecount.value; if( !samplecount ) samplecount = 0x8000; + +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) // SDL audio streams have spec, not desired, that's why we just copy values from them + dma.format.speed = desired.freq; + dma.format.channels = desired.channels; + dma.samples = samplecount * desired.channels; + + sdl_format = desired.format; +#else + dma.format.speed = obtained.freq; + dma.format.channels = obtained.channels; dma.samples = samplecount * obtained.channels; - dma.buffer = Mem_Calloc( sndpool, dma.samples * 2 ); - dma.samplepos = 0; sdl_format = obtained.format; +#endif + dma.format.width = 2; + dma.buffer = Mem_Calloc( sndpool, dma.samples * 2 ); + dma.samplepos = 0; - Con_Printf( "Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver( ), obtained.freq ); + Con_Printf( "Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver( ), dma.format.speed ); Q_snprintf( sdl_backend_name, sizeof( sdl_backend_name ), "SDL (%s)", SDL_GetCurrentAudioDriver( )); dma.initialized = true; dma.backendName = sdl_backend_name; @@ -204,7 +267,9 @@ Makes sure dma.buffer is valid */ void SNDDMA_BeginPainting( void ) { +#if !SDL_VERSION_ATLEAST(3, 2, 0) SDL_LockAudioDevice( sdl_dev ); +#endif } /* @@ -217,7 +282,9 @@ Also unlocks the dsound buffer */ void SNDDMA_Submit( void ) { +#if !SDL_VERSION_ATLEAST(3, 2, 0) SDL_UnlockAudioDevice( sdl_dev ); +#endif } /* @@ -237,7 +304,11 @@ void SNDDMA_Shutdown( void ) SNDDMA_Activate( false ); #if !XASH_EMSCRIPTEN +#if SDL_VERSION_ATLEAST(3, 2, 0) + SDL_DestroyAudioStream(sdl_dev); +#else SDL_CloseAudioDevice( sdl_dev ); +#endif #endif } @@ -266,7 +337,14 @@ void SNDDMA_Activate( qboolean active ) if( !dma.initialized ) return; +#if SDL_VERSION_ATLEAST(3, 2, 0) + if (active) + SDL_ResumeAudioStreamDevice(sdl_dev); + else + SDL_PauseAudioStreamDevice(sdl_dev); +#else SDL_PauseAudioDevice( sdl_dev, !active ); +#endif } /* @@ -274,7 +352,11 @@ void SNDDMA_Activate( qboolean active ) SDL_SoundInputCallback =========== */ +#if SDL_MAJOR_VERSION >= 3 +static void SDL_SoundInputCallback( void *userdata, SDL_AudioStream *stream, int len, int totalAmount ) +#else static void SDL_SoundInputCallback( void *userdata, Uint8 *stream, int len ) +#endif { int size = Q_min( len, sizeof( voice.input_buffer ) - voice.input_buffer_pos ); @@ -282,7 +364,11 @@ static void SDL_SoundInputCallback( void *userdata, Uint8 *stream, int len ) if( !size ) return; +#if SDL_VERSION_ATLEAST(3, 2, 0) + SDL_GetAudioStreamData(stream, voice.input_buffer + voice.input_buffer_pos, size); +#else memcpy( voice.input_buffer + voice.input_buffer_pos, stream, size ); +#endif voice.input_buffer_pos += size; } @@ -293,7 +379,10 @@ VoiceCapture_Init */ qboolean VoiceCapture_Init( void ) { - SDL_AudioSpec wanted, spec; + SDL_AudioSpec wanted; +#if !SDL_VERSION_ATLEAST(3, 2, 0) + SDL_AudioSpec spec; +#endif if( !SDLash_IsAudioError( in_dev )) { @@ -302,20 +391,33 @@ qboolean VoiceCapture_Init( void ) SDL_zero( wanted ); wanted.freq = voice.samplerate; - wanted.format = AUDIO_S16LSB; wanted.channels = VOICE_PCM_CHANNELS; +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + wanted.format = SDL_AUDIO_S16LE; +#else + wanted.format = AUDIO_S16LSB; wanted.samples = voice.frame_size; wanted.callback = SDL_SoundInputCallback; +#endif +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + sdl_dev = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &wanted, SDL_SoundInputCallback, NULL); +#else in_dev = SDL_OpenAudioDevice( NULL, SDL_TRUE, &wanted, &spec, 0 ); +#endif + if( SDLash_IsAudioError( in_dev )) { Con_Printf( "%s: error creating capture device (%s)\n", __func__, SDL_GetError() ); return false; } - + +#if SDL_VERSION_ATLEAST(3, 2, 0) + Con_Printf( S_NOTE "%s: capture device creation success (%p: %s)\n", __func__, in_dev, SDL_GetAudioDeviceName(SDL_GetAudioStreamDevice(in_dev)) ); +#else Con_Printf( S_NOTE "%s: capture device creation success (%i: %s)\n", __func__, in_dev, SDL_GetAudioDeviceName( in_dev, SDL_TRUE ) ); +#endif return true; } @@ -329,7 +431,14 @@ qboolean VoiceCapture_Activate( qboolean activate ) if( SDLash_IsAudioError( in_dev )) return false; +#if SDL_VERSION_ATLEAST(3, 2, 0) + if (activate) + SDL_ResumeAudioStreamDevice(in_dev); + else + SDL_PauseAudioStreamDevice(in_dev); +#else SDL_PauseAudioDevice( in_dev, activate ? SDL_FALSE : SDL_TRUE ); +#endif return true; } @@ -343,8 +452,10 @@ qboolean VoiceCapture_Lock( qboolean lock ) if( SDLash_IsAudioError( in_dev )) return false; +#if !SDL_VERSION_ATLEAST( 3, 2, 0 ) // SDL3 have internal locks for streams if( lock ) SDL_LockAudioDevice( in_dev ); else SDL_UnlockAudioDevice( in_dev ); +#endif return true; } @@ -359,7 +470,11 @@ void VoiceCapture_Shutdown( void ) if( SDLash_IsAudioError( in_dev )) return; +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDL_DestroyAudioStream(in_dev); +#else SDL_CloseAudioDevice( in_dev ); +#endif } #endif // XASH_SOUND == SOUND_SDL diff --git a/engine/platform/sdl/sys_sdl.c b/engine/platform/sdl/sys_sdl.c index 8461b67644..e9b6ea534c 100644 --- a/engine/platform/sdl/sys_sdl.c +++ b/engine/platform/sdl/sys_sdl.c @@ -13,10 +13,22 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#if XASH_SDL == 3 +// Officially recommended method of using SDL3 +#include +#else #include +#endif #include "platform/platform.h" #include "events.h" +#if SDL_MAJOR_VERSION >= 3 +// SDL3 moved to booleans, no more weird code with != 0 or < 0 +#define SDL_SUCCESS(expr) (expr) +#else +#define SDL_SUCCESS(expr) ((expr) == 0) +#endif + #if XASH_TIMER == TIMER_SDL double Platform_DoubleTime( void ) { @@ -96,6 +108,16 @@ void SDLash_Init( const char *basedir ) } #endif +#if SDL_MAJOR_VERSION >= 3 // Function renames + SDL_SetLogOutputFunction( SDLash_LogOutputFunction, NULL ); + + if( host_developer.value >= 2 ) + SDL_SetLogPriorities( SDL_LOG_PRIORITY_VERBOSE ); + else if( host_developer.value >= 1 ) + SDL_SetLogPriorities( SDL_LOG_PRIORITY_WARN ); + else + SDL_SetLogPriorities( SDL_LOG_PRIORITY_ERROR ); +#else SDL_LogSetOutputFunction( SDLash_LogOutputFunction, NULL ); if( host_developer.value >= 2 ) @@ -104,22 +126,27 @@ void SDLash_Init( const char *basedir ) SDL_LogSetAllPriority( SDL_LOG_PRIORITY_WARN ); else SDL_LogSetAllPriority( SDL_LOG_PRIORITY_ERROR ); +#endif #ifndef SDL_INIT_EVENTS #define SDL_INIT_EVENTS 0 #endif - if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) ) +#ifndef SDL_INIT_TIMER // No longer needed since SDL3 +#define SDL_INIT_TIMER 0 +#endif + if( !SDL_SUCCESS(SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS )) ) { Sys_Warn( "SDL_Init failed: %s", SDL_GetError() ); host.type = HOST_DEDICATED; } -#if SDL_MAJOR_VERSION >= 2 +#if SDL_MAJOR_VERSION == 2 SDL_SetHint( SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0" ); + SDL_StopTextInput(); +#endif +#if SDL_MAJOR_VERSION >= 2 SDL_SetHint( SDL_HINT_MOUSE_TOUCH_EVENTS, "0" ); SDL_SetHint( SDL_HINT_TOUCH_MOUSE_EVENTS, "0" ); - - SDL_StopTextInput(); #endif // XASH_SDL == 2 SDLash_InitCursors(); diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 72242a175a..91c4bf049d 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -13,12 +13,29 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #if !XASH_DEDICATED +#if XASH_SDL == 3 +#define SDL_DISABLE_OLD_NAMES +#include +#else #include +#endif #include "common.h" #include "client.h" #include "vid_common.h" #include "platform/sdl/events.h" +#if SDL_MAJOR_VERSION >= 3 +// SDL3 moved to booleans, no more weird code with != 0 or < 0 +#define SDL_SUCCESS(expr) (expr) +#define SDL_TRUE true +#define SDL_FALSE false +// SDL3 uses SDL_FRect for renderer +typedef SDL_FRect SDLRect; +#else +#define SDL_SUCCESS(expr) ((expr) == 0) +typedef SDL_Rect SDLRect; +#endif + static vidmode_t *vidmodes = NULL; static int num_vidmodes = 0; static void GL_SetupAttributes( void ); @@ -40,6 +57,10 @@ struct qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ) { +#if SDL_MAJOR_VERSION >= 3 + const SDL_PixelFormatDetails *win_format; +#endif + sw.width = width; sw.height = height; @@ -47,7 +68,12 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * if( sw.renderer ) { unsigned int format = SDL_GetWindowPixelFormat( host.hWnd ); +#if SDL_MAJOR_VERSION >= 3 + // TODO(Er2): Re-visit this code: SDL_RenderSetLogicalSize in SDL2-compat have some logic + SDL_SetRenderLogicalPresentation( sw.renderer, refState.width, refState.height, SDL_LOGICAL_PRESENTATION_STRETCH ); +#else SDL_RenderSetLogicalSize( sw.renderer, refState.width, refState.height ); +#endif if( sw.tex ) { @@ -88,7 +114,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * void *pixels; int pitch; - if( !SDL_LockTexture( sw.tex, NULL, &pixels, &pitch )) + if( SDL_SUCCESS(SDL_LockTexture( sw.tex, NULL, &pixels, &pitch )) ) { int bits; uint amask; @@ -97,7 +123,11 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * SDL_UnlockTexture( sw.tex ); // enough for building blitter tables +#if SDL_MAJOR_VERSION >= 3 + SDL_GetMasksForPixelFormat( format, &bits, r, g, b, &amask ); +#else SDL_PixelFormatEnumToMasks( format, &bits, r, g, b, &amask ); +#endif *bpp = SDL_BYTESPERPIXEL( format ); *stride = pitch / *bpp; @@ -130,11 +160,20 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * return false; } - *bpp = sw.win->format->BytesPerPixel; +#if SDL_MAJOR_VERSION >= 3 + win_format = SDL_GetPixelFormatDetails(sw.win->format); + *r = win_format->Rmask; + *g = win_format->Gmask; + *b = win_format->Bmask; + *bpp = SDL_BYTESPERPIXEL(sw.win->format); + *stride = sw.win->pitch / SDL_BYTESPERPIXEL(sw.win->format); +#else *r = sw.win->format->Rmask; *g = sw.win->format->Gmask; *b = sw.win->format->Bmask; + *bpp = sw.win->format->BytesPerPixel; *stride = sw.win->pitch / sw.win->format->BytesPerPixel; +#endif /// TODO: check somehow if ref_soft can handle native format #if 0 @@ -159,7 +198,7 @@ void *SW_LockBuffer( void ) void *pixels; int stride; - if( SDL_LockTexture(sw.tex, NULL, &pixels, &stride ) < 0 ) + if( !SDL_SUCCESS(SDL_LockTexture(sw.tex, NULL, &pixels, &stride )) ) Sys_Error( "%s: %s", __func__, SDL_GetError( )); return pixels; } @@ -197,7 +236,7 @@ void SW_UnlockBuffer( void ) #if SDL_VERSION_ATLEAST( 2, 0, 0 ) if( sw.renderer ) { - SDL_Rect src, dst; + SDLRect src, dst; src.x = src.y = 0; src.w = sw.width; src.h = sw.height; @@ -207,7 +246,11 @@ void SW_UnlockBuffer( void ) SDL_SetTextureBlendMode(sw.tex, SDL_BLENDMODE_NONE); +#if SDL_MAJOR_VERSION >= 3 + SDL_RenderTexture(sw.renderer, sw.tex, &src, &dst); +#else SDL_RenderCopy(sw.renderer, sw.tex, &src, &dst); +#endif SDL_RenderPresent(sw.renderer); return; @@ -256,13 +299,20 @@ vidmode_t *R_GetVideoMode( int num ) static void R_InitVideoModes( void ) { char buf[MAX_VA_STRING]; + #if SDL_VERSION_ATLEAST( 2, 0, 0 ) SDL_Point point = { window_xpos.value, window_ypos.value }; - int displayIndex = SDL_GetPointDisplayIndex( &point ); int i, modes; - num_vidmodes = 0; +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDL_DisplayID displayIndex = SDL_GetDisplayForPoint( &point ); + SDL_DisplayMode** disp_modes = SDL_GetFullscreenDisplayModes( displayIndex, &modes ); +#else + int displayIndex = SDL_GetPointDisplayIndex( &point ); modes = SDL_GetNumDisplayModes( displayIndex ); +#endif + + num_vidmodes = 0; if( !modes ) return; @@ -272,13 +322,17 @@ static void R_InitVideoModes( void ) for( i = 0; i < modes; i++ ) { int j; +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDL_DisplayMode mode = *disp_modes[i]; +#else SDL_DisplayMode mode; - if( SDL_GetDisplayMode( displayIndex, i, &mode ) < 0 ) + if( !SDL_SUCCESS(SDL_GetDisplayMode( displayIndex, i, &mode )) ) { Msg( "SDL_GetDisplayMode: %s\n", SDL_GetError() ); continue; } +#endif if( mode.w < VID_MIN_WIDTH || mode.h < VID_MIN_HEIGHT ) continue; @@ -301,6 +355,11 @@ static void R_InitVideoModes( void ) num_vidmodes++; } + +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDL_free( disp_modes ); +#endif + #else // SDL_VERSION_ATLEAST( 2, 0, 0 ) SDL_Rect **modes; int len = 0, i = 0, j; @@ -416,6 +475,21 @@ static void WIN_SetDPIAwareness( void ) } } +#if SDL_MAJOR_VERSION >= 3 +static qboolean WIN_SetWindowIcon( HICON ico ) +{ + HWND hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); + if (hwnd != NULL) + { + SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LONG_PTR)ico ); + SendMessage( hwnd, WM_SETICON, ICON_BIG, (LONG_PTR)ico ); + return true; + } + + Con_Reportf( S_ERROR "%s: %s", __func__, SDL_GetError() ); + return false; +} +#else #include static qboolean WIN_SetWindowIcon( HICON ico ) { @@ -434,6 +508,7 @@ static qboolean WIN_SetWindowIcon( HICON ico ) return false; } #endif +#endif /* @@ -492,8 +567,8 @@ void GL_UpdateSwapInterval( void ) { ClearBits( gl_vsync.flags, FCVAR_CHANGED ); - if( SDL_GL_SetSwapInterval( gl_vsync.value ) < 0 ) - Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( )); + if( !SDL_SUCCESS(SDL_GL_SetSwapInterval( gl_vsync.value )) ) + Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError() ); } #endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) } @@ -507,7 +582,13 @@ always return false */ qboolean GL_DeleteContext( void ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_MAJOR_VERSION >= 3 + if( glw_state.context ) + { + SDL_GL_DestroyContext(glw_state.context); + glw_state.context = NULL; + } +#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) if( glw_state.context ) { SDL_GL_DeleteContext(glw_state.context); @@ -542,7 +623,7 @@ GL_UpdateContext static qboolean GL_UpdateContext( void ) { #if SDL_VERSION_ATLEAST( 2, 0, 0 ) - if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context ) < 0 ) + if( !SDL_SUCCESS(SDL_GL_MakeCurrent( host.hWnd, glw_state.context )) ) { Con_Reportf( S_ERROR "%s: %s\n", __func__, SDL_GetError( )); return GL_DeleteContext(); @@ -555,7 +636,15 @@ void VID_SaveWindowSize( int width, int height, qboolean maximized ) { int render_w = width, render_h = height; -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_MAJOR_VERSION >= 3 + if( !glw_state.software ) + SDL_GetWindowSizeInPixels( host.hWnd, &render_w, &render_h ); + else + { + // TODO(Er2): SDL_RenderSetLogicalSize? + SDL_SetRenderLogicalPresentation( sw.renderer, width, height, SDL_LOGICAL_PRESENTATION_STRETCH ); + } +#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) if( !glw_state.software ) SDL_GL_GetDrawableSize( host.hWnd, &render_w, &render_h ); else @@ -569,30 +658,54 @@ void VID_SaveWindowSize( int width, int height, qboolean maximized ) static qboolean VID_SetScreenResolution( int width, int height, window_mode_t window_mode ) { #if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_VERSION_MAJOR < 3 SDL_DisplayMode got; +#endif Uint32 wndFlags = 0; if( vid_highdpi.value ) + { +#if SDL_MAJOR_VERSION >= 3 + SetBits( wndFlags, SDL_WINDOW_HIGH_PIXEL_DENSITY ); +#else SetBits( wndFlags, SDL_WINDOW_ALLOW_HIGHDPI ); +#endif + } SDL_SetWindowBordered( host.hWnd, SDL_FALSE ); if( window_mode == WINDOW_MODE_BORDERLESS ) { - if( SDL_GetDesktopDisplayMode( 0, &got ) < 0 ) +#if SDL_MAJOR_VERSION >= 3 + if( !SDL_SUCCESS(SDL_SetWindowFullscreenMode( host.hWnd, NULL )) ) + { + Con_Printf( S_ERROR "%s: SDL_SetWindowFullscreen (borderless): %s", __func__, SDL_GetError( )); + return false; + } +#else + if( !SDL_SUCCESS(SDL_GetDesktopDisplayMode( 0, &got )) ) { Con_Printf( S_ERROR "%s: SDL_GetDesktopDisplayMode: %s", __func__, SDL_GetError( )); return false; } - if( SDL_SetWindowFullscreen( host.hWnd, SDL_WINDOW_FULLSCREEN_DESKTOP ) < 0 ) + if( !SDL_SUCCESS(SDL_SetWindowFullscreen( host.hWnd, SDL_WINDOW_FULLSCREEN_DESKTOP )) ) { Con_Printf( S_ERROR "%s: SDL_SetWindowFullscreen (borderless): %s", __func__, SDL_GetError( )); return false; } +#endif } else if( window_mode == WINDOW_MODE_FULLSCREEN ) { +#if SDL_MAJOR_VERSION >= 3 + SDL_DisplayMode got; + if (!SDL_SUCCESS(SDL_GetClosestFullscreenDisplayMode(SDL_GetPrimaryDisplay(), width, height, 0.0f, false, &got))) + { + Con_Printf( S_ERROR "%s: SDL_GetClosestFullscreenDisplayMode: %s", __func__, SDL_GetError() ); + return false; + } +#else SDL_DisplayMode want = { 0 }; want.w = width; want.h = height; @@ -602,21 +715,30 @@ static qboolean VID_SetScreenResolution( int width, int height, window_mode_t wi Con_Printf( S_ERROR "%s: SDL_GetClosestDisplayMode: %s", __func__, SDL_GetError( )); return false; } +#endif - if( got.w != want.w || got.h != want.h ) - Con_Reportf( S_NOTE "Got closest display mode: %ix%i@%i\n", got.w, got.h, got.refresh_rate ); + if( got.w != width || got.h != height ) + Con_Reportf( S_NOTE "Got closest display mode: %dx%d@%f\n", got.w, got.h, got.refresh_rate ); - if( SDL_SetWindowDisplayMode( host.hWnd, &got ) < 0 ) +#if SDL_MAJOR_VERSION >= 3 + if (!SDL_SUCCESS(SDL_SetWindowFullscreenMode(host.hWnd, &got))) + { + Con_Printf( S_ERROR "%s: SDL_SetWindowFullscreenMode: %s", __func__, SDL_GetError() ); + return false; + } +#else + if( !SDL_SUCCESS(SDL_SetWindowDisplayMode( host.hWnd, &got )) ) { Con_Printf( S_ERROR "%s: SDL_SetWindowDisplayMode: %s", __func__, SDL_GetError( )); return false; } - if( SDL_SetWindowFullscreen( host.hWnd, SDL_WINDOW_FULLSCREEN ) < 0 ) + if( !SDL_SUCCESS(SDL_SetWindowFullscreen( host.hWnd, SDL_WINDOW_FULLSCREEN )) ) { Con_Printf( S_ERROR "%s: SDL_SetWindowFullscreen (fullscreen): %s", __func__, SDL_GetError( )); return false; } +#endif } SDL_SetWindowSize( host.hWnd, got.w, got.h ); @@ -677,14 +799,23 @@ static void VID_SetWindowIcon( SDL_Window *hWnd ) if( icon ) { +#if SDL_MAJOR_VERSION >= 3 + SDL_Surface *surface = SDL_CreateSurfaceFrom( icon->width, icon->height, + SDL_PIXELFORMAT_ABGR8888, icon->buffer, 4 * icon->width ); +#else SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( icon->buffer, icon->width, icon->height, 32, 4 * icon->width, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 ); +#endif if( surface ) { SDL_SetWindowIcon( host.hWnd, surface ); +#if SDL_MAJOR_VERSION >= 3 + SDL_DestroySurface( surface ); +#else SDL_FreeSurface( surface ); +#endif FS_FreeImage( icon ); return; } @@ -702,7 +833,17 @@ static qboolean VID_CreateWindowWithSafeGL( const char *wndname, int xpos, int y { while( glw_state.safe >= SAFE_NO && glw_state.safe < SAFE_LAST ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if SDL_VERSION_ATLEAST( 3, 2, 0 ) + SDL_PropertiesID props = SDL_CreateProperties(); + SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, wndname); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, xpos); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, ypos); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, w); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_FLAGS_NUMBER, flags); + host.hWnd = SDL_CreateWindowWithProperties(props); + SDL_DestroyProperties(props); +#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) host.hWnd = SDL_CreateWindow( wndname, xpos, ypos, w, h, flags ); #else host.hWnd = sw.surf = SDL_SetVideoMode( width, height, 16, flags ); @@ -758,15 +899,27 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ) string wndname; #if SDL_VERSION_ATLEAST( 2, 0, 0 ) qboolean maximized = vid_maximized.value != 0.0f; - Uint32 wndFlags = SDL_WINDOW_SHOWN | SDL_WINDOW_MOUSE_FOCUS; + Uint32 wndFlags = SDL_WINDOW_MOUSE_FOCUS; int xpos, ypos; - int num_displays = SDL_GetNumVideoDisplays(); SDL_Rect rect = { window_xpos.value, window_ypos.value, width, height }; +#if SDL_MAJOR_VERSION >= 3 + int num_displays; + SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); +#else + int num_displays = SDL_GetNumVideoDisplays(); + wndFlags |= SDL_WINDOW_SHOWN; +#endif Q_strncpy( wndname, GI->title, sizeof( wndname )); if( vid_highdpi.value ) + { +#if SDL_MAJOR_VERSION >= 3 + SetBits( wndFlags, SDL_WINDOW_HIGH_PIXEL_DENSITY ); +#else SetBits( wndFlags, SDL_WINDOW_ALLOW_HIGHDPI ); +#endif + } if( !glw_state.software ) SetBits( wndFlags, SDL_WINDOW_OPENGL ); @@ -788,7 +941,12 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ) { for( int i = 0; i < num_displays; i++ ) { - if( SDL_GetDisplayBounds( i, &display_rects[i] ) != 0 ) +#if SDL_MAJOR_VERSION >= 3 + SDL_DisplayID instance_id = displays[i]; + if( !SDL_SUCCESS(SDL_GetDisplayBounds( instance_id, &display_rects[i] )) ) +#else + if( !SDL_SUCCESS(SDL_GetDisplayBounds( i, &display_rects[i] )) ) +#endif { Con_Printf( S_ERROR "Failed to get bounds for display %d! SDL_Error: %s\n", i, SDL_GetError()); display_rects[i] = ( SDL_Rect ){ 0, 0, 0, 0 }; @@ -813,10 +971,23 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ) else { if( window_mode == WINDOW_MODE_FULLSCREEN ) + { // need input grab only in true fullscreen mode +#if SDL_MAJOR_VERSION >= 3 + SetBits( wndFlags, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MOUSE_GRABBED ); +#else SetBits( wndFlags, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_INPUT_GRABBED ); +#endif + } else + { +#if SDL_MAJOR_VERSION >= 3 + // XXX(Er2): Is this correct? Anyways it's fullscreen + SetBits( wndFlags, SDL_WINDOW_FULLSCREEN ); +#else SetBits( wndFlags, SDL_WINDOW_FULLSCREEN_DESKTOP ); +#endif + } SetBits( wndFlags, SDL_WINDOW_BORDERLESS ); if ( window_xpos.value < 0 || window_ypos.value < 0 ) { @@ -830,12 +1001,22 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ) } } +#if SDL_MAJOR_VERSION >= 3 + SDL_free(displays); +#endif + if( !VID_CreateWindowWithSafeGL( wndname, xpos, ypos, width, height, wndFlags )) return false; // update window size if it was maximized, just in case - if( FBitSet( SDL_GetWindowFlags( host.hWnd ), SDL_WINDOW_MAXIMIZED|SDL_WINDOW_FULLSCREEN_DESKTOP ) != 0 ) +#if SDL_MAJOR_VERSION >= 3 + if( FBitSet( SDL_GetWindowFlags( host.hWnd ), SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN ) != 0 ) +#else + if( FBitSet( SDL_GetWindowFlags( host.hWnd ), SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN_DESKTOP ) != 0 ) +#endif + { SDL_GetWindowSize( host.hWnd, &width, &height ); + } if( window_mode != WINDOW_MODE_WINDOWED ) { @@ -849,6 +1030,17 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ) if( glw_state.software ) { +#if SDL_MAJOR_VERSION >= 3 + char sdl_renderer[64]; + + Sys_GetParmFromCmdLine("-sdl_renderer", sdl_renderer ); + + sw.renderer = SDL_CreateRenderer(host.hWnd, sdl_renderer); + if( sw.renderer ) + Con_Printf( "SDL_Renderer %s initialized\n", SDL_GetRendererName(sw.renderer) ); + else + Con_Printf( S_ERROR "failed to create SDL renderer: %s\n", SDL_GetError() ); +#else int sdl_renderer = -2; char cmd[64]; @@ -867,6 +1059,7 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ) Con_Printf( "SDL_Renderer %s initialized\n", info.name ); } } +#endif } else { @@ -970,7 +1163,9 @@ int GL_SetAttribute( int attr, int val ) #if SDL_VERSION_ATLEAST( 2, 0, 0 ) MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION ); +#if SDL_MAJOR_VERSION < 3 // Maybe even earlier, SDL_GL_CONTEXT_PROFILE_MASK replaces it MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL ); +#endif MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE ); @@ -1015,7 +1210,9 @@ int GL_GetAttribute( int attr, int *val ) #if SDL_VERSION_ATLEAST( 2, 0, 0 ) MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION ); +#if SDL_MAJOR_VERSION < 3 // Maybe even earlier, SDL_GL_CONTEXT_PROFILE_MASK replaces it MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL ); +#endif MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE ); @@ -1049,9 +1246,14 @@ qboolean R_Init_Video( const int type ) qboolean retval; #if SDL_VERSION_ATLEAST( 2, 0, 0 ) - SDL_DisplayMode displayMode; SDL_Point point = { window_xpos.value, window_ypos.value }; +#if SDL_MAJOR_VERSION >= 3 + const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(SDL_GetDisplayForPoint(&point)); + const SDL_DisplayMode displayMode = *display_mode; +#else + SDL_DisplayMode displayMode; SDL_GetCurrentDisplayMode( SDL_GetPointDisplayIndex( &point ), &displayMode ); +#endif refState.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format ); #else refState.desktopBitsPixel = 16; @@ -1088,7 +1290,7 @@ qboolean R_Init_Video( const int type ) // refdll can request some attributes GL_SetupAttributes( ); - if( SDL_GL_LoadLibrary( EGL_LIB ) < 0 ) + if( !SDL_SUCCESS(SDL_GL_LoadLibrary( EGL_LIB )) ) { Con_Reportf( S_ERROR "Couldn't initialize OpenGL: %s\n", SDL_GetError()); return false; @@ -1125,14 +1327,25 @@ qboolean R_Init_Video( const int type ) rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mode ) { #if SDL_VERSION_ATLEAST( 2, 0, 0 ) - SDL_DisplayMode displayMode; - if( SDL_GetCurrentDisplayMode( 0, &displayMode ) < 0 ) +#if SDL_MAJOR_VERSION >= 3 + SDL_DisplayMode displayMode; + const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode( SDL_GetPrimaryDisplay() ); + if ( display_mode == NULL ) +#else + SDL_DisplayMode displayMode; + if( !SDL_SUCCESS(SDL_GetCurrentDisplayMode( 0, &displayMode )) ) +#endif { Con_Printf( S_ERROR "SDL_GetCurrentDisplayMode: %s\n", SDL_GetError( )); return rserr_invalid_mode; } +#if SDL_MAJOR_VERSION >= 3 + // FIXME(Er2): crutch + displayMode = *display_mode; +#endif + // check our desktop attributes refState.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format ); if( window_mode == WINDOW_MODE_BORDERLESS ) @@ -1160,7 +1373,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mod VID_RestoreScreenResolution(); #if SDL_VERSION_ATLEAST( 2, 0, 0 ) - if( SDL_SetWindowFullscreen( host.hWnd, 0 ) < 0 ) + if( !SDL_SUCCESS(SDL_SetWindowFullscreen( host.hWnd, 0 )) ) { Con_Printf( S_ERROR "SDL_SetWindowFullscreen: %s", SDL_GetError( )); return rserr_invalid_fullscreen; @@ -1197,18 +1410,21 @@ qboolean VID_SetMode( void ) if( iScreenWidth < VID_MIN_WIDTH || iScreenHeight < VID_MIN_HEIGHT ) // trying to get resolution automatically by default { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) -#if !defined( DEFAULT_MODE_WIDTH ) || !defined( DEFAULT_MODE_HEIGHT ) +#if defined( DEFAULT_MODE_WIDTH ) || defined( DEFAULT_MODE_HEIGHT ) + iScreenWidth = DEFAULT_MODE_WIDTH; + iScreenHeight = DEFAULT_MODE_HEIGHT; +#elif SDL_VERSION_ATLEAST( 3, 2, 0 ) + const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode( SDL_GetPrimaryDisplay() ); + + iScreenWidth = mode->w; + iScreenHeight = mode->h; +#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) SDL_DisplayMode mode; SDL_GetDesktopDisplayMode( 0, &mode ); iScreenWidth = mode.w; iScreenHeight = mode.h; -#else - iScreenWidth = DEFAULT_MODE_WIDTH; - iScreenHeight = DEFAULT_MODE_HEIGHT; -#endif #else // SDL_VERSION_ATLEAST( 2, 0, 0 ) iScreenWidth = 320; iScreenHeight = 240; diff --git a/engine/platform/stub/s_stub.c b/engine/platform/stub/s_stub.c index 6bd969664e..94635c115b 100644 --- a/engine/platform/stub/s_stub.c +++ b/engine/platform/stub/s_stub.c @@ -30,7 +30,7 @@ so it can unlock and free the data block after it has been played. ======================================================================= */ -dma_t dma; +//dma_t dma; void S_Activate( qboolean active ) {