vid_desktopfullscreen improvements; allow querying the desktop mode
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 18 Sep 2013 09:33:21 +0000 (09:33 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 18 Sep 2013 09:33:21 +0000 (09:33 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12006 d7cf8633-e32d-0410-b094-e92efae38249

mvm_cmds.c
vid.h
vid_agl.c
vid_glx.c
vid_null.c
vid_sdl.c
vid_wgl.c

index 9a23640..0e82830 100644 (file)
@@ -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 901c8f7..7e8f320 100644 (file)
--- 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);
index 87559d3..bacbb5f 100644 (file)
--- 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();
index b9c72d4..69155d1 100644 (file)
--- 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)
index 1663158..a539977 100644 (file)
@@ -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;
index 9fff961..c9600ce 100644 (file)
--- 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++;
        }
index fb21fad..be95856 100644 (file)
--- 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;