Browse Source

platform: minify changes, use SDL_VERSION_ATLEAST macro(left unfinished)

pull/2/head
Alibek Omarov 5 years ago
parent
commit
4d5e7c0557
  1. 71
      engine/platform/sdl/events.c
  2. 46
      engine/platform/sdl/in_sdl.c
  3. 25
      engine/platform/sdl/s_sdl.c
  4. 46
      engine/platform/sdl/vid_sdl.c

71
engine/platform/sdl/events.c

@ -27,6 +27,70 @@ GNU General Public License for more details.
static int wheelbutton; static int wheelbutton;
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
#define SDL_SCANCODE_A SDLK_a
#define SDL_SCANCODE_Z SDLK_z
#define SDL_SCANCODE_1 SDLK_1
#define SDL_SCANCODE_9 SDLK_9
#define SDL_SCANCODE_F1 SDLK_F1
#define SDL_SCANCODE_F12 SDLK_F12
#define SDL_SCANCODE_GRAVE SDLK_BACKQUOTE
#define SDL_SCANCODE_0 SDLK_0
#define SDL_SCANCODE_BACKSLASH SDLK_BACKSLASH
#define SDL_SCANCODE_LEFTBRACKET SDLK_LEFTBRACKET
#define SDL_SCANCODE_RIGHTBRACKET SDLK_RIGHTBRACKET
#define SDL_SCANCODE_EQUALS: keynum = '='; break;
#define SDL_SCANCODE_MINUS: keynum = '-'; break;
#define SDL_SCANCODE_TAB: keynum = K_TAB; break;
#define SDL_SCANCODE_RETURN: keynum = K_ENTER; break;
#define SDL_SCANCODE_ESCAPE: keynum = K_ESCAPE; break;
#define SDL_SCANCODE_SPACE: keynum = K_SPACE; break;
#define SDL_SCANCODE_BACKSPACE: keynum = K_BACKSPACE; break;
#define SDL_SCANCODE_UP: keynum = K_UPARROW; break;
#define SDL_SCANCODE_LEFT: keynum = K_LEFTARROW; break;
#define SDL_SCANCODE_DOWN: keynum = K_DOWNARROW; break;
#define SDL_SCANCODE_RIGHT: keynum = K_RIGHTARROW; break;
#define SDL_SCANCODE_LALT:
#define SDL_SCANCODE_RALT: keynum = K_ALT; break;
#define SDL_SCANCODE_LCTRL:
#define SDL_SCANCODE_RCTRL: keynum = K_CTRL; break;
#define SDL_SCANCODE_LSHIFT:
#define SDL_SCANCODE_RSHIFT: keynum = K_SHIFT; break;
#define SDL_SCANCODE_LGUI:
#define SDL_SCANCODE_RGUI: keynum = K_WIN; break;
#define SDL_SCANCODE_INSERT: keynum = K_INS; break;
#define SDL_SCANCODE_DELETE: keynum = K_DEL; break;
#define SDL_SCANCODE_PAGEDOWN: keynum = K_PGDN; break;
#define SDL_SCANCODE_PAGEUP: keynum = K_PGUP; break;
#define SDL_SCANCODE_HOME: keynum = K_HOME; break;
#define SDL_SCANCODE_END: keynum = K_END; break;
#define SDL_SCANCODE_KP_1: keynum = numLock ? '1' : K_KP_END; break;
#define SDL_SCANCODE_KP_2: keynum = numLock ? '2' : K_KP_DOWNARROW; break;
#define SDL_SCANCODE_KP_3: keynum = numLock ? '3' : K_KP_PGDN; break;
#define SDL_SCANCODE_KP_4: keynum = numLock ? '4' : K_KP_LEFTARROW; break;
#define SDL_SCANCODE_KP_5: keynum = numLock ? '5' : K_KP_5; break;
#define SDL_SCANCODE_KP_6: keynum = numLock ? '6' : K_KP_RIGHTARROW; break;
#define SDL_SCANCODE_KP_7: keynum = numLock ? '7' : K_KP_HOME; break;
#define SDL_SCANCODE_KP_8: keynum = numLock ? '8' : K_KP_UPARROW; break;
#define SDL_SCANCODE_KP_9: keynum = numLock ? '9' : K_KP_PGUP; break;
#define SDL_SCANCODE_KP_0: keynum = numLock ? '0' : K_KP_INS; break;
#define SDL_SCANCODE_KP_PERIOD: keynum = K_KP_DEL; break;
#define SDL_SCANCODE_KP_ENTER: keynum = K_KP_ENTER; break;
#define SDL_SCANCODE_KP_PLUS: keynum = K_KP_PLUS; break;
#define SDL_SCANCODE_KP_MINUS: keynum = K_KP_MINUS; break;
#define SDL_SCANCODE_KP_DIVIDE: keynum = K_KP_SLASH; break;
#define SDL_SCANCODE_KP_MULTIPLY: keynum = '*'; break;
#define SDL_SCANCODE_NUMLOCKCLEAR: keynum = K_KP_NUMLOCK; break;
#define SDL_SCANCODE_CAPSLOCK: keynum = K_CAPSLOCK; break;
#define SDL_SCANCODE_APPLICATION: keynum = K_WIN; break; // (compose key) ???
#define SDL_SCANCODE_SLASH: keynum = '/'; break;
#define SDL_SCANCODE_PERIOD: keynum = '.'; break;
#define SDL_SCANCODE_SEMICOLON: keynum = ';'; break;
#define SDL_SCANCODE_APOSTROPHE: keynum = '\''; break;
#define SDL_SCANCODE_COMMA: keynum = ','; break;
#define SDL_SCANCODE_PRINTSCREEN:
#endif
/* /*
============= =============
SDLash_KeyEvent SDLash_KeyEvent
@ -39,7 +103,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
int keynum = key.keysym.scancode; int keynum = key.keysym.scancode;
qboolean numLock = SDL_GetModState() & KMOD_NUM; qboolean numLock = SDL_GetModState() & KMOD_NUM;
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_IsTextInputActive() && down ) if( SDL_IsTextInputActive() && down )
{ {
if( SDL_GetModState() & KMOD_CTRL ) if( SDL_GetModState() & KMOD_CTRL )
@ -53,7 +117,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
return; return;
} }
} }
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
#define DECLARE_KEY_RANGE( min, max, repl ) \ #define DECLARE_KEY_RANGE( min, max, repl ) \
if( keynum >= (min) && keynum <= (max) ) \ if( keynum >= (min) && keynum <= (max) ) \
@ -61,7 +125,6 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
keynum = keynum - (min) + (repl); \ keynum = keynum - (min) + (repl); \
} }
#if XASH_SDL == 2
DECLARE_KEY_RANGE( SDL_SCANCODE_A, SDL_SCANCODE_Z, 'a' ) DECLARE_KEY_RANGE( SDL_SCANCODE_A, SDL_SCANCODE_Z, 'a' )
else DECLARE_KEY_RANGE( SDL_SCANCODE_1, SDL_SCANCODE_9, '1' ) else DECLARE_KEY_RANGE( SDL_SCANCODE_1, SDL_SCANCODE_9, '1' )
else DECLARE_KEY_RANGE( SDL_SCANCODE_F1, SDL_SCANCODE_F12, K_F1 ) else DECLARE_KEY_RANGE( SDL_SCANCODE_F1, SDL_SCANCODE_F12, K_F1 )
@ -129,6 +192,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
break; break;
} }
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
// don't console spam on known functional buttons, but not used in engine // don't console spam on known functional buttons, but not used in engine
case SDL_SCANCODE_MUTE: case SDL_SCANCODE_MUTE:
case SDL_SCANCODE_VOLUMEUP: case SDL_SCANCODE_VOLUMEUP:
@ -136,6 +200,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
case SDL_SCANCODE_BRIGHTNESSDOWN: case SDL_SCANCODE_BRIGHTNESSDOWN:
case SDL_SCANCODE_BRIGHTNESSUP: case SDL_SCANCODE_BRIGHTNESSUP:
return; return;
#endif
case SDL_SCANCODE_UNKNOWN: case SDL_SCANCODE_UNKNOWN:
{ {
if( down ) Con_Reportf( "SDLash_KeyEvent: Unknown scancode\n" ); if( down ) Con_Reportf( "SDLash_KeyEvent: Unknown scancode\n" );

46
engine/platform/sdl/in_sdl.c

@ -25,9 +25,13 @@ GNU General Public License for more details.
#include "vid_common.h" #include "vid_common.h"
static SDL_Joystick *joy; static SDL_Joystick *joy;
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
static SDL_GameController *gamecontroller; static SDL_GameController *gamecontroller;
#endif // XASH_SDL == 2 #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
#define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) )
#endif
/* /*
============= =============
@ -48,11 +52,7 @@ Platform_SetMousePos
*/ */
void Platform_SetMousePos( int x, int y ) void Platform_SetMousePos( int x, int y )
{ {
#if XASH_SDL == 2
SDL_WarpMouseInWindow( host.hWnd, x, y ); SDL_WarpMouseInWindow( host.hWnd, x, y );
#else
SDL_WarpMouse( x, y );
#endif
} }
/* /*
@ -63,7 +63,7 @@ Platform_GetClipobardText
*/ */
void Platform_GetClipboardText( char *buffer, size_t size ) void Platform_GetClipboardText( char *buffer, size_t size )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
char *sdlbuffer = SDL_GetClipboardText(); char *sdlbuffer = SDL_GetClipboardText();
if( !sdlbuffer ) if( !sdlbuffer )
@ -71,9 +71,9 @@ void Platform_GetClipboardText( char *buffer, size_t size )
Q_strncpy( buffer, sdlbuffer, size ); Q_strncpy( buffer, sdlbuffer, size );
SDL_free( sdlbuffer ); SDL_free( sdlbuffer );
#else #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
buffer[0] = 0; buffer[0] = 0;
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -84,9 +84,9 @@ Platform_SetClipobardText
*/ */
void Platform_SetClipboardText( const char *buffer, size_t size ) void Platform_SetClipboardText( const char *buffer, size_t size )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_SetClipboardText( buffer ); SDL_SetClipboardText( buffer );
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -108,9 +108,9 @@ SDLash_EnableTextInput
*/ */
void Platform_EnableTextInput( qboolean enable ) void Platform_EnableTextInput( qboolean enable )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
enable ? SDL_StartTextInput() : SDL_StopTextInput(); enable ? SDL_StartTextInput() : SDL_StopTextInput();
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -148,10 +148,10 @@ static int SDLash_JoyInit_Old( int numjoy )
return 0; return 0;
} }
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
for( i = 0; i < num; i++ ) for( i = 0; i < num; i++ )
Con_Reportf( "%i\t: %s\n", i, SDL_JoystickNameForIndex( i ) ); Con_Reportf( "%i\t: %s\n", i, SDL_JoystickNameForIndex( i ) );
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
Con_Reportf( "Pass +set joy_index N to command line, where N is number, to select active joystick\n" ); Con_Reportf( "Pass +set joy_index N to command line, where N is number, to select active joystick\n" );
@ -163,7 +163,7 @@ static int SDLash_JoyInit_Old( int numjoy )
return 0; return 0;
} }
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
Con_Reportf( "Selected joystick: %s\n" Con_Reportf( "Selected joystick: %s\n"
"\tAxes: %i\n" "\tAxes: %i\n"
"\tHats: %i\n" "\tHats: %i\n"
@ -173,13 +173,13 @@ static int SDLash_JoyInit_Old( int numjoy )
SDL_JoystickNumButtons( joy ), SDL_JoystickNumBalls( joy ) ); SDL_JoystickNumButtons( joy ), SDL_JoystickNumBalls( joy ) );
SDL_GameControllerEventState( SDL_DISABLE ); SDL_GameControllerEventState( SDL_DISABLE );
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_JoystickEventState( SDL_ENABLE ); SDL_JoystickEventState( SDL_ENABLE );
return num; return num;
} }
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
/* /*
============= =============
SDLash_JoyInit_New SDLash_JoyInit_New
@ -238,19 +238,19 @@ static int SDLash_JoyInit_New( int numjoy )
return 0; return 0;
} }
// was added in SDL2-2.0.6, allow build with earlier versions just in case // was added in SDL2-2.0.6, allow build with earlier versions just in case
#if SDL_MAJOR_VERSION > 2 || SDL_MINOR_VERSION > 0 || SDL_PATCHLEVEL >= 6 #if SDL_VERSION_ATLEAST( 2, 0, 6 )
Con_Reportf( "Selected joystick: %s (%i:%i:%i)\n", Con_Reportf( "Selected joystick: %s (%i:%i:%i)\n",
SDL_GameControllerName( gamecontroller ), SDL_GameControllerName( gamecontroller ),
SDL_GameControllerGetVendor( gamecontroller ), SDL_GameControllerGetVendor( gamecontroller ),
SDL_GameControllerGetProduct( gamecontroller ), SDL_GameControllerGetProduct( gamecontroller ),
SDL_GameControllerGetProductVersion( gamecontroller )); SDL_GameControllerGetProductVersion( gamecontroller ));
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 6 )
SDL_GameControllerEventState( SDL_ENABLE ); SDL_GameControllerEventState( SDL_ENABLE );
SDL_JoystickEventState( SDL_DISABLE ); SDL_JoystickEventState( SDL_DISABLE );
return num; return num;
} }
#endif // XASH_SDL == 2 #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
/* /*
============= =============
@ -260,12 +260,12 @@ Platform_JoyInit
*/ */
int Platform_JoyInit( int numjoy ) int Platform_JoyInit( int numjoy )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
// SDL_Joystick is now an old API // SDL_Joystick is now an old API
// SDL_GameController is preferred // SDL_GameController is preferred
if( !Sys_CheckParm( "-sdl_joy_old_api" ) ) if( !Sys_CheckParm( "-sdl_joy_old_api" ) )
return SDLash_JoyInit_New(numjoy); return SDLash_JoyInit_New(numjoy);
#endif // XASH_SDL == 2 #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return SDLash_JoyInit_Old(numjoy); return SDLash_JoyInit_Old(numjoy);
} }

25
engine/platform/sdl/s_sdl.c

@ -24,6 +24,15 @@ GNU General Public License for more details.
#define SAMPLE_16BIT_SHIFT 1 #define SAMPLE_16BIT_SHIFT 1
#define SECONDARY_BUFFER_SIZE 0x10000 #define SECONDARY_BUFFER_SIZE 0x10000
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <stdlib.h>
#define SDL_setenv setenv
#define SDL_GetCurrentAudioDriver() "legacysdl"
#define SDL_OpenAudioDevice( a, b, c, d, e ) SDL_OpenAudio( ( c ), ( d ) )
#define SDL_CloseAudioDevice( a ) SDL_CloseAudio()
#define SDL_PauseAudioDevice( a, b ) SDL_PauseAudio( ( b ) )
#endif
/* /*
======================================================================= =======================================================================
Global variables. Must be visible to window-procedure function Global variables. Must be visible to window-procedure function
@ -76,10 +85,8 @@ qboolean SNDDMA_Init( void )
// even if we don't have PA // even if we don't have PA
// we still can safely set env variables // we still can safely set env variables
#if XASH_SDL == 2
SDL_setenv( "PULSE_PROP_application.name", GI->title, 1 ); SDL_setenv( "PULSE_PROP_application.name", GI->title, 1 );
SDL_setenv( "PULSE_PROP_media.role", "game", 1 ); SDL_setenv( "PULSE_PROP_media.role", "game", 1 );
#endif
memset( &desired, 0, sizeof( desired ) ); memset( &desired, 0, sizeof( desired ) );
desired.freq = SOUND_DMA_SPEED; desired.freq = SOUND_DMA_SPEED;
@ -88,10 +95,7 @@ qboolean SNDDMA_Init( void )
desired.channels = 2; desired.channels = 2;
desired.callback = SDL_SoundCallback; desired.callback = SDL_SoundCallback;
#if XASH_SDL == 2
sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 ); sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 );
#endif
sdl_dev = SDL_OpenAudio( &desired, &obtained );
if( !sdl_dev ) if( !sdl_dev )
{ {
@ -121,11 +125,7 @@ qboolean SNDDMA_Init( void )
dma.buffer = Z_Malloc( dma.samples * 2 ); dma.buffer = Z_Malloc( dma.samples * 2 );
dma.samplepos = 0; dma.samplepos = 0;
#if XASH_SDL == 2
Con_Printf( "Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver( ), obtained.freq ); Con_Printf( "Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver( ), obtained.freq );
#else
Con_Printf( "Using SDL audio driver @ %d Hz\n", obtained.freq );
#endif
SNDDMA_Activate( true ); SNDDMA_Activate( true );
@ -230,10 +230,7 @@ void SNDDMA_Shutdown( void )
SNDDMA_Activate( false ); SNDDMA_Activate( false );
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
#if XASH_SDL == 2
SDL_CloseAudioDevice( sdl_dev ); SDL_CloseAudioDevice( sdl_dev );
#endif
SDL_CloseAudio( );
#endif #endif
} }
@ -259,10 +256,6 @@ between a deactivate and an activate.
*/ */
void SNDDMA_Activate( qboolean active ) void SNDDMA_Activate( qboolean active )
{ {
#if XASH_SDL == 2
SDL_PauseAudioDevice( sdl_dev, !active ); SDL_PauseAudioDevice( sdl_dev, !active );
#else
SDL_PauseAudio( !active );
#endif
} }
#endif // XASH_SOUND == SOUND_SDL #endif // XASH_SOUND == SOUND_SDL

46
engine/platform/sdl/vid_sdl.c

@ -31,7 +31,7 @@ struct
struct struct
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Renderer *renderer; SDL_Renderer *renderer;
SDL_Texture *tex; SDL_Texture *tex;
#endif #endif
@ -45,7 +45,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
sw.width = width; sw.width = width;
sw.height = height; sw.height = height;
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST(2, 0, 0)
if( sw.renderer ) if( sw.renderer )
{ {
unsigned int format = SDL_GetWindowPixelFormat( host.hWnd ); unsigned int format = SDL_GetWindowPixelFormat( host.hWnd );
@ -115,11 +115,11 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
} }
#endif #endif
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !sw.renderer ) if( !sw.renderer )
{ {
sw.win = SDL_GetWindowSurface( host.hWnd ); sw.win = SDL_GetWindowSurface( host.hWnd );
#else #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
{ {
sw.win = SDL_GetVideoSurface(); sw.win = SDL_GetVideoSurface();
#endif #endif
@ -154,7 +154,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
void *SW_LockBuffer( void ) void *SW_LockBuffer( void )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( sw.renderer ) if( sw.renderer )
{ {
void *pixels; void *pixels;
@ -169,22 +169,22 @@ void *SW_LockBuffer( void )
sw.win = SDL_GetWindowSurface( host.hWnd ); sw.win = SDL_GetWindowSurface( host.hWnd );
//if( !sw.win ) //if( !sw.win )
//SDL_GetWindowSurface( host.hWnd ); //SDL_GetWindowSurface( host.hWnd );
#else #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
sw.win = SDL_GetVideoSurface(); sw.win = SDL_GetVideoSurface();
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
// prevent buffer overrun // prevent buffer overrun
if( !sw.win || sw.win->w < sw.width || sw.win->h < sw.height ) if( !sw.win || sw.win->w < sw.width || sw.win->h < sw.height )
return NULL; return NULL;
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( sw.surf ) if( sw.surf )
{ {
SDL_LockSurface( sw.surf ); SDL_LockSurface( sw.surf );
return sw.surf->pixels; return sw.surf->pixels;
} }
else else
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
{ {
// real window pixels (x11 shm region, dma buffer, etc) // real window pixels (x11 shm region, dma buffer, etc)
// or SDL_Renderer texture if not supported // or SDL_Renderer texture if not supported
@ -195,7 +195,7 @@ void *SW_LockBuffer( void )
void SW_UnlockBuffer( void ) void SW_UnlockBuffer( void )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( sw.renderer ) if( sw.renderer )
{ {
SDL_Rect src, dst; SDL_Rect src, dst;
@ -227,14 +227,14 @@ void SW_UnlockBuffer( void )
SDL_BlitSurface( sw.surf, &src, sw.win, &dst ); SDL_BlitSurface( sw.surf, &src, sw.win, &dst );
return; return;
} }
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
// already blitted // already blitted
SDL_UnlockSurface( sw.win ); SDL_UnlockSurface( sw.win );
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_UpdateWindowSurface( host.hWnd ); SDL_UpdateWindowSurface( host.hWnd );
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
int R_MaxVideoModes( void ) int R_MaxVideoModes( void )
@ -254,7 +254,7 @@ vidmode_t *R_GetVideoMode( int num )
static void R_InitVideoModes( void ) static void R_InitVideoModes( void )
{ {
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
int displayIndex = 0; // TODO: handle multiple displays somehow int displayIndex = 0; // TODO: handle multiple displays somehow
int i, modes; int i, modes;
@ -299,8 +299,11 @@ static void R_InitVideoModes( void )
num_vidmodes++; num_vidmodes++;
} }
#else #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
int i;
# error TODO
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
static void R_FreeVideoModes( void ) static void R_FreeVideoModes( void )
@ -405,6 +408,7 @@ GL_UpdateSwapInterval
*/ */
void GL_UpdateSwapInterval( void ) void GL_UpdateSwapInterval( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
// disable VSync while level is loading // disable VSync while level is loading
if( cls.state < ca_active ) if( cls.state < ca_active )
{ {
@ -418,6 +422,7 @@ void GL_UpdateSwapInterval( void )
if( SDL_GL_SetSwapInterval( gl_vsync->value ) ) if( SDL_GL_SetSwapInterval( gl_vsync->value ) )
Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ) ); Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ) );
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -429,12 +434,13 @@ always return false
*/ */
qboolean GL_DeleteContext( void ) qboolean GL_DeleteContext( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( glw_state.context ) if( glw_state.context )
{ {
SDL_GL_DeleteContext(glw_state.context); SDL_GL_DeleteContext(glw_state.context);
glw_state.context = NULL; glw_state.context = NULL;
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return false; return false;
} }
@ -445,12 +451,13 @@ GL_CreateContext
*/ */
qboolean GL_CreateContext( void ) qboolean GL_CreateContext( void )
{ {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL) if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL)
{ {
Con_Reportf( S_ERROR "GL_CreateContext: %s\n", SDL_GetError()); Con_Reportf( S_ERROR "GL_CreateContext: %s\n", SDL_GetError());
return GL_DeleteContext(); return GL_DeleteContext();
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return true; return true;
} }
@ -461,12 +468,13 @@ GL_UpdateContext
*/ */
qboolean GL_UpdateContext( void ) qboolean GL_UpdateContext( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context )) if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context ))
{ {
Con_Reportf( S_ERROR "GL_UpdateContext: %s\n", SDL_GetError()); Con_Reportf( S_ERROR "GL_UpdateContext: %s\n", SDL_GetError());
return GL_DeleteContext(); return GL_DeleteContext();
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return true; return true;
} }

Loading…
Cancel
Save