lovr.graphics.newMesh accepts Blob again;
@@ -1125,6 +1125,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
int dataIndex = 0;
int formatIndex = 0;
int drawModeIndex = 2;
+ Blob* blob = NULL;
if (lua_isnumber(L, 1)) {
count = lua_tointeger(L, 1);
@@ -1139,6 +1140,10 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
formatIndex = 1;
count = lua_objlen(L, 2);
dataIndex = 2;
+ } else if ((blob = luax_totype(L, 2, Blob)) != NULL) {
+ drawModeIndex++;
+ formatIndex = 1;
+ dataIndex = 2;
} else {
count = lua_objlen(L, 1);
dataIndex = 1;
@@ -1186,6 +1191,10 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
}
}
+ if (blob) {
+ count = blob->size / stride;
+ }
+
DrawMode mode = luaL_checkoption(L, drawModeIndex, "fan", DrawModes);
BufferUsage usage = luaL_checkoption(L, drawModeIndex + 1, "dynamic", BufferUsages);
bool readable = lua_toboolean(L, drawModeIndex + 2);
@@ -1213,6 +1222,9 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
if (dataIndex) {
AttributeData data = { .raw = lovrBufferMap(vertexBuffer, 0) };
+ if (blob) {
+ memcpy(data.raw, blob->data, count * stride);
+ } else {
for (uint32_t i = 0; i < count; i++) {
lua_rawgeti(L, dataIndex, i + 1);
lovrAssert(lua_istable(L, -1), "Vertices should be specified as a table of tables");
@@ -1238,6 +1250,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
lua_pop(L, 1);
}
}
+ }
lovrBufferMarkRange(vertexBuffer, 0, count * stride);
lovrRelease(vertexBuffer);
