]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
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)
committerRudolf Polzer <divverent@xonotic.org>
Wed, 18 Sep 2013 17:30:33 +0000 (19:30 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12006 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=e32c37df7da8febe7fd6d5c97159b3fb01c14717

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

index 9a23640177f038636f3b38109af6426bd6e656fa..0e828304f72e4e3777840e47a35077ee2d2d403b 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 901c8f716807cac95a2cbadad0e5b3583b3b01c5..7e8f3203c7177acacfcb96e689e1b117c5dc46fe 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 87559d36f19a980d4cf2b7f1336af3f9959087e5..bacbb5ffd4d23a47fa49765cc489711257aa097c 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 b9c72d46e5197ac6c0acb8eed348ab253681bcaf..69155d1e9c8897e8f1511b7cb47a4cc5c0715bab 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 166315892c591ac60ccbe5424eb5e0cd4c6da7a5..a53997796db5411147e9eefbad5dc3940048aa44 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 9fff961384005f85c53818c1a6a25c1f7214a9c7..c9600ce713fa23da753196dfa3e30f9e83949c95 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 fb21fad7db2ffae31036674e654891dbb44c2daa..be95856a44ae8188864a582b0652d95d64f93a9c 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;