sdl: vid: refactor context creation, fix crash on exit on REF_SOFTWARE

This commit is contained in:
Alibek Omarov 2019-04-13 20:34:32 +03:00
parent 20c7c36996
commit 211d3c5213
2 changed files with 34 additions and 31 deletions

View File

@ -759,38 +759,11 @@ qboolean R_Init_Video( const int type )
glw_state.desktopWidth = displayMode.w;
glw_state.desktopHeight = displayMode.h;
if( type == REF_SOFTWARE )
{
glw_state.software = true;
if( !(retval = VID_SetMode()) )
{
return retval;
}
return true;
}
if( type != REF_GL )
{
Host_Error( "Can't initialize unknown context type %d!\n", type );
}
if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) )
glw_state.safe = bound( SAFE_NO, Q_atoi( safe ), SAFE_DONTCARE );
#if !defined(_WIN32)
SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" );
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
#endif
// refdll can request some attributes
GL_SetupAttributes( );
if( SDL_GL_LoadLibrary( EGL_LIB ) )
{
Con_Reportf( S_ERROR "Couldn't initialize OpenGL: %s\n", SDL_GetError());
return false;
}
R_InitVideoModes();
// must be initialized before creating window
@ -798,13 +771,44 @@ qboolean R_Init_Video( const int type )
WIN_SetDPIAwareness();
#endif
switch( type )
{
case REF_SOFTWARE:
glw_state.software = true;
break;
case REF_GL:
if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) )
glw_state.safe = bound( SAFE_NO, Q_atoi( safe ), SAFE_DONTCARE );
// refdll can request some attributes
GL_SetupAttributes( );
if( SDL_GL_LoadLibrary( EGL_LIB ) )
{
Con_Reportf( S_ERROR "Couldn't initialize OpenGL: %s\n", SDL_GetError());
return false;
}
break;
default:
Host_Error( "Can't initialize unknown context type %d!\n", type );
break;
}
if( !(retval = VID_SetMode()) )
{
return retval;
}
// refdll also can check extensions
ref.dllFuncs.GL_InitExtensions();
switch( type )
{
case REF_GL:
// refdll also can check extensions
ref.dllFuncs.GL_InitExtensions();
break;
case REF_SOFTWARE:
default:
break;
}
host.renderinfo_changed = false;

View File

@ -443,13 +443,12 @@ typedef struct ref_interface_s
// const char *(*R_GetInitError)( void );
void (*R_Shutdown)( void );
//
// only called for GL contexts
void (*GL_SetupAttributes)( int safegl );
void (*GL_OnContextCreated)( void );
void (*GL_InitExtensions)( void );
void (*GL_ClearExtensions)( void );
void (*R_BeginFrame)( qboolean clearScene );
void (*R_RenderScene)( void );
void (*R_EndFrame)( void );