mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Replace love.graphics.pop("all") with love.graphics.getStackDepth (resolves #1248 again)
The pop("all") api was a bit awkward, especially considering there's a
push("all") that does something else. I think any use case that benefited from
pop("all") benefits from getStackDepth just as much if not more. There is also
additional functionality, like being able to find the source of a mismatched
push/pop.
--HG--
branch : minor
This commit is contained in:
@@ -1288,6 +1288,11 @@ Graphics::Stats Graphics::getStats() const
|
|||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Graphics::getStackDepth() const
|
||||||
|
{
|
||||||
|
return stackTypeStack.size();
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::push(StackType type)
|
void Graphics::push(StackType type)
|
||||||
{
|
{
|
||||||
if (stackTypeStack.size() == MAX_USER_STACK_DEPTH)
|
if (stackTypeStack.size() == MAX_USER_STACK_DEPTH)
|
||||||
@@ -1303,30 +1308,25 @@ void Graphics::push(StackType type)
|
|||||||
stackTypeStack.push_back(type);
|
stackTypeStack.push_back(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::pop(PopMode mode)
|
void Graphics::pop()
|
||||||
{
|
{
|
||||||
size_t amount = mode == POP_ALL ? stackTypeStack.size() : 1;
|
if (stackTypeStack.size() < 1)
|
||||||
|
|
||||||
if (stackTypeStack.size() < amount)
|
|
||||||
throw Exception("Minimum stack depth reached (more pops than pushes?)");
|
throw Exception("Minimum stack depth reached (more pops than pushes?)");
|
||||||
|
|
||||||
for (size_t i = 0; i < amount; ++i)
|
popTransform();
|
||||||
|
pixelScaleStack.pop_back();
|
||||||
|
|
||||||
|
if (stackTypeStack.back() == STACK_ALL)
|
||||||
{
|
{
|
||||||
popTransform();
|
DisplayState &newstate = states[states.size() - 2];
|
||||||
pixelScaleStack.pop_back();
|
|
||||||
|
|
||||||
if (stackTypeStack.back() == STACK_ALL)
|
restoreStateChecked(newstate);
|
||||||
{
|
|
||||||
DisplayState &newstate = states[states.size() - 2];
|
|
||||||
|
|
||||||
restoreStateChecked(newstate);
|
// The last two states in the stack should be equal now.
|
||||||
|
states.pop_back();
|
||||||
// The last two states in the stack should be equal now.
|
|
||||||
states.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
stackTypeStack.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stackTypeStack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1520,16 +1520,6 @@ bool Graphics::getConstant(StackType in, const char *&out)
|
|||||||
return stackTypes.find(in, out);
|
return stackTypes.find(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graphics::getConstant(const char *in, PopMode &out)
|
|
||||||
{
|
|
||||||
return popModes.find(in, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Graphics::getConstant(PopMode in, const char *&out)
|
|
||||||
{
|
|
||||||
return popModes.find(in, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
||||||
{
|
{
|
||||||
{ "line", DRAW_LINE },
|
{ "line", DRAW_LINE },
|
||||||
@@ -1623,13 +1613,5 @@ StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM>::Entry Graphics::stackT
|
|||||||
|
|
||||||
StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM> Graphics::stackTypes(Graphics::stackTypeEntries, sizeof(Graphics::stackTypeEntries));
|
StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM> Graphics::stackTypes(Graphics::stackTypeEntries, sizeof(Graphics::stackTypeEntries));
|
||||||
|
|
||||||
StringMap<Graphics::PopMode, Graphics::POP_MAX_ENUM>::Entry Graphics::popModeEntries[] =
|
|
||||||
{
|
|
||||||
{ "one", POP_ONE },
|
|
||||||
{ "all", POP_ALL },
|
|
||||||
};
|
|
||||||
|
|
||||||
StringMap<Graphics::PopMode, Graphics::POP_MAX_ENUM> Graphics::popModes(Graphics::popModeEntries, sizeof(Graphics::popModeEntries));
|
|
||||||
|
|
||||||
} // graphics
|
} // graphics
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -194,13 +194,6 @@ public:
|
|||||||
STACK_MAX_ENUM
|
STACK_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum PopMode
|
|
||||||
{
|
|
||||||
POP_ONE,
|
|
||||||
POP_ALL,
|
|
||||||
POP_MAX_ENUM
|
|
||||||
};
|
|
||||||
|
|
||||||
enum TemporaryRenderTargetFlags
|
enum TemporaryRenderTargetFlags
|
||||||
{
|
{
|
||||||
TEMPORARY_RT_DEPTH = (1 << 0),
|
TEMPORARY_RT_DEPTH = (1 << 0),
|
||||||
@@ -741,8 +734,9 @@ public:
|
|||||||
**/
|
**/
|
||||||
Stats getStats() const;
|
Stats getStats() const;
|
||||||
|
|
||||||
|
size_t getStackDepth() const;
|
||||||
void push(StackType type = STACK_TRANSFORM);
|
void push(StackType type = STACK_TRANSFORM);
|
||||||
void pop(PopMode mode = POP_ONE);
|
void pop();
|
||||||
|
|
||||||
const Matrix4 &getTransform() const;
|
const Matrix4 &getTransform() const;
|
||||||
const Matrix4 &getProjection() const;
|
const Matrix4 &getProjection() const;
|
||||||
@@ -805,9 +799,6 @@ public:
|
|||||||
static bool getConstant(const char *in, StackType &out);
|
static bool getConstant(const char *in, StackType &out);
|
||||||
static bool getConstant(StackType in, const char *&out);
|
static bool getConstant(StackType in, const char *&out);
|
||||||
|
|
||||||
static bool getConstant(const char *in, PopMode &out);
|
|
||||||
static bool getConstant(PopMode in, const char *&out);
|
|
||||||
|
|
||||||
// Default shader code (a shader is always required internally.)
|
// Default shader code (a shader is always required internally.)
|
||||||
static Shader::ShaderSource defaultShaderCode[Shader::STANDARD_MAX_ENUM][Shader::LANGUAGE_MAX_ENUM][2];
|
static Shader::ShaderSource defaultShaderCode[Shader::STANDARD_MAX_ENUM][Shader::LANGUAGE_MAX_ENUM][2];
|
||||||
|
|
||||||
@@ -956,9 +947,6 @@ private:
|
|||||||
static StringMap<StackType, STACK_MAX_ENUM>::Entry stackTypeEntries[];
|
static StringMap<StackType, STACK_MAX_ENUM>::Entry stackTypeEntries[];
|
||||||
static StringMap<StackType, STACK_MAX_ENUM> stackTypes;
|
static StringMap<StackType, STACK_MAX_ENUM> stackTypes;
|
||||||
|
|
||||||
static StringMap<PopMode, POP_MAX_ENUM>::Entry popModeEntries[];
|
|
||||||
static StringMap<PopMode, POP_MAX_ENUM> popModes;
|
|
||||||
|
|
||||||
}; // Graphics
|
}; // Graphics
|
||||||
|
|
||||||
} // graphics
|
} // graphics
|
||||||
|
|||||||
@@ -2648,6 +2648,12 @@ int w_flushBatch(lua_State *)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_getStackDepth(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_pushnumber(L, instance()->getStackDepth());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_push(lua_State *L)
|
int w_push(lua_State *L)
|
||||||
{
|
{
|
||||||
Graphics::StackType stype = Graphics::STACK_TRANSFORM;
|
Graphics::StackType stype = Graphics::STACK_TRANSFORM;
|
||||||
@@ -2668,12 +2674,7 @@ int w_push(lua_State *L)
|
|||||||
|
|
||||||
int w_pop(lua_State *L)
|
int w_pop(lua_State *L)
|
||||||
{
|
{
|
||||||
Graphics::PopMode mode = Graphics::POP_ONE;
|
luax_catchexcept(L, [&](){ instance()->pop(); });
|
||||||
const char *modestring = lua_isnoneornil(L, 1) ? nullptr : luaL_checkstring(L, 1);
|
|
||||||
if (modestring && !Graphics::getConstant(modestring, mode))
|
|
||||||
return luaL_error(L, "Invalid pop mode: %s", modestring);
|
|
||||||
|
|
||||||
luax_catchexcept(L, [&](){ instance()->pop(mode); });
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2857,6 +2858,7 @@ static const luaL_Reg functions[] =
|
|||||||
|
|
||||||
{ "flushBatch", w_flushBatch },
|
{ "flushBatch", w_flushBatch },
|
||||||
|
|
||||||
|
{ "getStackDepth", w_getStackDepth },
|
||||||
{ "push", w_push },
|
{ "push", w_push },
|
||||||
{ "pop", w_pop },
|
{ "pop", w_pop },
|
||||||
{ "rotate", w_rotate },
|
{ "rotate", w_rotate },
|
||||||
|
|||||||
Reference in New Issue
Block a user