Mesh:attachAttribute: add an optional start array index parameter.

Allows easier use of a single instance buffer with multiple draws when instanced attributes are used (#1878).
This commit is contained in:
Sasha Szpakowski
2022-12-10 21:11:59 -04:00
parent f17d3d94f1
commit a37c2fb9a9
3 changed files with 16 additions and 6 deletions
+6 -2
View File
@@ -314,8 +314,9 @@ int w_Mesh_attachAttribute(lua_State *L)
return luax_enumerror(L, "vertex attribute step", getConstants(step), stepstr);
const char *attachname = luaL_optstring(L, 5, name);
int startindex = (int) luaL_optinteger(L, 6, 1) - 1;
luax_catchexcept(L, [&](){ t->attachAttribute(name, buffer, mesh, attachname, step); });
luax_catchexcept(L, [&](){ t->attachAttribute(name, buffer, mesh, attachname, startindex, step); });
return 0;
}
@@ -340,7 +341,7 @@ int w_Mesh_getAttachedAttributes(lua_State *L)
{
const auto &attrib = attributes[i];
lua_createtable(L, 4, 0);
lua_createtable(L, 5, 0);
luax_pushstring(L, attrib.name);
lua_rawseti(L, -1, 1);
@@ -358,6 +359,9 @@ int w_Mesh_getAttachedAttributes(lua_State *L)
luax_pushstring(L, member.decl.name);
lua_rawseti(L, -1, 4);
lua_pushinteger(L, attrib.startArrayIndex + 1);
lua_rawseti(L, -1, 5);
lua_rawseti(L, -1, i + 1);
}