mirror of
https://github.com/love2d/love.git
synced 2026-08-21 05:00:08 +02:00
Replace getCanvas/ImageFormats with getTextureFormats
This commit is contained in:
@@ -45,6 +45,16 @@ struct Optional
|
|||||||
value = val;
|
value = val;
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T get(T defaultVal)
|
||||||
|
{
|
||||||
|
return hasValue ? value : defaultVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
hasValue = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Optional<bool> OptionalBool;
|
typedef Optional<bool> OptionalBool;
|
||||||
|
|||||||
+18
-1
@@ -300,6 +300,23 @@ double luax_numberflag(lua_State *L, int table_index, const char *key, double de
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool luax_checkboolflag(lua_State *L, int table_index, const char *key)
|
||||||
|
{
|
||||||
|
lua_getfield(L, table_index, key);
|
||||||
|
|
||||||
|
bool retval = false;
|
||||||
|
if (lua_type(L, -1) != LUA_TBOOLEAN)
|
||||||
|
{
|
||||||
|
std::string err = "expected boolean field '" + std::string(key) + "' in table";
|
||||||
|
return luaL_argerror(L, table_index, err.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
retval = luax_toboolean(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
int luax_checkintflag(lua_State *L, int table_index, const char *key)
|
int luax_checkintflag(lua_State *L, int table_index, const char *key)
|
||||||
{
|
{
|
||||||
lua_getfield(L, table_index, key);
|
lua_getfield(L, table_index, key);
|
||||||
@@ -307,7 +324,7 @@ int luax_checkintflag(lua_State *L, int table_index, const char *key)
|
|||||||
int retval;
|
int retval;
|
||||||
if (!lua_isnumber(L, -1))
|
if (!lua_isnumber(L, -1))
|
||||||
{
|
{
|
||||||
std::string err = "expected integer field " + std::string(key) + " in table";
|
std::string err = "expected integer field '" + std::string(key) + "' in table";
|
||||||
return luaL_argerror(L, table_index, err.c_str());
|
return luaL_argerror(L, table_index, err.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ bool luax_boolflag(lua_State *L, int table_index, const char *key, bool defaultV
|
|||||||
int luax_intflag(lua_State *L, int table_index, const char *key, int defaultValue);
|
int luax_intflag(lua_State *L, int table_index, const char *key, int defaultValue);
|
||||||
double luax_numberflag(lua_State *L, int table_index, const char *key, double defaultValue);
|
double luax_numberflag(lua_State *L, int table_index, const char *key, double defaultValue);
|
||||||
|
|
||||||
|
bool luax_checkboolflag(lua_State *L, int table_index, const char *key);
|
||||||
int luax_checkintflag(lua_State *L, int table_index, const char *key);
|
int luax_checkintflag(lua_State *L, int table_index, const char *key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2371,6 +2371,45 @@ int w_getSupported(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_getTextureFormats(lua_State *L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
bool rt = luax_checkboolflag(L, 1, Texture::getConstant(Texture::SETTING_RENDER_TARGET));
|
||||||
|
bool linear = luax_boolflag(L, 1, Texture::getConstant(Texture::SETTING_LINEAR), false);
|
||||||
|
|
||||||
|
OptionalBool readable;
|
||||||
|
lua_getfield(L, 1, Texture::getConstant(Texture::SETTING_READABLE));
|
||||||
|
if (!lua_isnoneornil(L, -1))
|
||||||
|
readable.set(luax_checkboolean(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
if (lua_istable(L, 2))
|
||||||
|
lua_pushvalue(L, 2);
|
||||||
|
else
|
||||||
|
lua_createtable(L, 0, (int) PIXELFORMAT_MAX_ENUM);
|
||||||
|
|
||||||
|
for (int i = 0; i < (int) PIXELFORMAT_MAX_ENUM; i++)
|
||||||
|
{
|
||||||
|
PixelFormat format = (PixelFormat) i;
|
||||||
|
const char *name = nullptr;
|
||||||
|
|
||||||
|
if (format == PIXELFORMAT_UNKNOWN || !love::getConstant(format, name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (rt && isPixelFormatDepth(format))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool formatReadable = readable.get(!isPixelFormatDepthStencil(format));
|
||||||
|
bool sRGB = isGammaCorrect() && !linear;
|
||||||
|
|
||||||
|
luax_pushboolean(L, instance()->isPixelFormatSupported(format, rt, formatReadable, sRGB));
|
||||||
|
lua_setfield(L, -2, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int w__getFormats(lua_State *L, int idx, bool (*isFormatSupported)(PixelFormat), bool (*ignore)(PixelFormat))
|
static int w__getFormats(lua_State *L, int idx, bool (*isFormatSupported)(PixelFormat), bool (*ignore)(PixelFormat))
|
||||||
{
|
{
|
||||||
if (lua_istable(L, idx))
|
if (lua_istable(L, idx))
|
||||||
@@ -2395,6 +2434,8 @@ static int w__getFormats(lua_State *L, int idx, bool (*isFormatSupported)(PixelF
|
|||||||
|
|
||||||
int w_getCanvasFormats(lua_State *L)
|
int w_getCanvasFormats(lua_State *L)
|
||||||
{
|
{
|
||||||
|
luax_markdeprecated(L, "love.graphics.getCanvasFormats", API_FUNCTION, DEPRECATED_REPLACED, "love.graphics.getTextureFormats");
|
||||||
|
|
||||||
bool (*supported)(PixelFormat);
|
bool (*supported)(PixelFormat);
|
||||||
|
|
||||||
int idx = 1;
|
int idx = 1;
|
||||||
@@ -2430,6 +2471,8 @@ int w_getCanvasFormats(lua_State *L)
|
|||||||
|
|
||||||
int w_getImageFormats(lua_State *L)
|
int w_getImageFormats(lua_State *L)
|
||||||
{
|
{
|
||||||
|
luax_markdeprecated(L, "love.graphics.getImageFormats", API_FUNCTION, DEPRECATED_REPLACED, "love.graphics.getTextureFormats");
|
||||||
|
|
||||||
const auto supported = [](PixelFormat format) -> bool
|
const auto supported = [](PixelFormat format) -> bool
|
||||||
{
|
{
|
||||||
return instance()->isPixelFormatSupported(format, false, true, false);
|
return instance()->isPixelFormatSupported(format, false, true, false);
|
||||||
@@ -3181,8 +3224,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "_setDefaultShaderCode", w_setDefaultShaderCode },
|
{ "_setDefaultShaderCode", w_setDefaultShaderCode },
|
||||||
|
|
||||||
{ "getSupported", w_getSupported },
|
{ "getSupported", w_getSupported },
|
||||||
{ "getCanvasFormats", w_getCanvasFormats },
|
{ "getTextureFormats", w_getTextureFormats },
|
||||||
{ "getImageFormats", w_getImageFormats },
|
|
||||||
{ "getRendererInfo", w_getRendererInfo },
|
{ "getRendererInfo", w_getRendererInfo },
|
||||||
{ "getSystemLimits", w_getSystemLimits },
|
{ "getSystemLimits", w_getSystemLimits },
|
||||||
{ "getTextureTypes", w_getTextureTypes },
|
{ "getTextureTypes", w_getTextureTypes },
|
||||||
@@ -3247,6 +3289,8 @@ static const luaL_Reg functions[] =
|
|||||||
{ "newCubeImage", w_newCubeImage },
|
{ "newCubeImage", w_newCubeImage },
|
||||||
{ "setCanvas", w_setCanvas },
|
{ "setCanvas", w_setCanvas },
|
||||||
{ "getCanvas", w_getCanvas },
|
{ "getCanvas", w_getCanvas },
|
||||||
|
{ "getCanvasFormats", w_getCanvasFormats },
|
||||||
|
{ "getImageFormats", w_getImageFormats },
|
||||||
|
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user