diff --git a/src/modules/graphics/Buffer.cpp b/src/modules/graphics/Buffer.cpp index 211e84500..b839db8f9 100644 --- a/src/modules/graphics/Buffer.cpp +++ b/src/modules/graphics/Buffer.cpp @@ -51,7 +51,7 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vectornewBuffer(settings, format, nullptr, 0, arraylength); }); + + if (lua_istable(L, 1)) + { + Buffer::Mapper mapper(*b); + uint16 *u16data = (uint16 *) mapper.data; + uint32 *u32data = (uint32 *) mapper.data; + + for (int i = 0; i < arraylength; i++) + { + lua_rawgeti(L, 1, i + 1); + lua_Integer v = luaL_checkinteger(L, -1); + lua_pop(L, 1); + if (format == DATAFORMAT_UINT16) + u16data[i] = (uint16) v; + else + u32data[i] = (uint32) v; + } + } + + luax_pushtype(L, b); + b->release(); + return 1; +} + static PrimitiveType luax_optmeshdrawmode(lua_State *L, int idx, PrimitiveType def) { const char *modestr = lua_isnoneornil(L, idx) ? nullptr : luaL_checkstring(L, idx); @@ -1512,7 +1592,7 @@ static Mesh *newStandardMesh(lua_State *L) Mesh *t = nullptr; PrimitiveType drawmode = luax_optmeshdrawmode(L, 2, PRIMITIVE_TRIANGLE_FAN); - BufferUsage usage = luax_optmeshusage(L, 3, BUFFERUSAGE_DYNAMIC); + BufferUsage usage = luax_optbufferusage(L, 3, BUFFERUSAGE_DYNAMIC); std::vector format = Mesh::getDefaultVertexFormat(); @@ -1574,7 +1654,7 @@ static Mesh *newCustomMesh(lua_State *L) std::vector vertexformat; PrimitiveType drawmode = luax_optmeshdrawmode(L, 3, PRIMITIVE_TRIANGLE_FAN); - BufferUsage usage = luax_optmeshusage(L, 4, BUFFERUSAGE_DYNAMIC); + BufferUsage usage = luax_optbufferusage(L, 4, BUFFERUSAGE_DYNAMIC); lua_rawgeti(L, 1, 1); if (!lua_istable(L, -1)) @@ -1598,7 +1678,7 @@ static Mesh *newCustomMesh(lua_State *L) DataFormat format = DATAFORMAT_FLOAT; const char *tname = luaL_checkstring(L, -2); - if (!getConstant(tname, format)) + if (!lua_isnoneornil(L, -1)) { int components = (int) luaL_checkinteger(L, -1); @@ -1633,7 +1713,7 @@ static Mesh *newCustomMesh(lua_State *L) else luaL_error(L, "Invalid component count (%d) for vertex data type %s", components, tname); } - else + else if (!getConstant(tname, format)) luax_enumerror(L, "vertex data format", getConstants(format), tname); } @@ -3096,6 +3176,7 @@ static const luaL_Reg functions[] = { "newSpriteBatch", w_newSpriteBatch }, { "newParticleSystem", w_newParticleSystem }, { "newShader", w_newShader }, + { "newIndexBuffer", w_newIndexBuffer }, { "newMesh", w_newMesh }, { "newText", w_newText }, { "_newVideo", w_newVideo },