Add SDL 3 support to ref_gl4.

This is mostly a port of the same changes to ref_gl3:

* Add SDL 3 support to the Makefile.
* Port API changes.
* Bump renderer API to version 7.
This commit is contained in:
Yamagi 2024-04-06 11:25:43 +02:00
parent d510529f62
commit a884514f97
5 changed files with 71 additions and 5 deletions

View file

@ -44,6 +44,9 @@ WITH_OPENAL:=yes
# or libopenal.so. Not supported on Windows.
WITH_RPATH:=yes
# Builds with SDL 3 instead of SDL 2.
WITH_SDL3:=no
# Enable systemwide installation of game assets.
WITH_SYSTEMWIDE:=no
@ -262,7 +265,12 @@ endif
# ----------
# Extra CFLAGS for SDL.
ifeq ($(WITH_SDL3),yes)
SDLCFLAGS := $(shell pkgconf --cflags sdl3)
SDLCFLAGS += -DUSE_SDL3
else
SDLCFLAGS := $(shell sdl2-config --cflags)
endif
# ----------
@ -339,11 +347,19 @@ endif
# ----------
# Extra LDFLAGS for SDL
ifeq ($(WITH_SDL3),yes)
ifeq ($(YQ2_OSTYPE), Darwin)
SDLLDFLAGS := -lSDL3
else
SDLLDFLAGS := $(shell pkgconf --libs sdl3)
endif
else
ifeq ($(YQ2_OSTYPE), Darwin)
SDLLDFLAGS := -lSDL2
else # not Darwin
else
SDLLDFLAGS := $(shell sdl2-config --libs)
endif # Darwin
endif
endif
# The renderer libs don't need libSDL2main, libmingw32 or -mwindows.
ifeq ($(YQ2_OSTYPE), Windows)

View file

@ -1981,6 +1981,7 @@ GetRefAPI(refimport_t imp)
ri = imp;
re.api_version = API_VERSION;
re.framework_version = GL4_GetSDLVersion();
re.Init = GL4_Init;
re.Shutdown = GL4_Shutdown;

View file

@ -29,7 +29,11 @@
#include "header/local.h"
#ifdef USE_SDL3
#include <SDL3/SDL.h>
#else
#include <SDL2/SDL.h>
#endif
static SDL_Window* window = NULL;
static SDL_GLContext context = NULL;
@ -162,7 +166,20 @@ void GL4_SetVsync(void)
}
}
#ifdef USE_SDL3
int vsyncState;
if (SDL_GL_GetSwapInterval(&vsyncState) != 0)
{
R_Printf(PRINT_ALL, "Failed to get vsync state, assuming vsync inactive.\n");
vsyncActive = false;
}
else
{
vsyncActive = vsyncState ? true : false;
}
#else
vsyncActive = SDL_GL_GetSwapInterval() != 0;
#endif
}
/*
@ -345,9 +362,9 @@ int GL4_InitContext(void* win)
// Load GL pointrs through GLAD and check context.
#ifdef YQ2_GL3_GLES
if( !gladLoadGLES2Loader(SDL_GL_GetProcAddress))
if( !gladLoadGLES2Loader((void *)SDL_GL_GetProcAddress))
#else // Desktop GL
if( !gladLoadGLLoader(SDL_GL_GetProcAddress))
if( !gladLoadGLLoader((void *)SDL_GL_GetProcAddress))
#endif
{
R_Printf(PRINT_ALL, "GL4_InitContext(): ERROR: loading OpenGL function pointers failed!\n");
@ -406,7 +423,11 @@ int GL4_InitContext(void* win)
#if SDL_VERSION_ATLEAST(2, 26, 0)
// Figure out if we are high dpi aware.
int flags = SDL_GetWindowFlags(win);
#ifdef USE_SDL3
IsHighDPIaware = (flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) ? true : false;
#else
IsHighDPIaware = (flags & SDL_WINDOW_ALLOW_HIGHDPI) ? true : false;
#endif
#endif
return true;
@ -417,7 +438,11 @@ int GL4_InitContext(void* win)
*/
void GL4_GetDrawableSize(int* width, int* height)
{
#ifdef USE_SDL3
SDL_GetWindowSizeInPixels(window, width, height);
#else
SDL_GL_GetDrawableSize(window, width, height);
#endif
}
/*
@ -434,3 +459,21 @@ void GL4_ShutdownContext()
}
}
}
/*
* Returns the SDL major version. Implemented
* here to not polute gl3_main.c with the SDL
* headers.
*/
int GL4_GetSDLVersion()
{
#ifdef USE_SDL3
SDL_Version ver;
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
return ver.major;
}

View file

@ -395,6 +395,7 @@ extern qboolean GL4_IsVsyncActive(void);
extern void GL4_EndFrame(void);
extern void GL4_SetVsync(void);
extern void GL4_ShutdownContext(void);
extern int GL4_GetSDLVersion(void);
// gl4_misc.c
extern void GL4_InitParticleTexture(void);

View file

@ -125,7 +125,7 @@ typedef enum {
} ref_restart_t;
// FIXME: bump API_VERSION?
#define API_VERSION 6
#define API_VERSION 7
#define EXPORT
#define IMPORT
@ -137,6 +137,11 @@ typedef struct
// if api_version is different, the dll cannot be used
int api_version;
// if framework_version is different, the dll cannot be used
// necessary because differend SDL major version cannot be
// mixed.
int framework_version;
// called when the library is loaded
qboolean (EXPORT *Init) (void);