mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
vertex format table in newMesh uses the same fields as newBuffer.
Deprecate (but don't remove) the old {name, type, elementcount} vertex format style. The new style is {name=attributename, format=dataformat}.
This commit is contained in:
@@ -114,8 +114,6 @@ std::string getDeprecationNotice(const DeprecationInfo &info, bool usewhere)
|
|||||||
notice += "field ";
|
notice += "field ";
|
||||||
else if (info.apiType == API_CONSTANT)
|
else if (info.apiType == API_CONSTANT)
|
||||||
notice += "constant ";
|
notice += "constant ";
|
||||||
else
|
|
||||||
notice += "API ";
|
|
||||||
|
|
||||||
notice += info.name;
|
notice += info.name;
|
||||||
|
|
||||||
@@ -193,6 +191,7 @@ STRINGMAP_BEGIN(APIType, API_MAX_ENUM, apiType)
|
|||||||
{ "callback", API_CALLBACK },
|
{ "callback", API_CALLBACK },
|
||||||
{ "field", API_FIELD },
|
{ "field", API_FIELD },
|
||||||
{ "constant", API_CONSTANT },
|
{ "constant", API_CONSTANT },
|
||||||
|
{ "custom", API_CUSTOM },
|
||||||
}
|
}
|
||||||
STRINGMAP_END(APIType, API_MAX_ENUM, apiType)
|
STRINGMAP_END(APIType, API_MAX_ENUM, apiType)
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ enum APIType
|
|||||||
API_CALLBACK,
|
API_CALLBACK,
|
||||||
API_FIELD,
|
API_FIELD,
|
||||||
API_CONSTANT,
|
API_CONSTANT,
|
||||||
|
API_CUSTOM,
|
||||||
API_MAX_ENUM
|
API_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1538,6 +1538,44 @@ static void luax_optbuffersettings(lua_State *L, int idx, Buffer::Settings &sett
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Buffer::DataDeclaration luax_checkdatadeclaration(lua_State* L, int formattableidx, int arrayindex, int declindex, bool requirename)
|
||||||
|
{
|
||||||
|
Buffer::DataDeclaration decl("", DATAFORMAT_MAX_ENUM);
|
||||||
|
|
||||||
|
lua_getfield(L, declindex, "name");
|
||||||
|
if (requirename && lua_type(L, -1) != LUA_TSTRING)
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "'name' field expected in array element #";
|
||||||
|
ss << arrayindex;
|
||||||
|
ss << " of format table";
|
||||||
|
std::string str = ss.str();
|
||||||
|
luaL_argerror(L, formattableidx, str.c_str());
|
||||||
|
}
|
||||||
|
else if (!lua_isnoneornil(L, -1))
|
||||||
|
decl.name = luax_checkstring(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
lua_getfield(L, declindex, "format");
|
||||||
|
if (lua_type(L, -1) != LUA_TSTRING)
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "'format' field expected in array element #";
|
||||||
|
ss << arrayindex;
|
||||||
|
ss << " of format table";
|
||||||
|
std::string str = ss.str();
|
||||||
|
luaL_argerror(L, formattableidx, str.c_str());
|
||||||
|
}
|
||||||
|
const char* formatstr = luaL_checkstring(L, -1);
|
||||||
|
if (!getConstant(formatstr, decl.format))
|
||||||
|
luax_enumerror(L, "data format", getConstants(decl.format), formatstr);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
decl.arrayLength = luax_intflag(L, declindex, "arraylength", 0);
|
||||||
|
|
||||||
|
return decl;
|
||||||
|
}
|
||||||
|
|
||||||
static void luax_checkbufferformat(lua_State *L, int idx, std::vector<Buffer::DataDeclaration> &format)
|
static void luax_checkbufferformat(lua_State *L, int idx, std::vector<Buffer::DataDeclaration> &format)
|
||||||
{
|
{
|
||||||
if (lua_type(L, idx) == LUA_TSTRING)
|
if (lua_type(L, idx) == LUA_TSTRING)
|
||||||
@@ -1558,29 +1596,7 @@ static void luax_checkbufferformat(lua_State *L, int idx, std::vector<Buffer::Da
|
|||||||
lua_rawgeti(L, idx, i);
|
lua_rawgeti(L, idx, i);
|
||||||
luaL_checktype(L, -1, LUA_TTABLE);
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
|
|
||||||
Buffer::DataDeclaration decl("", DATAFORMAT_MAX_ENUM);
|
Buffer::DataDeclaration decl = luax_checkdatadeclaration(L, idx, i, -1, false);
|
||||||
|
|
||||||
lua_getfield(L, -1, "name");
|
|
||||||
if (!lua_isnoneornil(L, -1))
|
|
||||||
decl.name = luax_checkstring(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
lua_getfield(L, -1, "format");
|
|
||||||
if (lua_type(L, -1) != LUA_TSTRING)
|
|
||||||
{
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << "'format' field expected in array element #";
|
|
||||||
ss << i;
|
|
||||||
ss << " of format table";
|
|
||||||
std::string str = ss.str();
|
|
||||||
luaL_argerror(L, idx, str.c_str());
|
|
||||||
}
|
|
||||||
const char *formatstr = luaL_checkstring(L, -1);
|
|
||||||
if (!getConstant(formatstr, decl.format))
|
|
||||||
luax_enumerror(L, "data format", getConstants(decl.format), formatstr);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
decl.arrayLength = luax_intflag(L, -1, "arraylength", 0);
|
|
||||||
|
|
||||||
format.push_back(decl);
|
format.push_back(decl);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
@@ -1899,38 +1915,43 @@ static Mesh *newCustomMesh(lua_State *L)
|
|||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
// Per-vertex attribute formats.
|
// Per-vertex attribute data formats.
|
||||||
for (int i = 1; i <= (int) luax_objlen(L, 1); i++)
|
for (int i = 1; i <= (int) luax_objlen(L, 1); i++)
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, 1, i);
|
lua_rawgeti(L, 1, i);
|
||||||
|
|
||||||
// {name, datatype, components}
|
Buffer::DataDeclaration decl("", DATAFORMAT_MAX_ENUM);
|
||||||
for (int j = 1; j <= 3; j++)
|
|
||||||
lua_rawgeti(L, -j, j);
|
|
||||||
|
|
||||||
const char *name = luaL_checkstring(L, -3);
|
lua_getfield(L, -1, "format");
|
||||||
|
bool hasformatfield = !lua_isnoneornil(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
DataFormat format = DATAFORMAT_MAX_ENUM;
|
if (hasformatfield || luax_objlen(L, -1) == 0)
|
||||||
const char *tname = luaL_checkstring(L, -2);
|
decl = luax_checkdatadeclaration(L, 1, i, -1, true);
|
||||||
|
else
|
||||||
if (!lua_isnoneornil(L, -1))
|
|
||||||
{
|
{
|
||||||
int components = (int) luaL_checkinteger(L, -1);
|
// Legacy format arguments: {name, datatype, components}
|
||||||
|
for (int j = 1; j <= 3; j++)
|
||||||
|
lua_rawgeti(L, -j, j);
|
||||||
|
|
||||||
|
decl.name = luaL_checkstring(L, -3);
|
||||||
|
const char* tname = luaL_checkstring(L, -2);
|
||||||
|
int components = (int)luaL_checkinteger(L, -1);
|
||||||
|
|
||||||
// Check deprecated format names.
|
// Check deprecated format names.
|
||||||
if (strcmp(tname, "byte") == 0 || strcmp(tname, "unorm8") == 0)
|
if (strcmp(tname, "byte") == 0 || strcmp(tname, "unorm8") == 0)
|
||||||
{
|
{
|
||||||
if (components == 4)
|
if (components == 4)
|
||||||
format = DATAFORMAT_UNORM8_VEC4;
|
decl.format = DATAFORMAT_UNORM8_VEC4;
|
||||||
else
|
else
|
||||||
luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname);
|
luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname);
|
||||||
}
|
}
|
||||||
else if (strcmp(tname, "unorm16") == 0)
|
else if (strcmp(tname, "unorm16") == 0)
|
||||||
{
|
{
|
||||||
if (components == 2)
|
if (components == 2)
|
||||||
format = DATAFORMAT_UNORM16_VEC2;
|
decl.format = DATAFORMAT_UNORM16_VEC2;
|
||||||
else if (components == 4)
|
else if (components == 4)
|
||||||
format = DATAFORMAT_UNORM16_VEC4;
|
decl.format = DATAFORMAT_UNORM16_VEC4;
|
||||||
else
|
else
|
||||||
luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname);
|
luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname);
|
||||||
|
|
||||||
@@ -1938,23 +1959,27 @@ static Mesh *newCustomMesh(lua_State *L)
|
|||||||
else if (strcmp(tname, "float") == 0)
|
else if (strcmp(tname, "float") == 0)
|
||||||
{
|
{
|
||||||
if (components == 1)
|
if (components == 1)
|
||||||
format = DATAFORMAT_FLOAT;
|
decl.format = DATAFORMAT_FLOAT;
|
||||||
else if (components == 2)
|
else if (components == 2)
|
||||||
format = DATAFORMAT_FLOAT_VEC2;
|
decl.format = DATAFORMAT_FLOAT_VEC2;
|
||||||
else if (components == 3)
|
else if (components == 3)
|
||||||
format = DATAFORMAT_FLOAT_VEC3;
|
decl.format = DATAFORMAT_FLOAT_VEC3;
|
||||||
else if (components == 4)
|
else if (components == 4)
|
||||||
format = DATAFORMAT_FLOAT_VEC4;
|
decl.format = DATAFORMAT_FLOAT_VEC4;
|
||||||
else
|
else
|
||||||
luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname);
|
luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (decl.format == DATAFORMAT_MAX_ENUM)
|
||||||
|
luax_enumerror(L, "vertex data format", getConstants(decl.format), tname);
|
||||||
|
|
||||||
|
lua_pop(L, 3);
|
||||||
|
|
||||||
|
luax_markdeprecated(L, 1, "vertex format array values in love.graphics.newMesh", API_CUSTOM, DEPRECATED_REPLACED, "named table fields 'format' and 'name'");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == DATAFORMAT_MAX_ENUM && !getConstant(tname, format))
|
lua_pop(L, 1);
|
||||||
luax_enumerror(L, "vertex data format", getConstants(format), tname);
|
vertexformat.push_back(decl);
|
||||||
|
|
||||||
lua_pop(L, 4);
|
|
||||||
vertexformat.emplace_back(name, format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lua_isnumber(L, 2))
|
if (lua_isnumber(L, 2))
|
||||||
|
|||||||
Reference in New Issue
Block a user