From 33f3eb1c5a489a1b0c7d508e6a42f0dbb20e3a1b Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 22 Aug 2022 09:08:59 -0500 Subject: add types to gl_buffer_data --- src/gl/gl.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'src/gl/gl.c') diff --git a/src/gl/gl.c b/src/gl/gl.c index f9419e2..953cefb 100644 --- a/src/gl/gl.c +++ b/src/gl/gl.c @@ -181,26 +181,50 @@ int gl_bind_buffer(lua_State *L) int gl_buffer_data(lua_State *L) { - lua_Integer target, usage; + lua_Integer target, type, usage; int table; - hs_parse_args(L, hs_int(target), hs_tbl(table), hs_int(usage)); + hs_parse_args(L, hs_int(target), hs_int(type), hs_tbl(table), hs_int(usage)); + + if (type != GL_INT && type != GL_FLOAT) { + hs_throw_error(L, "invalid type"); + } /* build raw buffer */ size_t len = lua_objlen(L, table); - float *buf = malloc(len * sizeof(float)); - if (buf == NULL) - hs_throw_error(L, "failed to allocate intermediary buffer"); - for (int i=0; i