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/gl.c | |
parent | 5bb783912ac384156b8abbe6e83a5a61da73881d (diff) |
refactor: move glfw functions into separate table
Diffstat (limited to 'src/gl/gl.c')
-rw-r--r-- | src/gl/gl.c | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/src/gl/gl.c b/src/gl/gl.c deleted file mode 100644 index b8da1ec..0000000 --- a/src/gl/gl.c +++ /dev/null @@ -1,112 +0,0 @@ -#include <stdlib.h> -#include <stdbool.h> -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <lua.h> -#include <lauxlib.h> -#include "util/util.h" -#include "gl.h" - -/* needs to be here because glad uses macros to define glBufferData */ -#ifdef HONEY_TEST_H -#undef glBufferData -#define glBufferData mock_glBufferData_ -#endif - - -int gl_init(lua_State *L); -int glad_init(lua_State *L); -int gl_terminate(lua_State *L); -int gl_get_error(lua_State *L); -int gl_enable(lua_State *L); -int gl_disable(lua_State *L); - -void setup_gl(lua_State *L, int honey_index) -{ - struct honey_tbl_t tbl[] = { - /* functions */ - H_FUNC("Init", gl_init), - H_FUNC("InitGlad", glad_init), - H_FUNC("Terminate", gl_terminate), - H_FUNC("GetError", gl_get_error), - H_FUNC("Enable", gl_enable), - H_FUNC("Disable", gl_disable), - - /******** enums ********/ - /* data types */ - H_INT("UNSIGNED_BYTE", GL_UNSIGNED_BYTE), - H_INT("UNSIGNED_INT", GL_UNSIGNED_INT), - H_INT("INT", GL_INT), - H_INT("FLOAT", GL_FLOAT), - - /* error types */ - H_INT("NO_ERROR", GL_NO_ERROR), - H_INT("INVALID_ENUM", GL_INVALID_ENUM), - H_INT("INVALID_VALUE", GL_INVALID_VALUE), - H_INT("INVALID_OPERATION", GL_INVALID_OPERATION), - H_INT("INVALID_FRAMEBUFFER_OPERATION", GL_INVALID_FRAMEBUFFER_OPERATION), - H_INT("OUT_OF_MEMORY", GL_OUT_OF_MEMORY), - - /* opengl capabilities */ - H_INT("DEPTH_TEST", GL_DEPTH_TEST), - H_INT("CULL_FACE", GL_CULL_FACE), - - H_END - }; - create_table(L, tbl); - int gl_index = lua_gettop(L); - - setup_shader(L, gl_index); - setup_drawing(L, gl_index); - setup_data(L, gl_index); - setup_texture(L, gl_index); - - lua_setfield(L, honey_index, "gl"); -} - - -int gl_init(lua_State *L) -{ - if (!glfwInit()) { - luaL_error(L, "failed to initialize GLFW"); - } - return 0; -} - - -int glad_init(lua_State *L) -{ - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { - luaL_error(L, "failed to initialize GLAD"); - } -} - - -int gl_terminate(lua_State *L) -{ - glfwTerminate(); - return 0; -} - - -int gl_get_error(lua_State *L) -{ - lua_pushinteger(L, glGetError()); - return 1; -} - - -int gl_enable(lua_State *L) -{ - lua_Integer cap = luaL_checkinteger(L, 1); - glEnable(cap); - return 0; -} - - -int gl_disable(lua_State *L) -{ - lua_Integer cap = luaL_checkinteger(L, 1); - glDisable(cap); - return 0; -} |