[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43618] trunk/blender: Committing patch "[ #27676] Change window size/resolution in realtime" by me.

Mitchell Stokes mogurijin at gmail.com
Sun Jan 22 21:25:35 CET 2012


Revision: 43618
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43618
Author:   moguri
Date:     2012-01-22 20:25:25 +0000 (Sun, 22 Jan 2012)
Log Message:
-----------
Committing patch "[#27676] Change window size/resolution in realtime" by me.

Description:
This patch allows the user to change the size of the window (or the resolution in fullscreen mode) using the new bge.render.setWindowSize() method. This only works in the Blenderplayer since it doesn't make a whole lot of sense for the embedded player.

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/bge.render.rst
    trunk/blender/intern/ghost/GHOST_ISystem.h
    trunk/blender/intern/ghost/intern/GHOST_System.cpp
    trunk/blender/intern/ghost/intern/GHOST_System.h
    trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
    trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
    trunk/blender/source/gameengine/GamePlayer/common/GPC_Canvas.h
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Rasterizer/RAS_ICanvas.h

Modified: trunk/blender/doc/python_api/rst/bge.render.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.render.rst	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/doc/python_api/rst/bge.render.rst	2012-01-22 20:25:25 UTC (rev 43618)
@@ -77,6 +77,14 @@
    
    :rtype: integer
 
+.. function:: setWindowSize(width, height)
+
+   Set the width and height of the window (in pixels). This also works for fullscreen applications.
+   
+   :type width: integer
+   :type height: integer
+
+
 .. function:: makeScreenshot(filename)
 
    Writes a screenshot to the given filename.

Modified: trunk/blender/intern/ghost/GHOST_ISystem.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_ISystem.h	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/intern/ghost/GHOST_ISystem.h	2012-01-22 20:25:25 UTC (rev 43618)
@@ -271,6 +271,15 @@
 	 */
 	virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
 		const bool stereoVisual, const GHOST_TUns16 numOfAASamples=0) = 0;
+	
+	/**
+	 * Updates the resolution while in fullscreen mode.
+	 * @param setting	The new setting of the display.
+	 * @param window	Window displayed in full screen.
+	 *
+	 * @return	Indication of success.
+	 */
+	virtual GHOST_TSuccess updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window) = 0;
 
 	/**
 	 * Ends full screen mode.

Modified: trunk/blender/intern/ghost/intern/GHOST_System.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.cpp	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/intern/ghost/intern/GHOST_System.cpp	2012-01-22 20:25:25 UTC (rev 43618)
@@ -168,6 +168,19 @@
 }
 
 
+GHOST_TSuccess GHOST_System::updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window)
+{
+	GHOST_TSuccess success = GHOST_kFailure;
+	GHOST_ASSERT(m_windowManager, "GHOST_System::updateFullScreen(): invalid window manager");
+	if(m_displayManager) {
+		if (m_windowManager->getFullScreen()) {
+			success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, setting);
+		}
+	}
+
+	return success;
+}
+
 GHOST_TSuccess GHOST_System::endFullScreen(void)
 {
 	GHOST_TSuccess success = GHOST_kFailure;

Modified: trunk/blender/intern/ghost/intern/GHOST_System.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.h	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/intern/ghost/intern/GHOST_System.h	2012-01-22 20:25:25 UTC (rev 43618)
@@ -145,6 +145,15 @@
 	 */
 	virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
 		const bool stereoVisual, const GHOST_TUns16 numOfAASamples=0);
+		
+	/**
+	 * Updates the resolution while in fullscreen mode.
+	 * @param setting	The new setting of the display.
+	 * @param window	Window displayed in full screen.
+	 *
+	 * @return	Indication of success.
+	 */
+	virtual GHOST_TSuccess updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window);
 
 	/**
 	 * Ends full screen mode.

Modified: trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp	2012-01-22 20:25:25 UTC (rev 43618)
@@ -59,6 +59,11 @@
 	BL_SwapBuffers(m_win);
 }
 
+void KX_BlenderCanvas::ResizeWindow(int width, int height)
+{
+	// Not implemented for the embedded player
+}
+
 void KX_BlenderCanvas::BeginFrame()
 {
 	glEnable(GL_DEPTH_TEST);

Modified: trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h	2012-01-22 20:25:25 UTC (rev 43618)
@@ -78,7 +78,7 @@
 	SwapBuffers(
 	);
 		void 
-	Resize(
+	ResizeWindow(
 		int width,
 		int height
 	);

Modified: trunk/blender/source/gameengine/GamePlayer/common/GPC_Canvas.h
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/common/GPC_Canvas.h	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/GamePlayer/common/GPC_Canvas.h	2012-01-22 20:25:25 UTC (rev 43618)
@@ -103,6 +103,7 @@
 
 	void Resize(int width, int height);
 
+	virtual void ResizeWindow(int width, int height){};
 
 	/**
 	 * @section Methods inherited from abstract base class RAS_ICanvas.

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp	2012-01-22 20:25:25 UTC (rev 43618)
@@ -108,6 +108,26 @@
 	}
 }
 
+void GPG_Canvas::ResizeWindow(int width, int height)
+{
+	if (m_window->getState() == GHOST_kWindowStateFullScreen)
+	{
+		GHOST_ISystem* system = GHOST_ISystem::getSystem();
+		GHOST_DisplaySetting setting;
+		setting.xPixels = width;
+		setting.yPixels = height;
+		//XXX allow these to be changed or kept from previous state
+		setting.bpp = 32;
+		setting.frequency = 60;
+
+		system->updateFullScreen(setting, &m_window);
+	}
+
+	m_window->setClientSize(width, height);
+
+	Resize(width, height);
+}
+
 float GPG_Canvas::GetMouseNormalizedX(int x)
 {
 	return float(x)/this->GetWidth();

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.h
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.h	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Canvas.h	2012-01-22 20:25:25 UTC (rev 43618)
@@ -60,6 +60,8 @@
 	virtual float GetMouseNormalizedX(int x);
 	virtual float GetMouseNormalizedY(int y);
 
+	virtual void ResizeWindow(int width, int height);
+
 	bool BeginDraw() { return true;};
 	void EndDraw() {};
 };

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2012-01-22 20:25:25 UTC (rev 43618)
@@ -1288,6 +1288,16 @@
 	Py_RETURN_NONE;
 }
 
+static PyObject* gPySetWindowSize(PyObject*, PyObject* args)
+{
+	int width, height;
+	if (!PyArg_ParseTuple(args, "ii:resize", &width, &height))
+		return NULL;
+
+	gp_Canvas->ResizeWindow(width, height);
+	Py_RETURN_NONE;
+}
+
 static struct PyMethodDef rasterizer_methods[] = {
   {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
    METH_VARARGS, "getWindowWidth doc"},
@@ -1329,6 +1339,7 @@
   METH_VARARGS, "get the anisotropic filtering level"},
   {"drawLine", (PyCFunction) gPyDrawLine,
    METH_VARARGS, "draw a line on the screen"},
+  {"setWindowSize", (PyCFunction) gPySetWindowSize, METH_VARARGS, ""},
   { NULL, (PyCFunction) NULL, 0, NULL }
 };
 

Modified: trunk/blender/source/gameengine/Rasterizer/RAS_ICanvas.h
===================================================================
--- trunk/blender/source/gameengine/Rasterizer/RAS_ICanvas.h	2012-01-22 20:15:05 UTC (rev 43617)
+++ trunk/blender/source/gameengine/Rasterizer/RAS_ICanvas.h	2012-01-22 20:25:25 UTC (rev 43618)
@@ -205,6 +205,15 @@
 	MakeScreenShot(
 		const char* filename
 	)=0;
+
+	virtual
+		void 
+	ResizeWindow(
+		int width,
+		int height
+	)=0;
+
+		
 	
 protected:
 	RAS_MouseState m_mousestate;




More information about the Bf-blender-cvs mailing list