extern int cl_available;
+typedef struct viddef_mode_s
+{
+ int width;
+ int height;
+ int bitsperpixel;
+ qboolean fullscreen;
+ float refreshrate;
+ qboolean userefreshrate;
+ qboolean stereobuffer;
+ int samples;
+}
+viddef_mode_t;
+
typedef struct viddef_s
{
// these are set by VID_Mode
+ viddef_mode_t mode;
int width;
int height;
int bitsperpixel;
// sets the mode; only used by the Quake engine for resetting to mode 0 (the
// base mode) on memory allocation failures
-int VID_InitMode(int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples);
+qboolean VID_InitMode(viddef_mode_t *mode);
// allocates and opens an appropriate OpenGL context (and its window)
static qboolean sound_active = true;
-static int scr_width, scr_height;
-
static cvar_t apple_multithreadedgl = {CVAR_SAVE, "apple_multithreadedgl", "1", "makes use of a second thread for the OpenGL driver (if possible) rather than using the engine thread (note: this is done automatically on most other operating systems)"};
static cvar_t apple_mouse_noaccel = {CVAR_SAVE, "apple_mouse_noaccel", "1", "disables mouse acceleration while DarkPlaces is active"};
return iohandle;
}
-void VID_GetWindowSize (int *x, int *y, int *width, int *height)
-{
- *x = *y = 0;
- *width = scr_width;
- *height = scr_height;
-}
-
void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
{
if (!mouse_avail || !window)
*attrib++ = AGL_NONE;
}
-int VID_InitMode(int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
{
- const EventTypeSpec winEvents[] =
+ const EventTypeSpec winEvents[] =
{
{ kEventClassWindow, kEventWindowClosed },
{ kEventClassWindow, kEventWindowCollapsing },
// Create the window, a bit towards the center of the screen
windowBounds.left = 100;
windowBounds.top = 100;
- windowBounds.right = *width + 100;
- windowBounds.bottom = *height + 100;
+ windowBounds.right = mode->width + 100;
+ windowBounds.bottom = mode->height + 100;
carbonError = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &windowBounds, &window);
if (carbonError != noErr || window == NULL)
{
GetEventTypeCount(winEvents), winEvents, window, NULL);
// Create the desired attribute list
- VID_BuildAGLAttrib(attributes, bpp == 32, fullscreen, stereobuffer, samples);
+ VID_BuildAGLAttrib(attributes, mode->bitsperpixel == 32, mode->fullscreen, mode->stereobuffer, mode->samples);
- if (!fullscreen)
+ if (!mode->fullscreen)
{
// Output to Window
pixelFormat = qaglChoosePixelFormat(NULL, 0, attributes);
// TOCHECK: not sure whether or not it's necessary to change the resolution
// "by hand", or if aglSetFullscreen does the job anyway
- refDisplayMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty(mainDisplay, bpp, *width, *height, refreshrate, kCGDisplayModeIsSafeForHardware, NULL);
+ refDisplayMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty(mainDisplay, mode->bitsperpixel, mode->width, mode->height, mode->refreshrate, kCGDisplayModeIsSafeForHardware, NULL);
CGDisplaySwitchToMode(mainDisplay, refDisplayMode);
DMGetGDeviceByDisplayID((DisplayIDType)mainDisplay, &gdhDisplay, false);
qaglDestroyPixelFormat(pixelFormat);
// Attempt fullscreen if requested
- if (fullscreen)
+ if (mode->fullscreen)
{
- qaglSetFullScreen (context, *width, *height, refreshrate, 0);
+ qaglSetFullScreen (context, mode->width, mode->height, mode->refreshrate, 0);
error = qaglGetError();
if (error != AGL_NO_ERROR)
{
}
}
- scr_width = *width;
- scr_height = *height;
+ memset(&vid.support, 0, sizeof(vid.support));
if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
Sys_Error("glGetString not found in %s", gl_driver);
gl_videosyncavailable = true;
multithreadedgl = false;
- vid_isfullscreen = fullscreen;
+ vid_isfullscreen = mode->fullscreen;
vid_usingmouse = false;
vid_usinghidecursor = false;
vid_hidden = false;
*attrib++ = None;
}
-int VID_InitMode(int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
{
int i;
int attrib[32];
return false;
}
- VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer, samples);
+ VID_BuildGLXAttrib(attrib, mode->bitsperpixel == 32, mode->stereobuffer, mode->samples);
visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
if (!visinfo)
{
return false;
}
- if (fullscreen)
+ if (mode->fullscreen)
{
if(vid_netwmfullscreen.integer)
{
for (i = 0; i < num_vidmodes; i++)
{
- if (*width > vidmodes[i]->hdisplay || *height > vidmodes[i]->vdisplay)
+ if (mode->width > vidmodes[i]->hdisplay || mode->height > vidmodes[i]->vdisplay)
continue;
- x = *width - vidmodes[i]->hdisplay;
- y = *height - vidmodes[i]->vdisplay;
+ x = mode->width - vidmodes[i]->hdisplay;
+ y = mode->height - vidmodes[i]->vdisplay;
dist = (x * x) + (y * y);
if (best_fit == -1 || dist < best_dist)
{
// LordHavoc: changed from ActualWidth/ActualHeight =,
// to width/height =, so the window will take the full area of
// the mode chosen
- *width = vidmodes[best_fit]->hdisplay;
- *height = vidmodes[best_fit]->vdisplay;
+ mode->width = vidmodes[best_fit]->hdisplay;
+ mode->height = vidmodes[best_fit]->vdisplay;
// change to the mode
XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[best_fit]);
// Move the viewport to top left
XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
- Con_DPrintf("Using XVidMode fullscreen mode at %dx%d\n", *width, *height);
+ Con_DPrintf("Using XVidMode fullscreen mode at %dx%d\n", mode->width, mode->height);
}
free(vidmodes);
// use the full desktop resolution
vid_isfullscreen = true;
// width and height will be filled in later
- *width = DisplayWidth(vidx11_display, vidx11_screen);
- *height = DisplayHeight(vidx11_display, vidx11_screen);
- Con_DPrintf("Using X11 fullscreen mode at %dx%d\n", *width, *height);
+ mode->width = DisplayWidth(vidx11_display, vidx11_screen);
+ mode->height = DisplayHeight(vidx11_display, vidx11_screen);
+ Con_DPrintf("Using X11 fullscreen mode at %dx%d\n", mode->width, mode->height);
}
}
vidx11_colormap = attr.colormap = XCreateColormap(vidx11_display, root, visinfo->visual, AllocNone);
attr.event_mask = X_MASK;
- if (fullscreen)
+ if (mode->fullscreen)
{
if(vid_isnetwmfullscreen)
{
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
}
- win = XCreateWindow(vidx11_display, root, 0, 0, *width, *height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
+ win = XCreateWindow(vidx11_display, root, 0, 0, mode->width, mode->height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
wmhints = XAllocWMHints();
if(XpmCreatePixmapFromData(vidx11_display, win,
szhints = XAllocSizeHints();
if(vid_resizable.integer == 0 && !vid_isnetwmfullscreen)
{
- szhints->min_width = szhints->max_width = *width;
- szhints->min_height = szhints->max_height = *height;
+ szhints->min_width = szhints->max_width = mode->width;
+ szhints->min_height = szhints->max_height = mode->height;
szhints->flags |= PMinSize | PMaxSize;
}
gl_platform = "GLX";
gl_platformextensions = qglXQueryExtensionsString(vidx11_display, vidx11_screen);
- gl_videosyncavailable = false;
-
// COMMANDLINEOPTION: Linux GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
// COMMANDLINEOPTION: BSD GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
// COMMANDLINEOPTION: MacOSX GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
InitSig(); // trap evil signals
}
-int VID_InitMode(int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
{
return false;
}
version->major, version->minor, version->patch );
}
-int VID_InitMode(int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
{
int i;
static int notfirstvideomode = false;
int flags = SDL_OPENGL;
const char *drivername;
- win_half_width = *width>>1;
- win_half_height = *height>>1;
+ win_half_width = mode->width>>1;
+ win_half_height = mode->height>>1;
if(vid_resizable.integer)
flags |= SDL_RESIZABLE;
// Knghtbrd: should do platform-specific extension string function here
vid_isfullscreen = false;
- if (fullscreen) {
+ if (mode->fullscreen) {
flags |= SDL_FULLSCREEN;
vid_isfullscreen = true;
}
//flags |= SDL_HWSURFACE;
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
- if (bpp >= 32)
+ if (mode->bitsperpixel >= 32)
{
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
}
- if (stereobuffer)
+ if (mode->stereobuffer)
SDL_GL_SetAttribute (SDL_GL_STEREO, 1);
if (vid_vsync.integer)
SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
else
SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 0);
- if (samples > 1)
+ if (mode->samples > 1)
{
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
- SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, samples);
+ SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, mode->samples);
}
- video_bpp = bpp;
+ video_bpp = mode->bitsperpixel;
video_flags = flags;
VID_SetIcon();
- screen = SDL_SetVideoMode(*width, *height, bpp, flags);
+ screen = SDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
if (screen == NULL)
{
- Con_Printf("Failed to set video mode to %ix%i: %s\n", *width, *height, SDL_GetError());
+ Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
VID_Shutdown();
return false;
}
void VID_CheckExtensions(void)
{
- gl_stencil = vid_bitsperpixel.integer == 32;
-
// VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
Cvar_SetQuick(&gl_info_extensions, "");
Cvar_RegisterVariable(&gl_finish);
Cmd_AddCommand("force_centerview", Force_CenterView_f, "recenters view (stops looking up/down)");
Cmd_AddCommand("vid_restart", VID_Restart_f, "restarts video system (closes and reopens the window, restarts renderer)");
- if (gamemode == GAME_GOODVSBAD2)
- Cvar_Set("gl_combine", "0");
}
-int VID_Mode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples)
+int VID_Mode(int fullscreen, int width, int height, int bpp, float refreshrate, int stereobuffer, int samples)
{
- int requestedWidth = width;
- int requestedHeight = height;
+ viddef_mode_t mode;
+ memset(&mode, 0, sizeof(mode));
+ mode.fullscreen = fullscreen;
+ mode.width = width;
+ mode.height = height;
+ mode.bitsperpixel = bpp;
+ mode.refreshrate = vid_userefreshrate.integer ? max(1, refreshrate) : 0;
+ mode.userefreshrate = vid_userefreshrate.integer;
+ mode.stereobuffer = stereobuffer;
+ mode.samples = samples;
cl_ignoremousemoves = 2;
- Con_Printf("Initializing Video Mode: %s %dx%dx%dx%dhz%s%s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, refreshrate, stereobuffer ? " stereo" : "", samples > 1 ? va(" (%ix AA)", samples) : "");
- if (VID_InitMode(fullscreen, &width, &height, bpp, vid_userefreshrate.integer ? max(1, refreshrate) : 0, stereobuffer, samples))
+ if (VID_InitMode(&mode))
{
- vid.fullscreen = fullscreen != 0;
- vid.width = width;
- vid.height = height;
- vid.bitsperpixel = bpp;
- vid.samples = samples;
- vid.refreshrate = refreshrate;
- vid.stereobuffer = stereobuffer != 0;
- vid.userefreshrate = vid_userefreshrate.integer != 0;
- Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
- Cvar_SetValueQuick(&vid_width, width);
- Cvar_SetValueQuick(&vid_height, height);
- Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
- Cvar_SetValueQuick(&vid_samples, samples);
+ // accept the (possibly modified) mode
+ vid.mode = mode;
+ vid.fullscreen = vid.mode.fullscreen;
+ vid.width = vid.mode.width;
+ vid.height = vid.mode.height;
+ vid.bitsperpixel = vid.mode.bitsperpixel;
+ vid.refreshrate = vid.mode.refreshrate;
+ vid.userefreshrate = vid.mode.userefreshrate;
+ vid.stereobuffer = vid.mode.stereobuffer;
+ vid.samples = vid.mode.samples;
+ gl_stencil = vid.mode.bitsperpixel > 16;
+ Con_Printf("Video Mode: %s %dx%dx%dx%.2fhz%s%s\n", mode.fullscreen ? "fullscreen" : "window", mode.width, mode.height, mode.bitsperpixel, mode.refreshrate, mode.stereobuffer ? " stereo" : "", mode.samples > 1 ? va(" (%ix AA)", mode.samples) : "");
+
+ Cvar_SetValueQuick(&vid_fullscreen, vid.mode.fullscreen);
+ Cvar_SetValueQuick(&vid_width, vid.mode.width);
+ Cvar_SetValueQuick(&vid_height, vid.mode.height);
+ Cvar_SetValueQuick(&vid_bitsperpixel, vid.mode.bitsperpixel);
+ Cvar_SetValueQuick(&vid_samples, vid.mode.samples);
if(vid_userefreshrate.integer)
- Cvar_SetValueQuick(&vid_refreshrate, refreshrate);
- Cvar_SetValueQuick(&vid_stereobuffer, stereobuffer);
-
- if(width != requestedWidth || height != requestedHeight)
- Con_Printf("Chose a similar video mode %dx%d instead of the requested mode %dx%d\n", width, height, requestedWidth, requestedHeight);
+ Cvar_SetValueQuick(&vid_refreshrate, vid.mode.refreshrate);
+ Cvar_SetValueQuick(&vid_stereobuffer, vid.mode.stereobuffer);
return true;
}
return;
Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp%s%s, to %s %dx%dx%dbpp%s%s.\n",
- vid.fullscreen ? "fullscreen" : "window", vid.width, vid.height, vid.bitsperpixel, vid.fullscreen && vid_userefreshrate.integer ? va("x%ihz", vid.refreshrate) : "", vid.samples > 1 ? va(" (%ix AA)", vid.samples) : "",
- vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_fullscreen.integer && vid_userefreshrate.integer ? va("x%ihz", vid_refreshrate.integer) : "", vid_samples.integer > 1 ? va(" (%ix AA)", vid_samples.integer) : "");
+ vid.mode.fullscreen ? "fullscreen" : "window", vid.mode.width, vid.mode.height, vid.mode.bitsperpixel, vid.mode.fullscreen && vid.mode.userefreshrate ? va("x%.2fhz", vid.mode.refreshrate) : "", vid.mode.samples > 1 ? va(" (%ix AA)", vid.mode.samples) : "",
+ vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_fullscreen.integer && vid_userefreshrate.integer ? va("x%.2fhz", vid_refreshrate.value) : "", vid_samples.integer > 1 ? va(" (%ix AA)", vid_samples.integer) : "");
VID_CloseSystems();
VID_Shutdown();
- if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.integer, vid_stereobuffer.integer, vid_samples.integer))
+ if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer))
{
Con_Print("Video mode change failed\n");
- if (!VID_Mode(vid.fullscreen, vid.width, vid.height, vid.bitsperpixel, vid.refreshrate, vid.stereobuffer, vid.samples))
+ if (!VID_Mode(vid.mode.fullscreen, vid.mode.width, vid.mode.height, vid.mode.bitsperpixel, vid.mode.refreshrate, vid.mode.stereobuffer, vid.mode.samples))
Sys_Error("Unable to restore to last working video mode");
}
VID_OpenSystems();
Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
}
- success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.integer, vid_stereobuffer.integer, vid_samples.integer);
+ success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer);
if (!success)
{
Con_Print("Desired video mode fail, trying fallbacks...\n");
for (i = 0;!success && vidfallbacks[i][0] != NULL;i++)
{
Cvar_Set(vidfallbacks[i][0], vidfallbacks[i][1]);
- success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.integer, vid_stereobuffer.integer, vid_samples.integer);
+ success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer);
}
if (!success)
Sys_Error("Video modes failed");
IN_Init();
}
-int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
{
int i;
HDC hdc;
float *af;
int attribs[128];
float attribsf[16];
+ int bpp = mode->bitsperpixel;
+ int width = mode->width;
+ int height = mode->height;
+ int refreshrate = (int)floor(mode->refreshrate+0.5);
+ int stereobuffer = mode->stereobuffer;
+ int samples = mode->samples;
+ int fullscreen = mode->fullscreen;
if (vid_initialized)
Sys_Error("VID_InitMode called when video is already initialised");
foundmode = true;
gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
gdevmode.dmBitsPerPel = bpp;
- gdevmode.dmPelsWidth = *width;
- gdevmode.dmPelsHeight = *height;
+ gdevmode.dmPelsWidth = width;
+ gdevmode.dmPelsHeight = height;
gdevmode.dmSize = sizeof (gdevmode);
if(refreshrate)
{
Con_Printf("wrong bpp\n");
continue;
}
- if(thismode.dmPelsWidth != (DWORD)*width)
+ if(thismode.dmPelsWidth != (DWORD)width)
{
if(developer.integer >= 100)
Con_Printf("wrong width\n");
continue;
}
- if(thismode.dmPelsHeight != (DWORD)*height)
+ if(thismode.dmPelsHeight != (DWORD)height)
{
if(developer.integer >= 100)
Con_Printf("wrong height\n");
if (!foundmode)
{
VID_Shutdown();
- Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", *width, *height, bpp);
+ Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp);
return false;
}
else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
VID_Shutdown();
- Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", *width, *height, bpp);
+ Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
return false;
}
rect.top = 0;
rect.left = 0;
- rect.right = *width;
- rect.bottom = *height;
+ rect.right = width;
+ rect.bottom = height;
AdjustWindowRectEx(&rect, WindowStyle, false, 0);
if (fullscreen)
// fix the leftover Alt from any Alt-Tab or the like that switched us away
ClearAllStates ();
- gl_videosyncavailable = false;
-
// COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control
gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);