From 103a2fccaab26afd14fee88491aae81bd0a79adb Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 27 Jan 2019 02:26:23 +0300 Subject: [PATCH] sdl: vid: rework safegl option --- engine/client/gl_local.h | 15 +++-- engine/platform/sdl/vid_sdl.c | 112 +++++++++++++++++----------------- 2 files changed, 66 insertions(+), 61 deletions(-) diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index 0f89427b..fcc77848 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -609,17 +609,20 @@ typedef struct typedef enum { - SAFE_NO, - SAFE_NOACC, - SAFE_NODEPTH, - SAFE_NOATTRIB, - SAFE_DONTCARE + SAFE_NO = 0, + SAFE_NOMSAA, // skip msaa + SAFE_NOACC, // don't set acceleration flag + SAFE_NOSTENCIL, // don't set stencil bits + 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; typedef struct { void* context; // handle to GL rendering context - safe_context_t safe; + int safe; int desktopBitsPixel; int desktopWidth; diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 50081756..4c62d37b 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -585,14 +585,14 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) 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 - // window creating may fail on GLX visual choose - if( gl_wgl_msaa_samples->value || glw_state.safe >= 0 ) + // skip some attribs in hope that context creating will not fail + if( glw_state.safe >= SAFE_NO ) { - Cvar_Set( "gl_wgl_msaa_samples", "0" ); - glw_state.safe++; + if( !gl_wgl_msaa_samples->value && glw_state.safe + 1 == SAFE_NOMSAA ) + glw_state.safe += 2; // no need to skip msaa, if we already disabled it + else glw_state.safe++; GL_SetupAttributes(); // re-choose attributes // try again @@ -719,11 +719,9 @@ static void GL_SetupAttributes( void ) SDL_GL_ResetAttributes(); - #ifdef XASH_GLES SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_EGL, 1 ); - #ifdef XASH_NANOGL SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_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_MINOR_VERSION, 0 ); #endif - #else // GL1.x #ifndef XASH_GL_STATIC if( Sys_CheckParm( "-gldebug" ) ) @@ -754,77 +751,89 @@ static void GL_SetupAttributes( void ) } #endif // XASH_GLES - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - if( glw_state.safe > SAFE_DONTCARE ) { - glw_state.safe = -1; + glw_state.safe = -1; // can't retry anymore, can only shutdown engine 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 ); - 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 ) SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 ); - else if( glw_state.safe < 5 ) + else SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 ); - - if( glw_state.safe < SAFE_NOATTRIB ) + if( glw_state.safe < SAFE_NOCOLOR ) { 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_GREEN_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_GREEN_SIZE, 6 ); 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 ) - return; - - SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->value ); - - switch( (int)gl_wgl_msaa_samples->value ) + if( glw_state.safe < SAFE_NOMSAA ) { - case 2: - case 4: - case 8: - case 16: - samples = gl_wgl_msaa_samples->value; - break; - default: - samples = 0; // don't use, because invalid parameter is passed - } + switch( (int)gl_wgl_msaa_samples->value ) + { + case 2: + case 4: + case 8: + case 16: + samples = gl_wgl_msaa_samples->value; + break; + default: + samples = 0; // don't use, because invalid parameter is passed + } - if( samples ) - { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); + if( samples ) + { + SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); + 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 { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); - - glConfig.max_multisamples = 0; + Cvar_Set( "gl_wgl_msaa_samples", "0" ); } } @@ -849,14 +858,7 @@ qboolean R_Init_Video( void ) glw_state.desktopHeight = displayMode.h; if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) ) - { - 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; + glw_state.safe = bound( SAFE_NO, Q_atoi( safe ), SAFE_DONTCARE ); GL_SetupAttributes();