From ccd98d4dbdb7acde2433153a01d00a3b9bed02c0 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 27 Oct 2020 15:31:14 -0500 Subject: fix bug in honey.shader.new and add basic primitives bindings --- src/shader/shader.c | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'src/shader') diff --git a/src/shader/shader.c b/src/shader/shader.c index d733c60..122d59e 100644 --- a/src/shader/shader.c +++ b/src/shader/shader.c @@ -19,28 +19,6 @@ void honey_setup_shader(lua_State* L) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static bool compile_shader(int* shader, - const char* source, - int shader_type, - char* error_message, - size_t error_size) -{ - int success; - - *shader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(*shader, 1, source, NULL); - glCompileShader(*shader); - glGetShaderiv(*shader, GL_COMPILE_STATUS, &success); - if (!success) { - glGetShaderInfoLog(*shader, error_size, NULL, error_message); - return false; - } - - return true; -} - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - int honey_shader_new(lua_State* L) { if (!honey_lua_validate_types(L, 2, HONEY_STRING, HONEY_STRING)) @@ -48,23 +26,28 @@ int honey_shader_new(lua_State* L) const char* vertex_shader_source = lua_tostring(L, 1); const char* fragment_shader_source = lua_tostring(L, 2); - + + int success; char error[1024]; - int vertex_shader, fragment_shader; - - if (!compile_shader(&vertex_shader, - vertex_shader_source, - GL_VERTEX_SHADER, - error, 1024)) { + int vertex_shader = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vertex_shader, 1, + &vertex_shader_source, NULL); + glCompileShader(vertex_shader); + glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(vertex_shader, 1024, NULL, error); lua_pushstring(L, error); lua_error(L); } - if (!compile_shader(&fragment_shader, - fragment_shader_source, - GL_FRAGMENT_SHADER, - error, 1024)) { + int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fragment_shader, 1, + &fragment_shader_source, NULL); + glCompileShader(fragment_shader); + glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(fragment_shader, 1024, NULL, error); lua_pushstring(L, error); lua_error(L); } @@ -74,7 +57,6 @@ int honey_shader_new(lua_State* L) glAttachShader(shader, fragment_shader); glLinkProgram(shader); - int success; glGetShaderiv(shader, GL_LINK_STATUS, &success); if (!success) { glGetShaderInfoLog(shader, 1024, NULL, error); -- cgit v1.2.1