@ -31,8 +31,10 @@ struct
@@ -31,8 +31,10 @@ struct
struct
{
# if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Renderer * renderer ;
SDL_Texture * tex ;
# endif
int width , height ;
SDL_Surface * surf ;
SDL_Surface * win ;
@ -43,6 +45,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
@@ -43,6 +45,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
sw . width = width ;
sw . height = height ;
# if SDL_VERSION_ATLEAST(2, 0, 0)
if ( sw . renderer )
{
unsigned int format = SDL_GetWindowPixelFormat ( host . hWnd ) ;
@ -54,7 +57,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
@@ -54,7 +57,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
// guess
if ( format = = SDL_PIXELFORMAT_UNKNOWN )
{
if ( glw_s tate. desktopBitsPixel = = 16 )
if ( refS tate. desktopBitsPixel = = 16 )
format = SDL_PIXELFORMAT_RGB565 ;
else
format = SDL_PIXELFORMAT_RGBA8888 ;
@ -110,10 +113,16 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
@@ -110,10 +113,16 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
sw . renderer = NULL ;
}
}
# endif
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( ! sw . renderer )
{
sw . win = SDL_GetWindowSurface ( host . hWnd ) ;
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
{
sw . win = SDL_GetVideoSurface ( ) ;
# endif
// sdl will create renderer if hw framebuffer unavailiable, so cannot fallback here
// if it is failed, it is not possible to draw with SDL in REF_SOFTWARE mode
@ -145,6 +154,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
@@ -145,6 +154,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
void * SW_LockBuffer ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( sw . renderer )
{
void * pixels ;
@ -154,35 +164,38 @@ void *SW_LockBuffer( void )
@@ -154,35 +164,38 @@ void *SW_LockBuffer( void )
Sys_Error ( " %s " , SDL_GetError ( ) ) ;
return pixels ;
}
else
{
// ensure it not changed (do we really need this?)
sw . win = SDL_GetWindowSurface ( host . hWnd ) ;
//if( !sw.win )
//SDL_GetWindowSurface( host.hWnd );
// ensure it not changed (do we really need this?)
sw . win = SDL_GetWindowSurface ( host . hWnd ) ;
//if( !sw.win )
//SDL_GetWindowSurface( host.hWnd );
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
sw . win = SDL_GetVideoSurface ( ) ;
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
// prevent buffer overrun
if ( ! sw . win | | sw . win - > w < sw . width | | sw . win - > h < sw . height )
return NULL ;
// prevent buffer overrun
if ( ! sw . win | | sw . win - > w < sw . width | | sw . win - > h < sw . height )
return NULL ;
if ( sw . surf )
{
SDL_LockSurface ( sw . surf ) ;
return sw . surf - > pixels ;
}
else
{
// real window pixels (x11 shm region, dma buffer, etc)
// or SDL_Renderer texture if not supported
SDL_LockSurface ( sw . win ) ;
return sw . win - > pixels ;
}
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( sw . surf )
{
SDL_LockSurface ( sw . surf ) ;
return sw . surf - > pixels ;
}
else
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
{
// real window pixels (x11 shm region, dma buffer, etc)
// or SDL_Renderer texture if not supported
SDL_LockSurface ( sw . win ) ;
return sw . win - > pixels ;
}
}
void SW_UnlockBuffer ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( sw . renderer )
{
SDL_Rect src , dst ;
@ -197,26 +210,33 @@ void SW_UnlockBuffer( void )
@@ -197,26 +210,33 @@ void SW_UnlockBuffer( void )
SDL_RenderCopy ( sw . renderer , sw . tex , & src , & dst ) ;
SDL_RenderPresent ( sw . renderer ) ;
return ;
//Con_Printf("%s\n", SDL_GetError());
}
else
{
// blit if blitting surface availiable
if ( sw . surf )
{
SDL_Rect src , dst ;
src . x = src . y = 0 ;
src . w = sw . width ;
src . h = sw . height ;
dst = src ;
SDL_UnlockSurface ( sw . surf ) ;
SDL_BlitSurface ( sw . surf , & src , sw . win , & dst ) ;
}
else // already blitted
SDL_UnlockSurface ( sw . win ) ;
SDL_UpdateWindowSurface ( host . hWnd ) ;
// blit if blitting surface availiable
if ( sw . surf )
{
SDL_Rect src , dst ;
src . x = src . y = 0 ;
src . w = sw . width ;
src . h = sw . height ;
dst = src ;
SDL_UnlockSurface ( sw . surf ) ;
SDL_BlitSurface ( sw . surf , & src , sw . win , & dst ) ;
return ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
// already blitted
SDL_UnlockSurface ( sw . win ) ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_UpdateWindowSurface ( host . hWnd ) ;
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Flip ( host . hWnd ) ;
# endif
}
int R_MaxVideoModes ( void )
@ -236,6 +256,7 @@ vidmode_t *R_GetVideoMode( int num )
@@ -236,6 +256,7 @@ vidmode_t *R_GetVideoMode( int num )
static void R_InitVideoModes ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
int displayIndex = 0 ; // TODO: handle multiple displays somehow
int i , modes ;
@ -250,7 +271,6 @@ static void R_InitVideoModes( void )
@@ -250,7 +271,6 @@ static void R_InitVideoModes( void )
for ( i = 0 ; i < modes ; i + + )
{
int j ;
qboolean skip = false ;
SDL_DisplayMode mode ;
if ( SDL_GetDisplayMode ( displayIndex , i , & mode ) )
@ -267,7 +287,6 @@ static void R_InitVideoModes( void )
@@ -267,7 +287,6 @@ static void R_InitVideoModes( void )
if ( mode . w = = vidmodes [ j ] . width & &
mode . h = = vidmodes [ j ] . height )
{
skip = true ;
break ;
}
}
@ -280,6 +299,43 @@ static void R_InitVideoModes( void )
@@ -280,6 +299,43 @@ static void R_InitVideoModes( void )
num_vidmodes + + ;
}
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Rect * * modes ;
int len = 0 , i = 0 , j ;
modes = SDL_ListModes ( NULL , SDL_FULLSCREEN ) ;
if ( ! modes | | modes = = ( void * ) - 1 )
return ;
for ( len = 0 ; modes [ len ] ; len + + ) ;
vidmodes = Mem_Malloc ( host . mempool , len * sizeof ( vidmode_t ) ) ;
// from smallest to largest
for ( ; i < len ; i + + )
{
SDL_Rect * mode = modes [ len - i - 1 ] ;
for ( j = 0 ; j < num_vidmodes ; j + + )
{
if ( mode - > w = = vidmodes [ j ] . width & &
mode - > h = = vidmodes [ j ] . height )
{
break ;
}
}
if ( j ! = num_vidmodes )
continue ;
vidmodes [ num_vidmodes ] . width = mode - > w ;
vidmodes [ num_vidmodes ] . height = mode - > h ;
vidmodes [ num_vidmodes ] . desc = copystring ( va ( " %ix%i " , mode - > w , mode - > h ) ) ;
num_vidmodes + + ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
static void R_FreeVideoModes ( void )
@ -364,9 +420,9 @@ GL_GetProcAddress
@@ -364,9 +420,9 @@ GL_GetProcAddress
void * GL_GetProcAddress ( const char * name )
{
# if defined( XASH_NANOGL )
void * func = nanoGL_GetProcAddress ( name ) ;
void * func = nanoGL_GetProcAddress ( name ) ;
# else
void * func = SDL_GL_GetProcAddress ( name ) ;
void * func = SDL_GL_GetProcAddress ( name ) ;
# endif
if ( ! func )
@ -384,6 +440,7 @@ GL_UpdateSwapInterval
@@ -384,6 +440,7 @@ GL_UpdateSwapInterval
*/
void GL_UpdateSwapInterval ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
// disable VSync while level is loading
if ( cls . state < ca_active )
{
@ -397,6 +454,7 @@ void GL_UpdateSwapInterval( void )
@@ -397,6 +454,7 @@ void GL_UpdateSwapInterval( void )
if ( SDL_GL_SetSwapInterval ( gl_vsync - > value ) )
Con_Reportf ( S_ERROR " SDL_GL_SetSwapInterval: %s \n " , SDL_GetError ( ) ) ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
/*
@ -408,12 +466,13 @@ always return false
@@ -408,12 +466,13 @@ always return false
*/
qboolean GL_DeleteContext ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( glw_state . context )
{
SDL_GL_DeleteContext ( glw_state . context ) ;
glw_state . context = NULL ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return false ;
}
@ -424,12 +483,13 @@ GL_CreateContext
@@ -424,12 +483,13 @@ GL_CreateContext
*/
qboolean GL_CreateContext ( void )
{
# if SDL_VERSION_ATLEAST(2, 0, 0)
if ( ( glw_state . context = SDL_GL_CreateContext ( host . hWnd ) ) = = NULL )
{
Con_Reportf ( S_ERROR " GL_CreateContext: %s \n " , SDL_GetError ( ) ) ;
return GL_DeleteContext ( ) ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return true ;
}
@ -440,12 +500,13 @@ GL_UpdateContext
@@ -440,12 +500,13 @@ GL_UpdateContext
*/
qboolean GL_UpdateContext ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( SDL_GL_MakeCurrent ( host . hWnd , glw_state . context ) )
{
Con_Reportf ( S_ERROR " GL_UpdateContext: %s \n " , SDL_GetError ( ) ) ;
return GL_DeleteContext ( ) ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return true ;
}
@ -454,10 +515,12 @@ void VID_SaveWindowSize( int width, int height )
@@ -454,10 +515,12 @@ void VID_SaveWindowSize( int width, int height )
int render_w = width , render_h = height ;
uint rotate = vid_rotate - > value ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( ! glw_state . software )
SDL_GL_GetDrawableSize ( host . hWnd , & render_w , & render_h ) ;
else
SDL_RenderSetLogicalSize ( sw . renderer , width , height ) ;
# endif
if ( ref . dllFuncs . R_SetDisplayTransform ( rotate , 0 , 0 , vid_scale - > value , vid_scale - > value ) )
{
@ -482,6 +545,7 @@ void VID_SaveWindowSize( int width, int height )
@@ -482,6 +545,7 @@ void VID_SaveWindowSize( int width, int height )
static qboolean VID_SetScreenResolution ( int width , int height )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode want , got ;
Uint32 wndFlags = 0 ;
static string wndname ;
@ -511,12 +575,15 @@ static qboolean VID_SetScreenResolution( int width, int height )
@@ -511,12 +575,15 @@ static qboolean VID_SetScreenResolution( int width, int height )
SDL_SetWindowSize ( host . hWnd , got . w , got . h ) ;
VID_SaveWindowSize ( got . w , got . h ) ;
# else
VID_SaveWindowSize ( width , height ) ;
# endif
return true ;
}
void VID_RestoreScreenResolution ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( ! Cvar_VariableInteger ( " fullscreen " ) )
{
SDL_SetWindowBordered ( host . hWnd , SDL_TRUE ) ;
@ -527,6 +594,7 @@ void VID_RestoreScreenResolution( void )
@@ -527,6 +594,7 @@ void VID_RestoreScreenResolution( void )
SDL_MinimizeWindow ( host . hWnd ) ;
SDL_SetWindowFullscreen ( host . hWnd , 0 ) ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
# if defined(_WIN32) && !defined(XASH_64BIT) // ICO support only for Win32
@ -553,6 +621,7 @@ VID_CreateWindow
@@ -553,6 +621,7 @@ VID_CreateWindow
qboolean VID_CreateWindow ( int width , int height , qboolean fullscreen )
{
static string wndname ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
Uint32 wndFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_MOUSE_FOCUS ;
rgbdata_t * icon = NULL ;
qboolean iconLoaded = false ;
@ -704,6 +773,52 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
@@ -704,6 +773,52 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
}
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
Uint32 flags = 0 ;
if ( fullscreen )
{
flags | = SDL_FULLSCREEN | SDL_HWSURFACE ;
}
if ( glw_state . software )
{
// flags |= SDL_ASYNCBLIT;
}
else
{
flags | = SDL_OPENGL ;
}
while ( glw_state . safe > = SAFE_NO & & glw_state . safe < SAFE_LAST )
{
host . hWnd = sw . surf = SDL_SetVideoMode ( width , height , 16 , flags ) ;
// we have window, exit loop
if ( host . hWnd )
break ;
Con_Reportf ( S_ERROR " VID_CreateWindow: couldn't create '%s' with safegl level %d: %s \n " , wndname , glw_state . safe , SDL_GetError ( ) ) ;
glw_state . safe + + ;
if ( ! gl_wgl_msaa_samples - > value & & glw_state . safe = = SAFE_NOMSAA )
glw_state . safe + + ; // no need to skip msaa, if we already disabled it
GL_SetupAttributes ( ) ; // re-choose attributes
// try again create window
}
// window creation has failed...
if ( glw_state . safe > = SAFE_LAST )
{
return false ;
}
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
VID_SaveWindowSize ( width , height ) ;
return true ;
@ -721,7 +836,9 @@ void VID_DestroyWindow( void )
@@ -721,7 +836,9 @@ void VID_DestroyWindow( void )
VID_RestoreScreenResolution ( ) ;
if ( host . hWnd )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DestroyWindow ( host . hWnd ) ;
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
host . hWnd = NULL ;
}
@ -738,14 +855,20 @@ GL_SetupAttributes
@@ -738,14 +855,20 @@ GL_SetupAttributes
*/
static void GL_SetupAttributes ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_GL_ResetAttributes ( ) ;
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
ref . dllFuncs . GL_SetupAttributes ( glw_state . safe ) ;
}
void GL_SwapBuffers ( void )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_GL_SwapWindow ( host . hWnd ) ;
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Flip ( host . hWnd ) ;
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
int GL_SetAttribute ( int attr , int val )
@ -763,12 +886,20 @@ int GL_SetAttribute( int attr, int val )
@@ -763,12 +886,20 @@ int GL_SetAttribute( int attr, int val )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_MULTISAMPLEBUFFERS ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_MULTISAMPLESAMPLES ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_ACCELERATED_VISUAL ) ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_MAJOR_VERSION ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_MINOR_VERSION ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_EGL ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_FLAGS ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_SHARE_WITH_CURRENT_CONTEXT ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_FRAMEBUFFER_SRGB_CAPABLE ) ;
case REF_GL_CONTEXT_PROFILE_MASK :
# ifdef SDL_HINT_OPENGL_ES_DRIVER
if ( val = = REF_GL_CONTEXT_PROFILE_ES )
SDL_SetHint ( SDL_HINT_OPENGL_ES_DRIVER , " 1 " ) ;
# endif // SDL_HINT_OPENGL_ES_DRIVER
return SDL_GL_SetAttribute ( SDL_GL_CONTEXT_PROFILE_MASK , val ) ;
# endif
# if SDL_VERSION_ATLEAST( 2, 0, 4 )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_RELEASE_BEHAVIOR ) ;
# endif
@ -776,16 +907,9 @@ int GL_SetAttribute( int attr, int val )
@@ -776,16 +907,9 @@ int GL_SetAttribute( int attr, int val )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_RESET_NOTIFICATION ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_NO_ERROR ) ;
# endif
case REF_GL_CONTEXT_PROFILE_MASK :
# ifdef SDL_HINT_OPENGL_ES_DRIVER
if ( val = = REF_GL_CONTEXT_PROFILE_ES )
SDL_SetHint ( SDL_HINT_OPENGL_ES_DRIVER , " 1 " ) ;
# endif // SDL_HINT_OPENGL_ES_DRIVER
return SDL_GL_SetAttribute ( SDL_GL_CONTEXT_PROFILE_MASK , val ) ;
# undef MAP_REF_API_ATTRIBUTE_TO_SDL
}
ASSERT ( 0 ) ;
return - 1 ;
}
@ -804,12 +928,15 @@ int GL_GetAttribute( int attr, int *val )
@@ -804,12 +928,15 @@ int GL_GetAttribute( int attr, int *val )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_MULTISAMPLEBUFFERS ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_MULTISAMPLESAMPLES ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_ACCELERATED_VISUAL ) ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_MAJOR_VERSION ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_MINOR_VERSION ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_EGL ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_FLAGS ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_SHARE_WITH_CURRENT_CONTEXT ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_FRAMEBUFFER_SRGB_CAPABLE ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_PROFILE_MASK ) ;
# endif
# if SDL_VERSION_ATLEAST( 2, 0, 4 )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_RELEASE_BEHAVIOR ) ;
# endif
@ -817,11 +944,9 @@ int GL_GetAttribute( int attr, int *val )
@@ -817,11 +944,9 @@ int GL_GetAttribute( int attr, int *val )
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_RESET_NOTIFICATION ) ;
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_NO_ERROR ) ;
# endif
MAP_REF_API_ATTRIBUTE_TO_SDL ( GL_CONTEXT_PROFILE_MASK ) ;
# undef MAP_REF_API_ATTRIBUTE_TO_SDL
}
ASSERT ( 0 ) ;
return 0 ;
}
@ -836,22 +961,21 @@ R_Init_Video
@@ -836,22 +961,21 @@ R_Init_Video
*/
qboolean R_Init_Video ( const int type )
{
SDL_DisplayMode displayMode ;
string safe ;
qboolean retval ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode displayMode ;
SDL_GetCurrentDisplayMode ( 0 , & displayMode ) ;
glw_state . desktopBitsPixel = SDL_BITSPERPIXEL ( displayMode . format ) ;
glw_state . desktopWidth = displayMode . w ;
glw_state . desktopHeight = displayMode . h ;
refState . desktopBitsPixel = SDL_BITSPERPIXEL ( displayMode . format ) ;
# else
refState . desktopBitsPixel = 16 ;
# endif
# if !defined(_WIN32)
# if SDL_VERSION_ATLEAST( 2, 0, 0 ) && !defined(_WIN32)
SDL_SetHint ( " SDL_VIDEO_X11_XRANDR " , " 1 " ) ;
SDL_SetHint ( " SDL_VIDEO_X11_XVIDMODE " , " 1 " ) ;
# endif
R_InitVideoModes ( ) ;
// must be initialized before creating window
# ifdef _WIN32
WIN_SetDPIAwareness ( ) ;
@ -896,6 +1020,8 @@ qboolean R_Init_Video( const int type )
@@ -896,6 +1020,8 @@ qboolean R_Init_Video( const int type )
break ;
}
R_InitVideoModes ( ) ;
host . renderinfo_changed = false ;
return true ;
@ -903,16 +1029,16 @@ qboolean R_Init_Video( const int type )
@@ -903,16 +1029,16 @@ qboolean R_Init_Video( const int type )
rserr_t R_ChangeDisplaySettings ( int width , int height , qboolean fullscreen )
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode displayMode ;
SDL_GetCurrentDisplayMode ( 0 , & displayMode ) ;
Con_Reportf ( " R_ChangeDisplaySettings: Setting video mode to %dx%d %s \n " , width , height , fullscreen ? " fullscreen " : " windowed " ) ;
// check our desktop attributes
glw_state . desktopBitsPixel = SDL_BITSPERPIXEL ( displayMode . format ) ;
glw_state . desktopWidth = displayMode . w ;
glw_state . desktopHeight = displayMode . h ;
refState . desktopBitsPixel = SDL_BITSPERPIXEL ( displayMode . format ) ;
# endif
Con_Reportf ( " R_ChangeDisplaySettings: Setting video mode to %dx%d %s \n " , width , height , fullscreen ? " fullscreen " : " windowed " ) ;
refState . fullScreen = fullscreen ;
@ -929,6 +1055,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
@@ -929,6 +1055,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
else
{
VID_RestoreScreenResolution ( ) ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
if ( SDL_SetWindowFullscreen ( host . hWnd , 0 ) )
return rserr_invalid_fullscreen ;
# if SDL_VERSION_ATLEAST( 2, 0, 5 )
@ -936,6 +1063,8 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
@@ -936,6 +1063,8 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
# endif
SDL_SetWindowBordered ( host . hWnd , SDL_TRUE ) ;
SDL_SetWindowSize ( host . hWnd , width , height ) ;
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
VID_SaveWindowSize ( width , height ) ;
}
@ -961,6 +1090,7 @@ qboolean VID_SetMode( void )
@@ -961,6 +1090,7 @@ qboolean VID_SetMode( void )
if ( iScreenWidth < VID_MIN_WIDTH | |
iScreenHeight < VID_MIN_HEIGHT ) // trying to get resolution automatically by default
{
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
# if !defined( DEFAULT_MODE_WIDTH ) || !defined( DEFAULT_MODE_HEIGHT )
SDL_DisplayMode mode ;
@ -972,13 +1102,17 @@ qboolean VID_SetMode( void )
@@ -972,13 +1102,17 @@ qboolean VID_SetMode( void )
iScreenWidth = DEFAULT_MODE_WIDTH ;
iScreenHeight = DEFAULT_MODE_HEIGHT ;
# endif
if ( ! FBitSet ( vid_fullscreen - > flags , FCVAR_CHANGED ) )
Cvar_SetValue ( " fullscreen " , DEFAULT_FULLSCREEN ) ;
else
ClearBits ( vid_fullscreen - > flags , FCVAR_CHANGED ) ;
# else // SDL_VERSION_ATLEAST( 2, 0, 0 )
iScreenWidth = 320 ;
iScreenHeight = 240 ;
# endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
if ( ! FBitSet ( vid_fullscreen - > flags , FCVAR_CHANGED ) )
Cvar_SetValue ( " fullscreen " , DEFAULT_FULLSCREEN ) ;
else
ClearBits ( vid_fullscreen - > flags , FCVAR_CHANGED ) ;
SetBits ( gl_vsync - > flags , FCVAR_CHANGED ) ;
fullscreen = Cvar_VariableInteger ( " fullscreen " ) ! = 0 ;
@ -1028,6 +1162,10 @@ void R_Free_Video( void )
@@ -1028,6 +1162,10 @@ void R_Free_Video( void )
R_FreeVideoModes ( ) ;
ref . dllFuncs . GL_ClearExtensions ( ) ;
# if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_VideoQuit ( ) ;
# endif
}
# endif // XASH_DEDICATED