Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorAlex Fraser <alex@phatcore.com>2012-01-02 16:25:14 +0400
committerAlex Fraser <alex@phatcore.com>2012-01-02 16:25:14 +0400
commitc2bb2857506a33ca12c4fbc08eee2ce5e2f73145 (patch)
tree8c362f824230919cb5abedd94f03a77ae4cd456a /intern
parent7d19ff14979e47c6f91eac892b2a3cd5b7108cec (diff)
Mode switching for GHOST under X11: adds the ability to change screen resolutions in the blenderplayer on GNU/Linux.
Code ported from Quake 2.
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/CMakeLists.txt7
-rw-r--r--intern/ghost/intern/GHOST_DisplayManagerX11.cpp76
2 files changed, 79 insertions, 4 deletions
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index a84ff5825a9..35b617e5452 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -234,6 +234,13 @@ elseif(UNIX)
)
endif()
+ if(WITH_X11_XF86VMODE)
+ add_definitions(-DWITH_X11_XF86VMODE)
+ list(APPEND INC_SYS
+ ${X11_xf86vmode_INCLUDE_PATH}
+ )
+ endif()
+
if(WITH_INPUT_NDOF)
list(APPEND SRC
intern/GHOST_NDOFManagerX11.cpp
diff --git a/intern/ghost/intern/GHOST_DisplayManagerX11.cpp b/intern/ghost/intern/GHOST_DisplayManagerX11.cpp
index 34f5fda2a16..411203b6475 100644
--- a/intern/ghost/intern/GHOST_DisplayManagerX11.cpp
+++ b/intern/ghost/intern/GHOST_DisplayManagerX11.cpp
@@ -20,7 +20,9 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): none yet.
+ * Video mode switching
+ * Copyright (C) 1997-2001 Id Software, Inc.
+ * Ported from Quake 2 by Alex Fraser <alex@phatcore.com>
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -29,6 +31,10 @@
* \ingroup GHOST
*/
+#ifdef WITH_X11_XF86VMODE
+# include <X11/Xlib.h>
+# include <X11/extensions/xf86vmode.h>
+#endif
#include "GHOST_DisplayManagerX11.h"
#include "GHOST_SystemX11.h"
@@ -112,12 +118,74 @@ setCurrentDisplaySetting(
GHOST_TUns8 display,
const GHOST_DisplaySetting& setting
){
- // This is never going to work robustly in X
- // but it's currently part of the full screen interface
+#ifdef WITH_X11_XF86VMODE
+ //
+ // Mode switching code ported from Quake 2:
+ // ftp://ftp.idsoftware.com/idstuff/source/q2source-3.21.zip
+ // See linux/gl_glx.c:GLimp_SetMode
+ //
+ int majorVersion, minorVersion;
+ XF86VidModeModeInfo **vidmodes;
+ Display *dpy = m_system->getXDisplay();
+ int scrnum, num_vidmodes;
+ int best_fit, best_dist, dist, x, y;
+
+ scrnum = DefaultScreen(dpy);
+
+ // Get video mode list
+ majorVersion = minorVersion = 0;
+ if (!XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion)) {
+ fprintf(stderr, "Error: XF86VidMode extension missing!\n");
+ return GHOST_kFailure;
+ }
+# ifdef _DEBUG
+ printf("Using XFree86-VidModeExtension Version %d.%d\n",
+ majorVersion, minorVersion);
+# endif
+
+ XF86VidModeGetAllModeLines(dpy, scrnum, &num_vidmodes, &vidmodes);
+
+ best_dist = 9999999;
+ best_fit = -1;
+
+ for (int i = 0; i < num_vidmodes; i++) {
+ if (setting.xPixels > vidmodes[i]->hdisplay ||
+ setting.yPixels > vidmodes[i]->vdisplay)
+ continue;
+
+ x = setting.xPixels - vidmodes[i]->hdisplay;
+ y = setting.yPixels - vidmodes[i]->vdisplay;
+ dist = (x * x) + (y * y);
+ if (dist < best_dist) {
+ best_dist = dist;
+ best_fit = i;
+ }
+ }
- // we fudge it for now.
+ if (best_fit != -1) {
+# ifdef _DEBUG
+ int actualWidth, actualHeight;
+ actualWidth = vidmodes[best_fit]->hdisplay;
+ actualHeight = vidmodes[best_fit]->vdisplay;
+ printf("Switching to video mode %dx%d\n",
+ actualWidth, actualHeight);
+# endif
+
+ // change to the mode
+ XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]);
+
+ // Move the viewport to top left
+ XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
+ } else
+ return GHOST_kFailure;
+
+ XFlush(dpy);
+ return GHOST_kSuccess;
+#else
+ // Just pretend the request was successful.
return GHOST_kSuccess;
+#endif
}