diff options
author | sanine <sanine.not@pm.me> | 2023-03-10 02:05:18 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-03-10 02:05:18 -0600 |
commit | 51c7235d4e0a2df109dd5050328a0ad4a1878ae4 (patch) | |
tree | 201b065e93bf6a35d2bab0e49bcd32f7a971da94 /src/gl/drawing.c | |
parent | 5bb783912ac384156b8abbe6e83a5a61da73881d (diff) |
refactor: move glfw functions into separate table
Diffstat (limited to 'src/gl/drawing.c')
-rw-r--r-- | src/gl/drawing.c | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/src/gl/drawing.c b/src/gl/drawing.c deleted file mode 100644 index eeb0496..0000000 --- a/src/gl/drawing.c +++ /dev/null @@ -1,127 +0,0 @@ -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <lua.h> -#include <lauxlib.h> -#include "util/util.h" - -int gl_set_viewport(lua_State *L); -int gl_draw_arrays(lua_State *L); -int gl_draw_elements(lua_State *L); -int gl_set_clear_color(lua_State *L); -int gl_clear(lua_State *L); -int gl_gen_framebuffers(lua_State *L); -int gl_bind_framebuffer(lua_State *L); -int gl_framebuffer_texture_2d(lua_State *L); - -void setup_drawing(lua_State *L, int gl_index) -{ - struct honey_tbl_t tbl[] = { - /* functions */ - H_FUNC("DrawArrays", gl_draw_arrays), - H_FUNC("DrawElements", gl_draw_elements), - H_FUNC("ClearColor", gl_set_clear_color), - H_FUNC("Clear", gl_clear), - H_FUNC("Viewport", gl_set_viewport), - - /******** enums ********/ - /* rendering primitives */ - H_INT("POINTS", GL_POINTS), - H_INT("LINES", GL_LINES), - H_INT("TRIANGLES", GL_TRIANGLES), - - /* clear bitmasks */ - H_INT("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT), - H_INT("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), - H_INT("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT), - - H_END - }; - create_table(L, tbl); - append_table(L, gl_index, lua_gettop(L)); - lua_pop(L, 1); -} - -int gl_set_clear_color(lua_State *L) -{ - lua_Number r, g, b, a; - r = luaL_checknumber(L, 1); - g = luaL_checknumber(L, 2); - b = luaL_checknumber(L, 3); - a = luaL_checknumber(L, 4); - glClearColor(r, g, b, a); - return 0; -} - - -int gl_clear(lua_State *L) -{ - lua_Integer mask = luaL_checkinteger(L, 1); - glClear(mask); - return 0; -} - - -int gl_draw_arrays(lua_State *L) -{ - lua_Integer mode, first, count; - mode = luaL_checkinteger(L, 1); - first = luaL_checkinteger(L, 2); - count = luaL_checkinteger(L, 3); - glDrawArrays(mode, first, count); - return 0; -} - - -int gl_draw_elements(lua_State *L) -{ - lua_Integer mode, count, type, offset; - mode = luaL_checkinteger(L, 1); - count = luaL_checkinteger(L, 2); - type = luaL_checkinteger(L, 3); - offset = luaL_checkinteger(L, 4); - glDrawElements(mode, count, type, (const void*)offset); - return 0; -} - - -int gl_set_viewport(lua_State *L) -{ - lua_Integer x, y, w, h; - x = luaL_checkinteger(L, 1); - y = luaL_checkinteger(L, 2); - w = luaL_checkinteger(L, 3); - h = luaL_checkinteger(L, 4); - glViewport(x, y, w, h); - return 0; -} - - -int gl_gen_framebuffers(lua_State *L) -{ - int framebuffer; - glGenFramebuffers(1, &framebuffer); - lua_pushinteger(L, framebuffer); - return 1; -} - - -int gl_bind_framebuffer(lua_State *L) -{ - int target = luaL_checkinteger(L, 1); - int framebuffer = luaL_checkinteger(L, 2); - glBindFramebuffer(target, framebuffer); - return 0; -} - - -int gl_framebuffer_texture_2d(lua_State *L) -{ - int target = luaL_checkinteger(L, 1); - int attachment = luaL_checkinteger(L, 2); - int textarget = luaL_checkinteger(L, 3); - int texture = luaL_checkinteger(L, 4); - int level = luaL_checkinteger(L, 5); - - glFramebufferTexture2D(target, attachment, textarget, texture, level); - return 0; -} |