Added love.graphics.isActive. love.graphics function calls (and method calls on objects created via love.graphics) are only guaranteed to work when isActive is true, otherwise bad things might happen (the program crashing, for example.)

It's usually only false when the app is inactive on iOS, and when the window hasn't been created yet.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2015-02-17 02:24:09 -04:00
parent cafbf1ffbe
commit ac2b03e8a4
8 changed files with 78 additions and 6 deletions
+21
View File
@@ -49,6 +49,7 @@ Graphics::Graphics()
: width(0)
, height(0)
, created(false)
, active(true)
, writingToStencil(false)
{
gl = OpenGL();
@@ -322,6 +323,23 @@ void Graphics::unSetMode()
created = false;
}
void Graphics::setActive(bool enable)
{
// Make sure all pending OpenGL commands have fully executed before
// returning, if we're going from active to inactive.
if (isCreated() && this->active && !enable)
glFinish();
active = enable;
}
bool Graphics::isActive() const
{
// The graphics module is only completely 'active' if there's a window, a
// context, and the active variable is set.
return active && isCreated() && currentWindow && currentWindow->isCreated();
}
static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/)
{
// Human-readable strings for the debug info.
@@ -409,6 +427,9 @@ void Graphics::clear(ClearType type)
void Graphics::present()
{
if (!isActive())
return;
// Make sure we don't have a canvas active.
std::vector<StrongRef<Canvas>> canvases = states.back().canvases;
setCanvas();
+4
View File
@@ -68,6 +68,9 @@ public:
virtual bool setMode(int width, int height, bool &sRGB);
virtual void unSetMode();
virtual void setActive(bool active);
virtual bool isActive() const;
void setDebug(bool enable);
/**
@@ -470,6 +473,7 @@ private:
int width;
int height;
bool created;
bool active;
bool writingToStencil;
@@ -69,6 +69,12 @@ int w_isCreated(lua_State *L)
return 1;
}
int w_isActive(lua_State *L)
{
luax_pushboolean(L, instance()->isActive());
return 1;
}
int w_getWidth(lua_State *L)
{
lua_pushinteger(L, instance()->getWidth());
@@ -1510,6 +1516,7 @@ static const luaL_Reg functions[] =
{ "printf", w_printf },
{ "isCreated", w_isCreated },
{ "isActive", w_isActive },
{ "getWidth", w_getWidth },
{ "getHeight", w_getHeight },
{ "getDimensions", w_getDimensions },
@@ -44,6 +44,7 @@ int w_reset(lua_State *L);
int w_clear(lua_State *L);
int w_present(lua_State *L);
int w_isCreated(lua_State *L);
int w_isActive(lua_State *L);
int w_getWidth(lua_State *L);
int w_getHeight(lua_State *L);
int w_getDimensions(lua_State *L);