Skip to content

Commit

Permalink
[Incomplete] Initial SDL3 support
Browse files Browse the repository at this point in the history
Add VL, SD, and IN backends for SDL3. We do this instead of using the
combined SDL1/2 backends for SD and IN, as so many functions have been
renamed. This does present some problems, as otherwise they share a lot
of code, so one will likely end up outdated.

Ideally, some of the 'generic' code, particularly in id_sd, can be split
out a bit.

Otherwise, this is still incomplete:
- Some code, particularly in id_sd, is dead.
- Graphics is probably broken on big-endian. (Though even SDL2 seemed
  broken on NetBSD/arm64eb, though that's weird enough I can't guarantee
  it'd work anyway.)
- The pkg-config bits in the makefile are a bit ugly.
- We'll possibly want support for vendored SDL3 at some point, too.
- One day we'll want an SDL3_gpu based VL backend, but the renderer is
  good for now.
- The SDL3 API is changing rapidly, so this needs to keep up

One notable change is that all includes of "SDL.h" need to be replaced
with an include of "ck_cross.h", which has the correct logic to include
"SDL3/SDL.h" where needed. WITH_SDL is now set to 3 for SDL3 builds.
  • Loading branch information
sulix committed Sep 13, 2024
1 parent 40defb8 commit d1af049
Show file tree
Hide file tree
Showing 10 changed files with 1,484 additions and 12 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ elseif(RENDERER STREQUAL "sdl1")
${SDL_INCLUDE_DIR}
)
add_definitions(-DWITH_SDL)
elseif(RENDERER STREQUAL "sdl3")
message(STATUS "Using SDL3 renderer backend")
find_package(SDL3 REQUIRED)
set(OMNISPEAK_PLATFORM_SRCS
src/id_in_sdl3.c
src/id_sd_sdl3.c
src/id_vl_sdl3.c
)
set(OMNISPEAK_PLATFORM_LIBRARIES
${SDL3_LIBRARIES}
)
include_directories(
${SDL3_INCLUDE_DIRS}
)
add_definitions(-DWITH_SDL=3)
else()
message(WARNING "Using NULL platform layer.")
set(OMNISPEAK_PLATFORM_SRCS
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This Makefile supports the following options:
sdl2sw = SDL 2.0 + Software SDL_Renderer
sdl2gl = SDL 2.0 + OpenGL 2.0 (default)
sdl2vk = SDL 2.0 + Vulkan (experimental)
sdl3 = SDL 3.0 + SDL_Renderer
null = dummy renderer

WITH_KEEN4 whether to include support for Keen 4: Secret of the Oracle (0/1; default: on)
Expand Down Expand Up @@ -352,6 +353,12 @@ ifeq ($(RENDERER), sdl2vk)
CXXFLAGS += -I$(OBJDIR) #For generated SPIR-V headers
endif

ifeq ($(RENDERER), sdl3)
RENDER_OBJS = id_vl_sdl3.o id_sd_sdl3.o id_in_sdl3.o
SDL_CFLAGS = `pkg-config sdl3 --cflags` -DWITH_SDL=3
SDL_LIBS = `pkg-config sdl3 $(SDL_LIB_QUERY)`
endif

ifeq ($(RENDERER), dos)
RENDER_OBJS = id_vl_dos.o id_sd_dos.o id_in_dos.o
endif
Expand Down
4 changes: 4 additions & 0 deletions src/ck_cross.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include <stdio.h>

#ifdef WITH_SDL
#if WITH_SDL == 3
#include <SDL3/SDL.h>
#else
#include "SDL.h"
#endif
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define CK_CROSS_IS_BIGENDIAN
#elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
Expand Down
3 changes: 0 additions & 3 deletions src/ck_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdlib.h>
#include <string.h>

#ifdef WITH_SDL
#include <SDL.h> // For main (SDL_main) function prototype
#endif
/*
* The 'episode' we're playing.
*/
Expand Down
14 changes: 11 additions & 3 deletions src/icon.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/id_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#include <stdio.h>
#include <string.h>
#ifdef WITH_SDL
#include "SDL.h"
#endif

#define CA_THREEBYTEHEADERS

Expand Down
Loading

0 comments on commit d1af049

Please sign in to comment.