From: divverent Date: Wed, 18 Sep 2013 09:33:21 +0000 (+0000) Subject: vid_desktopfullscreen improvements; allow querying the desktop mode X-Git-Tag: xonotic-v0.8.0~131 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=db9522b47d3c0ff38f461c08dcae62035fb28faa;p=xonotic%2Fdarkplaces.git vid_desktopfullscreen improvements; allow querying the desktop mode git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12006 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=e32c37df7da8febe7fd6d5c97159b3fb01c14717 --- diff --git a/mvm_cmds.c b/mvm_cmds.c index 9a236401..0e828304 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -176,12 +176,28 @@ static void VM_M_getresolution(prvm_prog_t *prog) fs = ((prog->argc <= 1) || ((int)PRVM_G_FLOAT(OFS_PARM1))); - if(nr < 0 || nr >= (fs ? video_resolutions_count : video_resolutions_hardcoded_count)) + if(nr < -1 || nr >= (fs ? video_resolutions_count : video_resolutions_hardcoded_count)) { PRVM_G_VECTOR(OFS_RETURN)[0] = 0; PRVM_G_VECTOR(OFS_RETURN)[1] = 0; PRVM_G_VECTOR(OFS_RETURN)[2] = 0; } + else if(nr == -1) + { + vid_mode_t *m = VID_GetDesktopMode(); + if (m) + { + PRVM_G_VECTOR(OFS_RETURN)[0] = m->width; + PRVM_G_VECTOR(OFS_RETURN)[1] = m->height; + PRVM_G_VECTOR(OFS_RETURN)[2] = m->pixelheight_num / (prvm_vec_t) m->pixelheight_denom; + } + else + { + PRVM_G_VECTOR(OFS_RETURN)[0] = 0; + PRVM_G_VECTOR(OFS_RETURN)[1] = 0; + PRVM_G_VECTOR(OFS_RETURN)[2] = 0; + } + } else { video_resolution_t *r = &((fs ? video_resolutions : video_resolutions_hardcoded)[nr]); diff --git a/vid.h b/vid.h index 901c8f71..7e8f3203 100644 --- a/vid.h +++ b/vid.h @@ -299,6 +299,7 @@ typedef struct int pixelheight_num, pixelheight_denom; } vid_mode_t; +vid_mode_t *VID_GetDesktopMode(void); size_t VID_ListModes(vid_mode_t *modes, size_t maxcount); size_t VID_SortModes(vid_mode_t *modes, size_t count, qboolean usebpp, qboolean userefreshrate, qboolean useaspect); void VID_Soft_SharedSetup(void); diff --git a/vid_agl.c b/vid_agl.c index 87559d36..bacbb5ff 100644 --- a/vid_agl.c +++ b/vid_agl.c @@ -1158,6 +1158,11 @@ long GetDictionaryLong(CFDictionaryRef d, const void *key) return value; } +vid_mode_t *VID_GetDesktopMode(void) +{ + return NULL; // FIXME add desktopfullscreen +} + size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) { CGDirectDisplayID mainDisplay = CGMainDisplayID(); diff --git a/vid_glx.c b/vid_glx.c index b9c72d46..69155d1e 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -140,6 +140,7 @@ static qboolean vid_isvidmodefullscreen = false; static qboolean vid_isdesktopfullscreen = false; static qboolean vid_isoverrideredirect = false; +static vid_mode_t desktop_mode; static Visual *vidx11_visual; static Colormap vidx11_colormap; @@ -1051,6 +1052,13 @@ static qboolean VID_InitModeSoft(viddef_mode_t *mode) vidx11_screen = DefaultScreen(vidx11_display); root = RootWindow(vidx11_display, vidx11_screen); + desktop_mode.width = DisplayWidth(vidx11_display, vidx11_screen); + desktop_mode.height = DisplayHeight(vidx11_display, vidx11_screen); + desktop_mode.bpp = DefaultDepth(vidx11_display, vidx11_screen); + desktop_mode.refreshrate = 60; // FIXME + desktop_mode.pixelheight_num = 1; // FIXME + desktop_mode.pixelheight_denom = 1; // FIXME + // Get video mode list MajorVersion = MinorVersion = 0; if (!XF86VidModeQueryVersion(vidx11_display, &MajorVersion, &MinorVersion)) @@ -1367,6 +1375,13 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) vidx11_screen = DefaultScreen(vidx11_display); root = RootWindow(vidx11_display, vidx11_screen); + desktop_mode.width = DisplayWidth(vidx11_display, vidx11_screen); + desktop_mode.height = DisplayHeight(vidx11_display, vidx11_screen); + desktop_mode.bpp = DefaultDepth(vidx11_display, vidx11_screen); + desktop_mode.refreshrate = 60; // FIXME + desktop_mode.pixelheight_num = 1; // FIXME + desktop_mode.pixelheight_denom = 1; // FIXME + // Get video mode list MajorVersion = MinorVersion = 0; if (!XF86VidModeQueryVersion(vidx11_display, &MajorVersion, &MinorVersion)) @@ -1711,6 +1726,11 @@ void IN_Move (void) VID_ApplyJoyState(&joystate); } +vid_mode_t *VID_GetDesktopMode(void) +{ + return &desktop_mode; +} + size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) { if(vidmode_ext) diff --git a/vid_null.c b/vid_null.c index 16631589..a5399779 100644 --- a/vid_null.c +++ b/vid_null.c @@ -96,6 +96,11 @@ void IN_Move(void) { } +vid_mode_t *VID_GetDesktopMode(void) +{ + return NULL; +} + size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) { return 0; diff --git a/vid_sdl.c b/vid_sdl.c index 9fff9613..c9600ce7 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -91,6 +91,7 @@ static SDL_Window *window; static int window_flags; #endif static SDL_Surface *vid_softsurface; +static vid_mode_t desktop_mode; ///////////////////////// // Input handling @@ -2474,21 +2475,36 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) // Knghtbrd: should do platform-specific extension string function here vid_isfullscreen = false; - if (mode->fullscreen) { #if SDL_MAJOR_VERSION == 1 + { SDL_VideoInfo *vi = SDL_GetVideoInfo(); - mode->width = vi->current_w; - mode->height = vi->current_h; - mode->bitsperpixel = vi->vfmt->BitsPerPixel; - flags |= SDL_FULLSCREEN; + desktop_mode.width = vi->current_w; + desktop_mode.height = vi->current_h; + desktop_mode.bpp = vi->vfmt->BitsPerPixel; + desktop_mode.pixelheight_num = 1; + desktop_mode.pixelheight_denom = 1; // SDL does not provide this + if (mode->fullscreen) { + if (vid_desktopfullscreen.integer) + { + mode->width = vi->current_w; + mode->height = vi->current_h; + mode->bitsperpixel = vi->vfmt->BitsPerPixel; + } + flags |= SDL_FULLSCREEN; + vid_isfullscreen = true; + } + } #else - if (vid_desktopfullscreen.integer) - windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP; - else - windowflags |= SDL_WINDOW_FULLSCREEN; -#endif - vid_isfullscreen = true; + { + if (mode->fullscreen) { + if (vid_desktopfullscreen.integer) + windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + else + windowflags |= SDL_WINDOW_FULLSCREEN; + vid_isfullscreen = true; + } } +#endif //flags |= SDL_HWSURFACE; SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); @@ -2855,6 +2871,24 @@ void VID_Finish (void) } } +vid_mode_t *VID_GetDesktopMode(void) +{ +#if SDL_MAJOR_VERSION != 1 + SDL_DisplayMode mode; + int bpp; + Uint32 rmask, gmask, bmask, amask; + SDL_GetDesktopDisplayMode(0, &mode); + SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask); + modes[k].width = mode.w; + modes[k].height = mode.h; + modes[k].bpp = bpp; + modes[k].refreshrate = mode.refreshrate; + modes[k].pixelheight_num = 1; + modes[k].pixelheight_denom = 1; // SDL does not provide this +#endif + return &desktop_mode; +} + size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) { size_t k = 0; @@ -2886,9 +2920,9 @@ size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) continue; modes[k].width = mode.w; modes[k].height = mode.h; + // FIXME bpp? modes[k].refreshrate = mode.refresh_rate; modes[k].pixelheight_num = 1; - modes[k].pixelheight_num = 1; modes[k].pixelheight_denom = 1; // SDL does not provide this k++; } diff --git a/vid_wgl.c b/vid_wgl.c index fb21fad7..be95856a 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -126,6 +126,7 @@ static dllfunction_t wglpixelformatfuncs[] = }; static DEVMODE gdevmode, initialdevmode; +static vid_mode_t desktop_mode; static qboolean vid_initialized = false; static qboolean vid_wassuspended = false; static qboolean vid_usingmouse = false; @@ -866,6 +867,13 @@ void VID_Init(void) memset(&initialdevmode, 0, sizeof(initialdevmode)); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &initialdevmode); + desktop_mode.width = initialdevmode.dmPelsWidth; + desktop_mode.height = initialdevmode.dmPelsHeight; + desktop_mode.bpp = initialdevmode.dmBitsPerPel; + desktop_mode.refreshrate = initialdevmode.dmDisplayFrequency; + desktop_mode.pixelheight_num = 1; + desktop_mode.pixelheight_denom = 1; // Win32 apparently does not provide this (FIXME) + IN_Init(); } @@ -2293,6 +2301,11 @@ static void IN_Shutdown(void) #endif } +Vid_mode_t *VID_GetDesktopMode(void) +{ + return &desktop_mode; +} + size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) { int i;