Skip to content

Commit

Permalink
Fix SDL gl and video mode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn committed Apr 15, 2018
1 parent c5e2d4a commit 515438c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
1 change: 1 addition & 0 deletions engine/client/gl_local.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ typedef struct
qboolean software; // OpenGL software emulation
qboolean initialized; // OpenGL subsystem started
qboolean extended;
int safe;
} glwstate_t;

extern glconfig_t glConfig;

This comment has been minimized.

Copy link
@ilyastray777
Expand Down
80 changes: 72 additions & 8 deletions engine/platform/sdl/gl_sdl.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ void GL_UpdateSwapInterval( void )
}
}

#define SAFE_NO 0
#define SAFE_NOACC 1
#define SAFE_NODEPTH 2
#define SAFE_NOATTRIB 3
#define SAFE_DONTCARE 4


/*
==================
GL_SetupAttributes
Expand All @@ -495,15 +502,8 @@ void GL_SetupAttributes()
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
#endif

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
SDL_GL_ResetAttributes();

SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->integer );

#ifdef XASH_GLES
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES );
Expand All @@ -527,6 +527,52 @@ void GL_SetupAttributes()

#endif // XASH_GLES

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

if( glw_state.safe > SAFE_DONTCARE )
{
glw_state.safe = -1;
return;
}

if( glw_state.safe > SAFE_NO )
Msg("Trying safe opengl mode %d\n", glw_state.safe );

if( glw_state.safe >= SAFE_NOACC )
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );

Msg ("bpp %d\n", glw_state.desktopBitsPixel );

if( glw_state.safe < SAFE_NODEPTH )
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
else if( glw_state.safe < 5 )
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );


if( glw_state.safe < SAFE_NOATTRIB )
{
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
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
}
}

if( glw_state.safe >= SAFE_DONTCARE )
return;

SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->integer );

switch( gl_msaa->integer )
{
case 2:
Expand Down Expand Up @@ -904,6 +950,24 @@ R_Init_OpenGL
*/
qboolean R_Init_OpenGL( void )
{
SDL_DisplayMode displayMode;
string safe;

SDL_GetCurrentDisplayMode(0, &displayMode);
glw_state.desktopBitsPixel = SDL_BITSPERPIXEL(displayMode.format);
glw_state.desktopWidth = displayMode.w;
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;

GL_SetupAttributes();

if( SDL_GL_LoadLibrary( EGL_LIB ) )
Expand Down
6 changes: 4 additions & 2 deletions engine/platform/sdl/vid_sdl.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )

// remove MSAA, if it present, because
// window creating may fail on GLX visual choose
if( gl_msaa->integer )
if( gl_msaa->integer || glw_state.safe >= 0 )
{
Cvar_Set("gl_msaa", "0");
glw_state.safe++;
GL_SetupAttributes(); // re-choose attributes

// try again
Expand Down Expand Up @@ -369,6 +370,7 @@ void R_ChangeDisplaySettingsFast( int width, int height )
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
{
SDL_DisplayMode displayMode;
qboolean old_fullscreen = glState.fullScreen;

SDL_GetCurrentDisplayMode(0, &displayMode);
#ifdef XASH_NOMODESWITCH
Expand Down Expand Up @@ -404,7 +406,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
if( !VID_SetScreenResolution( width, height ) )
return rserr_invalid_fullscreen;
}
else
else if( old_fullscreen )
{
VID_RestoreScreenResolution();
if( SDL_SetWindowFullscreen(host.hWnd, 0) )
Expand Down

0 comments on commit 515438c

Please sign in to comment.