gl_vidsdl.c: make VID_Init independent from modelist

git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@817 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
svdijk 2013-02-24 13:23:26 +00:00
parent fed26aabf1
commit 593b72da23

View file

@ -65,7 +65,6 @@ static SDL_Surface *draw_context;
static qboolean vid_locked = false; //johnfitz static qboolean vid_locked = false; //johnfitz
static qboolean vid_changed = false; static qboolean vid_changed = false;
static int vid_default = MS_WINDOWED;
static qboolean fullsbardraw = false; static qboolean fullsbardraw = false;
static void VID_Menu_Init (void); //johnfitz static void VID_Menu_Init (void); //johnfitz
@ -931,10 +930,9 @@ 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; const SDL_VideoInfo *info = SDL_GetVideoInfo();
int i, existingmode;
int width, height, bpp; int width, height, bpp;
int p; qboolean fullscreen;
const char *read_vars[] = { "vid_fullscreen", const char *read_vars[] = { "vid_fullscreen",
"vid_width", "vid_width",
"vid_height", "vid_height",
@ -952,7 +950,6 @@ void VID_Init (void)
Cvar_SetCallback (&vid_height, VID_Changed_f); Cvar_SetCallback (&vid_height, VID_Changed_f);
Cvar_SetCallback (&vid_bpp, VID_Changed_f); Cvar_SetCallback (&vid_bpp, VID_Changed_f);
Cvar_SetCallback (&vid_vsync, VID_Changed_f); Cvar_SetCallback (&vid_vsync, VID_Changed_f);
// Cvar_RegisterVariable (&vid_refreshrate); //johnfitz
Cmd_AddCommand ("vid_unlock", VID_Unlock); //johnfitz Cmd_AddCommand ("vid_unlock", VID_Unlock); //johnfitz
Cmd_AddCommand ("vid_restart", VID_Restart); //johnfitz Cmd_AddCommand ("vid_restart", VID_Restart); //johnfitz
@ -975,133 +972,64 @@ void VID_Init (void)
VID_InitDIB(); VID_InitDIB();
VID_InitFullDIB(); VID_InitFullDIB();
if (COM_CheckParm("-window") || COM_CheckParm("-w")) width = (int)vid_width.value;
{ height = (int)vid_height.value;
Cvar_SetQuick (&vid_fullscreen, "0"); bpp = (int)vid_bpp.value;
} fullscreen = (int)vid_fullscreen.value;
else if (COM_CheckParm("-fullscreen") || COM_CheckParm("-f"))
{
Cvar_SetQuick (&vid_fullscreen, "1");
}
if (!vid_fullscreen.value) if (COM_CheckParm("-current"))
{ {
vid_default = MS_WINDOWED; width = info->current_w;
height = info->current_h;
bpp = info->vfmt->BitsPerPixel;
fullscreen = true;
} }
else else
{ {
vid_default = MS_UNINIT; int p;
width = vid_width.value; p = COM_CheckParm("-width");
height = vid_height.value; if (p && p < com_argc-1)
bpp = vid_bpp.value;
if (COM_CheckParm("-current"))
{ {
info = SDL_GetVideoInfo(); width = Q_atoi(com_argv[p+1]);
width = info->current_w;
height = info->current_h;
bpp = info->vfmt->BitsPerPixel;
}
else
{
p = COM_CheckParm("-width");
if (p && p < com_argc-1)
{
width = Q_atoi(com_argv[p+1]);
if(!COM_CheckParm("-height")) if(!COM_CheckParm("-height"))
height = width * 3 / 4; height = width * 3 / 4;
}
p = COM_CheckParm("-height");
if (p && p < com_argc-1)
{
height = Q_atoi(com_argv[p+1]);
if(!COM_CheckParm("-width"))
width = height * 4 / 3;
}
p = COM_CheckParm("-bpp");
if (p && p < com_argc-1)
bpp = Q_atoi(com_argv[p+1]);
} }
// if they want to force it, add the specified mode to the list p = COM_CheckParm("-height");
if (COM_CheckParm("-force") && (nummodes < MAX_MODE_LIST)) if (p && p < com_argc-1)
{ {
modelist[nummodes].type = MS_FULLSCREEN; height = Q_atoi(com_argv[p+1]);
modelist[nummodes].width = width;
modelist[nummodes].height = height;
modelist[nummodes].fullscreen = 1;
modelist[nummodes].bpp = bpp;
for (i=nummodes, existingmode = 0 ; i<nummodes ; i++) if(!COM_CheckParm("-width"))
{ width = height * 4 / 3;
if ((modelist[nummodes].width == modelist[i].width) &&
(modelist[nummodes].height == modelist[i].height) &&
(modelist[nummodes].bpp == modelist[i].bpp))
{
existingmode = 1;
break;
}
}
if (!existingmode)
{
nummodes++;
}
} }
// Try to find a mode with matching width, height and bpp p = COM_CheckParm("-bpp");
if (vid_default == MS_UNINIT) if (p && p < com_argc-1)
{ bpp = Q_atoi(com_argv[p+1]);
for (i = 1; i < nummodes; i++)
{
if ((modelist[i].width == width) &&
(modelist[i].height == height) &&
(modelist[i].bpp == bpp))
{
vid_default = i;
break;
}
}
}
// Try to find a mode with matching width and height if (COM_CheckParm("-window") || COM_CheckParm("-w"))
if (vid_default == MS_UNINIT) fullscreen = false;
{ else if (COM_CheckParm("-fullscreen") || COM_CheckParm("-f"))
for (i = 1; i < nummodes; i++) fullscreen = true;
{ }
if ((modelist[i].width == width) &&
(modelist[i].height == height))
{
vid_default = i;
break;
}
}
}
// Try to find a mode with matching width if (!VID_ValidMode(width, height, bpp, fullscreen))
if (vid_default == MS_UNINIT) {
{ width = (int)vid_width.value;
for (i = 1; i < nummodes; i++) height = (int)vid_height.value;
{ bpp = (int)vid_bpp.value;
if (modelist[i].width == width) fullscreen = (int)vid_fullscreen.value;
{ }
vid_default = i;
break;
}
}
}
// Still no luck? Default to windowed mode if (!VID_ValidMode(width, height, bpp, fullscreen))
if (vid_default == MS_UNINIT) {
{ width = 640;
Cvar_SetQuick (&vid_fullscreen, "0"); height = 480;
vid_default = MS_WINDOWED; bpp = info->vfmt->BitsPerPixel;
} fullscreen = false;
} }
vid_initialized = true; vid_initialized = true;
@ -1114,10 +1042,7 @@ void VID_Init (void)
// set window icon // set window icon
PL_SetWindowIcon(); PL_SetWindowIcon();
VID_SetMode (modelist[vid_default].width, VID_SetMode (width, height, bpp, fullscreen);
modelist[vid_default].height,
modelist[vid_default].bpp,
modelist[vid_default].type == MS_FULLSCREEN);
GL_Init (); GL_Init ();
GL_SetupState (); GL_SetupState ();