Browse Source

Add love.graphics.getMode, thanks Boolsheet (issue #254)

Bart van Strien 14 years ago
parent
commit
cc4f0e2661

+ 17 - 1
src/modules/graphics/opengl/Graphics.cpp

@@ -229,7 +229,10 @@ namespace opengl
 
 
 			// Don't fail because of this, but issue a warning.
 			// Don't fail because of this, but issue a warning.
 			if ( ! buffers || (samples != fsaa))
 			if ( ! buffers || (samples != fsaa))
+			{
 				std::cerr << "Warning, quality setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl;
 				std::cerr << "Warning, quality setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl;
+				fsaa = !buffers ? 0 : samples;
+			}
 		}
 		}
 
 
 		// Okay, setup OpenGL.
 		// Okay, setup OpenGL.
@@ -265,13 +268,17 @@ namespace opengl
 		// Set pixel row alignment
 		// Set pixel row alignment
 		glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
 		glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
 
 
+		// Get the actual vsync status
+		int real_vsync;
+		SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &real_vsync);
+
 		// Set the new display mode as the current display mode.
 		// Set the new display mode as the current display mode.
 		currentMode.width = width;
 		currentMode.width = width;
 		currentMode.height = height;
 		currentMode.height = height;
 		currentMode.colorDepth = 32;
 		currentMode.colorDepth = 32;
 		currentMode.fsaa = fsaa;
 		currentMode.fsaa = fsaa;
 		currentMode.fullscreen = fullscreen;
 		currentMode.fullscreen = fullscreen;
-		currentMode.vsync = vsync;
+		currentMode.vsync = real_vsync;
 
 
 		// Reload all volatile objects.
 		// Reload all volatile objects.
 		if(!Volatile::loadAll())
 		if(!Volatile::loadAll())
@@ -288,6 +295,15 @@ namespace opengl
 		return true;
 		return true;
 	}
 	}
 
 
+	void Graphics::getMode(int *width, int *height, bool *fullscreen, bool *vsync, int *fsaa)
+	{
+		*width = currentMode.width;
+		*height = currentMode.height;
+		*fullscreen = currentMode.fullscreen;
+		*vsync = currentMode.vsync;
+		*fsaa = currentMode.fsaa;
+	}
+
 	bool Graphics::toggleFullscreen()
 	bool Graphics::toggleFullscreen()
 	{
 	{
 		// Try to do the change.
 		// Try to do the change.

+ 10 - 0
src/modules/graphics/opengl/Graphics.h

@@ -151,6 +151,16 @@ namespace opengl
 		**/
 		**/
 		bool setMode(int width, int height, bool fullscreen, bool vsync, int fsaa);
 		bool setMode(int width, int height, bool fullscreen, bool vsync, int fsaa);
 
 
+		/**
+		* Gets the current display mode.
+		* @param width Pointer to an integer for the window width.
+		* @param height Pointer to an integer for the window height.
+		* @param fullscreen Pointer to a boolean for the fullscreen status.
+		* @param vsync Pointer to a boolean for the vsync status.
+		* @param fsaa Pointer to an integer for the current number of full scene anti-aliasing buffers.
+		**/
+		void getMode(int * width, int * height, bool * fullscreen, bool * vsync, int * fsaa);
+
 		/**
 		/**
 		* Toggles fullscreen. Note that this also needs to reload the
 		* Toggles fullscreen. Note that this also needs to reload the
 		* entire OpenGL context.
 		* entire OpenGL context.

+ 14 - 0
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -53,6 +53,19 @@ namespace opengl
 		return 1;
 		return 1;
 	}
 	}
 
 
+	int w_getMode(lua_State * L)
+	{
+		int w, h, fsaa;
+		bool fs, vsync;
+		instance->getMode(&w, &h, &fs, &vsync, &fsaa);
+		lua_pushnumber(L, w);
+		lua_pushnumber(L, h);
+		lua_pushboolean(L, fs);
+		lua_pushboolean(L, vsync);
+		lua_pushnumber(L, fsaa);
+		return 5;
+	}
+
 	int w_toggleFullscreen(lua_State * L)
 	int w_toggleFullscreen(lua_State * L)
 	{
 	{
 		luax_pushboolean(L, instance->toggleFullscreen());
 		luax_pushboolean(L, instance->toggleFullscreen());
@@ -1049,6 +1062,7 @@ namespace opengl
 	static const luaL_Reg functions[] = {
 	static const luaL_Reg functions[] = {
 		{ "checkMode", w_checkMode },
 		{ "checkMode", w_checkMode },
 		{ "setMode", w_setMode },
 		{ "setMode", w_setMode },
+		{ "getMode", w_getMode },
 		{ "toggleFullscreen", w_toggleFullscreen },
 		{ "toggleFullscreen", w_toggleFullscreen },
 		{ "reset", w_reset },
 		{ "reset", w_reset },
 		{ "clear", w_clear },
 		{ "clear", w_clear },

+ 2 - 1
src/modules/graphics/opengl/wrap_Graphics.h

@@ -38,6 +38,7 @@ namespace opengl
 {
 {
 	int w_checkMode(lua_State * L);
 	int w_checkMode(lua_State * L);
 	int w_setMode(lua_State * L);
 	int w_setMode(lua_State * L);
+	int w_getMode(lua_State * L);
 	int w_toggleFullscreen(lua_State * L);
 	int w_toggleFullscreen(lua_State * L);
 	int w_reset(lua_State * L);
 	int w_reset(lua_State * L);
 	int w_clear(lua_State * L);
 	int w_clear(lua_State * L);
@@ -59,7 +60,7 @@ namespace opengl
 	int w_newImageFont(lua_State * L);
 	int w_newImageFont(lua_State * L);
 	int w_newSpriteBatch(lua_State * L);
 	int w_newSpriteBatch(lua_State * L);
 	int w_newParticleSystem(lua_State * L);
 	int w_newParticleSystem(lua_State * L);
-	int w_newFramebuffer(lua_State * L); // commetns in function
+	int w_newFramebuffer(lua_State * L); // comments in function
 	int w_setColor(lua_State * L);
 	int w_setColor(lua_State * L);
 	int w_getColor(lua_State * L);
 	int w_getColor(lua_State * L);
 	int w_setBackgroundColor(lua_State * L);
 	int w_setBackgroundColor(lua_State * L);