Don't link to libGL at compile time

Get all OpenGL functions using SDL_GL_GetProcAddress(). This makes it
easier to cross-arch compile on Linux and add support for OpenGL ES
in the future.

Users still have to supply their own libSDL2 for cross-arch compiling
on Linux. But now the user does not have to re-install libgl1-mesa-dev
package for i386 or amd64 on Debian when switching between compiling
ioquake3 for x86 and x86_64.
This commit is contained in:
Zack Middleton 2017-10-01 18:59:01 -05:00
parent 51e9aa2df0
commit 20573bce43
4 changed files with 163 additions and 348 deletions

View file

@ -60,6 +60,11 @@ void (APIENTRYP qglMultiTexCoord2fARB) (GLenum target, GLfloat s, GLfloat t);
void (APIENTRYP qglLockArraysEXT) (GLint first, GLsizei count);
void (APIENTRYP qglUnlockArraysEXT) (void);
#define GLE(ret, name, ...) name##proc * qgl##name;
QGL_1_0_PROCS;
QGL_1_1_PROCS;
#undef GLE
/*
===============
GLimp_Shutdown
@ -210,6 +215,50 @@ static void GLimp_DetectAvailableModes(void)
SDL_free( modes );
}
/*
===============
GLimp_GetProcAddresses
Get addresses for OpenGL functions.
===============
*/
static qboolean GLimp_GetProcAddresses( void ) {
qboolean success = qtrue;
#ifdef __SDL_NOGETPROCADDR__
#define GLE( ret, name, ... ) qgl##name = gl#name;
#else
#define GLE( ret, name, ... ) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name); \
if ( qgl##name == NULL ) { \
ri.Printf( PRINT_ALL, "ERROR: Missing OpenGL function %s\n", "gl" #name ); \
success = qfalse; \
}
#endif
QGL_1_0_PROCS;
QGL_1_1_PROCS;
#undef GLE
return success;
}
/*
===============
GLimp_ClearProcAddresses
Clear addresses for OpenGL functions.
===============
*/
static void GLimp_ClearProcAddresses( void ) {
#define GLE( ret, name, ... ) qgl##name = NULL;
QGL_1_0_PROCS;
QGL_1_1_PROCS;
#undef GLE
}
/*
===============
GLimp_SetMode
@ -309,6 +358,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool
// Destroy existing state if it exists
if( SDL_glContext != NULL )
{
GLimp_ClearProcAddresses();
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
}
@ -503,11 +553,22 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool
ri.Printf(PRINT_ALL, "SDL_GL_CreateContext succeeded.\n");
renderer = (const char *)qglGetString(GL_RENDERER);
if (renderer && (strstr(renderer, "Software Renderer") || strstr(renderer, "Software Rasterizer")))
if ( GLimp_GetProcAddresses() )
{
ri.Printf(PRINT_ALL, "GL_RENDERER is %s, rejecting context\n", renderer);
renderer = (const char *)qglGetString(GL_RENDERER);
}
else
{
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed for OpenGL 3.2 core context\n" );
renderer = NULL;
}
if (!renderer || (strstr(renderer, "Software Renderer") || strstr(renderer, "Software Rasterizer")))
{
if ( renderer )
ri.Printf(PRINT_ALL, "GL_RENDERER is %s, rejecting context\n", renderer);
GLimp_ClearProcAddresses();
SDL_GL_DeleteContext(SDL_glContext);
SDL_glContext = NULL;
@ -522,10 +583,24 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool
SDL_glContext = NULL;
}
if( !SDL_glContext && ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
if ( !SDL_glContext )
{
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
continue;
if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
{
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
continue;
}
if ( !GLimp_GetProcAddresses() )
{
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed\n" );
GLimp_ClearProcAddresses();
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
SDL_DestroyWindow( SDL_window );
SDL_window = NULL;
continue;
}
}
qglClearColor( 0, 0, 0, 1 );