diff options
author | sanine-a <sanine.not@pm.me> | 2020-05-24 20:53:24 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-05-24 20:53:24 -0500 |
commit | 2b6ddb0810a60b159501d60dbeaea5fd1b24daa7 (patch) | |
tree | 3b77d52f8526681ffe6c03b1b08f814aff28eaca | |
parent | e147d9409ce56f63c1a45199ff262c079bd557a4 (diff) |
add honey_shader_new()
-rw-r--r-- | include/shader.h | 12 | ||||
-rw-r--r-- | src/shader.c | 24 |
2 files changed, 30 insertions, 6 deletions
diff --git a/include/shader.h b/include/shader.h index 771ea4a..552af5d 100644 --- a/include/shader.h +++ b/include/shader.h @@ -34,6 +34,18 @@ enum honey_shader_result honey_shader_load(honey_shader* shader, char* vertex_shader_path, char* fragment_shader_path); +/** @brief Create a shader from code strings. + * + * @param[out] shader Pointer to the shader destination. + * @param[in] vertex_shader_code Zero-terminated string containing the vertex shader code to compile + * @param[in] fragment_shader_code Zero-terminated string containing the fragment shader code to compile + * + * @return The result of the shader creation. + */ +enum honey_shader_result honey_shader_new(honey_shader* shader, + char* vertex_shader_code, + char* fragment_shader_code); + /** @brief Set an integer uniform. * * @param[in] shader The shader to which the uniform belongs diff --git a/src/shader.c b/src/shader.c index cba83f7..b7f2916 100644 --- a/src/shader.c +++ b/src/shader.c @@ -37,7 +37,24 @@ enum honey_shader_result honey_shader_load(honey_shader* shader, /* load fragment shader code */ char* fragment_shader_code = read_file(fragment_shader_path); - /* compile shaders */ + result = honey_shader_new(shader, + vertex_shader_code, + fragment_shader_code); + + free(vertex_shader_code); + free(fragment_shader_code); + + return result; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +enum honey_shader_result honey_shader_new(honey_shader* shader, + char* vertex_shader_code, + char* fragment_shader_code) { + enum honey_shader_result result; + + /* compile shaders */ int success; char error[512]; @@ -79,12 +96,7 @@ enum honey_shader_result honey_shader_load(honey_shader* shader, glDeleteShader(vertex_shader); glDeleteShader(fragment_shader); - free(vertex_shader_code); - free(fragment_shader_code); - result = SHADER_OK; - - return result; } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |