Partial fixes for SDL3

This commit is contained in:
erysdren 2024-08-19 23:49:15 -05:00 committed by Yamagi
parent 667ddafd83
commit 5ace09caac
6 changed files with 47 additions and 51 deletions

View file

@ -594,7 +594,7 @@ IN_Update(void)
/* workaround for AZERTY-keyboards, which don't have 1, 2, ..., 9, 0 in first row: /* workaround for AZERTY-keyboards, which don't have 1, 2, ..., 9, 0 in first row:
* always map those physical keys (scancodes) to those keycodes anyway * always map those physical keys (scancodes) to those keycodes anyway
* see also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 */ * see also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 */
SDL_Scancode sc = event.key.keysym.scancode; SDL_Scancode sc = event.key.scancode;
if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_0) if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_0)
{ {
@ -612,14 +612,14 @@ IN_Update(void)
} }
else else
{ {
SDL_Keycode kc = event.key.keysym.sym; SDL_Keycode kc = event.key.key;
if(sc == SDL_SCANCODE_GRAVE && kc != '\'' && kc != '"') if(sc == SDL_SCANCODE_GRAVE && kc != '\'' && kc != '"')
{ {
// special case/hack: open the console with the "console key" // special case/hack: open the console with the "console key"
// (beneath Esc, left of 1, above Tab) // (beneath Esc, left of 1, above Tab)
// but not if the keycode for this is a quote (like on Brazilian // but not if the keycode for this is a quote (like on Brazilian
// keyboards) - otherwise you couldn't type them in the console // keyboards) - otherwise you couldn't type them in the console
if((event.key.keysym.mod & (SDL_KMOD_CAPS|SDL_KMOD_SHIFT|SDL_KMOD_ALT|SDL_KMOD_CTRL|SDL_KMOD_GUI)) == 0) if((event.key.mod & (SDL_KMOD_CAPS|SDL_KMOD_SHIFT|SDL_KMOD_ALT|SDL_KMOD_CTRL|SDL_KMOD_GUI)) == 0)
{ {
// also, only do this if no modifiers like shift or AltGr or whatever are pressed // also, only do this if no modifiers like shift or AltGr or whatever are pressed
// so kc will most likely be the ascii char generated by this and can be ignored // so kc will most likely be the ascii char generated by this and can be ignored
@ -797,7 +797,7 @@ IN_Update(void)
#else // gyro read as "secondary joystick" #else // gyro read as "secondary joystick"
case SDL_EVENT_JOYSTICK_AXIS_MOTION : case SDL_EVENT_JOYSTICK_AXIS_MOTION :
if ( !imu_joystick || event.gdevice.which != SDL_GetJoystickInstanceID(imu_joystick) ) if ( !imu_joystick || event.gdevice.which != SDL_GetJoystickID(imu_joystick) )
{ {
break; // controller axes handled by SDL_CONTROLLERAXISMOTION break; // controller axes handled by SDL_CONTROLLERAXISMOTION
} }
@ -881,7 +881,7 @@ IN_Update(void)
break; break;
case SDL_EVENT_JOYSTICK_BATTERY_UPDATED : case SDL_EVENT_JOYSTICK_BATTERY_UPDATED :
if (!controller || event.jbattery.which != SDL_GetJoystickInstanceID(SDL_GetGamepadJoystick(controller))) if (!controller || event.jbattery.which != SDL_GetJoystickID(SDL_GetGamepadJoystick(controller)))
{ {
break; break;
} }
@ -2184,9 +2184,9 @@ IN_Controller_Init(qboolean notify_user)
if (!is_controller) if (!is_controller)
{ {
char joystick_guid[65] = {0}; char joystick_guid[65] = {0};
SDL_JoystickGUID guid = SDL_GetJoystickInstanceGUID(joysticks[i]); SDL_GUID guid = SDL_GetJoystickGUIDForID(joysticks[i]);
SDL_GetJoystickGUIDString(guid, joystick_guid, 64); SDL_GUIDToString(guid, joystick_guid, 64);
Com_Printf ("To identify joystick as Gamepad, provide its config by either:\n" Com_Printf ("To identify joystick as Gamepad, provide its config by either:\n"
" * Putting 'gamecontrollerdb.txt' file in your game directory.\n" " * Putting 'gamecontrollerdb.txt' file in your game directory.\n"
@ -2345,7 +2345,10 @@ IN_Init(void)
} }
} }
#if 0
// needs an SDL_Window pointer now??
SDL_StartTextInput(); SDL_StartTextInput();
#endif
IN_Controller_Init(false); IN_Controller_Init(false);

View file

@ -350,7 +350,7 @@ RI_ShutdownContext(void)
{ {
if(context) if(context)
{ {
SDL_GL_DeleteContext(context); SDL_GL_DestroyContext(context);
context = NULL; context = NULL;
} }
} }
@ -364,12 +364,11 @@ RI_ShutdownContext(void)
int RI_GetSDLVersion() int RI_GetSDLVersion()
{ {
#ifdef USE_SDL3 #ifdef USE_SDL3
SDL_Version ver; int version = SDL_GetVersion();
return SDL_VERSIONNUM_MAJOR(version);
#else #else
SDL_version ver; SDL_version ver;
#endif
SDL_VERSION(&ver); SDL_VERSION(&ver);
return ver.major; return ver.major;
#endif
} }

View file

@ -454,7 +454,7 @@ void GL3_ShutdownContext()
{ {
if(context) if(context)
{ {
SDL_GL_DeleteContext(context); SDL_GL_DestroyContext(context);
context = NULL; context = NULL;
} }
} }
@ -468,12 +468,11 @@ void GL3_ShutdownContext()
int GL3_GetSDLVersion() int GL3_GetSDLVersion()
{ {
#ifdef USE_SDL3 #ifdef USE_SDL3
SDL_Version ver; int version = SDL_GetVersion();
return SDL_VERSIONNUM_MAJOR(version);
#else #else
SDL_version ver; SDL_version ver;
#endif
SDL_VERSION(&ver); SDL_VERSION(&ver);
return ver.major; return ver.major;
#endif
} }

View file

@ -1786,8 +1786,7 @@ RE_IsVsyncActive(void)
static int RE_PrepareForWindow(void) static int RE_PrepareForWindow(void)
{ {
int flags = SDL_SWSURFACE; return 0;
return flags;
} }
/* /*
@ -1815,17 +1814,18 @@ GetRefAPI(refimport_t imp)
// Need to communicate the SDL major version to the client. // Need to communicate the SDL major version to the client.
#ifdef USE_SDL3 #ifdef USE_SDL3
SDL_Version ver; int version = SDL_VERSIONNUM_MAJOR(SDL_GetVersion());
#else #else
SDL_version ver; SDL_version ver;
#endif
SDL_VERSION(&ver); SDL_VERSION(&ver);
int version = ver.major;
#endif
memset(&refexport, 0, sizeof(refexport_t)); memset(&refexport, 0, sizeof(refexport_t));
ri = imp; ri = imp;
refexport.api_version = API_VERSION; refexport.api_version = API_VERSION;
refexport.framework_version = ver.major; refexport.framework_version = version;
refexport.BeginRegistration = RE_BeginRegistration; refexport.BeginRegistration = RE_BeginRegistration;
refexport.RegisterModel = RE_RegisterModel; refexport.RegisterModel = RE_RegisterModel;
@ -1910,7 +1910,8 @@ RE_InitContext(void *win)
if (r_vsync->value) if (r_vsync->value)
{ {
#ifdef USE_SDL3 #ifdef USE_SDL3
renderer = SDL_CreateRenderer(window, NULL, SDL_RENDERER_PRESENTVSYNC); renderer = SDL_CreateRenderer(window, NULL);
SDL_SetRenderVSync(renderer, 1);
#else #else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
#endif #endif
@ -1918,7 +1919,7 @@ RE_InitContext(void *win)
else else
{ {
#ifdef USE_SDL3 #ifdef USE_SDL3
renderer = SDL_CreateRenderer(window, NULL, 0); renderer = SDL_CreateRenderer(window, NULL);
#else #else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
#endif #endif

View file

@ -1423,7 +1423,7 @@ SDL_BackendInit(void)
spec.channels = sndchans; spec.channels = sndchans;
/* Okay, let's try our luck */ /* Okay, let's try our luck */
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, SDL_SDL3Callback, NULL); stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, SDL_SDL3Callback, NULL);
if (stream == NULL) if (stream == NULL)
{ {
Com_Printf("SDL_OpenAudio() failed: %s\n", SDL_GetError()); Com_Printf("SDL_OpenAudio() failed: %s\n", SDL_GetError());

View file

@ -123,6 +123,9 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h);
SDL_SetNumberProperty(props, "flags", flags); SDL_SetNumberProperty(props, "flags", flags);
if (flags & SDL_WINDOW_OPENGL)
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, SDL_TRUE);
window = SDL_CreateWindowWithProperties(props); window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props); SDL_DestroyProperties(props);
@ -153,19 +156,17 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
/* Otherwise try to find a mode near the requested one and /* Otherwise try to find a mode near the requested one and
switch to it in exclusive fullscreen mode. */ switch to it in exclusive fullscreen mode. */
/* TODO SDL3: Leak? */ SDL_DisplayMode closestMode;
const SDL_DisplayMode *closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false);
if (closestMode == NULL) if (SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false, &closestMode) != 0)
{ {
Com_Printf("SDL was unable to find a mode close to %ix%i@%f\n", w, h, vid_rate->value); Com_Printf("SDL was unable to find a mode close to %ix%i@%f\n", w, h, vid_rate->value);
if (vid_rate->value != 0) if (vid_rate->value != 0)
{ {
Com_Printf("Retrying with desktop refresh rate\n"); Com_Printf("Retrying with desktop refresh rate\n");
closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, w, h, 0, false);
if (closestMode != NULL) if (SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false, &closestMode) == 0)
{ {
Cvar_SetValue("vid_rate", 0); Cvar_SetValue("vid_rate", 0);
} }
@ -178,12 +179,12 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
} }
Com_Printf("User requested %ix%i@%f, setting closest mode %ix%i@%f\n", Com_Printf("User requested %ix%i@%f, setting closest mode %ix%i@%f\n",
w, h, vid_rate->value, closestMode->w, closestMode->h , closestMode->refresh_rate); w, h, vid_rate->value, closestMode.w, closestMode.h , closestMode.refresh_rate);
/* TODO SDL3: Same code is in InitGraphics(), refactor into /* TODO SDL3: Same code is in InitGraphics(), refactor into
* a function? */ * a function? */
if (SDL_SetWindowFullscreenMode(window, closestMode) < 0) if (SDL_SetWindowFullscreenMode(window, &closestMode) < 0)
{ {
Com_Printf("Couldn't set closest mode: %s\n", SDL_GetError()); Com_Printf("Couldn't set closest mode: %s\n", SDL_GetError());
return false; return false;
@ -304,7 +305,7 @@ PrintDisplayModes(void)
} }
int nummodes = 0; int nummodes = 0;
const SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(curdisplay, &nummodes); SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(curdisplay, &nummodes);
if (modes) if (modes)
{ {
@ -347,7 +348,7 @@ SetSDLIcon()
amask = (q2icon64.bytes_per_pixel == 3) ? 0 : 0xff000000; amask = (q2icon64.bytes_per_pixel == 3) ? 0 : 0xff000000;
#endif #endif
SDL_Surface* icon = SDL_CreateSurfaceFrom((void *)q2icon64.pixel_data, q2icon64.width, q2icon64.height, q2icon64.bytes_per_pixel * q2icon64.width, SDL_GetPixelFormatEnumForMasks(q2icon64.bytes_per_pixel * 8, rmask, gmask, bmask, amask)); SDL_Surface* icon = SDL_CreateSurfaceFrom(q2icon64.width, q2icon64.height, SDL_GetPixelFormatForMasks(q2icon64.bytes_per_pixel * 8, rmask, gmask, bmask, amask), (void *)q2icon64.pixel_data, q2icon64.bytes_per_pixel * q2icon64.width);
SDL_SetWindowIcon(window, icon); SDL_SetWindowIcon(window, icon);
SDL_DestroySurface(icon); SDL_DestroySurface(icon);
} }
@ -414,11 +415,10 @@ GLimp_Init(void)
return false; return false;
} }
SDL_Version version; int version = SDL_GetVersion();
SDL_GetVersion(&version);
Com_Printf("-------- vid initialization --------\n"); Com_Printf("-------- vid initialization --------\n");
Com_Printf("SDL version is: %i.%i.%i\n", (int)version.major, (int)version.minor, (int)version.patch); Com_Printf("SDL version is: %i.%i.%i\n", SDL_VERSIONNUM_MAJOR(version), SDL_VERSIONNUM_MINOR(version), SDL_VERSIONNUM_MICRO(version));
Com_Printf("SDL video driver is \"%s\".\n", SDL_GetCurrentVideoDriver()); Com_Printf("SDL video driver is \"%s\".\n", SDL_GetCurrentVideoDriver());
SDL_DisplayID *displays; SDL_DisplayID *displays;
@ -506,26 +506,22 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
if (initSuccessful && GetWindowSize(&curWidth, &curHeight) if (initSuccessful && GetWindowSize(&curWidth, &curHeight)
&& (curWidth == width) && (curHeight == height)) && (curWidth == width) && (curHeight == height))
{ {
/* TODO SDL3: Leak? */ SDL_DisplayMode closestMode;
const SDL_DisplayMode *closestMode = NULL;
/* If we want fullscreen, but aren't */ /* If we want fullscreen, but aren't */
if (GetFullscreenType()) if (GetFullscreenType())
{ {
if (fullscreen == FULLSCREEN_EXCLUSIVE) if (fullscreen == FULLSCREEN_EXCLUSIVE)
{ {
closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, width, height, vid_rate->value, false); if (SDL_GetClosestFullscreenDisplayMode(last_display, width, height, vid_rate->value, false, &closestMode) != 0)
if (closestMode == NULL)
{ {
Com_Printf("SDL was unable to find a mode close to %ix%i@%f\n", width, height, vid_rate->value); Com_Printf("SDL was unable to find a mode close to %ix%i@%f\n", width, height, vid_rate->value);
if (vid_rate->value != 0) if (vid_rate->value != 0)
{ {
Com_Printf("Retrying with desktop refresh rate\n"); Com_Printf("Retrying with desktop refresh rate\n");
closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, width, height, 0, false);
if (closestMode != NULL) if (SDL_GetClosestFullscreenDisplayMode(last_display, width, height, 0, false, &closestMode) == 0)
{ {
Cvar_SetValue("vid_rate", 0); Cvar_SetValue("vid_rate", 0);
} }
@ -540,10 +536,10 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
else if (fullscreen == FULLSCREEN_DESKTOP) else if (fullscreen == FULLSCREEN_DESKTOP)
{ {
/* Fullscreen window */ /* Fullscreen window */
closestMode = NULL; /* closestMode = NULL; */
} }
if (SDL_SetWindowFullscreenMode(window, closestMode) < 0) if (SDL_SetWindowFullscreenMode(window, &closestMode) < 0)
{ {
Com_Printf("Couldn't set fullscreen modmode: %s\n", SDL_GetError()); Com_Printf("Couldn't set fullscreen modmode: %s\n", SDL_GetError());
Cvar_SetValue("vid_fullscreen", 0); Cvar_SetValue("vid_fullscreen", 0);
@ -782,7 +778,7 @@ GLimp_GrabInput(qboolean grab)
SDL_SetWindowMouseGrab(window, grab ? SDL_TRUE : SDL_FALSE); SDL_SetWindowMouseGrab(window, grab ? SDL_TRUE : SDL_FALSE);
} }
if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0) if(SDL_SetWindowRelativeMouseMode(window, grab ? SDL_TRUE : SDL_FALSE) < 0)
{ {
Com_Printf("WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError()); Com_Printf("WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError());
Com_Printf(" You should probably update to SDL 2.0.3 or newer!\n"); Com_Printf(" You should probably update to SDL 2.0.3 or newer!\n");
@ -906,8 +902,6 @@ GLimp_GetWindowDisplayIndex(void)
int int
GLimp_GetFrameworkVersion(void) GLimp_GetFrameworkVersion(void)
{ {
SDL_Version ver; int version = SDL_GetVersion();
SDL_VERSION(&ver); return SDL_VERSIONNUM_MAJOR(version);
return ver.major;
} }