Browse Source

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

pull/2/head
Alibek Omarov 6 years ago
parent
commit
211d3c5213
  1. 62
      engine/platform/sdl/vid_sdl.c
  2. 3
      engine/ref_api.h

62
engine/platform/sdl/vid_sdl.c

@ -759,38 +759,11 @@ qboolean R_Init_Video( const int type )
glw_state.desktopWidth = displayMode.w; glw_state.desktopWidth = displayMode.w;
glw_state.desktopHeight = displayMode.h; 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) #if !defined(_WIN32)
SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" ); SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" );
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" ); SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
#endif #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(); R_InitVideoModes();
// must be initialized before creating window // must be initialized before creating window
@ -798,13 +771,44 @@ qboolean R_Init_Video( const int type )
WIN_SetDPIAwareness(); WIN_SetDPIAwareness();
#endif #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()) ) if( !(retval = VID_SetMode()) )
{ {
return retval; return retval;
} }
// refdll also can check extensions switch( type )
ref.dllFuncs.GL_InitExtensions(); {
case REF_GL:
// refdll also can check extensions
ref.dllFuncs.GL_InitExtensions();
break;
case REF_SOFTWARE:
default:
break;
}
host.renderinfo_changed = false; host.renderinfo_changed = false;

3
engine/ref_api.h

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

Loading…
Cancel
Save