diff options
Diffstat (limited to 'src/gl/data.c')
-rw-r--r-- | src/gl/data.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/gl/data.c b/src/gl/data.c index d36608b..b7dc581 100644 --- a/src/gl/data.c +++ b/src/gl/data.c @@ -3,7 +3,7 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> #include "util/util.h" #include "gl.h" @@ -19,29 +19,31 @@ int gl_vertex_array_enable_attrib(lua_State *L); void setup_data(lua_State *L, int gl_index) { - int tbl = hs_create_table(L, + struct honey_tbl_t tbl[] = { /* functions */ - hs_str_cfunc("GenBuffers", gl_create_buffer), - hs_str_cfunc("BindBuffer", gl_bind_buffer), - hs_str_cfunc("BufferData", gl_buffer_data), + H_FUNC("GenBuffers", gl_create_buffer), + H_FUNC("BindBuffer", gl_bind_buffer), + H_FUNC("BufferData", gl_buffer_data), - hs_str_cfunc("GenVertexArrays", gl_vertex_array_create), - hs_str_cfunc("BindVertexArray", gl_vertex_array_bind), - hs_str_cfunc("VertexAttribPointer", gl_vertex_attrib_pointer), - hs_str_cfunc("EnableVertexAttribArray", gl_vertex_array_enable_attrib), + H_FUNC("GenVertexArrays", gl_vertex_array_create), + H_FUNC("BindVertexArray", gl_vertex_array_bind), + H_FUNC("VertexAttribPointer", gl_vertex_attrib_pointer), + H_FUNC("EnableVertexAttribArray", gl_vertex_array_enable_attrib), /******** enums ********/ /* buffer bind targets */ - hs_str_int("ARRAY_BUFFER", GL_ARRAY_BUFFER), - hs_str_int("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER), + H_INT("ARRAY_BUFFER", GL_ARRAY_BUFFER), + H_INT("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER), /* buffer usage patters */ - hs_str_int("STREAM_DRAW", GL_STREAM_DRAW), - hs_str_int("STATIC_DRAW", GL_STATIC_DRAW), - hs_str_int("DYNAMIC_DRAW", GL_DYNAMIC_DRAW), - ); - - append_table(L, gl_index, tbl); + H_INT("STREAM_DRAW", GL_STREAM_DRAW), + H_INT("STATIC_DRAW", GL_STATIC_DRAW), + H_INT("DYNAMIC_DRAW", GL_DYNAMIC_DRAW), + + H_END + }; + create_table(L, tbl); + append_table(L, gl_index, lua_gettop(L)); lua_pop(L, 1); } @@ -57,8 +59,8 @@ int gl_create_buffer(lua_State *L) int gl_bind_buffer(lua_State *L) { - lua_Integer target, buf; - hs_parse_args(L, hs_int(target), hs_int(buf)); + int target = luaL_checkinteger(L, 1); + int buf = luaL_checkinteger(L, 2); glBindBuffer(target, buf); return 0; } @@ -70,11 +72,11 @@ int gl_bind_buffer(lua_State *L) *sz = len * sizeof(type); \ type *buf = malloc(*sz); \ if (buf == NULL) \ - hs_throw_error(L, "failed to allocate intermediary buffer"); \ + luaL_error(L, "failed to allocate intermediary buffer"); \ for (int i=0; i<len; i++) { \ lua_rawgeti(L, tbl, i+1); \ if (!lua_isnumber(L, -1)) \ - hs_throw_error(L, "all elements must be numbers (failed at index %d)", i); \ + luaL_error(L, "all elements must be numbers (failed at index %d)", i); \ buf[i] = conversion(L, -1); \ lua_pop(L, 1); \ } \ @@ -88,8 +90,11 @@ GET_BUFFER_TYPE(float, float, lua_tonumber) int gl_buffer_data(lua_State *L) { lua_Integer target, type, usage; - int table; - hs_parse_args(L, hs_int(target), hs_int(type), hs_tbl(table), hs_int(usage)); + target = luaL_checkinteger(L, 1); + type = luaL_checkinteger(L, 2); + luaL_checktype(L, 3, LUA_TTABLE); + int table = 3; + usage = luaL_checkinteger(L, 4); /* build raw buffer */ void *buf; size_t len; @@ -107,7 +112,7 @@ int gl_buffer_data(lua_State *L) break; default: - hs_throw_error(L, "invalid type"); + luaL_error(L, "invalid type"); } /* call */ @@ -128,8 +133,7 @@ int gl_vertex_array_create(lua_State *L) int gl_vertex_array_bind(lua_State *L) { - lua_Integer array; - hs_parse_args(L, hs_int(array)); + lua_Integer array = luaL_checkinteger(L, 1); glBindVertexArray(array); return 0; } @@ -139,7 +143,12 @@ int gl_vertex_attrib_pointer(lua_State *L) { lua_Integer index, size, stride, offset; bool normalized; - hs_parse_args(L, hs_int(index), hs_int(size), hs_bool(normalized), hs_int(stride), hs_int(offset)); + index = luaL_checkinteger(L, 1); + size = luaL_checkinteger(L, 2); + normalized = lua_toboolean(L, 3); + stride = luaL_checkinteger(L, 4); + offset = luaL_checkinteger(L, 5); + glVertexAttribPointer(index, size, GL_FLOAT, normalized, stride*sizeof(float), (void*) (offset*sizeof(float))); @@ -149,8 +158,7 @@ int gl_vertex_attrib_pointer(lua_State *L) int gl_vertex_array_enable_attrib(lua_State *L) { - lua_Integer index; - hs_parse_args(L, hs_int(index)); + lua_Integer index = luaL_checkinteger(L, 1); glEnableVertexAttribArray(index); return 0; } |