Skip to content

Commit 515438c

Browse files
committed
Fix SDL gl and video mode setting
1 parent c5e2d4a commit 515438c

File tree

3 files changed

+77
-10
lines changed

3 files changed

+77
-10
lines changed

engine/client/gl_local.h

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ typedef struct
635635
qboolean software; // OpenGL software emulation
636636
qboolean initialized; // OpenGL subsystem started
637637
qboolean extended;
638+
int safe;
638639
} glwstate_t;
639640

640641
extern glconfig_t glConfig;

engine/platform/sdl/gl_sdl.c

100644100755
+72-8
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,13 @@ void GL_UpdateSwapInterval( void )
481481
}
482482
}
483483

484+
#define SAFE_NO 0
485+
#define SAFE_NOACC 1
486+
#define SAFE_NODEPTH 2
487+
#define SAFE_NOATTRIB 3
488+
#define SAFE_DONTCARE 4
489+
490+
484491
/*
485492
==================
486493
GL_SetupAttributes
@@ -495,15 +502,8 @@ void GL_SetupAttributes()
495502
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
496503
#endif
497504

498-
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
499-
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
505+
SDL_GL_ResetAttributes();
500506

501-
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
502-
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
503-
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
504-
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
505-
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
506-
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->integer );
507507

508508
#ifdef XASH_GLES
509509
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES );
@@ -527,6 +527,52 @@ void GL_SetupAttributes()
527527

528528
#endif // XASH_GLES
529529

530+
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
531+
532+
if( glw_state.safe > SAFE_DONTCARE )
533+
{
534+
glw_state.safe = -1;
535+
return;
536+
}
537+
538+
if( glw_state.safe > SAFE_NO )
539+
Msg("Trying safe opengl mode %d\n", glw_state.safe );
540+
541+
if( glw_state.safe >= SAFE_NOACC )
542+
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
543+
544+
Msg ("bpp %d\n", glw_state.desktopBitsPixel );
545+
546+
if( glw_state.safe < SAFE_NODEPTH )
547+
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
548+
else if( glw_state.safe < 5 )
549+
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );
550+
551+
552+
if( glw_state.safe < SAFE_NOATTRIB )
553+
{
554+
if( glw_state.desktopBitsPixel >= 24 )
555+
{
556+
if( glw_state.desktopBitsPixel == 32 )
557+
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
558+
559+
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
560+
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
561+
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
562+
}
563+
else
564+
{
565+
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
566+
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
567+
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
568+
}
569+
}
570+
571+
if( glw_state.safe >= SAFE_DONTCARE )
572+
return;
573+
574+
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->integer );
575+
530576
switch( gl_msaa->integer )
531577
{
532578
case 2:
@@ -904,6 +950,24 @@ R_Init_OpenGL
904950
*/
905951
qboolean R_Init_OpenGL( void )
906952
{
953+
SDL_DisplayMode displayMode;
954+
string safe;
955+
956+
SDL_GetCurrentDisplayMode(0, &displayMode);
957+
glw_state.desktopBitsPixel = SDL_BITSPERPIXEL(displayMode.format);
958+
glw_state.desktopWidth = displayMode.w;
959+
glw_state.desktopHeight = displayMode.h;
960+
961+
if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) )
962+
{
963+
glw_state.safe = Q_atoi( safe );
964+
if( glw_state.safe < SAFE_NOACC || glw_state.safe > SAFE_DONTCARE )
965+
glw_state.safe = SAFE_DONTCARE;
966+
}
967+
968+
if( glw_state.safe < SAFE_NO || glw_state.safe > SAFE_DONTCARE )
969+
return false;
970+
907971
GL_SetupAttributes();
908972

909973
if( SDL_GL_LoadLibrary( EGL_LIB ) )

engine/platform/sdl/vid_sdl.c

100644100755
+4-2
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
226226

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

234235
// try again
@@ -369,6 +370,7 @@ void R_ChangeDisplaySettingsFast( int width, int height )
369370
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
370371
{
371372
SDL_DisplayMode displayMode;
373+
qboolean old_fullscreen = glState.fullScreen;
372374

373375
SDL_GetCurrentDisplayMode(0, &displayMode);
374376
#ifdef XASH_NOMODESWITCH
@@ -404,7 +406,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
404406
if( !VID_SetScreenResolution( width, height ) )
405407
return rserr_invalid_fullscreen;
406408
}
407-
else
409+
else if( old_fullscreen )
408410
{
409411
VID_RestoreScreenResolution();
410412
if( SDL_SetWindowFullscreen(host.hWnd, 0) )

0 commit comments

Comments
 (0)