Port ref_gl3 to SDL 3.

Not many changes here. `make ref_gl3` now builds a library and it works
with the proof of concept port of the client.
This commit is contained in:
Yamagi 2024-03-28 12:01:29 +01:00
parent 9a1990ecc4
commit 61e7ec9697

View file

@ -27,9 +27,14 @@
* =======================================================================
*/
#include "SDL3/SDL_video.h"
#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 +167,20 @@ void GL3_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 +363,9 @@ int GL3_InitContext(void* win)
// Load GL pointers 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, "GL3_InitContext(): ERROR: loading OpenGL function pointers failed!\n");
@ -406,7 +424,11 @@ int GL3_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 +439,11 @@ int GL3_InitContext(void* win)
*/
void GL3_GetDrawableSize(int* width, int* height)
{
#ifdef USE_SDL3
SDL_GetWindowSizeInPixels(window, width, height);
#else
SDL_GL_GetDrawableSize(window, width, height);
#endif
}
/*