diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index fca3e50b3..c32c53e40 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -1288,6 +1288,11 @@ Graphics::Stats Graphics::getStats() const return stats; } +size_t Graphics::getStackDepth() const +{ + return stackTypeStack.size(); +} + void Graphics::push(StackType type) { if (stackTypeStack.size() == MAX_USER_STACK_DEPTH) @@ -1303,30 +1308,25 @@ void Graphics::push(StackType 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() < amount) + if (stackTypeStack.size() < 1) 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(); - pixelScaleStack.pop_back(); + DisplayState &newstate = states[states.size() - 2]; - if (stackTypeStack.back() == STACK_ALL) - { - DisplayState &newstate = states[states.size() - 2]; + restoreStateChecked(newstate); - restoreStateChecked(newstate); - - // The last two states in the stack should be equal now. - states.pop_back(); - } - - stackTypeStack.pop_back(); + // The last two states in the stack should be equal now. + states.pop_back(); } + + stackTypeStack.pop_back(); } /** @@ -1520,16 +1520,6 @@ bool Graphics::getConstant(StackType in, const char *&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::Entry Graphics::drawModeEntries[] = { { "line", DRAW_LINE }, @@ -1623,13 +1613,5 @@ StringMap::Entry Graphics::stackT StringMap Graphics::stackTypes(Graphics::stackTypeEntries, sizeof(Graphics::stackTypeEntries)); -StringMap::Entry Graphics::popModeEntries[] = -{ - { "one", POP_ONE }, - { "all", POP_ALL }, -}; - -StringMap Graphics::popModes(Graphics::popModeEntries, sizeof(Graphics::popModeEntries)); - } // graphics } // love diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index f824d2119..5a21917d8 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -194,13 +194,6 @@ public: STACK_MAX_ENUM }; - enum PopMode - { - POP_ONE, - POP_ALL, - POP_MAX_ENUM - }; - enum TemporaryRenderTargetFlags { TEMPORARY_RT_DEPTH = (1 << 0), @@ -741,8 +734,9 @@ public: **/ Stats getStats() const; + size_t getStackDepth() const; void push(StackType type = STACK_TRANSFORM); - void pop(PopMode mode = POP_ONE); + void pop(); const Matrix4 &getTransform() const; const Matrix4 &getProjection() const; @@ -805,9 +799,6 @@ public: static bool getConstant(const char *in, StackType &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.) static Shader::ShaderSource defaultShaderCode[Shader::STANDARD_MAX_ENUM][Shader::LANGUAGE_MAX_ENUM][2]; @@ -956,9 +947,6 @@ private: static StringMap::Entry stackTypeEntries[]; static StringMap stackTypes; - static StringMap::Entry popModeEntries[]; - static StringMap popModes; - }; // Graphics } // graphics diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 5ec7e1375..990c48b6c 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -2648,6 +2648,12 @@ int w_flushBatch(lua_State *) return 0; } +int w_getStackDepth(lua_State *L) +{ + lua_pushnumber(L, instance()->getStackDepth()); + return 1; +} + int w_push(lua_State *L) { Graphics::StackType stype = Graphics::STACK_TRANSFORM; @@ -2668,12 +2674,7 @@ int w_push(lua_State *L) int w_pop(lua_State *L) { - Graphics::PopMode mode = Graphics::POP_ONE; - 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); }); + luax_catchexcept(L, [&](){ instance()->pop(); }); return 0; } @@ -2857,6 +2858,7 @@ static const luaL_Reg functions[] = { "flushBatch", w_flushBatch }, + { "getStackDepth", w_getStackDepth }, { "push", w_push }, { "pop", w_pop }, { "rotate", w_rotate },