From a796c9255698a63f8d6d35938812a3ad10d0e82f Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 3 Sep 2022 10:49:25 -0700 Subject: [PATCH] Buffer:clear and Pass:clear(Buffer) use the same units; --- src/api/l_graphics_buffer.c | 6 +++--- src/api/l_graphics_pass.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/api/l_graphics_buffer.c b/src/api/l_graphics_buffer.c index 2c8030ba..02d09466 100644 --- a/src/api/l_graphics_buffer.c +++ b/src/api/l_graphics_buffer.c @@ -173,7 +173,7 @@ void luax_readbufferdata(lua_State* L, int index, Buffer* buffer, char* data) { uint32_t length = luax_len(L, index); uint32_t limit = nested ? MIN(length - srcIndex, info->length - dstIndex) : info->length - dstIndex; - uint32_t count = luaL_optinteger(L, index + 3, limit); + uint32_t count = luax_optu32(L, index + 3, limit); lovrCheck(dstIndex + count <= info->length, "Tried to write Buffer elements [%d,%d] but Buffer can only hold %d things", dstIndex + 1, dstIndex + count - 1, info->length); data = data ? data : lovrBufferMap(buffer, dstIndex * stride, count * stride); @@ -290,8 +290,8 @@ static int l_lovrBufferSetData(lua_State* L) { static int l_lovrBufferClear(lua_State* L) { Buffer* buffer = luax_checkbuffer(L, 1); const BufferInfo* info = lovrBufferGetInfo(buffer); - uint32_t index = luaL_optinteger(L, 2, 1); - uint32_t count = luaL_optinteger(L, 3, info->length - index + 1); + uint32_t index = luax_optu32(L, 2, 1); + uint32_t count = luax_optu32(L, 3, info->length - index + 1); lovrBufferClear(buffer, (index - 1) * info->stride, count * info->stride); return 0; } diff --git a/src/api/l_graphics_pass.c b/src/api/l_graphics_pass.c index 210bce0f..e155440f 100644 --- a/src/api/l_graphics_pass.c +++ b/src/api/l_graphics_pass.c @@ -797,9 +797,10 @@ static int l_lovrPassClear(lua_State* L) { Buffer* buffer = luax_totype(L, 2, Buffer); if (buffer) { - uint32_t offset = luax_optu32(L, 3, 0); - uint32_t extent = luax_optu32(L, 4, ~0u); - lovrPassClearBuffer(pass, buffer, offset, extent); + const BufferInfo* info = lovrBufferGetInfo(buffer); + uint32_t index = luax_optu32(L, 3, 1); + uint32_t count = luax_optu32(L, 4, info->length - index + 1); + lovrBufferClear(buffer, (index - 1) * info->stride, count * info->stride); return 0; }