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

This commit is contained in:
Bart van Strien
2011-07-11 17:14:52 +02:00
parent 1f50a932dc
commit cc4f0e2661
4 changed files with 43 additions and 2 deletions
+17 -1
View File
@@ -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
View File
@@ -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.
@@ -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
View File
@@ -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);