sdl2 support

This commit is contained in:
Eric Wasylishen 2014-05-18 19:31:32 -06:00
parent ed18fc95eb
commit 8b2cce1f37
14 changed files with 643 additions and 61 deletions

View file

@ -20,7 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#import "AppController.h" #import "AppController.h"
#import "ScreenInfo.h" #import "ScreenInfo.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#import <SDL2/SDL.h>
#else
#import <SDL/SDL.h> #import <SDL/SDL.h>
#endif
#else #else
#import "SDL.h" #import "SDL.h"
#endif #endif
@ -60,6 +64,19 @@ NSString *FQPrefScreenModeKey = @"ScreenMode";
if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
return self; return self;
#if defined(USE_SDL2)
const int sdlmodes = SDL_GetNumDisplayModes(0);
for (i = 0; i < sdlmodes; i++)
{
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(0, i, &mode) == 0)
{
info = [[ScreenInfo alloc] initWithWidth:mode.w height:mode.h bpp:SDL_BITSPERPIXEL(mode.format)];
[screenModes addObject:info];
[info release];
}
}
#else
flags = SDL_OPENGL | SDL_FULLSCREEN; flags = SDL_OPENGL | SDL_FULLSCREEN;
format.palette = NULL; format.palette = NULL;
@ -76,6 +93,7 @@ NSString *FQPrefScreenModeKey = @"ScreenMode";
[info release]; [info release];
} }
} }
#endif
SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_QuitSubSystem(SDL_INIT_VIDEO);

View file

@ -20,7 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#import "SDLApplication.h" #import "SDLApplication.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#import <SDL2/SDL.h>
#else
#import <SDL/SDL.h> #import <SDL/SDL.h>
#endif
#else #else
#import "SDL.h" #import "SDL.h"
#endif #endif

View file

@ -6,7 +6,11 @@
*/ */
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#import <SDL2/SDL.h>
#else
#import <SDL/SDL.h> #import <SDL/SDL.h>
#endif
#else #else
#import "SDL.h" #import "SDL.h"
#endif #endif

View file

@ -26,7 +26,11 @@
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif
@ -35,7 +39,7 @@
/* SDL dropped support for /* SDL dropped support for
cd audio since v1.3.0 */ cd audio since v1.3.0 */
#warning SDL CDAudio support disabled #pragma message ( "SDL CDAudio support disabled" )
#include "cd_null.c" #include "cd_null.c"
#else /* SDL_INIT_CDROM */ #else /* SDL_INIT_CDROM */

View file

@ -27,7 +27,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "bgmusic.h" #include "bgmusic.h"
#include "resource.h" #include "resource.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif
@ -58,7 +62,12 @@ static int nummodes;
static qboolean vid_initialized = false; static qboolean vid_initialized = false;
#if defined(USE_SDL2)
static SDL_Window *window;
static SDL_GLContext draw_context;
#else
static SDL_Surface *draw_context; static SDL_Surface *draw_context;
#endif
static qboolean vid_locked = false; //johnfitz static qboolean vid_locked = false; //johnfitz
static qboolean vid_changed = false; static qboolean vid_changed = false;
@ -128,8 +137,13 @@ static void VID_Gamma_SetGamma (void)
if (draw_context && gammaworks) if (draw_context && gammaworks)
{ {
#if USE_GAMMA_RAMPS #if USE_GAMMA_RAMPS
#if defined(USE_SDL2)
if (SDL_SetWindowGammaRamp(window, vid_gamma_red, vid_gamma_green, vid_gamma_blue) != 0)
Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetWindowGammaRamp\n");
#else
if (SDL_SetGammaRamp(vid_gamma_red, vid_gamma_green, vid_gamma_blue) == -1) if (SDL_SetGammaRamp(vid_gamma_red, vid_gamma_green, vid_gamma_blue) == -1)
Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetGammaRamp\n"); Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetGammaRamp\n");
#endif
#else #else
float value; float value;
@ -138,8 +152,13 @@ static void VID_Gamma_SetGamma (void)
else else
value = GAMMA_MAX; value = GAMMA_MAX;
#if defined(USE_SDL2)
if (SDL_SetWindowBrightness(window, value) != 0)
Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetWindowBrightness\n");
#else
if (SDL_SetGamma(value,value,value) == -1) if (SDL_SetGamma(value,value,value) == -1)
Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetGamma\n"); Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetGamma\n");
#endif
#endif #endif
} }
} }
@ -154,11 +173,21 @@ static void VID_Gamma_Restore (void)
if (draw_context && gammaworks) if (draw_context && gammaworks)
{ {
#if USE_GAMMA_RAMPS #if USE_GAMMA_RAMPS
#if defined(USE_SDL2)
if (SDL_SetWindowGammaRamp(window, vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0);
Con_Printf ("VID_Gamma_Restore: failed on SDL_SetWindowGammaRamp\n");
#else
if (SDL_SetGammaRamp(vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == -1) if (SDL_SetGammaRamp(vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == -1)
Con_Printf ("VID_Gamma_Restore: failed on SDL_SetGammaRamp\n"); Con_Printf ("VID_Gamma_Restore: failed on SDL_SetGammaRamp\n");
#endif
#else
#if defined(USE_SDL2)
if (SDL_SetWindowBrightness(window, 1) != 0)
Con_Printf ("VID_Gamma_Restore: failed on SDL_SetWindowBrightness\n");
#else #else
if (SDL_SetGamma(1, 1, 1) == -1) if (SDL_SetGamma(1, 1, 1) == -1)
Con_Printf ("VID_Gamma_Restore: failed on SDL_SetGamma\n"); Con_Printf ("VID_Gamma_Restore: failed on SDL_SetGamma\n");
#endif
#endif #endif
} }
} }
@ -202,13 +231,23 @@ VID_Gamma_Init -- call on init
static void VID_Gamma_Init (void) static void VID_Gamma_Init (void)
{ {
#if USE_GAMMA_RAMPS #if USE_GAMMA_RAMPS
#if defined(USE_SDL2)
gammaworks = (SDL_GetWindowGammaRamp(window, vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0);
if (gammaworks)
gammaworks = (SDL_SetWindowGammaRamp(window, vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0);
#else
gammaworks = (SDL_GetGammaRamp(vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0); gammaworks = (SDL_GetGammaRamp(vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0);
if (gammaworks) if (gammaworks)
gammaworks = (SDL_SetGammaRamp(vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0); gammaworks = (SDL_SetGammaRamp(vid_sysgamma_red, vid_sysgamma_green, vid_sysgamma_blue) == 0);
#endif
#else
#if defined(USE_SDL2)
gammaworks = (SDL_SetWindowBrightness(window, 1) == 0);
#else #else
gammaworks = (SDL_SetGamma(1, 1, 1) == 0); gammaworks = (SDL_SetGamma(1, 1, 1) == 0);
#endif #endif
#endif
if (!gammaworks) if (!gammaworks)
Con_SafePrintf("gamma adjustment not available\n"); Con_SafePrintf("gamma adjustment not available\n");
@ -216,6 +255,126 @@ static void VID_Gamma_Init (void)
Cvar_SetCallback (&vid_gamma, VID_Gamma_f); Cvar_SetCallback (&vid_gamma, VID_Gamma_f);
} }
/*
======================
VID_GetCurrentWidth
======================
*/
static int VID_GetCurrentWidth (void)
{
#if defined(USE_SDL2)
int w = 0, h = 0;
SDL_GetWindowSize(window, &w, &h);
return w;
#else
return draw_context->w;
#endif
}
/*
=======================
VID_GetCurrentHeight
=======================
*/
static int VID_GetCurrentHeight (void)
{
#if defined(USE_SDL2)
int w=0, h=0;
SDL_GetWindowSize(window, &w, &h);
return h;
#else
return draw_context->h;
#endif
}
/*
====================
VID_GetCurrentBPP
====================
*/
static int VID_GetCurrentBPP (void)
{
#if defined(USE_SDL2)
const Uint32 pixelFormat = SDL_GetWindowPixelFormat(window);
return SDL_BITSPERPIXEL(pixelFormat);
#else
return draw_context->format->BitsPerPixel;
#endif
}
/*
====================
VID_GetFullscreen
====================
*/
static qboolean VID_GetFullscreen (void)
{
#if defined(USE_SDL2)
return (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN;
#else
return (draw_context->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN;
#endif
}
/*
====================
VID_GetVSync
====================
*/
static qboolean VID_GetVSync (void)
{
#if defined(USE_SDL2)
return SDL_GL_GetSwapInterval() == 1;
#else
int swap_control;
if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == 0)
return swap_control == 1;
return false;
#endif
}
/*
====================
VID_HasMouseOrInputFocus
====================
*/
qboolean VID_HasMouseOrInputFocus (void)
{
#if defined(USE_SDL2)
return (SDL_GetWindowFlags(window) & (SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS)) != 0;
#else
return (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) != 0;
#endif
}
/*
====================
VID_GetWindowVisible
====================
*/
qboolean VID_GetWindowVisible (void)
{
#if defined(USE_SDL2)
return (SDL_GetWindowFlags(window) & SDL_WINDOW_SHOWN) != 0;
#else
return (SDL_GetAppState() & SDL_APPACTIVE) != 0;
#endif
}
/*
====================
VID_GetWindow
====================
*/
void *VID_GetWindow (void)
{
#if defined(USE_SDL2)
return window;
#else
return NULL;
#endif
}
/* /*
================ ================
VID_ValidMode VID_ValidMode
@ -223,6 +382,9 @@ VID_ValidMode
*/ */
static qboolean VID_ValidMode (int width, int height, int bpp, qboolean fullscreen) static qboolean VID_ValidMode (int width, int height, int bpp, qboolean fullscreen)
{ {
#if defined(USE_SDL2)
return true;
#else
Uint32 flags = DEFAULT_SDL_FLAGS; Uint32 flags = DEFAULT_SDL_FLAGS;
if (width < 320) if (width < 320)
@ -247,6 +409,7 @@ static qboolean VID_ValidMode (int width, int height, int bpp, qboolean fullscre
} }
return true; return true;
#endif
} }
/* /*
@ -257,12 +420,9 @@ VID_SetMode
static int VID_SetMode (int width, int height, int bpp, qboolean fullscreen) static int VID_SetMode (int width, int height, int bpp, qboolean fullscreen)
{ {
int temp; int temp;
Uint32 flags = DEFAULT_SDL_FLAGS; Uint32 flags;
char caption[50]; char caption[50];
if (fullscreen)
flags |= SDL_FULLSCREEN;
// so Con_Printfs don't mess us up by forcing vid and snd updates // so Con_Printfs don't mess us up by forcing vid and snd updates
temp = scr_disabled_for_loading; temp = scr_disabled_for_loading;
scr_disabled_for_loading = true; scr_disabled_for_loading = true;
@ -270,30 +430,74 @@ static int VID_SetMode (int width, int height, int bpp, qboolean fullscreen)
CDAudio_Pause (); CDAudio_Pause ();
BGM_Pause (); BGM_Pause ();
q_snprintf(caption, sizeof(caption), "QuakeSpasm %1.2f.%d", (float)FITZQUAKE_VERSION, QUAKESPASM_VER_PATCH);
#if defined(USE_SDL2)
if (!window) // Create a new window
{
flags = SDL_WINDOW_OPENGL;
if (fullscreen)
flags |= SDL_WINDOW_FULLSCREEN;
window = SDL_CreateWindow(caption,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
width, height, flags);
if (!window)
Sys_Error ("Couldn't set video mode");
draw_context = SDL_GL_CreateContext(window);
}
else // A window already exists
{
if (VID_GetFullscreen())
{
if (SDL_SetWindowFullscreen(window, 0) != 0)
Sys_Error ("Couldn't set fullscreen state mode");
}
SDL_SetWindowSize(window, width, height);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
if (fullscreen)
{
if (SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN) != 0)
Sys_Error ("Couldn't set fullscreen state mode");
}
}
gl_swap_control = true;
if (SDL_GL_SetSwapInterval((vid_vsync.value) ? 1 : 0) == -1)
gl_swap_control = false;
#else
flags = DEFAULT_SDL_FLAGS;
if (fullscreen)
flags |= SDL_FULLSCREEN;
// //
// swap control (the "before SDL_SetVideoMode" part) // swap control (the "before SDL_SetVideoMode" part)
// //
gl_swap_control = true; gl_swap_control = true;
if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, (vid_vsync.value) ? 1 : 0) == -1) if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, (vid_vsync.value) ? 1 : 0) == -1)
gl_swap_control = false; gl_swap_control = false;
bpp = SDL_VideoModeOK(width, height, bpp, flags); bpp = SDL_VideoModeOK(width, height, bpp, flags);
draw_context = SDL_SetVideoMode(width, height, bpp, flags); draw_context = SDL_SetVideoMode(width, height, bpp, flags);
if (!draw_context) if (!draw_context)
Sys_Error ("Couldn't set video mode"); Sys_Error ("Couldn't set video mode");
q_snprintf(caption, sizeof(caption), "QuakeSpasm %1.2f.%d", (float)FITZQUAKE_VERSION, QUAKESPASM_VER_PATCH);
SDL_WM_SetCaption(caption, caption); SDL_WM_SetCaption(caption, caption);
#endif
vid.width = draw_context->w; vid.width = VID_GetCurrentWidth();
vid.height = draw_context->h; vid.height = VID_GetCurrentHeight();
vid.conwidth = vid.width & 0xFFFFFFF8; vid.conwidth = vid.width & 0xFFFFFFF8;
vid.conheight = vid.conwidth * vid.height / vid.width; vid.conheight = vid.conwidth * vid.height / vid.width;
vid.numpages = 2; vid.numpages = 2;
modestate = draw_context->flags & SDL_FULLSCREEN ? MS_FULLSCREEN : MS_WINDOWED; modestate = VID_GetFullscreen() ? MS_FULLSCREEN : MS_WINDOWED;
CDAudio_Resume (); CDAudio_Resume ();
BGM_Resume (); BGM_Resume ();
scr_disabled_for_loading = temp; scr_disabled_for_loading = temp;
@ -302,9 +506,9 @@ static int VID_SetMode (int width, int height, int bpp, qboolean fullscreen)
ClearAllStates (); ClearAllStates ();
Con_SafePrintf ("Video mode %dx%dx%d initialized\n", Con_SafePrintf ("Video mode %dx%dx%d initialized\n",
draw_context->w, VID_GetCurrentWidth(),
draw_context->h, VID_GetCurrentHeight(),
draw_context->format->BitsPerPixel); VID_GetCurrentBPP());
vid.recalc_refdef = 1; vid.recalc_refdef = 1;
@ -399,10 +603,10 @@ static void VID_Test (void)
// //
// now try the switch // now try the switch
// //
old_width = draw_context->w; old_width = VID_GetCurrentWidth();
old_height = draw_context->h; old_height = VID_GetCurrentHeight();
old_bpp = draw_context->format->BitsPerPixel; old_bpp = VID_GetCurrentBPP();
old_fullscreen = draw_context->flags & SDL_FULLSCREEN ? true : false; old_fullscreen = VID_GetFullscreen() ? true : false;
VID_Restart (); VID_Restart ();
@ -603,11 +807,13 @@ static void GL_CheckExtensions (void)
{ {
Con_Warning ("vertical sync not supported (SDL_GL_SetAttribute failed)\n"); Con_Warning ("vertical sync not supported (SDL_GL_SetAttribute failed)\n");
} }
#if !defined(USE_SDL2)
else if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == -1) else if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == -1)
{ {
gl_swap_control = false; gl_swap_control = false;
Con_Warning ("vertical sync not supported (SDL_GL_GetAttribute failed)\n"); Con_Warning ("vertical sync not supported (SDL_GL_GetAttribute failed)\n");
} }
#endif
else if ((vid_vsync.value && swap_control != 1) || (!vid_vsync.value && swap_control != 0)) else if ((vid_vsync.value && swap_control != 1) || (!vid_vsync.value && swap_control != 0))
{ {
gl_swap_control = false; gl_swap_control = false;
@ -737,7 +943,13 @@ GL_EndRendering
void GL_EndRendering (void) void GL_EndRendering (void)
{ {
if (!scr_skipupdate) if (!scr_skipupdate)
{
#if defined(USE_SDL2)
SDL_GL_SwapWindow(window);
#else
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
#endif
}
} }
@ -749,6 +961,9 @@ void VID_Shutdown (void)
SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_QuitSubSystem(SDL_INIT_VIDEO);
draw_context = NULL; draw_context = NULL;
#if defined(USE_SDL2)
window = NULL;
#endif
PL_VID_Shutdown(); PL_VID_Shutdown();
} }
@ -792,10 +1007,10 @@ static void VID_DescribeCurrentMode_f (void)
{ {
if (draw_context) if (draw_context)
Con_Printf("%dx%dx%d %s\n", Con_Printf("%dx%dx%d %s\n",
draw_context->w, VID_GetCurrentWidth(),
draw_context->h, VID_GetCurrentHeight(),
draw_context->format->BitsPerPixel, VID_GetCurrentBPP(),
draw_context->flags & SDL_FULLSCREEN ? "fullscreen" : "windowed"); VID_GetFullscreen() ? "fullscreen" : "windowed");
} }
/* /*
@ -839,6 +1054,26 @@ VID_InitModelist
*/ */
static void VID_InitModelist (void) static void VID_InitModelist (void)
{ {
#if defined(USE_SDL2)
const int sdlmodes = SDL_GetNumDisplayModes(0);
int i;
nummodes = 0;
for (i = 0; i < sdlmodes; i++)
{
if (nummodes >= MAX_MODE_LIST)
break;
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(0, i, &mode) == 0)
{
modelist[nummodes].width = mode.w;
modelist[nummodes].height = mode.h;
modelist[nummodes].bpp = SDL_BITSPERPIXEL(mode.format);
nummodes++;
}
}
#else
SDL_PixelFormat format; SDL_PixelFormat format;
SDL_Rect **modes; SDL_Rect **modes;
Uint32 flags; Uint32 flags;
@ -890,6 +1125,7 @@ static void VID_InitModelist (void)
if (nummodes == originalnummodes) if (nummodes == originalnummodes)
Con_SafePrintf ("No fullscreen DIB modes found\n"); Con_SafePrintf ("No fullscreen DIB modes found\n");
#endif
} }
/* /*
@ -900,8 +1136,7 @@ VID_Init
void VID_Init (void) void VID_Init (void)
{ {
static char vid_center[] = "SDL_VIDEO_CENTERED=center"; static char vid_center[] = "SDL_VIDEO_CENTERED=center";
const SDL_VideoInfo *info; int width, height, bpp, display_width, display_height, display_bpp;
int width, height, bpp;
qboolean fullscreen; qboolean fullscreen;
const char *read_vars[] = { "vid_fullscreen", const char *read_vars[] = { "vid_fullscreen",
"vid_width", "vid_width",
@ -932,9 +1167,8 @@ void VID_Init (void)
if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
Sys_Error("Could not initialize SDL Video"); Sys_Error("Could not initialize SDL Video");
info = SDL_GetVideoInfo();
Cvar_SetValueQuick (&vid_bpp, (float)info->vfmt->BitsPerPixel);
if (CFG_OpenConfig("config.cfg") == 0) if (CFG_OpenConfig("config.cfg") == 0)
{ {
CFG_ReadCvars(read_vars, num_readvars); CFG_ReadCvars(read_vars, num_readvars);
@ -949,11 +1183,37 @@ void VID_Init (void)
bpp = (int)vid_bpp.value; bpp = (int)vid_bpp.value;
fullscreen = (int)vid_fullscreen.value; fullscreen = (int)vid_fullscreen.value;
#if defined(USE_SDL2)
{
SDL_DisplayMode mode;
if (SDL_GetDesktopDisplayMode(0, &mode) == 0)
{
display_width = mode.w;
display_height = mode.h;
display_bpp = SDL_BITSPERPIXEL(mode.format);
}
else
{
display_width = width;
display_height = height;
display_bpp = bpp;
}
}
#else
{
const SDL_VideoInfo *info = SDL_GetVideoInfo();
Cvar_SetValueQuick (&vid_bpp, (float)info->vfmt->BitsPerPixel);
display_width = info->current_w;
display_height = info->current_h;
display_bpp = info->vfmt->BitsPerPixel;
}
#endif
if (COM_CheckParm("-current")) if (COM_CheckParm("-current"))
{ {
width = info->current_w; width = display_width;
height = info->current_h; height = display_height;
bpp = info->vfmt->BitsPerPixel; bpp = display_bpp;
fullscreen = true; fullscreen = true;
} }
else else
@ -1000,7 +1260,7 @@ void VID_Init (void)
{ {
width = 640; width = 640;
height = 480; height = 480;
bpp = info->vfmt->BitsPerPixel; bpp = display_bpp;
fullscreen = false; fullscreen = false;
} }
@ -1038,16 +1298,24 @@ void VID_Init (void)
void VID_Toggle (void) void VID_Toggle (void)
{ {
static qboolean vid_toggle_works = true; static qboolean vid_toggle_works = true;
qboolean toggleWorked;
S_ClearBuffer (); S_ClearBuffer ();
if (!vid_toggle_works) if (!vid_toggle_works)
goto vrestart; goto vrestart;
if (SDL_WM_ToggleFullScreen(draw_context) == 1)
#if defined(USE_SDL2)
toggleWorked = SDL_SetWindowFullscreen(window, VID_GetFullscreen() ? 0 : SDL_WINDOW_FULLSCREEN) == 0;
#else
toggleWorked = SDL_WM_ToggleFullScreen(draw_context) == 1;
#endif
if (toggleWorked)
{ {
Sbar_Changed (); // Sbar seems to need refreshing Sbar_Changed (); // Sbar seems to need refreshing
modestate = draw_context->flags & SDL_FULLSCREEN ? MS_FULLSCREEN : MS_WINDOWED; modestate = VID_GetFullscreen() ? MS_FULLSCREEN : MS_WINDOWED;
VID_SyncCvars(); VID_SyncCvars();
@ -1065,7 +1333,7 @@ void VID_Toggle (void)
vid_toggle_works = false; vid_toggle_works = false;
Con_DPrintf ("SDL_WM_ToggleFullScreen failed, attempting VID_Restart\n"); Con_DPrintf ("SDL_WM_ToggleFullScreen failed, attempting VID_Restart\n");
vrestart: vrestart:
Cvar_SetQuick (&vid_fullscreen, draw_context-> flags & SDL_FULLSCREEN ? "0" : "1"); Cvar_SetQuick (&vid_fullscreen, VID_GetFullscreen() ? "0" : "1");
Cbuf_AddText ("vid_restart\n"); Cbuf_AddText ("vid_restart\n");
} }
} }
@ -1077,17 +1345,13 @@ VID_SyncCvars -- johnfitz -- set vid cvars to match current video mode
*/ */
void VID_SyncCvars (void) void VID_SyncCvars (void)
{ {
int swap_control;
if (draw_context) if (draw_context)
{ {
Cvar_SetValueQuick (&vid_width, draw_context->w); Cvar_SetValueQuick (&vid_width, VID_GetCurrentWidth());
Cvar_SetValueQuick (&vid_height, draw_context->h); Cvar_SetValueQuick (&vid_height, VID_GetCurrentHeight());
Cvar_SetValueQuick (&vid_bpp, draw_context->format->BitsPerPixel); Cvar_SetValueQuick (&vid_bpp, VID_GetCurrentBPP());
Cvar_SetQuick (&vid_fullscreen, draw_context->flags & SDL_FULLSCREEN ? "1" : "0"); Cvar_SetQuick (&vid_fullscreen, VID_GetFullscreen() ? "1" : "0");
Cvar_SetQuick (&vid_vsync, VID_GetVSync() ? "1" : "0");
if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == 0)
Cvar_SetQuick (&vid_vsync, (swap_control > 0)? "1" : "0");
} }
vid_changed = false; vid_changed = false;

View file

@ -22,7 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif
@ -74,6 +78,47 @@ static int FilterMouseEvents (const SDL_Event *event)
return 1; return 1;
} }
static int FilterMouseEvents_SDL2 (void *userdata, SDL_Event *event)
{
switch (event->type)
{
case SDL_MOUSEMOTION:
// case SDL_MOUSEBUTTONDOWN:
// case SDL_MOUSEBUTTONUP:
return 0;
}
return 1;
}
static void IN_BeginIgnoringMouseEvents()
{
#if defined(USE_SDL2)
SDL_EventFilter currentFilter = NULL;
void *currentUserdata = NULL;
SDL_GetEventFilter(&currentFilter, &currentUserdata);
if (currentFilter != FilterMouseEvents_SDL2)
SDL_SetEventFilter(FilterMouseEvents_SDL2, NULL);
#else
if (SDL_GetEventFilter() != FilterMouseEvents)
SDL_SetEventFilter(FilterMouseEvents);
#endif
}
static void IN_EndIgnoringMouseEvents()
{
#if defined(USE_SDL2)
SDL_EventFilter currentFilter;
void *currentUserdata;
if (SDL_GetEventFilter(&currentFilter, &currentUserdata) == SDL_TRUE)
SDL_SetEventFilter(NULL, NULL);
#else
if (SDL_GetEventFilter() != NULL)
SDL_SetEventFilter(NULL);
#endif
}
#ifdef MACOS_X_ACCELERATION_HACK #ifdef MACOS_X_ACCELERATION_HACK
static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE}; static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE};
static double originalMouseSpeed = -1.0; static double originalMouseSpeed = -1.0;
@ -155,6 +200,12 @@ void IN_Activate (void)
IN_DisableOSXMouseAccel(); IN_DisableOSXMouseAccel();
#endif #endif
#if defined(USE_SDL2)
if (SDL_SetRelativeMouseMode(SDL_TRUE) != 0)
{
Con_Printf("WARNING: SDL_SetRelativeMouseMode(SDL_TRUE) failed.\n");
}
#else
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON) if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
{ {
SDL_WM_GrabInput(SDL_GRAB_ON); SDL_WM_GrabInput(SDL_GRAB_ON);
@ -168,10 +219,10 @@ void IN_Activate (void)
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE) if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
Con_Printf("WARNING: SDL_ShowCursor(SDL_DISABLE) failed.\n"); Con_Printf("WARNING: SDL_ShowCursor(SDL_DISABLE) failed.\n");
} }
#endif
if (SDL_GetEventFilter() != NULL) IN_EndIgnoringMouseEvents();
SDL_SetEventFilter(NULL);
total_dx = 0; total_dx = 0;
total_dy = 0; total_dy = 0;
} }
@ -188,6 +239,9 @@ void IN_Deactivate (qboolean free_cursor)
if (free_cursor) if (free_cursor)
{ {
#if defined(USE_SDL2)
SDL_SetRelativeMouseMode(SDL_FALSE);
#else
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF) if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
{ {
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_OFF);
@ -201,25 +255,27 @@ void IN_Deactivate (qboolean free_cursor)
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE) if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
Con_Printf("WARNING: SDL_ShowCursor(SDL_ENABLE) failed.\n"); Con_Printf("WARNING: SDL_ShowCursor(SDL_ENABLE) failed.\n");
} }
#endif
} }
/* discard all mouse events when input is deactivated */ /* discard all mouse events when input is deactivated */
if (SDL_GetEventFilter() != FilterMouseEvents) IN_BeginIgnoringMouseEvents();
SDL_SetEventFilter(FilterMouseEvents);
} }
void IN_Init (void) void IN_Init (void)
{ {
prev_gamekey = ((key_dest == key_game && !con_forcedup) || m_keys_bind_grab); prev_gamekey = ((key_dest == key_game && !con_forcedup) || m_keys_bind_grab);
#if !defined(USE_SDL2)
SDL_EnableUNICODE (!prev_gamekey); SDL_EnableUNICODE (!prev_gamekey);
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1) if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n"); Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
#endif
if (safemode || COM_CheckParm("-nomouse")) if (safemode || COM_CheckParm("-nomouse"))
{ {
no_mouse = true; no_mouse = true;
/* discard all mouse events when input is deactivated */ /* discard all mouse events when input is deactivated */
SDL_SetEventFilter(FilterMouseEvents); IN_BeginIgnoringMouseEvents();
} }
#ifdef MACOS_X_ACCELERATION_HACK #ifdef MACOS_X_ACCELERATION_HACK
@ -307,10 +363,135 @@ void IN_UpdateForKeydest (void)
{ {
prev_gamekey = gamekey; prev_gamekey = gamekey;
Key_ClearStates(); Key_ClearStates();
#if !defined(USE_SDL2)
SDL_EnableUNICODE(!gamekey); SDL_EnableUNICODE(!gamekey);
#endif
} }
} }
#if defined(USE_SDL2)
static inline int IN_SDL2_ScancodeToQuakeKey(SDL_Scancode scancode)
{
switch (scancode)
{
case SDL_SCANCODE_TAB: return K_TAB;
case SDL_SCANCODE_RETURN: return K_ENTER;
case SDL_SCANCODE_RETURN2: return K_ENTER;
case SDL_SCANCODE_ESCAPE: return K_ESCAPE;
case SDL_SCANCODE_SPACE: return K_SPACE;
case SDL_SCANCODE_A: return 'a';
case SDL_SCANCODE_B: return 'b';
case SDL_SCANCODE_C: return 'c';
case SDL_SCANCODE_D: return 'd';
case SDL_SCANCODE_E: return 'e';
case SDL_SCANCODE_F: return 'f';
case SDL_SCANCODE_G: return 'g';
case SDL_SCANCODE_H: return 'h';
case SDL_SCANCODE_I: return 'i';
case SDL_SCANCODE_J: return 'j';
case SDL_SCANCODE_K: return 'k';
case SDL_SCANCODE_L: return 'l';
case SDL_SCANCODE_M: return 'm';
case SDL_SCANCODE_N: return 'n';
case SDL_SCANCODE_O: return 'o';
case SDL_SCANCODE_P: return 'p';
case SDL_SCANCODE_Q: return 'q';
case SDL_SCANCODE_R: return 'r';
case SDL_SCANCODE_S: return 's';
case SDL_SCANCODE_T: return 't';
case SDL_SCANCODE_U: return 'u';
case SDL_SCANCODE_V: return 'v';
case SDL_SCANCODE_W: return 'w';
case SDL_SCANCODE_X: return 'x';
case SDL_SCANCODE_Y: return 'y';
case SDL_SCANCODE_Z: return 'z';
case SDL_SCANCODE_1: return '1';
case SDL_SCANCODE_2: return '2';
case SDL_SCANCODE_3: return '3';
case SDL_SCANCODE_4: return '4';
case SDL_SCANCODE_5: return '5';
case SDL_SCANCODE_6: return '6';
case SDL_SCANCODE_7: return '7';
case SDL_SCANCODE_8: return '8';
case SDL_SCANCODE_9: return '9';
case SDL_SCANCODE_0: return '0';
case SDL_SCANCODE_MINUS: return '-';
case SDL_SCANCODE_EQUALS: return '=';
case SDL_SCANCODE_LEFTBRACKET: return '[';
case SDL_SCANCODE_RIGHTBRACKET: return ']';
case SDL_SCANCODE_BACKSLASH: return '\\';
case SDL_SCANCODE_NONUSHASH: return '#';
case SDL_SCANCODE_SEMICOLON: return ';';
case SDL_SCANCODE_APOSTROPHE: return '\'';
case SDL_SCANCODE_GRAVE: return '`';
case SDL_SCANCODE_COMMA: return ',';
case SDL_SCANCODE_PERIOD: return '.';
case SDL_SCANCODE_SLASH: return '/';
case SDL_SCANCODE_NONUSBACKSLASH: return '\\';
case SDL_SCANCODE_BACKSPACE: return K_BACKSPACE;
case SDL_SCANCODE_UP: return K_UPARROW;
case SDL_SCANCODE_DOWN: return K_DOWNARROW;
case SDL_SCANCODE_LEFT: return K_LEFTARROW;
case SDL_SCANCODE_RIGHT: return K_RIGHTARROW;
case SDL_SCANCODE_LALT: return K_ALT;
case SDL_SCANCODE_RALT: return K_ALT;
case SDL_SCANCODE_LCTRL: return K_CTRL;
case SDL_SCANCODE_RCTRL: return K_CTRL;
case SDL_SCANCODE_LSHIFT: return K_SHIFT;
case SDL_SCANCODE_RSHIFT: return K_SHIFT;
case SDL_SCANCODE_F1: return K_F1;
case SDL_SCANCODE_F2: return K_F2;
case SDL_SCANCODE_F3: return K_F3;
case SDL_SCANCODE_F4: return K_F4;
case SDL_SCANCODE_F5: return K_F5;
case SDL_SCANCODE_F6: return K_F6;
case SDL_SCANCODE_F7: return K_F7;
case SDL_SCANCODE_F8: return K_F8;
case SDL_SCANCODE_F9: return K_F9;
case SDL_SCANCODE_F10: return K_F10;
case SDL_SCANCODE_F11: return K_F11;
case SDL_SCANCODE_F12: return K_F12;
case SDL_SCANCODE_INSERT: return K_INS;
case SDL_SCANCODE_DELETE: return K_DEL;
case SDL_SCANCODE_PAGEDOWN: return K_PGDN;
case SDL_SCANCODE_PAGEUP: return K_PGUP;
case SDL_SCANCODE_HOME: return K_HOME;
case SDL_SCANCODE_END: return K_END;
case SDL_SCANCODE_NUMLOCKCLEAR: return K_KP_NUMLOCK;
case SDL_SCANCODE_KP_DIVIDE: return K_KP_SLASH;
case SDL_SCANCODE_KP_MULTIPLY: return K_KP_STAR;
case SDL_SCANCODE_KP_MINUS: return K_KP_MINUS;
case SDL_SCANCODE_KP_7: return K_KP_HOME;
case SDL_SCANCODE_KP_8: return K_KP_UPARROW;
case SDL_SCANCODE_KP_9: return K_KP_PGUP;
case SDL_SCANCODE_KP_PLUS: return K_KP_PLUS;
case SDL_SCANCODE_KP_4: return K_KP_LEFTARROW;
case SDL_SCANCODE_KP_5: return K_KP_5;
case SDL_SCANCODE_KP_6: return K_KP_RIGHTARROW;
case SDL_SCANCODE_KP_1: return K_KP_END;
case SDL_SCANCODE_KP_2: return K_KP_DOWNARROW;
case SDL_SCANCODE_KP_3: return K_KP_PGDN;
case SDL_SCANCODE_KP_ENTER: return K_KP_ENTER;
case SDL_SCANCODE_KP_0: return K_KP_INS;
case SDL_SCANCODE_KP_PERIOD: return K_KP_DEL;
case SDL_SCANCODE_LGUI: return K_COMMAND;
case SDL_SCANCODE_RGUI: return K_COMMAND;
case SDL_SCANCODE_PAUSE: return K_PAUSE;
default: return 0;
}
}
#endif
void IN_SendKeyEvents (void) void IN_SendKeyEvents (void)
{ {
SDL_Event event; SDL_Event event;
@ -320,6 +501,14 @@ void IN_SendKeyEvents (void)
{ {
switch (event.type) switch (event.type)
{ {
#if defined(USE_SDL2)
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
S_UnblockSound();
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
S_BlockSound();
break;
#else
case SDL_ACTIVEEVENT: case SDL_ACTIVEEVENT:
if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE)) if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE))
{ {
@ -329,7 +518,8 @@ void IN_SendKeyEvents (void)
} }
break; break;
case SDL_KEYDOWN: #endif
case SDL_KEYDOWN:
if ((event.key.keysym.sym == SDLK_RETURN) && if ((event.key.keysym.sym == SDLK_RETURN) &&
(event.key.keysym.mod & KMOD_ALT)) (event.key.keysym.mod & KMOD_ALT))
{ {
@ -344,10 +534,17 @@ void IN_SendKeyEvents (void)
} }
/* fallthrough */ /* fallthrough */
case SDL_KEYUP: case SDL_KEYUP:
#if defined(USE_SDL2)
sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode);
state = event.key.state;
modstate = SDL_GetModState();
Key_Event (sym, state);
#else
sym = event.key.keysym.sym; sym = event.key.keysym.sym;
state = event.key.state; state = event.key.state;
modstate = SDL_GetModState(); modstate = SDL_GetModState();
if (event.key.keysym.unicode != 0) if (event.key.keysym.unicode != 0)
{ {
if ((event.key.keysym.unicode & 0xFF80) == 0) if ((event.key.keysym.unicode & 0xFF80) == 0)
@ -570,6 +767,7 @@ void IN_SendKeyEvents (void)
break; break;
} }
Key_Event (sym, state); Key_Event (sym, state);
#endif
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@ -584,6 +782,21 @@ void IN_SendKeyEvents (void)
Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED); Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED);
break; break;
#if defined(USE_SDL2)
case SDL_MOUSEWHEEL:
if (event.wheel.y > 0)
{
Key_Event(K_MWHEELUP, false);
Key_Event(K_MWHEELUP, true);
}
else if (event.wheel.y < 0)
{
Key_Event(K_MWHEELDOWN, false);
Key_Event(K_MWHEELDOWN, true);
}
break;
#endif
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
IN_MouseMove(event.motion.xrel, event.motion.yrel); IN_MouseMove(event.motion.xrel, event.motion.yrel);
break; break;

View file

@ -21,13 +21,29 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "quakedef.h" #include "quakedef.h"
#include "arch_def.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
#if defined(USE_SDL2)
/* need at least SDL_2.0.0 */
#define SDL_MIN_X 2
#define SDL_MIN_Y 0
#define SDL_MIN_Z 0
#define SDL_REQUIREDVERSION (SDL_VERSIONNUM(SDL_MIN_X,SDL_MIN_Y,SDL_MIN_Z))
#define SDL_NEW_VERSION_REJECT (SDL_VERSIONNUM(6,6,6))
#else
/* need at least SDL_1.2.10 */ /* need at least SDL_1.2.10 */
#define SDL_MIN_X 1 #define SDL_MIN_X 1
#define SDL_MIN_Y 2 #define SDL_MIN_Y 2
@ -36,9 +52,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* reject 1.3.0 and newer at runtime. */ /* reject 1.3.0 and newer at runtime. */
#define SDL_NEW_VERSION_REJECT (SDL_VERSIONNUM(1,3,0)) #define SDL_NEW_VERSION_REJECT (SDL_VERSIONNUM(1,3,0))
#endif
static void Sys_CheckSDL (void) static void Sys_CheckSDL (void)
{ {
#if defined(USE_SDL2)
SDL_version v;
SDL_version *sdl_version = &v;
SDL_GetVersion(&v);
#else
const SDL_version *sdl_version = SDL_Linked_Version(); const SDL_version *sdl_version = SDL_Linked_Version();
#endif
Sys_Printf("Found SDL version %i.%i.%i\n",sdl_version->major,sdl_version->minor,sdl_version->patch); Sys_Printf("Found SDL version %i.%i.%i\n",sdl_version->major,sdl_version->minor,sdl_version->patch);
if (SDL_VERSIONNUM(sdl_version->major,sdl_version->minor,sdl_version->patch) < SDL_REQUIREDVERSION) if (SDL_VERSIONNUM(sdl_version->major,sdl_version->minor,sdl_version->patch) < SDL_REQUIREDVERSION)
@ -59,7 +83,11 @@ static void Sys_CheckSDL (void)
#endif #endif
static quakeparms_t parms; static quakeparms_t parms;
static Uint8 appState;
// FIXME: Not sure why this is necessary
#if defined(USE_SDL2) && defined(PLATFORM_OSX)
#define main SDL_main
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -128,14 +156,13 @@ int main(int argc, char *argv[])
else else
while (1) while (1)
{ {
appState = SDL_GetAppState();
/* If we have no input focus at all, sleep a bit */ /* If we have no input focus at all, sleep a bit */
if ( !(appState & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) || cl.paused) if ( !VID_HasMouseOrInputFocus() || cl.paused)
{ {
SDL_Delay(16); SDL_Delay(16);
} }
/* If we're minimised, sleep a bit more */ /* If we're minimised, sleep a bit more */
if ( !(appState & SDL_APPACTIVE) ) if ( !VID_GetWindowVisible() )
{ {
scr_skipupdate = 1; scr_skipupdate = 1;
SDL_Delay(32); SDL_Delay(32);

View file

@ -47,8 +47,13 @@ void PL_SetWindowIcon (void)
return; return;
/* make pure magenta (#ff00ff) tranparent */ /* make pure magenta (#ff00ff) tranparent */
colorkey = SDL_MapRGB(icon->format, 255, 0, 255); colorkey = SDL_MapRGB(icon->format, 255, 0, 255);
#if defined(USE_SDL2)
SDL_SetColorKey(icon, SDL_TRUE, colorkey);
SDL_SetWindowIcon(VID_GetWindow(), icon);
#else
SDL_SetColorKey(icon, SDL_SRCCOLORKEY, colorkey); SDL_SetColorKey(icon, SDL_SRCCOLORKEY, colorkey);
SDL_WM_SetIcon(icon, NULL); SDL_WM_SetIcon(icon, NULL);
#endif
SDL_FreeSurface(icon); SDL_FreeSurface(icon);
} }

View file

@ -22,7 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif

View file

@ -46,10 +46,17 @@ void PL_SetWindowIcon (void)
SDL_VERSION(&wminfo.version); SDL_VERSION(&wminfo.version);
#if defined(USE_SDL2)
if (SDL_GetWindowWMInfo(VID_GetWindow(), &wminfo) != SDL_TRUE)
return; /* wrong SDL version */
hwnd = wminfo.info.win.window;
#else
if (SDL_GetWMInfo(&wminfo) != 1) if (SDL_GetWMInfo(&wminfo) != 1)
return; /* wrong SDL version */ return; /* wrong SDL version */
hwnd = wminfo.window; hwnd = wminfo.window;
#endif
#ifdef _WIN64 #ifdef _WIN64
SetClassLongPtr(hwnd, GCLP_HICON, (LONG_PTR) icon); SetClassLongPtr(hwnd, GCLP_HICON, (LONG_PTR) icon);
#else #else

View file

@ -214,8 +214,13 @@ typedef struct
#include "platform.h" #include "platform.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <SDL/SDL_opengl.h> #include <SDL/SDL_opengl.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"

View file

@ -24,7 +24,11 @@
#include "quakedef.h" #include "quakedef.h"
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif
@ -150,8 +154,23 @@ qboolean SNDDMA_Init (dma_t *dma)
Con_Printf ("SDL audio spec : %d Hz, %d samples, %d channels\n", Con_Printf ("SDL audio spec : %d Hz, %d samples, %d channels\n",
obtained.freq, obtained.samples, obtained.channels); obtained.freq, obtained.samples, obtained.channels);
#if defined(USE_SDL2)
{
const char *drivername_temp = SDL_GetAudioDeviceName(0, SDL_FALSE);
if (drivername_temp == NULL)
{
strcpy(drivername, "(UNKNOWN)");
}
else
{
strncpy(drivername, drivername_temp, sizeof(drivername) - 1);
drivername[sizeof(drivername) - 1] = '\0';
}
}
#else
if (SDL_AudioDriverName(drivername, sizeof(drivername)) == NULL) if (SDL_AudioDriverName(drivername, sizeof(drivername)) == NULL)
strcpy(drivername, "(UNKNOWN)"); strcpy(drivername, "(UNKNOWN)");
#endif
buffersize = shm->samples * (shm->samplebits / 8); buffersize = shm->samples * (shm->samplebits / 8);
Con_Printf ("SDL audio driver: %s, %d bytes buffer\n", drivername, buffersize); Con_Printf ("SDL audio driver: %s, %d bytes buffer\n", drivername, buffersize);

View file

@ -31,7 +31,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <time.h> #include <time.h>
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif
#else #else
#include "SDL.h" #include "SDL.h"
#endif #endif

View file

@ -83,5 +83,9 @@ void VID_SyncCvars (void);
void VID_Toggle (void); void VID_Toggle (void);
qboolean VID_HasMouseOrInputFocus (void);
qboolean VID_GetWindowVisible (void);
void *VID_GetWindow (void);
#endif /* __VID_DEFS_H */ #endif /* __VID_DEFS_H */