diff --git a/src/api/l_graphics_pass.c b/src/api/l_graphics_pass.c index af044d78..7f32c775 100644 --- a/src/api/l_graphics_pass.c +++ b/src/api/l_graphics_pass.c @@ -823,24 +823,20 @@ static int l_lovrPassMesh(lua_State* L) { Pass* pass = luax_checktype(L, 1, Pass); Buffer* vertices = !lua_toboolean(L, 2) ? NULL : luax_checktype(L, 2, Buffer); Buffer* indices = luax_totype(L, 3, Buffer); - float transform[16]; - int index = luax_readmat4(L, indices ? 4 : 3, transform, 1); - uint32_t start = luax_optu32(L, index++, 1) - 1; - uint32_t count = luax_optu32(L, index++, ~0u); - uint32_t instances = luax_optu32(L, index, 1); - lovrPassMesh(pass, vertices, indices, transform, start, count, instances); - return 0; -} - -static int l_lovrPassMultimesh(lua_State* L) { - Pass* pass = luax_checktype(L, 1, Pass); - Buffer* vertices = !lua_toboolean(L, 2) ? NULL : luax_totype(L, 2, Buffer); - Buffer* indices = luax_totype(L, 3, Buffer); - Buffer* draws = luax_checktype(L, 4, Buffer); - uint32_t count = luax_optu32(L, 5, 1); - uint32_t offset = luax_optu32(L, 6, 0); - uint32_t stride = luax_optu32(L, 7, 0); - lovrPassMultimesh(pass, vertices, indices, draws, count, offset, stride); + Buffer* indirect = luax_totype(L, 4, Buffer); + if (indirect) { + uint32_t count = luax_optu32(L, 5, 1); + uint32_t offset = luax_optu32(L, 6, 0); + uint32_t stride = luax_optu32(L, 7, 0); + lovrPassMeshIndirect(pass, vertices, indices, indirect, count, offset, stride); + } else { + float transform[16]; + int index = luax_readmat4(L, indices ? 4 : 3, transform, 1); + uint32_t start = luax_optu32(L, index++, 1) - 1; + uint32_t count = luax_optu32(L, index++, ~0u); + uint32_t instances = luax_optu32(L, index, 1); + lovrPassMesh(pass, vertices, indices, transform, start, count, instances); + } return 0; } @@ -1164,7 +1160,6 @@ const luaL_Reg lovrPass[] = { { "monkey", l_lovrPassMonkey }, { "draw", l_lovrPassDraw }, { "mesh", l_lovrPassMesh }, - { "multimesh", l_lovrPassMultimesh }, { "compute", l_lovrPassCompute }, diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index bbed9d3d..e95accfc 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -5044,13 +5044,13 @@ void lovrPassMesh(Pass* pass, Buffer* vertices, Buffer* indices, float* transfor }); } -void lovrPassMultimesh(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* draws, uint32_t count, uint32_t offset, uint32_t stride) { +void lovrPassMeshIndirect(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* draws, uint32_t count, uint32_t offset, uint32_t stride) { lovrCheck(pass->info.type == PASS_RENDER, "This function can only be called on a render pass"); - lovrCheck(offset % 4 == 0, "Multimesh draw buffer offset must be a multiple of 4"); + lovrCheck(offset % 4 == 0, "Buffer offset must be a multiple of 4 when sourcing draws from a Buffer"); uint32_t commandSize = indices ? 20 : 16; stride = stride ? stride : commandSize; uint32_t totalSize = stride * (count - 1) + commandSize; - lovrCheck(offset + totalSize < draws->size, "Multimesh draw range exceeds size of draw buffer"); + lovrCheck(offset + totalSize < draws->size, "Draw buffer range exceeds the size of the buffer"); Draw draw = (Draw) { .mode = pass->pipeline->mode, @@ -5059,12 +5059,13 @@ void lovrPassMultimesh(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* dr }; Shader* shader = pass->pipeline->shader; - lovrCheck(shader, "A custom Shader must be bound to draw a multimesh"); + lovrCheck(shader, "A custom Shader must be bound to source draws from a Buffer"); flushPipeline(pass, &draw, shader); flushConstants(pass, shader); flushBindings(pass, shader); flushBuiltins(pass, &draw, shader); + flushMaterial(pass, &draw, shader); flushBuffers(pass, &draw); if (indices) { diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 95ddd35f..0413e34c 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -648,7 +648,7 @@ void lovrPassFill(Pass* pass, Texture* texture); void lovrPassMonkey(Pass* pass, float* transform); void lovrPassDrawModel(Pass* pass, Model* model, float* transform, uint32_t node, bool recurse, uint32_t instances); void lovrPassMesh(Pass* pass, Buffer* vertices, Buffer* indices, float* transform, uint32_t start, uint32_t count, uint32_t instances); -void lovrPassMultimesh(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* indirect, uint32_t count, uint32_t offset, uint32_t stride); +void lovrPassMeshIndirect(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* indirect, uint32_t count, uint32_t offset, uint32_t stride); void lovrPassCompute(Pass* pass, uint32_t x, uint32_t y, uint32_t z, Buffer* indirect, uint32_t offset);