Move current love.graphics.setStencilMode functionality to setStencilState.

Add new higher level love.graphics.setStencilMode function.
- Add love.graphics.setStencilMode(mode [, value = 1])
- Add love.graphics.setStencilMode().
- Add mode, value = love.graphics.getStencilMode().

The possible modes are "off" (same as no parameters), "draw", and "test".
The "draw" mode disables color writes and sets the stencil state to ("replace", "always") using the given value.
The "test" mode enables color writes and sets the stencil state to ("keep", "equal") using the given value to compare to.
This commit is contained in:
Sasha Szpakowski
2024-01-04 16:23:49 -04:00
parent 77c5ea1d6b
commit 9b5851e039
15 changed files with 166 additions and 46 deletions
+40 -5
View File
@@ -608,7 +608,40 @@ int w_setStencilMode(lua_State *L)
{
if (lua_gettop(L) <= 1 && lua_isnoneornil(L, 1))
{
luax_catchexcept(L, [&](){ instance()->setStencilMode(); });
luax_catchexcept(L, [&]() { instance()->setStencilMode(); });
return 0;
}
StencilMode mode = STENCIL_MODE_OFF;
const char *modestr = luaL_checkstring(L, 1);
if (!getConstant(modestr, mode))
return luax_enumerror(L, "stencil mode", getConstants(mode), modestr);
int value = (int) luaL_optinteger(L, 3, 1);
luax_catchexcept(L, [&]() { instance()->setStencilMode(mode, value); });
return 0;
}
int w_getStencilMode(lua_State *L)
{
int value = 0;
StencilMode mode = instance()->getStencilMode(value);
const char *modestr;
if (!getConstant(mode, modestr))
return luaL_error(L, "Unknown stencil mode.");
lua_pushstring(L, modestr);
lua_pushinteger(L, value);
return 2;
}
int w_setStencilState(lua_State *L)
{
if (lua_gettop(L) <= 1 && lua_isnoneornil(L, 1))
{
luax_catchexcept(L, [&](){ instance()->setStencilState(); });
return 0;
}
@@ -627,11 +660,11 @@ int w_setStencilMode(lua_State *L)
uint32 readmask = (uint32) luaL_optnumber(L, 4, LOVE_UINT32_MAX);
uint32 writemask = (uint32) luaL_optnumber(L, 5, LOVE_UINT32_MAX);
luax_catchexcept(L, [&](){ instance()->setStencilMode(action, compare, value, readmask, writemask); });
luax_catchexcept(L, [&](){ instance()->setStencilState(action, compare, value, readmask, writemask); });
return 0;
}
int w_getStencilMode(lua_State *L)
int w_getStencilState(lua_State *L)
{
StencilAction action = STENCIL_KEEP;
CompareMode compare = COMPARE_ALWAYS;
@@ -639,7 +672,7 @@ int w_getStencilMode(lua_State *L)
uint32 readmask = LOVE_UINT32_MAX;
uint32 writemask = LOVE_UINT32_MAX;
instance()->getStencilMode(action, compare, value, readmask, writemask);
instance()->getStencilState(action, compare, value, readmask, writemask);
const char *actionstr;
if (!getConstant(action, actionstr))
@@ -651,7 +684,7 @@ int w_getStencilMode(lua_State *L)
lua_pushstring(L, actionstr);
lua_pushstring(L, comparestr);
lua_pushnumber(L, value);
lua_pushinteger(L, value);
lua_pushnumber(L, readmask);
lua_pushnumber(L, writemask);
return 5;
@@ -3936,6 +3969,8 @@ static const luaL_Reg functions[] =
{ "setStencilMode", w_setStencilMode },
{ "getStencilMode", w_getStencilMode },
{ "setStencilState", w_setStencilState },
{ "getStencilState", w_getStencilState },
{ "points", w_points },
{ "line", w_line },