Mesh:setVertexMap accepts a Blob for fast updates;

This commit is contained in:
bjorn 2018-03-22 11:22:06 -07:00
parent 471540433c
commit f9ce6d3425
1 changed files with 31 additions and 22 deletions

View File

@ -203,6 +203,14 @@ int l_lovrMeshSetVertexMap(lua_State* L) {
return 0;
}
if (lua_type(L, 2) == LUA_TUSERDATA) {
Blob* blob = luax_checktypeof(L, 2, Blob);
size_t size = luaL_optinteger(L, 3, 4);
lovrAssert(size == 2 || size == 4, "Size of Mesh indices should be 2 bytes or 4 bytes");
uint32_t count = blob->size / size;
IndexPointer indices = lovrMeshWriteIndices(mesh, count, size);
memcpy(indices.raw, blob->data, blob->size);
} else {
luaL_checktype(L, 2, LUA_TTABLE);
uint32_t count = lua_objlen(L, 2);
uint32_t vertexCount = lovrMeshGetVertexCount(mesh);
@ -228,6 +236,7 @@ int l_lovrMeshSetVertexMap(lua_State* L) {
lua_pop(L, 1);
}
}
return 0;
}