From a2c162f12337142c054c2e1f01ad508ee56963d2 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 22 Aug 2022 11:00:42 -0500 Subject: refactor: move data functions into separate file --- src/gl/gl.c | 143 +----------------------------------------------------------- 1 file changed, 1 insertion(+), 142 deletions(-) (limited to 'src/gl/gl.c') diff --git a/src/gl/gl.c b/src/gl/gl.c index 876df9d..8a1cb17 100644 --- a/src/gl/gl.c +++ b/src/gl/gl.c @@ -18,16 +18,6 @@ int glad_init(lua_State *L); int gl_terminate(lua_State *L); int gl_get_error(lua_State *L); -/* buffers */ -int gl_create_buffer(lua_State *L); -int gl_bind_buffer(lua_State *L); -int gl_buffer_data(lua_State *L); - -int gl_vertex_array_create(lua_State *L); -int gl_vertex_array_bind(lua_State *L); -int gl_vertex_attrib_pointer(lua_State *L); -int gl_vertex_array_enable_attrib(lua_State *L); - void setup_gl(lua_State *L, int honey_index) { int data_types = hs_create_table(L, @@ -44,17 +34,6 @@ void setup_gl(lua_State *L, int honey_index) hs_str_int("outOfMemory", GL_OUT_OF_MEMORY), ); - int buffer_binding_targets = hs_create_table(L, - hs_str_int("arrayBuffer", GL_ARRAY_BUFFER), - hs_str_int("elementArrayBuffer", GL_ELEMENT_ARRAY_BUFFER), - ); - - int buffer_usage_patterns = hs_create_table(L, - hs_str_int("streamDraw", GL_STREAM_DRAW), - hs_str_int("staticDraw", GL_STATIC_DRAW), - hs_str_int("dynamicDraw", GL_DYNAMIC_DRAW), - ); - int gl_index = hs_create_table(L, hs_str_cfunc("init", gl_init), hs_str_cfunc("initGlad", glad_init), @@ -63,23 +42,11 @@ void setup_gl(lua_State *L, int honey_index) hs_str_tbl("dataType", data_types), hs_str_tbl("errorType", error_types), - - /* buffer */ - hs_str_cfunc("createBuffer", gl_create_buffer), - hs_str_cfunc("bindBuffer", gl_bind_buffer), - hs_str_cfunc("bufferData", gl_buffer_data), - - hs_str_cfunc("createVertexArray", gl_vertex_array_create), - hs_str_cfunc("bindVertexArray", gl_vertex_array_bind), - hs_str_cfunc("vertexAttribPointer", gl_vertex_attrib_pointer), - hs_str_cfunc("vertexArrayEnableAttrib", gl_vertex_array_enable_attrib), - - hs_str_tbl("bufferTarget", buffer_binding_targets), - hs_str_tbl("bufferUsage", buffer_usage_patterns), ); setup_shader(L, gl_index); setup_drawing(L, gl_index); + setup_data(L, gl_index); lua_setfield(L, honey_index, "gl"); } @@ -113,111 +80,3 @@ int gl_get_error(lua_State *L) lua_pushinteger(L, glGetError()); return 1; } - - -int gl_create_buffer(lua_State *L) -{ - int buf; - glGenBuffers(1, &buf); - lua_pushinteger(L, buf); - return 1; -} - - -int gl_bind_buffer(lua_State *L) -{ - lua_Integer target, buf; - hs_parse_args(L, hs_int(target), hs_int(buf)); - glBindBuffer(target, buf); - return 0; -} - - -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)); - - if (type != GL_INT && type != GL_FLOAT) { - hs_throw_error(L, "invalid type"); - } - - /* build raw buffer */ - size_t len = lua_objlen(L, table); - void *buf; - if (type == GL_FLOAT) { - float *fbuf = malloc(len * sizeof(float)); - if (fbuf == NULL) - hs_throw_error(L, "failed to allocate intermediary fbuffer"); - for (int i=0; i