Browse Source

sdl: vid: rework safegl option

pull/2/head
Alibek Omarov 6 years ago
parent
commit
103a2fccaa
  1. 15
      engine/client/gl_local.h
  2. 112
      engine/platform/sdl/vid_sdl.c

15
engine/client/gl_local.h

@ -609,17 +609,20 @@ typedef struct
typedef enum typedef enum
{ {
SAFE_NO, SAFE_NO = 0,
SAFE_NOACC, SAFE_NOMSAA, // skip msaa
SAFE_NODEPTH, SAFE_NOACC, // don't set acceleration flag
SAFE_NOATTRIB, SAFE_NOSTENCIL, // don't set stencil bits
SAFE_DONTCARE SAFE_NOALPHA, // don't set alpha bits
SAFE_NODEPTH, // don't set depth bits
SAFE_NOCOLOR, // don't set color bits
SAFE_DONTCARE // ignore everything, let SDL/EGL decide
} safe_context_t; } safe_context_t;
typedef struct typedef struct
{ {
void* context; // handle to GL rendering context void* context; // handle to GL rendering context
safe_context_t safe; int safe;
int desktopBitsPixel; int desktopBitsPixel;
int desktopWidth; int desktopWidth;

112
engine/platform/sdl/vid_sdl.c

@ -585,14 +585,14 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
if( !host.hWnd ) if( !host.hWnd )
{ {
Con_Reportf( S_ERROR "VID_CreateWindow: couldn't create '%s': %s\n", wndname, SDL_GetError()); Con_Reportf( S_ERROR "VID_CreateWindow: couldn't create '%s': %s\n", wndname, SDL_GetError());
// remove MSAA, if it present, because // skip some attribs in hope that context creating will not fail
// window creating may fail on GLX visual choose if( glw_state.safe >= SAFE_NO )
if( gl_wgl_msaa_samples->value || glw_state.safe >= 0 )
{ {
Cvar_Set( "gl_wgl_msaa_samples", "0" ); if( !gl_wgl_msaa_samples->value && glw_state.safe + 1 == SAFE_NOMSAA )
glw_state.safe++; glw_state.safe += 2; // no need to skip msaa, if we already disabled it
else glw_state.safe++;
GL_SetupAttributes(); // re-choose attributes GL_SetupAttributes(); // re-choose attributes
// try again // try again
@ -719,11 +719,9 @@ static void GL_SetupAttributes( void )
SDL_GL_ResetAttributes(); SDL_GL_ResetAttributes();
#ifdef XASH_GLES #ifdef XASH_GLES
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_EGL, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_EGL, 1 );
#ifdef XASH_NANOGL #ifdef XASH_NANOGL
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
@ -731,7 +729,6 @@ static void GL_SetupAttributes( void )
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 );
#endif #endif
#else // GL1.x #else // GL1.x
#ifndef XASH_GL_STATIC #ifndef XASH_GL_STATIC
if( Sys_CheckParm( "-gldebug" ) ) if( Sys_CheckParm( "-gldebug" ) )
@ -754,77 +751,89 @@ static void GL_SetupAttributes( void )
} }
#endif // XASH_GLES #endif // XASH_GLES
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if( glw_state.safe > SAFE_DONTCARE ) if( glw_state.safe > SAFE_DONTCARE )
{ {
glw_state.safe = -1; glw_state.safe = -1; // can't retry anymore, can only shutdown engine
return; return;
} }
if( glw_state.safe > SAFE_NO ) Msg( "Trying safe opengl mode %d\n", glw_state.safe );
Msg("Trying safe opengl mode %d\n", glw_state.safe );
if( glw_state.safe >= SAFE_NOACC ) if( glw_state.safe == SAFE_DONTCARE )
return;
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if( glw_state.safe < SAFE_NOACC )
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ); SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
Msg ("bpp %d\n", glw_state.desktopBitsPixel ); Msg( "bpp %d\n", glw_state.desktopBitsPixel );
if( glw_state.safe < SAFE_NOSTENCIL )
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->value );
if( glw_state.safe < SAFE_NOALPHA )
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
if( glw_state.safe < SAFE_NODEPTH ) if( glw_state.safe < SAFE_NODEPTH )
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
else if( glw_state.safe < 5 ) else
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );
if( glw_state.safe < SAFE_NOCOLOR )
if( glw_state.safe < SAFE_NOATTRIB )
{ {
if( glw_state.desktopBitsPixel >= 24 ) if( glw_state.desktopBitsPixel >= 24 )
{ {
if( glw_state.desktopBitsPixel == 32 )
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
} }
else else if( glw_state.desktopBitsPixel >= 16 )
{ {
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
} }
else
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 3 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 3 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 2 );
}
} }
if( glw_state.safe >= SAFE_DONTCARE ) if( glw_state.safe < SAFE_NOMSAA )
return;
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->value );
switch( (int)gl_wgl_msaa_samples->value )
{ {
case 2: switch( (int)gl_wgl_msaa_samples->value )
case 4: {
case 8: case 2:
case 16: case 4:
samples = gl_wgl_msaa_samples->value; case 8:
break; case 16:
default: samples = gl_wgl_msaa_samples->value;
samples = 0; // don't use, because invalid parameter is passed break;
} default:
samples = 0; // don't use, because invalid parameter is passed
}
if( samples ) if( samples )
{ {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
glConfig.max_multisamples = samples;
}
else
{
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 0 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 0 );
glConfig.max_multisamples = samples; glConfig.max_multisamples = 0;
}
} }
else else
{ {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); Cvar_Set( "gl_wgl_msaa_samples", "0" );
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
glConfig.max_multisamples = 0;
} }
} }
@ -849,14 +858,7 @@ qboolean R_Init_Video( void )
glw_state.desktopHeight = displayMode.h; glw_state.desktopHeight = displayMode.h;
if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) ) if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) )
{ glw_state.safe = bound( SAFE_NO, Q_atoi( safe ), SAFE_DONTCARE );
glw_state.safe = Q_atoi( safe );
if( glw_state.safe < SAFE_NOACC || glw_state.safe > SAFE_DONTCARE )
glw_state.safe = SAFE_DONTCARE;
}
if( glw_state.safe < SAFE_NO || glw_state.safe > SAFE_DONTCARE )
return false;
GL_SetupAttributes(); GL_SetupAttributes();

Loading…
Cancel
Save