diff --git a/src/client/input/sdl3.c b/src/client/input/sdl3.c index a4dc39ae..cd7b711e 100644 --- a/src/client/input/sdl3.c +++ b/src/client/input/sdl3.c @@ -594,7 +594,7 @@ IN_Update(void) /* 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 * 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) { @@ -612,14 +612,14 @@ IN_Update(void) } else { - SDL_Keycode kc = event.key.keysym.sym; + SDL_Keycode kc = event.key.key; if(sc == SDL_SCANCODE_GRAVE && kc != '\'' && kc != '"') { // special case/hack: open the console with the "console key" // (beneath Esc, left of 1, above Tab) // but not if the keycode for this is a quote (like on Brazilian // 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 // 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" 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 } @@ -881,7 +881,7 @@ IN_Update(void) break; 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; } @@ -2184,9 +2184,9 @@ IN_Controller_Init(qboolean notify_user) if (!is_controller) { 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" " * 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(); +#endif IN_Controller_Init(false); diff --git a/src/client/refresh/gl1/gl1_sdl.c b/src/client/refresh/gl1/gl1_sdl.c index 9d4d6eaa..7237a46f 100644 --- a/src/client/refresh/gl1/gl1_sdl.c +++ b/src/client/refresh/gl1/gl1_sdl.c @@ -350,7 +350,7 @@ RI_ShutdownContext(void) { if(context) { - SDL_GL_DeleteContext(context); + SDL_GL_DestroyContext(context); context = NULL; } } @@ -364,12 +364,11 @@ RI_ShutdownContext(void) int RI_GetSDLVersion() { #ifdef USE_SDL3 - SDL_Version ver; + int version = SDL_GetVersion(); + return SDL_VERSIONNUM_MAJOR(version); #else SDL_version ver; -#endif - SDL_VERSION(&ver); - return ver.major; +#endif } diff --git a/src/client/refresh/gl3/gl3_sdl.c b/src/client/refresh/gl3/gl3_sdl.c index de48cdb8..506dd457 100644 --- a/src/client/refresh/gl3/gl3_sdl.c +++ b/src/client/refresh/gl3/gl3_sdl.c @@ -454,7 +454,7 @@ void GL3_ShutdownContext() { if(context) { - SDL_GL_DeleteContext(context); + SDL_GL_DestroyContext(context); context = NULL; } } @@ -468,12 +468,11 @@ void GL3_ShutdownContext() int GL3_GetSDLVersion() { #ifdef USE_SDL3 - SDL_Version ver; + int version = SDL_GetVersion(); + return SDL_VERSIONNUM_MAJOR(version); #else SDL_version ver; -#endif - SDL_VERSION(&ver); - return ver.major; +#endif } diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 7190db48..2966aee4 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -1786,8 +1786,7 @@ RE_IsVsyncActive(void) static int RE_PrepareForWindow(void) { - int flags = SDL_SWSURFACE; - return flags; + return 0; } /* @@ -1815,17 +1814,18 @@ GetRefAPI(refimport_t imp) // Need to communicate the SDL major version to the client. #ifdef USE_SDL3 - SDL_Version ver; + int version = SDL_VERSIONNUM_MAJOR(SDL_GetVersion()); #else SDL_version ver; -#endif SDL_VERSION(&ver); + int version = ver.major; +#endif memset(&refexport, 0, sizeof(refexport_t)); ri = imp; refexport.api_version = API_VERSION; - refexport.framework_version = ver.major; + refexport.framework_version = version; refexport.BeginRegistration = RE_BeginRegistration; refexport.RegisterModel = RE_RegisterModel; @@ -1910,7 +1910,8 @@ RE_InitContext(void *win) if (r_vsync->value) { #ifdef USE_SDL3 - renderer = SDL_CreateRenderer(window, NULL, SDL_RENDERER_PRESENTVSYNC); + renderer = SDL_CreateRenderer(window, NULL); + SDL_SetRenderVSync(renderer, 1); #else renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); #endif @@ -1918,7 +1919,7 @@ RE_InitContext(void *win) else { #ifdef USE_SDL3 - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); #else renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); #endif diff --git a/src/client/sound/sdl.c b/src/client/sound/sdl.c index 626bc658..d545a058 100644 --- a/src/client/sound/sdl.c +++ b/src/client/sound/sdl.c @@ -1423,7 +1423,7 @@ SDL_BackendInit(void) spec.channels = sndchans; /* 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) { Com_Printf("SDL_OpenAudio() failed: %s\n", SDL_GetError()); diff --git a/src/client/vid/glimp_sdl3.c b/src/client/vid/glimp_sdl3.c index 7d1023ff..dc42241c 100644 --- a/src/client/vid/glimp_sdl3.c +++ b/src/client/vid/glimp_sdl3.c @@ -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, "flags", flags); + if (flags & SDL_WINDOW_OPENGL) + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, SDL_TRUE); + window = SDL_CreateWindowWithProperties(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 switch to it in exclusive fullscreen mode. */ - /* TODO SDL3: Leak? */ - const SDL_DisplayMode *closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false); + SDL_DisplayMode closestMode; - 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); if (vid_rate->value != 0) { 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); } @@ -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", - 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 * 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()); return false; @@ -304,7 +305,7 @@ PrintDisplayModes(void) } int nummodes = 0; - const SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(curdisplay, &nummodes); + SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(curdisplay, &nummodes); if (modes) { @@ -347,7 +348,7 @@ SetSDLIcon() amask = (q2icon64.bytes_per_pixel == 3) ? 0 : 0xff000000; #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_DestroySurface(icon); } @@ -414,11 +415,10 @@ GLimp_Init(void) return false; } - SDL_Version version; + int version = SDL_GetVersion(); - SDL_GetVersion(&version); 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()); SDL_DisplayID *displays; @@ -506,26 +506,22 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) if (initSuccessful && GetWindowSize(&curWidth, &curHeight) && (curWidth == width) && (curHeight == height)) { - /* TODO SDL3: Leak? */ - const SDL_DisplayMode *closestMode = NULL; + SDL_DisplayMode closestMode; /* If we want fullscreen, but aren't */ if (GetFullscreenType()) { if (fullscreen == FULLSCREEN_EXCLUSIVE) { - closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, width, height, vid_rate->value, false); - - if (closestMode == NULL) + if (SDL_GetClosestFullscreenDisplayMode(last_display, width, height, vid_rate->value, false, &closestMode) != 0) { 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) { 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); } @@ -540,10 +536,10 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) else if (fullscreen == FULLSCREEN_DESKTOP) { /* 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()); Cvar_SetValue("vid_fullscreen", 0); @@ -782,7 +778,7 @@ GLimp_GrabInput(qboolean grab) 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(" You should probably update to SDL 2.0.3 or newer!\n"); @@ -906,8 +902,6 @@ GLimp_GetWindowDisplayIndex(void) int GLimp_GetFrameworkVersion(void) { - SDL_Version ver; - SDL_VERSION(&ver); - - return ver.major; + int version = SDL_GetVersion(); + return SDL_VERSIONNUM_MAJOR(version); }