diff --git a/src/api/l_graphics_pass.c b/src/api/l_graphics_pass.c index 59812168..76482b67 100644 --- a/src/api/l_graphics_pass.c +++ b/src/api/l_graphics_pass.c @@ -400,16 +400,21 @@ static void luax_readvertices(lua_State* L, int index, float* vertices, uint32_t static int l_lovrPassPoints(lua_State* L) { Pass* pass = luax_checktype(L, 1, Pass); - Buffer* buffer = luax_totype(L, 2, Buffer); + float* vertices; + uint32_t count = luax_getvertexcount(L, 2); + lovrPassPoints(pass, count, &vertices); + luax_readvertices(L, 2, vertices, count); + return 0; +} - if (buffer || !lua_toboolean(L, 2)) { - // - } else { - float* vertices; - uint32_t count = luax_getvertexcount(L, 2); - lovrPassPoints(pass, count, &vertices); - luax_readvertices(L, 2, vertices, count); - } +static int l_lovrPassLine(lua_State* L) { + Pass* pass = luax_checktype(L, 1, Pass); + float* vertices; + uint32_t count = luax_getvertexcount(L, 2); + lovrPassLine(pass, count, &vertices); + luax_readvertices(L, 2, vertices, count); + return 0; +} return 0; } @@ -590,6 +595,7 @@ const luaL_Reg lovrPass[] = { { "send", l_lovrPassSend }, { "points", l_lovrPassPoints }, + { "line", l_lovrPassLine }, { "clear", l_lovrPassClear }, { "copy", l_lovrPassCopy }, diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index 9c7859f2..5f2de3f7 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -1995,15 +1995,33 @@ static void lovrPassDraw(Pass* pass, Draw* draw) { pass->drawCount++; } -void lovrPassPoints(Pass* pass, uint32_t count, float** vertices) { +void lovrPassPoints(Pass* pass, uint32_t count, float** points) { lovrPassDraw(pass, &(Draw) { .mode = GPU_DRAW_POINTS, .vertex.format = VERTEX_POINT, - .vertex.pointer = (void**) vertices, + .vertex.pointer = (void**) points, .vertex.count = count }); } +void lovrPassLine(Pass* pass, uint32_t count, float** points) { + uint16_t* indices; + + lovrPassDraw(pass, &(Draw) { + .mode = GPU_DRAW_LINES, + .vertex.format = VERTEX_POINT, + .vertex.pointer = (void**) points, + .vertex.count = count, + .index.pointer = (void**) &indices, + .index.count = 2 * (count - 1) + }); + + for (uint32_t i = 0; i < count - 1; i++) { + indices[2 * i + 0] = i; + indices[2 * i + 1] = i + 1; + } +} + void lovrPassClearBuffer(Pass* pass, Buffer* buffer, uint32_t offset, uint32_t extent) { if (extent == 0) return; if (extent == ~0u) extent = buffer->size - offset; diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 2c191b56..515b3f75 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -389,6 +389,7 @@ void lovrPassSendBuffer(Pass* pass, const char* name, size_t length, uint32_t sl void lovrPassSendTexture(Pass* pass, const char* name, size_t length, uint32_t slot, Texture* texture); void lovrPassSendSampler(Pass* pass, const char* name, size_t length, uint32_t slot, Sampler* sampler); void lovrPassPoints(Pass* pass, uint32_t count, float** vertices); +void lovrPassLine(Pass* pass, uint32_t count, float** vertices); void lovrPassClearBuffer(Pass* pass, Buffer* buffer, uint32_t offset, uint32_t extent); void lovrPassClearTexture(Pass* pass, Texture* texture, float value[4], uint32_t layer, uint32_t layerCount, uint32_t level, uint32_t levelCount); void lovrPassCopyDataToBuffer(Pass* pass, void* data, Buffer* buffer, uint32_t offset, uint32_t size);