From b2c0dd12d2a39e74f8e6d63bffec073ef0871ea7 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 22 Aug 2022 12:39:51 -0500 Subject: add uniforms --- src/gl/CMakeLists.txt | 12 ++++++++++++ src/gl/shader.c | 27 +++++++++++++++++++++++++++ src/gl/window.c | 10 ++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/gl/CMakeLists.txt (limited to 'src') diff --git a/src/gl/CMakeLists.txt b/src/gl/CMakeLists.txt new file mode 100644 index 0000000..f995ef5 --- /dev/null +++ b/src/gl/CMakeLists.txt @@ -0,0 +1,12 @@ +project(honey_engine) + +set (GL ${CMAKE_CURRENT_LIST_DIR}) + +target_sources(honey PUBLIC + ${GL}/data.c + ${GL}/drawing.c + ${GL}/shader.c + ${GL}/window.c + ${GL}/gl.c + ${GL}/glad/glad.c +) diff --git a/src/gl/shader.c b/src/gl/shader.c index 96946fe..fb64bc0 100644 --- a/src/gl/shader.c +++ b/src/gl/shader.c @@ -13,6 +13,9 @@ int gl_program_attach_shader(lua_State *L); int gl_program_link(lua_State *L); int gl_program_use(lua_State *L); +int gl_uniform_get_location(lua_State *L); +int gl_uniform_4f(lua_State *L); + void setup_shader(lua_State *L, int gl_index) { @@ -32,6 +35,9 @@ void setup_shader(lua_State *L, int gl_index) hs_str_cfunc("link", gl_program_link), hs_str_cfunc("use", gl_program_use), + hs_str_cfunc("getUniformLocation", gl_uniform_get_location), + hs_str_cfunc("uniform4f", gl_uniform_4f), + hs_str_tbl("type", shader_types), ); @@ -122,3 +128,24 @@ int gl_program_use(lua_State *L) glUseProgram(program); return 0; } + + +int gl_uniform_get_location(lua_State *L) +{ + lua_Integer program; + char *name; + hs_parse_args(L, hs_int(program), hs_str(name)); + int location = glGetUniformLocation(program, (const GLchar*)name); + lua_pushinteger(L, location); + return 1; +} + + +int gl_uniform_4f(lua_State *L) +{ + lua_Integer location; + lua_Number v0, v1, v2, v3; + hs_parse_args(L, hs_int(location), hs_num(v0), hs_num(v1), hs_num(v2), hs_num(v3)); + glUniform4f(location, v0, v1, v2, v3); + return 0; +} diff --git a/src/gl/window.c b/src/gl/window.c index 075bd6c..1b8c4bb 100644 --- a/src/gl/window.c +++ b/src/gl/window.c @@ -27,6 +27,8 @@ int window_should_close(lua_State *L); int window_poll_events(lua_State *L); int window_swap_buffers(lua_State *L); int window_set_framebuffer_size_callback(lua_State *L); +int window_get_time(lua_State *L); + void setup_window(lua_State *L, int honey_index) @@ -50,6 +52,7 @@ void setup_window(lua_State *L, int honey_index) hs_str_cfunc("pollEvents", window_poll_events), hs_str_cfunc("swapBuffers", window_swap_buffers), hs_str_cfunc("setFramebufferSizeCallback", window_set_framebuffer_size_callback), + hs_str_cfunc("getTime", window_get_time), hs_str_tbl("hintType", hint_types), hs_str_tbl("profileType", profile_types), @@ -158,3 +161,10 @@ int window_set_framebuffer_size_callback(lua_State *L) wdata->framebuffer_size_callback = hs_rstore(L); return 0; } + + +int window_get_time(lua_State *L) +{ + lua_pushnumber(L, glfwGetTime()); + return 1; +} -- cgit v1.2.1