From cc4f0e26615357e449481804318d66241319b692 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Mon, 11 Jul 2011 17:14:52 +0200 Subject: [PATCH] Add love.graphics.getMode, thanks Boolsheet (issue #254) --- src/modules/graphics/opengl/Graphics.cpp | 18 +++++++++++++++++- src/modules/graphics/opengl/Graphics.h | 10 ++++++++++ src/modules/graphics/opengl/wrap_Graphics.cpp | 14 ++++++++++++++ src/modules/graphics/opengl/wrap_Graphics.h | 3 ++- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index c131f6c6f..fc58f8d64 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -229,7 +229,10 @@ namespace opengl // Don't fail because of this, but issue a warning. if ( ! buffers || (samples != fsaa)) + { std::cerr << "Warning, quality setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl; + fsaa = !buffers ? 0 : samples; + } } // Okay, setup OpenGL. @@ -265,13 +268,17 @@ namespace opengl // Set pixel row alignment 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. currentMode.width = width; currentMode.height = height; currentMode.colorDepth = 32; currentMode.fsaa = fsaa; currentMode.fullscreen = fullscreen; - currentMode.vsync = vsync; + currentMode.vsync = real_vsync; // Reload all volatile objects. if(!Volatile::loadAll()) @@ -288,6 +295,15 @@ namespace opengl 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() { // Try to do the change. diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index cccd09a39..1c1de32f7 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -151,6 +151,16 @@ namespace opengl **/ 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 * entire OpenGL context. diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 47c23c8a4..8cf9f5270 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -53,6 +53,19 @@ namespace opengl 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) { luax_pushboolean(L, instance->toggleFullscreen()); @@ -1049,6 +1062,7 @@ namespace opengl static const luaL_Reg functions[] = { { "checkMode", w_checkMode }, { "setMode", w_setMode }, + { "getMode", w_getMode }, { "toggleFullscreen", w_toggleFullscreen }, { "reset", w_reset }, { "clear", w_clear }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index f2baf8c36..d01ce0055 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -38,6 +38,7 @@ namespace opengl { int w_checkMode(lua_State * L); int w_setMode(lua_State * L); + int w_getMode(lua_State * L); int w_toggleFullscreen(lua_State * L); int w_reset(lua_State * L); int w_clear(lua_State * L); @@ -59,7 +60,7 @@ namespace opengl int w_newImageFont(lua_State * L); int w_newSpriteBatch(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_getColor(lua_State * L); int w_setBackgroundColor(lua_State * L);