OpenGL2: Use an OpenGL 3.2 core context if available.
This commit is contained in:
parent
51ca4d35ea
commit
d549b642bc
20 changed files with 313 additions and 349 deletions
|
@ -215,7 +215,7 @@ static void GLimp_DetectAvailableModes(void)
|
|||
GLimp_SetMode
|
||||
===============
|
||||
*/
|
||||
static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
||||
static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean coreContext)
|
||||
{
|
||||
const char *glstring;
|
||||
int perChannelColorBits;
|
||||
|
@ -477,7 +477,37 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
|||
|
||||
SDL_SetWindowIcon( SDL_window, icon );
|
||||
|
||||
if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
|
||||
if (coreContext)
|
||||
{
|
||||
int profileMask, majorVersion, minorVersion;
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorVersion);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorVersion);
|
||||
|
||||
ri.Printf(PRINT_ALL, "Trying to get an OpenGL 3.2 core context\n");
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
if ((SDL_glContext = SDL_GL_CreateContext(SDL_window)) == NULL)
|
||||
{
|
||||
ri.Printf(PRINT_ALL, "SDL_GL_CreateContext failed: %s\n", SDL_GetError());
|
||||
ri.Printf(PRINT_ALL, "Reverting to default context\n");
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profileMask);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
ri.Printf(PRINT_ALL, "SDL_GL_CreateContext succeeded, but: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_glContext = NULL;
|
||||
}
|
||||
|
||||
if( !SDL_glContext && ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
|
||||
continue;
|
||||
|
@ -522,7 +552,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
|||
GLimp_StartDriverAndSetMode
|
||||
===============
|
||||
*/
|
||||
static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qboolean noborder)
|
||||
static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean gl3Core)
|
||||
{
|
||||
rserr_t err;
|
||||
|
||||
|
@ -549,7 +579,7 @@ static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qbool
|
|||
fullscreen = qfalse;
|
||||
}
|
||||
|
||||
err = GLimp_SetMode(mode, fullscreen, noborder);
|
||||
err = GLimp_SetMode(mode, fullscreen, noborder, gl3Core);
|
||||
|
||||
switch ( err )
|
||||
{
|
||||
|
@ -744,7 +774,7 @@ This routine is responsible for initializing the OS specific portions
|
|||
of OpenGL
|
||||
===============
|
||||
*/
|
||||
void GLimp_Init( void )
|
||||
void GLimp_Init( qboolean coreContext)
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "Glimp_Init( )\n" );
|
||||
|
||||
|
@ -764,13 +794,13 @@ void GLimp_Init( void )
|
|||
ri.Sys_GLimpInit( );
|
||||
|
||||
// Create the window and set up the context
|
||||
if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, r_noborder->integer))
|
||||
if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, r_noborder->integer, coreContext))
|
||||
goto success;
|
||||
|
||||
// Try again, this time in a platform specific "safe mode"
|
||||
ri.Sys_GLimpSafeInit( );
|
||||
|
||||
if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, qfalse))
|
||||
if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, qfalse, coreContext))
|
||||
goto success;
|
||||
|
||||
// Finally, try the default screen resolution
|
||||
|
@ -779,7 +809,7 @@ void GLimp_Init( void )
|
|||
ri.Printf( PRINT_ALL, "Setting r_mode %d failed, falling back on r_mode %d\n",
|
||||
r_mode->integer, R_MODE_FALLBACK );
|
||||
|
||||
if(GLimp_StartDriverAndSetMode(R_MODE_FALLBACK, qfalse, qfalse))
|
||||
if(GLimp_StartDriverAndSetMode(R_MODE_FALLBACK, qfalse, qfalse, coreContext))
|
||||
goto success;
|
||||
}
|
||||
|
||||
|
@ -801,7 +831,10 @@ success:
|
|||
if (*glConfig.renderer_string && glConfig.renderer_string[strlen(glConfig.renderer_string) - 1] == '\n')
|
||||
glConfig.renderer_string[strlen(glConfig.renderer_string) - 1] = 0;
|
||||
Q_strncpyz( glConfig.version_string, (char *) qglGetString (GL_VERSION), sizeof( glConfig.version_string ) );
|
||||
Q_strncpyz( glConfig.extensions_string, (char *) qglGetString (GL_EXTENSIONS), sizeof( glConfig.extensions_string ) );
|
||||
if (qglGetString(GL_EXTENSIONS))
|
||||
Q_strncpyz( glConfig.extensions_string, (char *) qglGetString (GL_EXTENSIONS), sizeof( glConfig.extensions_string ) );
|
||||
else
|
||||
Q_strncpyz( glConfig.extensions_string, "Not available (core context, fixme)", sizeof( glConfig.extensions_string ) );
|
||||
|
||||
// initialize extensions
|
||||
GLimp_InitExtensions( );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue