Skip to content

Commit

Permalink
Mesh:getVertexFormat uses named fields, to match the new format synta…
Browse files Browse the repository at this point in the history
…x in newMesh.
  • Loading branch information
slime73 committed Apr 8, 2024
1 parent 8140817 commit 994079e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/modules/graphics/wrap_Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,28 @@ int w_Mesh_getVertexFormat(lua_State *L)

for (size_t i = 0; i < vertexformat.size(); i++)
{
const auto &decl = vertexformat[i].decl;
const auto &member = vertexformat[i];

if (!getConstant(decl.format, tname))
return luax_enumerror(L, "vertex attribute data type", getConstants(decl.format), tname);
if (!getConstant(member.decl.format, tname))
return luax_enumerror(L, "vertex attribute data type", getConstants(member.decl.format), tname);

lua_createtable(L, 3, 0);
lua_createtable(L, 0, 4);

lua_pushstring(L, decl.name.c_str());
lua_rawseti(L, -2, 1);
lua_pushstring(L, member.decl.name.c_str());
lua_setfield(L, -2, "name");

lua_pushstring(L, tname);
lua_rawseti(L, -2, 2);
const char *formatstr = "unknown";
getConstant(member.decl.format, formatstr);
lua_pushstring(L, formatstr);
lua_setfield(L, -2, "format");

// format[i] = {name, type}
lua_rawseti(L, -2, (int) i + 1);
lua_pushinteger(L, member.decl.arrayLength);
lua_setfield(L, -2, "arraylength");

lua_pushinteger(L, member.offset);
lua_setfield(L, -2, "offset");

lua_rawseti(L, -2, i + 1);
}

return 1;
Expand Down
4 changes: 2 additions & 2 deletions testing/tests/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ love.test.graphics.Mesh = function(test)

-- check def vertex format
local format = mesh1:getVertexFormat()
test:assertEquals('floatvec2', format[2][2], 'check def vertex format 2')
test:assertEquals('VertexColor', format[3][1], 'check def vertex format 3')
test:assertEquals('floatvec2', format[2].format, 'check def vertex format 2')
test:assertEquals('VertexColor', format[3].name, 'check def vertex format 3')

-- check vertext attributes
test:assertTrue(mesh1:isAttributeEnabled('VertexPosition'), 'check def attribute VertexPosition')
Expand Down

0 comments on commit 994079e

Please sign in to comment.