mirror of
https://github.com/love2d/love.git
synced 2026-08-17 02:58:31 +02:00
Add love.graphics.getMode, thanks Boolsheet (issue #254)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user