Conversation
This builds the compat stack against either SDL major version from one source tree, selected by the SDL_BACKEND make variable. When unset, the build auto-detects: it prefers SDL3 when both sdl3 and sdl3-ttf are visible to pkg-config, and falls back to SDL2; an explicit SDL_BACKEND= sdl2|sdl3 always wins. SDL2 remains the wrapper-shim path (dlopen the host SDL2); SDL3 links libSDL3 / libSDL3_ttf directly. Translation lives in two new chokepoint headers, src/sdl-compat.h and src/sdl-ttf-compat.h, that every source includes instead of <SDL2/SDL.h>. The SDL2 branch is a pass-through; the SDL3 branch enables SDL_ENABLE_OLD_NAMES (so SDL3's old-names layer carries the pure renames) and wraps only the symbols whose signature or semantics changed: the render float migration, surface mask->enum creation, the MapRGB/GetRGB palette argument, SDL_RenderReadPixels returning a surface, SDL_CreateWindow losing x/y, SDL_SetTextInputArea, mouse-coordinate floats, ns->ms event timestamps, the SDL_ttf 3.x renames, and the SDL2 int (0/-1) return convention the call sites test. Wrappers are defined before the #define that renames the call sites so their bodies bind the real SDL3 symbol. mk/sdl.mk gains the SDL_BACKEND switch + auto-detect and a content-hashed SDL_BACKEND_STAMP that every object depends on, so switching backends forces a rebuild without manual object deletion. The SDL2 dlopen wrapper is gated off under SDL3 (mk/sdl-wrapper.mk), and the two wrappers' shared dlopen/dlsym/atomic-cache machinery is consolidated into src/wrapper/dlwrap.h. Per-site SDL3 fixes: font.c pins the glyph texture to nearest scaling (SDL3 defaults to linear, which smeared opaque strokes); pixmap.c populates the render-target pixmap via a staging-texture render (SDL_UpdateTexture into a target did not survive readback on SDL3's software renderer); events.c restructures the flattened window events, key fields, and timestamps, and reconciles the per-display event-queue accounting at the client SDL_FlushEvent/PeepEvents/WaitEvent boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This builds the compat stack against either SDL major version from one source tree, selected by the SDL_BACKEND make variable. When unset, the build auto-detects: it prefers SDL3 when both sdl3 and sdl3-ttf are visible to pkg-config, and falls back to SDL2; an explicit SDL_BACKEND= sdl2|sdl3 always wins. SDL2 remains the wrapper-shim path (dlopen the host SDL2); SDL3 links libSDL3 / libSDL3_ttf directly.
Translation lives in two new chokepoint headers, src/sdl-compat.h and src/sdl-ttf-compat.h, that every source includes instead of <SDL2/SDL.h>. The SDL2 branch is a pass-through; the SDL3 branch enables SDL_ENABLE_OLD_NAMES (so SDL3's old-names layer carries the pure renames) and wraps only the symbols whose signature or semantics changed: the render float migration, surface mask->enum creation, the MapRGB/GetRGB palette argument, SDL_RenderReadPixels returning a surface, SDL_CreateWindow losing x/y, SDL_SetTextInputArea, mouse-coordinate floats, ns->ms event timestamps, the SDL_ttf 3.x renames, and the SDL2 int (0/-1) return convention the call sites test. Wrappers are defined before the #define that renames the call sites so their bodies bind the real SDL3 symbol.
mk/sdl.mk gains the SDL_BACKEND switch + auto-detect and a content-hashed SDL_BACKEND_STAMP that every object depends on, so switching backends forces a rebuild without manual object deletion. The SDL2 dlopen wrapper is gated off under SDL3 (mk/sdl-wrapper.mk), and the two wrappers' shared dlopen/dlsym/atomic-cache machinery is consolidated into src/wrapper/dlwrap.h.
Per-site SDL3 fixes: font.c pins the glyph texture to nearest scaling (SDL3 defaults to linear, which smeared opaque strokes); pixmap.c populates the render-target pixmap via a staging-texture render (SDL_UpdateTexture into a target did not survive readback on SDL3's software renderer); events.c restructures the flattened window events, key fields, and timestamps, and reconciles the per-display event-queue accounting at the client SDL_FlushEvent/PeepEvents/WaitEvent boundary.
Summary by cubic
Add optional
SDL3backend alongsideSDL2, selectable viaSDL_BACKEND, with auto-detect that preferssdl3when available. Compat headers keep source changes small; CI adds ansdl3job to exercise the new path.New Features
SDL2orSDL3viaSDL_BACKEND=sdl2|sdl3; auto-detect preferssdl3/sdl3-ttf, unknown values fail fast.src/sdl-compat.handsrc/sdl-ttf-compat.hunify APIs (SDL_ENABLE_OLD_NAMES+ small wrappers for changed calls/returns); all sources and examples include them.SDL_BACKEND_STAMPforces rebuilds on backend switch;sdl2uses dlopen shims,sdl3linkslibSDL3/libSDL3_ttf; shared dlopen/dlsym logic moved tosrc/wrapper/dlwrap.h.sdl3job builds and tests theSDL3path from source, caches the prefix, and runs headless; other jobs stay onsdl2.strcpyin the text-event shim with boundedsnprintf.Migration
SDL3: installsdl3andsdl3-ttf, then build withSDL_BACKEND=sdl3.SDL2: build withSDL_BACKEND=sdl2; auto-detect pickssdl3when bothsdl3andsdl3-ttfare available.sdl2uses wrapper shims;sdl3linkslibSDL3/libSDL3_ttfdirectly.Written for commit 9046ba1. Summary will update on new commits.