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.

a884514f97
https://github.com/yquake2/yquake2/issues/1097
This commit is contained in:
Yamagi 2024-04-06 11:25:43 +02:00 committed by Denis Pauk
parent 4fedab5914
commit 352d87af15
3 changed files with 46 additions and 1 deletions

View file

@ -1954,6 +1954,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;
@ -149,7 +153,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
}
/*
@ -323,7 +340,7 @@ int GL4_InitContext(void* win)
GL4_SetVsync();
// Load GL pointrs through GLAD and check context.
if( !gladLoadGLLoader(SDL_GL_GetProcAddress))
if( !gladLoadGLLoader((void *)SDL_GL_GetProcAddress))
{
R_Printf(PRINT_ALL, "GL4_InitContext(): ERROR: loading OpenGL function pointers failed!\n");
@ -361,7 +378,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;
@ -372,7 +393,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
}
/*
@ -389,3 +414,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

@ -383,6 +383,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);