From 40453f3c58be439a5bafff7b1916b93aa049a986 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 30 Nov 2005 15:03:08 +0000 Subject: [PATCH] implemented vid_refreshrate cvar to specify display refresh rate in windows added vid_minwidth/vid_minheight for use by menu, this lets a mod specify minimum acceptable resolution git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5854 d7cf8633-e32d-0410-b094-e92efae38249 --- vid.h | 7 ++++++- vid_agl.c | 4 +++- vid_glx.c | 5 ++++- vid_null.c | 4 +++- vid_sdl.c | 5 ++++- vid_shared.c | 27 ++++++++++++++++++--------- vid_wgl.c | 7 +++++-- 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/vid.h b/vid.h index 34cd729e..6943a854 100644 --- a/vid.h +++ b/vid.h @@ -31,6 +31,7 @@ typedef struct viddef_s int height; int bitsperpixel; int fullscreen; + int refreshrate; } viddef_t; // global video state @@ -42,13 +43,17 @@ extern qboolean vid_hidden; extern qboolean vid_activewindow; extern cvar_t vid_hardwaregammasupported; extern qboolean vid_usinghwgamma; +extern qboolean vid_supportrefreshrate; extern cvar_t vid_fullscreen; extern cvar_t vid_width; extern cvar_t vid_height; extern cvar_t vid_bitsperpixel; +extern cvar_t vid_refreshrate; extern cvar_t vid_vsync; extern cvar_t vid_mouse; +extern cvar_t vid_minwidth; +extern cvar_t vid_minheight; extern cvar_t gl_combine; extern cvar_t gl_finish; @@ -117,7 +122,7 @@ int VID_SetMode (int modenum); // 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 VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate); // allocates and opens an appropriate OpenGL context (and its window) diff --git a/vid_agl.c b/vid_agl.c index cbca607a..83de5e8d 100644 --- a/vid_agl.c +++ b/vid_agl.c @@ -31,6 +31,8 @@ // Tell startup code that we have a client int cl_available = true; +qboolean vid_supportrefreshrate = false; + // AGL prototypes AGLPixelFormat (*qaglChoosePixelFormat) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList); AGLContext (*qaglCreateContext) (AGLPixelFormat pix, AGLContext share); @@ -299,7 +301,7 @@ static void VID_BuildAGLAttrib(GLint *attrib, int stencil, qboolean fullscreen) *attrib++ = AGL_NONE; } -int VID_InitMode(int fullscreen, int width, int height, int bpp) +int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate) { const EventTypeSpec winEvents[] = { diff --git a/vid_glx.c b/vid_glx.c index cc503fda..8f477f3e 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -45,6 +45,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Tell startup code that we have a client int cl_available = true; +// note: if we used the XRandR extension we could support refresh rates +qboolean vid_supportrefreshrate = false; + //GLX prototypes XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList); GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); @@ -625,7 +628,7 @@ void VID_BuildGLXAttrib(int *attrib, int stencil) *attrib++ = None; } -int VID_InitMode(int fullscreen, int width, int height, int bpp) +int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate) { int i; int attrib[32]; diff --git a/vid_null.c b/vid_null.c index 2ce3321c..41be51fa 100644 --- a/vid_null.c +++ b/vid_null.c @@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int cl_available = false; +qboolean vid_supportrefreshrate = false; + void VID_Shutdown(void) { } @@ -68,7 +70,7 @@ void VID_Init(void) InitSig(); // trap evil signals } -int VID_InitMode(int fullscreen, int width, int height, int bpp) +int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate) { return false; } diff --git a/vid_sdl.c b/vid_sdl.c index 2580104f..e5c844e5 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Tell startup code that we have a client int cl_available = true; + +qboolean vid_supportrefreshrate = false; + static qboolean vid_usingmouse; static qboolean vid_isfullscreen; @@ -360,7 +363,7 @@ static void VID_OutputVersion() version->major, version->minor, version->patch ); } -int VID_InitMode(int fullscreen, int width, int height, int bpp) +int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate) { int i; int flags = SDL_OPENGL; diff --git a/vid_shared.c b/vid_shared.c index 75c7c2cc..b5cee081 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -73,9 +73,12 @@ cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"}; cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"}; cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"}; cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32"}; +cvar_t vid_refreshrate = {CVAR_SAVE, "vid_refreshrate", "60"}; cvar_t vid_vsync = {CVAR_SAVE, "vid_vsync", "0"}; cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"}; +cvar_t vid_minwidth = {0, "vid_minwidth", "0"}; +cvar_t vid_minheight = {0, "vid_minheight", "0"}; cvar_t gl_combine = {0, "gl_combine", "1"}; cvar_t gl_finish = {0, "gl_finish", "0"}; @@ -893,8 +896,11 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&vid_width); Cvar_RegisterVariable(&vid_height); Cvar_RegisterVariable(&vid_bitsperpixel); + Cvar_RegisterVariable(&vid_refreshrate); Cvar_RegisterVariable(&vid_vsync); Cvar_RegisterVariable(&vid_mouse); + Cvar_RegisterVariable(&vid_minwidth); + Cvar_RegisterVariable(&vid_minheight); Cvar_RegisterVariable(&gl_combine); Cvar_RegisterVariable(&gl_finish); Cmd_AddCommand("force_centerview", Force_CenterView_f); @@ -903,19 +909,21 @@ void VID_Shared_Init(void) Cvar_Set("gl_combine", "0"); } -int VID_Mode(int fullscreen, int width, int height, int bpp) +int VID_Mode(int fullscreen, int width, int height, int bpp, int refreshrate) { - Con_Printf("Video: %s %dx%dx%d\n", fullscreen ? "fullscreen" : "window", width, height, bpp); - if (VID_InitMode(fullscreen, width, height, bpp)) + Con_Printf("Video: %s %dx%dx%dx%dhz\n", fullscreen ? "fullscreen" : "window", width, height, bpp, refreshrate); + if (VID_InitMode(fullscreen, width, height, bpp, refreshrate)) { vid.fullscreen = fullscreen; vid.width = width; vid.height = height; vid.bitsperpixel = bpp; + vid.refreshrate = refreshrate; Cvar_SetValueQuick(&vid_fullscreen, fullscreen); Cvar_SetValueQuick(&vid_width, width); Cvar_SetValueQuick(&vid_height, height); Cvar_SetValueQuick(&vid_bitsperpixel, bpp); + Cvar_SetValueQuick(&vid_refreshrate, refreshrate); return true; } else @@ -947,10 +955,10 @@ void VID_Restart_f(void) vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer); VID_CloseSystems(); VID_Shutdown(); - if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.integer)) { Con_Print("Video mode change failed\n"); - if (!VID_Mode(vid.fullscreen, vid.width, vid.height, vid.bitsperpixel)) + if (!VID_Mode(vid.fullscreen, vid.width, vid.height, vid.bitsperpixel, vid.refreshrate)) Sys_Error("Unable to restore to last working video mode"); } VID_OpenSystems(); @@ -992,16 +1000,17 @@ void VID_Start(void) } Con_Print("Starting video system\n"); - success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer); + success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.integer); if (!success) { Con_Print("Desired video mode fail, trying fallbacks...\n"); + success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, 60); if (!success && vid_bitsperpixel.integer > 16) - success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, 16); + success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, 16, 60); if (!success && (vid_width.integer > 640 || vid_height.integer > 480)) - success = VID_Mode(vid_fullscreen.integer, 640, 480, 16); + success = VID_Mode(vid_fullscreen.integer, 640, 480, 16, 60); if (!success && vid_fullscreen.integer) - success = VID_Mode(false, 640, 480, 16); + success = VID_Mode(false, 640, 480, 16, 60); if (!success) Sys_Error("Video modes failed"); } diff --git a/vid_wgl.c b/vid_wgl.c index 8c118008..8cce143a 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -40,6 +40,8 @@ extern HINSTANCE global_hInstance; // Tell startup code that we have a client int cl_available = true; +qboolean vid_supportrefreshrate = true; + static int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *); static int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR); //static int (WINAPI *qwglGetPixelFormat)(HDC); @@ -723,7 +725,7 @@ void VID_Init(void) IN_Init(); } -int VID_InitMode (int fullscreen, int width, int height, int bpp) +int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate) { int i; HDC hdc; @@ -787,10 +789,11 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) vid_isfullscreen = false; if (fullscreen) { - gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; + gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; gdevmode.dmBitsPerPel = bpp; gdevmode.dmPelsWidth = width; gdevmode.dmPelsHeight = height; + gdevmode.dmDisplayFrequency = refreshrate; gdevmode.dmSize = sizeof (gdevmode); if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { -- 2.39.2