WIP: delete glSDL shim, replace with sdl_compat.h

Step 1+2 of the SDL 3 migration. The 2300-line graphics/glSDL.{c,h}
OpenGL-on-top-of-SDL-1.2 shim is obsolete under SDL 3 (SDL_Renderer
does what glSDL did natively), and its #define overrides of SDL
surface APIs collided directly with SDL 3's SDL_oldnames.h.

- Add graphics/sdl_compat.h: a one-line umbrella that just pulls in
  <SDL3/SDL.h>.
- Replace every #include "glSDL.h" with #include "sdl_compat.h" (15
  files across the tree).
- Delete graphics/glSDL.c, graphics/glSDL.h.
- Drop glSDL.c from graphics/CMakeLists.txt.
- Remove GFX_DRIVER_GLSDL from the gfx_drivers_t enum and from all
  switches/conditions in gfxengine.cpp.
- Drop the glSDL_VSync() call site (will be re-introduced as
  SDL_SetRenderVSync once gfxengine is ported to SDL_Renderer).
- Drop the two glSDL_Invalidate() calls in window.cpp (texture
  re-upload hints with no equivalent in a pure-surface compositor).
- options.cpp: remove the now-empty "OpenGL/glSDL" menu item; force
  videodriver to GFX_DRIVER_SDL2D.
- prefs.cpp: collapse legacy GLSDL setting onto SDL2D on load.

After this commit the macro-collision wall is gone (renamed_-token
errors drop from many to zero). The build still fails on the next
layer of work: SDL 1.2 surface APIs that no longer exist
(SDL_FreeSurface, SDL_SetAlpha, SDL_CreateRGBSurface, SDL_DisplayFormat,
SDL_PixelFormat struct member access, SDL audio callback API, etc.).

🤖 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:37:01 +03:00
parent 9b0662865e
commit 762b095462
No known key found for this signature in database
GPG Key ID: 89AE9EAA3B6FDE7C
22 changed files with 52 additions and 2822 deletions

View File

@ -23,7 +23,7 @@
#ifndef _KOBO_GAMECTL_H_
#define _KOBO_GAMECTL_H_
#include "glSDL.h"
#include "sdl_compat.h"
#include "config.h"
#define KEY_KP_DOWN SDLK_KP2

View File

@ -2,7 +2,6 @@ add_library(graphics STATIC
cs.c
sprite.c
filters.c
glSDL.c
gfxengine.cpp
window.cpp
sofont.cpp

View File

@ -22,7 +22,7 @@
#include <string.h>
#include <math.h>
#include "logger.h"
#include "glSDL.h"
#include "sdl_compat.h"
#include <SDL3_image/SDL_image.h>
#include "sprite.h"
#include "filters.h"

View File

@ -29,7 +29,7 @@
#include "gfxengine.h"
#include "filters.h"
#include <SDL3_image/SDL_image.h>
#include "glSDL.h"
#include "sdl_compat.h"
#include "sofont.h"
#include "window.h"
@ -442,25 +442,12 @@ void gfxengine_t::dither(int type, int _broken_rgba8)
return;
if(_dither)
{
if(_driver == GFX_DRIVER_GLSDL)
{
//Klugde for glSDL, which doesn't give us a faked
//screen surface - while we're interested only in
//the *texture* depth; not the display depth!
df->args.r = df->args.g = df->args.b = 0;
//Another kludge, because some cards support RGB8
//(24 bit) textures, but not RGBA8 (32 bit).
df->args.x = broken_rgba8;
}
else
{
df->args.x = 0;
df->args.r = 1<<(screen_surface->format->Rloss-1);
df->args.g = 1<<(screen_surface->format->Gloss-1);
df->args.b = 1<<(screen_surface->format->Bloss-1);
}
}
else
df->args.x = df->args.r = df->args.g = df->args.b = 0;
df->args.y = type;
@ -775,36 +762,6 @@ int gfxengine_t::show()
return -2;
}
switch(_driver)
{
case GFX_DRIVER_SDL2D:
break;
case GFX_DRIVER_GLSDL:
if(!_doublebuf)
{
log_printf(WLOG, "Only double buffering is supported"
" with OpenGL drivers!\n");
doublebuffer(1);
}
if(_shadow)
{
log_printf(WLOG, "Shadow buffer not supported"
" with OpenGL drivers!\n");
shadow(0);
}
break;
}
switch(_driver)
{
case GFX_DRIVER_SDL2D:
/* Nothing extra */
break;
case GFX_DRIVER_GLSDL:
flags |= SDL_GLSDL;
break;
}
if(_doublebuf)
flags |= SDL_DOUBLEBUF | SDL_HWSURFACE;
else
@ -816,7 +773,6 @@ int gfxengine_t::show()
if(_fullscreen)
flags |= SDL_FULLSCREEN;
glSDL_VSync(_vsync);
flags |= xflags;
screen_surface = SDL_SetVideoMode(_width, _height, _depth, flags);
@ -826,8 +782,6 @@ int gfxengine_t::show()
return -3;
}
if(_driver != GFX_DRIVER_GLSDL)
{
if((screen_surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
{
if(!_doublebuf)
@ -846,7 +800,6 @@ int gfxengine_t::show()
doublebuffer(0);
}
}
}
if((screen_surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
{

View File

@ -29,14 +29,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "glSDL.h"
#include "sdl_compat.h"
#include "sprite.h"
#include "cs.h"
enum gfx_drivers_t
{
GFX_DRIVER_SDL2D = 0,
GFX_DRIVER_GLSDL = 1
GFX_DRIVER_SDL2D = 0
};
enum gfx_scalemodes_t

File diff suppressed because it is too large Load Diff

View File

@ -1,399 +0,0 @@
/*(LGPL)
------------------------------------------------------------
glSDL 0.9 - SDL 2D API on top of OpenGL
------------------------------------------------------------
* Copyright (C) 2001-2004, 2006-2007 David Olofson
* This code is released under the terms of the GNU LGPL.
*/
#ifndef _GLSDL_H_
#define _GLSDL_H_
/*
* If you don't use GNU autotools or similar, uncomment this to
* compile with OpenGL enabled:
#define HAVE_OPENGL
*
* NOTE:
* See README about using this glSDL wrapper with
* SDL versions that have the glSDL backend!
*/
/* We're still using SDL datatypes here - we just add some stuff. */
#include <SDL3/SDL.h>
/*
* Ignore the flag from SDL w/ glSDL backend, since we're going
* to use glSDL/wrapper by default.
*/
#ifdef SDL_GLSDL
#undef SDL_GLSDL
#endif
#ifndef HAVE_OPENGL
/* Fakes to make glSDL code compile with SDL. */
#define SDL_GLSDL 0
#define GLSDL_FIX_SURFACE(s)
#else /* HAVE_OPENGL */
#ifdef __cplusplus
extern "C" {
#endif
#if (SDL_MAJOR_VERSION <= 1) && (SDL_MINOR_VERSION <= 2) && \
(SDL_PATCHLEVEL < 5)
#warning glSDL: Using SDL version 1.2.5 or later is strongly recommended!
#endif
/*----------------------------------------------------------
SDL style API
----------------------------------------------------------*/
typedef enum glSDL_TileModes
{
GLSDL_TM_SINGLE,
GLSDL_TM_HORIZONTAL,
GLSDL_TM_VERTICAL,
GLSDL_TM_HUGE
} glSDL_TileModes;
typedef struct glSDL_TexInfo
{
int textures;
int *texture;
int texsize; /* width/height of OpenGL texture */
glSDL_TileModes tilemode;
int tilew, tileh; /* At least one must equal texsize! */
int tilespertex;
/* Area of surface to download when/after unlocking */
SDL_Rect invalid_area;
} glSDL_TexInfo;
#define GLSDL_FIX_SURFACE(s) (s)->unused1 = 0;
#define IS_GLSDL_SURFACE(s) ((s) && texinfotab && glSDL_GetTexInfo(s))
#ifdef SDL_GLSDL
#undef SDL_GLSDL /* In case SDL has the glSDL backend... */
#endif
#define SDL_GLSDL 0x00100000 /* Create an OpenGL 2D rendering context */
/*
* Wraps SDL_SetVideoMode(), and adds support for the SDL_GLSDL flag.
*
* If 'flags' contains SDL_GLSDL, glSDL_SetVideoMode() sets up a "pure"
* OpenGL rendering context for use with the glSDL_ calls.
*
* SDL can be closed as usual (using SDL_ calls), but you should call
* glSDL_Quit() (kludge) to allow glSDL to clean up it's internal stuff.
*/
SDL_Surface *glSDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
void glSDL_Quit(void);
void glSDL_QuitSubSystem(Uint32 flags);
/* Replaces SDL_Quit() entirely, when using the override defines */
void glSDL_FullQuit(void);
SDL_Surface *glSDL_GetVideoSurface(void);
void glSDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
void glSDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
/*
* Works like SDL_Flip(), but may also perform enqueued blits.
* (That is, it's possible that the implementation renders
* *nothing* until glSDL_Flip() is called.)
*/
int glSDL_Flip(SDL_Surface *screen);
void glSDL_FreeSurface(SDL_Surface *surface);
int glSDL_LockSurface(SDL_Surface *surface);
void glSDL_UnlockSurface(SDL_Surface *surface);
/*
* Like the respective SDL functions, although they ignore
* SDL_RLEACCEL, as it makes no sense in this context.
*/
int glSDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
int glSDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
/*
* Sets up clipping for the screen, or a SDL_Surface.
*
* Note that this function takes both SDL_Surfaces and
* glSDL_Surfaces.
*/
SDL_bool glSDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect);
int glSDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
int glSDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
/*
* Convert the given surface into a SDL_Surface (if it isn't
* one already), and makes sure that the underlying SDL_Surface
* is of a pixel format suitable for fast texture downloading.
*
* Note that you *only* have to use this function if you want
* fast pixel access to surfaces (ie "procedural textures").
* Any surfaces that aren't converted will be downloaded
* automatically upon the first call to glSDL_BlitSurface(),
* but if conversion is required, it will be required for
* every glSDL_UnlockSurface() call.
*
* IMPORTANT:
* You *can* pass an SDL_Surface directly to this function,
* and it will try to deal with it nicely. However, this
* requires that a temporary SDL_Surface is created, and
* this surface is cached only until the texture memory is
* needed for new surfaces.
*/
SDL_Surface *glSDL_DisplayFormat(SDL_Surface *surface);
SDL_Surface *glSDL_DisplayFormatAlpha(SDL_Surface *surface);
SDL_Surface *glSDL_ConvertSurface
(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags);
SDL_Surface *glSDL_CreateRGBSurface
(Uint32 flags, int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
SDL_Surface *glSDL_CreateRGBSurfaceFrom(void *pixels,
int width, int height, int depth, int pitch,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
SDL_Surface *glSDL_LoadBMP(const char *file);
int glSDL_SaveBMP(SDL_Surface *surface, const char *file);
#ifdef __cplusplus
}
#endif
/* Some ugly "overriding"... */
#ifndef _GLSDL_NO_REDEFINES_
/*
* You *always* need to lock and unlock a glSDL surface in
* order to get glSDL to update the OpenGL texture!
*/
#undef SDL_MUSTLOCK
#define SDL_MUSTLOCK(surface) \
(surface->offset || \
((surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0) || \
IS_GLSDL_SURFACE(surface))
#define SDL_SetVideoMode glSDL_SetVideoMode
#define SDL_GetVideoSurface glSDL_GetVideoSurface
#define SDL_Quit glSDL_FullQuit
#define SDL_QuitSubSystem glSDL_QuitSubSystem
#define SDL_UpdateRects glSDL_UpdateRects
#define SDL_UpdateRect glSDL_UpdateRect
#define SDL_Flip glSDL_Flip
#define SDL_FreeSurface glSDL_FreeSurface
#define SDL_LockSurface glSDL_LockSurface
#define SDL_UnlockSurface glSDL_UnlockSurface
#define SDL_SetColorKey glSDL_SetColorKey
#define SDL_SetAlpha glSDL_SetAlpha
#define SDL_SetClipRect glSDL_SetClipRect
#undef SDL_BlitSurface
#define SDL_BlitSurface glSDL_BlitSurface
#define SDL_FillRect glSDL_FillRect
#define SDL_DisplayFormat glSDL_DisplayFormat
#define SDL_DisplayFormatAlpha glSDL_DisplayFormatAlpha
#define SDL_ConvertSurface glSDL_ConvertSurface
#define SDL_CreateRGBSurface glSDL_CreateRGBSurface
#define SDL_CreateRGBSurfaceFrom glSDL_CreateRGBSurfaceFrom
#undef SDL_AllocSurface
#define SDL_AllocSurface glSDL_CreateRGBSurface
#undef SDL_LoadBMP
#define SDL_LoadBMP glSDL_LoadBMP
#undef SDL_SaveBMP
#define SDL_SaveBMP glSDL_SaveBMP
#define IMG_Load(x) glSDL_IMG_Load(x)
#endif
#endif /* HAVE_OPENGL */
#ifdef HAVE_OPENGL
/* Some extra overloading for common external lib calls... */
#include "SDL_image.h"
#ifdef __cplusplus
extern "C" {
#endif
SDL_Surface *glSDL_IMG_Load(const char *file);
#ifdef __cplusplus
}
#endif
#endif /* HAVE_OPENGL */
/*----------------------------------------------------------
glSDL API extensions, transparent
----------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* Invalidate part of a texture.
*
* This function can be used either between calls to
* glSDL_LockSurface() and glSDL_UnlockSurface(), or before
* calling glSDL_DownloadSurface().
*
* In either case, it causes only the specified area to be
* downloaded when unlocking the surface, or calling
* glSDL_UnlockSurface(), respectively.
*
* Note that if this function is not used, glSDL assumes that
* the entire surface has to be updated. (That is, it's safe
* to ignore this function - it's "just a performance hack.")
*
* Passing a rectangle with zero height or width cancels the
* downloading when/after unlocking the surface. Use if you
* just want to read the texture, but feel like being nice and
* obeying SDL_MUSTLOCK() - which is a good idea, as things
* may change...
*
* Passing NULL for the 'area' argument results in the entire
* surface being invalidated.
*
* NOTE: This function does NOT perform clipping! Weird or
* even Bad Things may happen if you specify areas
* that protrude outside the edges of the actual
* surface.
*/
void glSDL_Invalidate(SDL_Surface *surface, SDL_Rect *area);
/*
* Make sure that the texture of the specified surface is up
* to date in OpenGL texture memory.
*
* This can be used together with glSDL_UnloadSurface() to
* implement custom texture caching schemes.
*
* Returns 0 on success, or a negative value if something
* went wrong.
*/
int glSDL_UploadSurface(SDL_Surface *surface);
/*
* Free the texture space used by the specified surface.
*
* Normally, glSDL should download textures when needed, and
* unload the oldest (in terms of use) surfaces, if it runs out
* of texture space.
*/
void glSDL_UnloadSurface(SDL_Surface *surface);
/*----------------------------------------------------------
glSDL API extensions, OpenGL mode ONLY
----------------------------------------------------------*/
/*
* Enable, disable or check the state of "vsync" or
* vertical retrace synchronization. Note that enabling
* this does not *guarantee* that the driver actually
* uses vsync; it only instructs OpenGL to do so if
* possible.
* Pass 1 for 'use' to enable vsync, '0' to disable
* it, and -1 to just return the current state without
* changing it.
* Returns the vsync state *before* any change made
* by the call.
*
* NOTE: Ignored when not using OpenGL acceleration!
*/
int glSDL_VSync(int use);
/*
* Set alpha multiplier. This is multiplied with any full
* surface alpha or alpha channels of surfaces.
*
* The default value is 255, which makes glSDL render like
* the standard SDL 2D backends, ie based only on the
* surface settings.
*
* This function affects the global state of glSDL.
*
* NOTE: NOT available without OpenGL acceleration!
*/
void glSDL_SetBlendAlpha(Uint8 alpha);
/*
* Set color multipliers. These are multiplied with the
* respective color channers of rendered surfaces,
* modulating the brightness of the resulting output.
*
* The default values are 255, which makes glSDL render
* like the standard SDL 2D backends.
*
* This function affects the global state of glSDL.
*
* NOTE: NOT available without OpenGL acceleration!
*/
void glSDL_SetBlendColor(Uint8 r, Uint8 g, Uint8 b);
/*
* Set center offset in pixels for scaling and rotation.
*
* The default is (0, 0), which makes surfaces rotate and
* scale around their centers.
*
* This function affects the global state of glSDL.
*
* NOTE: NOT available without OpenGL acceleration!
*/
void glSDL_SetCenter(float x, float y);
/*
* Set rotation angle in degrees. Rotation is done around
* the center point, which is defined as
* (w/2 + cx, h/2 + cy)
* where w and h are the width and height of the source
* surface, and cx and cy are the center offsets set by
* glSDL_SetCenter().
*
* The default value is 0.0f, which makes glSDL render
* like a normal SDL 2D backend.
*
* This function affects the global state of glSDL.
*
* NOTE: NOT available without OpenGL acceleration!
*/
void glSDL_SetRotation(float angle);
/*
* Set scale factor. Scaling is centered around around
* the point
* (w/2 + cx, h/2 + cy)
* where w and h are the width and height of the source
* surface, and cx and cy are the center offsets set by
* glSDL_SetCenter().
*
* The default value is 1.0f, which makes glSDL render
* like a normal SDL 2D backend.
*
* This function affects the global state of glSDL.
*
* NOTE: NOT available without OpenGL acceleration!
*/
void glSDL_SetScale(float x, float y);
/*
* Reset glSDL global state to defaults.
*/
void glSDL_ResetState(void);
#ifdef __cplusplus
}
#endif
#endif /* _GLSDL_H_ */

View File

@ -22,7 +22,7 @@
#ifndef KOBO_REGION_H
#define KOBO_REGION_H
#include "glSDL.h"
#include "sdl_compat.h"
#ifdef __cplusplus
extern "C" {

16
graphics/sdl_compat.h Normal file
View File

@ -0,0 +1,16 @@
/*
* sdl_compat.h - umbrella SDL 3 include for Kobo Deluxe.
*
* Replaces the legacy graphics/glSDL.h shim that wrapped SDL 1.2 with
* an OpenGL backend. SDL 3's renderer makes that unnecessary.
*
* This header exists so the codebase can use #include "sdl_compat.h"
* rather than scatter <SDL3/SDL.h> across the tree (which would also
* make a later SDL 4 swap painful).
*/
#ifndef _KOBO_SDL_COMPAT_H_
#define _KOBO_SDL_COMPAT_H_
#include <SDL3/SDL.h>
#endif /* _KOBO_SDL_COMPAT_H_ */

View File

@ -34,7 +34,7 @@
* Cursor tests first check if '|' is present.
* Shadowed variables fixed.
* Garbage data in spacing table fixed. (Thanks to
Andreas Spångberg for discovering this one!)
Andreas Sp<EFBFBD>ngberg for discovering this one!)
* Added ExtraSpace(). (Scaling support hack...)
* Disabled colorkeying. (Ruins some RGBA fonts!)
*/
@ -42,7 +42,7 @@
#ifndef __SOFONT_H
#define __SOFONT_H
#include "glSDL.h"
#include "sdl_compat.h"
class SoFont
{

View File

@ -29,7 +29,7 @@ TODO: tables as needed when loading banks.
#include <stdlib.h>
#include <string.h>
#include "logger.h"
#include "glSDL.h"
#include "sdl_compat.h"
#include <SDL3_image/SDL_image.h>
#include "sprite.h"
#include "filters.h"

View File

@ -26,7 +26,7 @@
extern "C" {
#endif
#include "glSDL.h"
#include "sdl_compat.h"
typedef enum
{

View File

@ -186,13 +186,9 @@ void window_t::invalidate(SDL_Rect *r)
rr.w = phys_rect.w;
rr.h = phys_rect.h;
phys_refresh(&rr);
glSDL_Invalidate(surface, &rr);
}
else
{
phys_refresh(r);
glSDL_Invalidate(surface, r);
}
return;
}

View File

@ -213,7 +213,7 @@
#ifndef _WINDOW_H_
#define _WINDOW_H_
#include "glSDL.h"
#include "sdl_compat.h"
class gfxengine_t;

View File

@ -25,7 +25,7 @@
#include "config.h"
#include "logger.h"
#include "glSDL.h"
#include "sdl_compat.h"
#define LOG_BUFFER 1024

View File

@ -24,7 +24,7 @@
#ifndef _KOBO_MANAGE_H_
#define _KOBO_MANAGE_H_
#include "glSDL.h"
#include "sdl_compat.h"
#include "score.h"
class _manage

View File

@ -184,14 +184,7 @@ void video_options_t::build()
item("16 bits", 16);
item("24 bits", 24);
item("32 bits", 32);
#if defined(HAVE_OPENGL) && !defined(GLSDL_OFF)
list("Display Driver", &prf->videodriver, OS_RESTART_VIDEO |
OS_REBUILD);
item("SDL 2D", GFX_DRIVER_SDL2D);
item("OpenGL/glSDL", GFX_DRIVER_GLSDL);
#else
prf->videodriver = GFX_DRIVER_SDL2D;
#endif
space();
xoffs = 0.55;
switch(prf->videodriver)

View File

@ -171,7 +171,8 @@ void prefs_t::postload()
scrollradar = 2;
}
// Some unimplemented enums were removed in 0.4.1
// Only the SDL 2D driver remains since the SDL 3 migration; collapse
// any legacy GLSDL setting onto it.
if(videodriver != GFX_DRIVER_SDL2D)
videodriver = GFX_DRIVER_GLSDL;
videodriver = GFX_DRIVER_SDL2D;
}

View File

@ -24,7 +24,7 @@
#define _KOBO_RANDOM_H_
#include <time.h>
#include "glSDL.h"
#include "sdl_compat.h"
class rand_num_t
{

View File

@ -22,7 +22,7 @@
#ifndef _A_TOOLS_H_
#define _A_TOOLS_H_
#include "glSDL.h"
#include "sdl_compat.h"
#include <string.h>
#include "kobolog.h"
#include "a_types.h"

View File

@ -22,7 +22,7 @@
#ifndef _A_TYPES_H_
#define _A_TYPES_H_
#include "glSDL.h"
#include "sdl_compat.h"
/* Builtin patch drivers */
typedef enum

View File

@ -21,7 +21,7 @@
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "glSDL.h"
#include "sdl_compat.h"
#include <math.h>
#ifndef M_PI
# define M_PI 3.14159265358979323846 /* pi */