WIP: port renderer + supporting layers to SDL 3 (builds clean)

Completes phases 3-6 of the migration plan. After this commit, the
codebase compiles and links against pure SDL 3 (no compat shim). The
binary is unverified at runtime but the build is clean.

Renderer (graphics/gfxengine.{cpp,h}):
- Replace SDL_SetVideoMode + SDL_Flip + page-flip machinery with
  SDL_CreateWindow + SDL_CreateRenderer + a streaming SDL_Texture.
  The CPU-side back buffer (softbuf) is now always ARGB8888; legacy
  HW/double-buffer/page flags are dead.
- flip() does a single full-frame SDL_UpdateTexture + SDL_RenderClear
  + SDL_RenderTexture + SDL_RenderPresent each frame. The dirtyrect
  iteration is retained only to drive widget phys_refresh() callbacks.
- SDL_SetRenderLogicalPresentation gives us letterbox scaling for free.
- SDL_SetRenderVSync replaces glSDL_VSync.
- title()/cursor() ported to SDL 3 window/cursor APIs.

Surface API (graphics/sprite.c, filters.c, window.cpp, sofont.cpp,
region.c):
- SDL_FreeSurface → SDL_DestroySurface
- SDL_FillRect → SDL_FillSurfaceRect
- SDL_SetClipRect → SDL_SetSurfaceClipRect
- SDL_SetColorKey(s, flags, key) → SDL_SetSurfaceColorKey(s, bool, key)
- SDL_SetAlpha(s, flags, a) → SDL_SetSurfaceAlphaMod + BlendMode
- SDL_SetColors → SDL_SetSurfacePalette
- SDL_CreateRGBSurface(...) → SDL_CreateSurface(w, h, format_enum)
- SDL_DisplayFormat[Alpha] → SDL_ConvertSurface(s, ARGB8888)
- SDL_MapRGB(surf->format, ...) → SDL_MapSurfaceRGB(surf, ...)
- surface->format->Field → SDL_GetPixelFormatDetails(surf->format)->field
- surface->format->Amask test → SDL_ISPIXELFORMAT_ALPHA
- surface->clip_rect → SDL_GetSurfaceClipRect

Events (kobo.cpp):
- SDL_{KEYDOWN,KEYUP,QUIT,VIDEOEXPOSE,MOUSE*,JOY*} → SDL_EVENT_*
- SDL_ACTIVEEVENT (with gain check) → SDL_EVENT_WINDOW_FOCUS_LOST
- ev.key.keysym.sym → ev.key.key (.unicode → text input, deferred)
- SDLK_PRINT/SYSREQ → SDLK_PRINTSCREEN; lowercase SDLK_p/y/n → uppercase
- ev.motion.x/y for button events → ev.button.x/y (struct layout differs)
- KMOD_META → SDL_KMOD_GUI
- SDL_INIT_NOPARACHUTE → SDL_Init(0) (no parachute by default in SDL 3)

Keymap (gamectl.{cpp,h}):
- SDLKey → SDL_Keycode
- SDLK_KP{1..9} → SDLK_KP_{1..9}

Stubs deferred for later phases (binary will run but with degraded
behavior):
- sound/audio.c: _start_SDL_output returns -1 immediately; SDL 1.2
  audio callback model needs full rewrite onto SDL_AudioStream.
- kobo.cpp init_js/close_js: SDL 3 joystick API uses instance IDs;
  re-port deferred.
- states.cpp SDL_WM_GrabInput/SDL_EnableUNICODE: need window pointer
  exposed from gfxengine; stubbed.
- gamectl.cpp SDL_EnableKeyRepeat: removed; relies on ev.key.repeat.

Other adjustments:
- options.cpp: GFX_DRIVER_GLSDL menu paths removed; show vsync option
  always (renderer handles it).
- sound/a_wave.c: AUDIO_S8/AUDIO_S16SYS → SDL_AUDIO_S8/S16, SDL_FreeWAV
  → SDL_free.
- gfxengine.cpp: SDL_putenv("SDL_VIDEO_CENTERED=1") obsolete (handled
  by SDL_CreateWindow defaults).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ville Lindholm
2026-05-28 21:54:55 +03:00
co-authored by Claude
parent 762b095462
commit f11b6516da
15 changed files with 374 additions and 382 deletions
+4 -4
View File
@@ -832,15 +832,15 @@ int audio_wave_load(int wid, const char *name, int looped)
{
switch (spec.format)
{
case AUDIO_S8:
case SDL_AUDIO_S8:
wavetab[wid].format = AF_MONO8;
break;
case AUDIO_S16SYS:
case SDL_AUDIO_S16:
wavetab[wid].format = AF_MONO16;
break;
default:
log_printf(ELOG, "sound_load(): Unsupported wave format!\n");
SDL_FreeWAV((Uint8 *)(wavetab[wid].data.si8));
SDL_free(wavetab[wid].data.si8);
res = -1;
break;
}
@@ -862,7 +862,7 @@ int audio_wave_load(int wid, const char *name, int looped)
audio_wave_load_mem(wid, data, size, looped);
if(using_loadwav)
SDL_FreeWAV(data);
SDL_free(data);
else
free(data);
+28
View File
@@ -49,6 +49,29 @@
#include <SDL3/SDL_audio.h>
#include "logger.h"
/*
* SDL 3 migration: the SDL 1.2 audio API (SDL_OpenAudio + callback model,
* AUDIO_S16SYS, SDL_LockAudio/PauseAudio/CloseAudio, SDL_AudioSpec.samples
* and .callback) is gone. SDL 3 uses SDL_OpenAudioDeviceStream with a
* pull-stream callback. Porting that bridge is a separate phase; for now
* we provide local stubs so the engine links, and _start_SDL_output()
* below returns -1 so audio is silently disabled.
*/
#define AUDIO_S16SYS 0
#define SDL_OpenAudio(a, b) (-1)
#define SDL_CloseAudio() ((void)0)
#define SDL_PauseAudio(x) ((void)0)
#define SDL_LockAudio() ((void)0)
#define SDL_UnlockAudio() ((void)0)
typedef struct {
int freq;
Uint16 format;
Uint8 channels;
Uint16 samples;
void (*callback)(void *userdata, Uint8 *stream, int len);
} kobo_legacy_audio_spec_t;
#define SDL_AudioSpec kobo_legacy_audio_spec_t
#include "a_struct.h"
#include "a_commands.h"
#include "a_control.h"
@@ -569,6 +592,10 @@ static int _start_oss_output()
static int _start_SDL_output(void)
{
log_printf(WLOG, "audio.c: SDL 3 audio backend not yet ported;"
" sound disabled.\n");
return -1;
#if 0
SDL_AudioSpec as;
SDL_AudioSpec audiospec;
@@ -629,6 +656,7 @@ static int _start_SDL_output(void)
_audio_running = 1;
SDL_PauseAudio(0);
return 0;
#endif
}