From 211d3c521344f7dc3888318c49787806228908df Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 13 Apr 2019 20:34:32 +0300 Subject: [PATCH] sdl: vid: refactor context creation, fix crash on exit on REF_SOFTWARE --- engine/platform/sdl/vid_sdl.c | 62 +++++++++++++++++++---------------- engine/ref_api.h | 3 +- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index c5cd5ac2..da600542 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -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; diff --git a/engine/ref_api.h b/engine/ref_api.h index ae434afe..8bbf2b7f 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -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 );