summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--demo/main.lua61
-rw-r--r--src/honey.c3
-rw-r--r--src/mesh/mesh.c4
-rw-r--r--src/mesh/mesh.h2
-rw-r--r--src/model/model.c121
-rw-r--r--src/model/model.h29
-rw-r--r--src/shader/shader.c350
-rw-r--r--src/shader/shader.h137
9 files changed, 239 insertions, 469 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ef6be9d..1dc8e94 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,6 @@ set(SOURCE_FILES
src/honey_lua.c
src/light/light.c
src/mesh/mesh.c
- src/model/model.c
src/primitives/primitives.c
src/shader/shader.c
src/texture/texture.c
diff --git a/demo/main.lua b/demo/main.lua
index fe33f87..0ec77a9 100644
--- a/demo/main.lua
+++ b/demo/main.lua
@@ -1,65 +1,8 @@
-local fullscreen = false
-local cursor_mode = honey.input.mouse.mode.normal
-
-local a_func = function(action, data)
- if (action == 0) then return end
- fullscreen = not fullscreen
- honey.window.set_fullscreen(fullscreen)
-end
-
-local resize_func = function(width, height, data)
- local w, h = honey.window.get_size()
- print('resized!', w, h)
+for k, v in pairs(honey.shader) do
+ print(k, v)
end
-local mousemove = function(x, y)
- print(x, y)
-end
-
-honey.window.set_title('honey engine demo')
-
-honey.input.key.bind(honey.input.key.a, a_func)
honey.input.key.bind(honey.input.key.escape, honey.exit)
-honey.input.key.bind(
- honey.input.key.c,
- function(action)
- local next_mode
- if cursor_mode == honey.input.mouse.mode.normal then
- next_mode = honey.input.mouse.mode.disabled
- else
- next_mode = honey.input.mouse.mode.normal
- end
-
- if action == 1 then
- honey.input.mouse.set_mode(next_mode)
- cursor_mode = next_mode
- end
- end
-)
-honey.window.resize_bind(resize_func)
-honey.input.mouse.set_mode( honey.input.mouse.mode.disabled )
-honey.input.mouse.bind_movement(mousemove)
-
-function demo_cglm()
- local array = honey.cglm.new_array_zero(3)
- honey.cglm.set_value(array, 0, 0)
- honey.cglm.set_value(array, 1, 5)
- honey.cglm.set_value(array, 2, 2)
- local x = honey.cglm.get_value(array, 0)
- local y = honey.cglm.get_value(array, 1)
- local z = honey.cglm.get_value(array, 2)
-
- print(x, y, z)
- print(honey.cglm.vec3.norm(array))
-end
-demo_cglm()
-
-local focus_func = function(focus)
- print('focus:', focus)
-end
-
-honey.window.focus_bind(focus_func)
-
function honey.update(dt)
end
diff --git a/src/honey.c b/src/honey.c
index 73fb285..950fc25 100644
--- a/src/honey.c
+++ b/src/honey.c
@@ -73,6 +73,9 @@ bool honey_setup(lua_State** L)
honey_setup_cglm(*L);
lua_setfield(*L, -2, "cglm");
+ honey_setup_shader(*L);
+ lua_setfield(*L, -2, "shader");
+
lua_pushcfunction(*L, honey_exit);
lua_setfield(*L, -2, "exit");
diff --git a/src/mesh/mesh.c b/src/mesh/mesh.c
index 231fcc9..99210eb 100644
--- a/src/mesh/mesh.c
+++ b/src/mesh/mesh.c
@@ -66,8 +66,8 @@ honey_result honey_mesh_new(honey_mesh* mesh,
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_mesh_draw(honey_mesh mesh, honey_shader shader) {
- honey_shader_use(shader);
+void honey_mesh_draw(honey_mesh mesh, int shader) {
+ glUseProgram(shader);
glBindVertexArray(mesh.vertex_array);
glDrawElements(GL_TRIANGLES, mesh.n_indices, GL_UNSIGNED_INT, 0);
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index a3e1e2a..6392faa 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -46,7 +46,7 @@ honey_result honey_mesh_new(honey_mesh* mesh,
* @param[in] shader The shader to use when drawing the mesh
*/
void honey_mesh_draw(honey_mesh mesh,
- honey_shader shader);
+ int shader);
/** @brief Delete a mesh.
*
diff --git a/src/model/model.c b/src/model/model.c
deleted file mode 100644
index b317f15..0000000
--- a/src/model/model.c
+++ /dev/null
@@ -1,121 +0,0 @@
-#include "model.h"
-
-static honey_mesh assimp_to_honey_mesh(struct aiMesh* mesh, struct aiScene* scene) {
- unsigned int vertex_step = 6;
- bool mesh_has_uvs = false;
- unsigned int n_vertices = mesh->mNumVertices;
-
- if (mesh->mTextureCoords[0]) {
- mesh_has_uvs = true;
- vertex_step = 8;
- }
-
- float* vertices = malloc(sizeof(float) * vertex_step * n_vertices);
- for (int i=0; i<n_vertices; i++) {
- int j = i*vertex_step;
- /* positions */
- vertices[j+0] = mesh->mVertices[i].x;
- vertices[j+1] = mesh->mVertices[i].y;
- vertices[j+2] = mesh->mVertices[i].z;
-
- /* normals */
- vertices[j+3] = mesh->mNormals[i].x;
- vertices[j+4] = mesh->mNormals[i].y;
- vertices[j+5] = mesh->mNormals[i].z;
-
- /* uvs? */
- if (mesh_has_uvs) {
- vertices[j+6] = mesh->mTextureCoords[0][i].x;
- vertices[j+7] = mesh->mTextureCoords[0][i].y;
- }
- }
-
- unsigned int n_indices = mesh->mNumFaces*3;
- unsigned int* indices = malloc(sizeof(unsigned int) * n_indices);
- for (int i=0; i<mesh->mNumFaces; i++) {
- int j = 3*i;
- struct aiFace face = mesh->mFaces[i];
- indices[j+0] = face.mIndices[0];
- indices[j+1] = face.mIndices[1];
- indices[j+2] = face.mIndices[2];
- }
-
- honey_mesh result;
-
- if (mesh_has_uvs) {
- unsigned int n_attributes = 3;
- unsigned int attribute_sizes[] = { 3, 3, 2 };
- honey_mesh_new(&result,
- vertices, n_vertices,
- n_attributes, attribute_sizes,
- indices, n_indices);
- }
- else {
- unsigned int n_attributes = 2;
- unsigned int attribute_sizes[] = { 3, 3 };
- honey_mesh_new(&result,
- vertices, n_vertices,
- n_attributes, attribute_sizes,
- indices, n_indices);
- }
-
- free(vertices);
- free(indices);
-
- return result;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-static void process_assimp_node(honey_model* model, struct aiNode* node, struct aiScene* scene) {
- for (int i=0; i<node->mNumMeshes; i++) {
- struct aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
- model->meshes[model->n_meshes] = assimp_to_honey_mesh(mesh, scene);
- model->n_meshes++;
- }
-
- for (int i=0; i<node->mNumChildren; i++) {
- process_assimp_node(model, node->mChildren[i], scene);
- }
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-honey_result honey_model_load(honey_model* model,
- char* path) {
- model->n_meshes = 0;
-
- struct aiScene* scene = aiImportFile(path,
- aiProcess_Triangulate |
- aiProcess_FlipUVs);
- if (scene == NULL) {
- honey_error_set_string1(path);
- return HONEY_FILE_READ_ERROR;
- }
-
- if (scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE ||
- scene->mRootNode == NULL) {
- honey_error_set_string1(path);
- return HONEY_MODEL_LOAD_ERROR;
- }
-
- process_assimp_node(model, scene->mRootNode, scene);
-
- return HONEY_OK;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-void honey_model_draw(honey_model* model, honey_shader shader) {
- for (int i=0; i<model->n_meshes; i++) {
- honey_mesh_draw(model->meshes[i], shader);
- }
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-void honey_model_delete(honey_model* model) {
- for (int i=0; i<model->n_meshes; i++) {
- honey_mesh_delete(model->meshes[i]);
- }
-}
diff --git a/src/model/model.h b/src/model/model.h
deleted file mode 100644
index 3672a44..0000000
--- a/src/model/model.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef HONEY_MODEL_H
-#define HONEY_MODEL_H
-
-#include "../common.h"
-#include "../mesh/mesh.h"
-#include "../shader/shader.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-#define HONEY_MODEL_MAX_MESHES 32
-
-typedef struct {
- mat4 model_matrix;
- honey_mesh meshes[HONEY_MODEL_MAX_MESHES];
- unsigned int n_meshes;
-} honey_model;
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-/** @brief Load a model.
- *
- * @param[out] model Pointer to the destination honey_model struct.
- * @param[in] path Path of the model to be loaded.
- */
-honey_result honey_model_load(honey_model* model, char* path);
-void honey_model_draw(honey_model* model, honey_shader shader);
-void honey_model_delete(honey_model* model);
-
-#endif
diff --git a/src/shader/shader.c b/src/shader/shader.c
index 817d451..3deb5b8 100644
--- a/src/shader/shader.c
+++ b/src/shader/shader.c
@@ -1,224 +1,216 @@
#include "shader.h"
+void honey_setup_shader(lua_State* L)
+{
+ honey_lua_element shader_elements[] = {
+ { "new", HONEY_FUNC, { .function = honey_shader_new } },
+ { "use", HONEY_FUNC, { .function = honey_shader_use } },
+ { "set_int", HONEY_FUNC, { .function = honey_shader_set_int } },
+ { "set_float", HONEY_FUNC, { .function = honey_shader_set_float } },
+ { "set_vec3", HONEY_FUNC, { .function = honey_shader_set_vec3 } },
+ { "set_vec4", HONEY_FUNC, { .function = honey_shader_set_vec4 } },
+ { "set_mat3", HONEY_FUNC, { .function = honey_shader_set_mat3 } },
+ { "set_mat4", HONEY_FUNC, { .function = honey_shader_set_mat4 } },
+ { "delete", HONEY_FUNC, { .function = honey_shader_delete } },
+ };
+
+ honey_lua_create_table(L, shader_elements, 9);
+}
+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-static honey_result read_file(char** destination, char* file_path) {
- FILE* f = fopen(file_path, "r");
- if (f == NULL) {
- honey_error_set_string1(file_path);
- return HONEY_FILE_READ_ERROR;
- }
+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;
+}
- fseek(f, 0, SEEK_END);
- long fsize = ftell(f);
- fseek(f, 0, SEEK_SET);
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- *destination = malloc(fsize + 1);
- if (*destination == NULL) {
- return HONEY_MEMORY_ALLOCATION_ERROR;
- }
- fread(*destination, 1, fsize, f);
- fclose(f);
+int honey_shader_new(lua_State* L)
+{
+ if (!honey_lua_validate_types(L, 2, HONEY_STRING, HONEY_STRING))
+ lua_error(L);
- (*destination)[fsize] = 0;
+ const char* vertex_shader_source = lua_tostring(L, 1);
+ const char* fragment_shader_source = lua_tostring(L, 2);
+
+ char error[1024];
- return HONEY_OK;
+ int vertex_shader, fragment_shader;
+
+ if (!compile_shader(&vertex_shader,
+ vertex_shader_source,
+ GL_VERTEX_SHADER,
+ error, 1024)) {
+ lua_pushstring(L, error);
+ lua_error(L);
+ }
+
+ if (!compile_shader(&fragment_shader,
+ fragment_shader_source,
+ GL_FRAGMENT_SHADER,
+ error, 1024)) {
+ lua_pushstring(L, error);
+ lua_error(L);
+ }
+
+ int shader = glCreateProgram();
+ glAttachShader(shader, vertex_shader);
+ glAttachShader(shader, fragment_shader);
+ glLinkProgram(shader);
+
+ int success;
+ glGetShaderiv(shader, GL_LINK_STATUS, &success);
+ if (!success) {
+ glGetShaderInfoLog(shader, 1024, NULL, error);
+ lua_pushstring(L, error);
+ lua_error(L);
+ }
+
+ glDeleteShader(vertex_shader);
+ glDeleteShader(fragment_shader);
+
+ lua_pushinteger(L, shader);
+ return 1;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-honey_result honey_shader_load(honey_shader* shader,
- char* vertex_shader_path,
- char* fragment_shader_path) {
- /* load vertex shader code */
- char* vertex_shader_code;
- honey_result result = read_file(&vertex_shader_code,
- vertex_shader_path);
- if (result != HONEY_OK)
- return result;
-
- /* load fragment shader code */
- char* fragment_shader_code;
- result = read_file(&fragment_shader_code,
- fragment_shader_path);
- if (result != HONEY_OK)
- return result;
-
- result = honey_shader_new(shader,
- vertex_shader_code,
- fragment_shader_code);
-
- if (result == HONEY_VERTEX_SHADER_COMPILATION_ERROR)
- honey_error_set_string2(vertex_shader_path);
-
- if (result == HONEY_FRAGMENT_SHADER_COMPILATION_ERROR)
- honey_error_set_string2(fragment_shader_path);
-
- free(vertex_shader_code);
- free(fragment_shader_code);
-
- return result;
+int honey_shader_use(lua_State* L)
+{
+ if (!honey_lua_validate_types(L, 1, HONEY_INT))
+ lua_error(L);
+
+ int shader = lua_tointeger(L, 1);
+ glUseProgram(shader);
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-honey_result honey_shader_new(honey_shader* shader,
- char* vertex_shader_code,
- char* fragment_shader_code) {
- /* compile shaders */
- int success;
- char error[512];
-
- int vertex_shader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vertex_shader, 1, ((const char**)&vertex_shader_code), NULL);
- glCompileShader(vertex_shader);
- glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success);
- if (!success) {
- honey_error_clear_strings();
- char compiler_error[HONEY_ERROR_DATA_STRING_LENGTH];
- glGetShaderInfoLog(vertex_shader, HONEY_ERROR_DATA_STRING_LENGTH, NULL, compiler_error);
- honey_error_set_string1(compiler_error);
- return HONEY_VERTEX_SHADER_COMPILATION_ERROR;
- }
-
- int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragment_shader, 1, ((const char**)&fragment_shader_code), NULL);
- glCompileShader(fragment_shader);
- glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success);
- if (!success) {
- honey_error_clear_strings();
- char compiler_error[HONEY_ERROR_DATA_STRING_LENGTH];
- glGetShaderInfoLog(fragment_shader, HONEY_ERROR_DATA_STRING_LENGTH, NULL, compiler_error);
- honey_error_set_string1(compiler_error);
- return HONEY_FRAGMENT_SHADER_COMPILATION_ERROR;
- }
-
- /* link shaders */
- *shader = glCreateProgram();
- glAttachShader(*shader, vertex_shader);
- glAttachShader(*shader, fragment_shader);
- glLinkProgram(*shader);
- glGetShaderiv(*shader, GL_LINK_STATUS, &success);
- if (!success) {
- honey_error_clear_strings();
- char compiler_error[HONEY_ERROR_DATA_STRING_LENGTH];
- glGetShaderInfoLog(vertex_shader, HONEY_ERROR_DATA_STRING_LENGTH, NULL, compiler_error);
- honey_error_set_string1(compiler_error);
- return HONEY_SHADER_LINK_ERROR;
- }
-
- glDeleteShader(vertex_shader);
- glDeleteShader(fragment_shader);
-
- return HONEY_OK;
+int honey_shader_set_int(lua_State* L)
+{
+ if (!honey_lua_validate_types(L, 2, HONEY_INT, HONEY_STRING, HONEY_INT))
+ lua_error(L);
+
+ int shader = lua_tointeger(L, 1);
+ const char* name = lua_tostring(L, 2);
+ int value = lua_tointeger(L, 3);
+
+ glUseProgram(shader);
+ unsigned int location = glGetUniformLocation(shader, name);
+ glUniform1i(location, value);
+
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_int(honey_shader shader,
- char* int_name,
- int value) {
- honey_shader_use(shader);
- unsigned int int_location = glGetUniformLocation(shader, int_name);
- glUniform1i(int_location, value);
+int honey_shader_set_float(lua_State* L)
+{
+ if (!honey_lua_validate_types(L, 2, HONEY_INT, HONEY_STRING, HONEY_NUM))
+ lua_error(L);
+
+ int shader = lua_tointeger(L, 1);
+ const char* name = lua_tostring(L, 2);
+ float value = lua_tonumber(L, 3);
+
+ glUseProgram(shader);
+ unsigned int location = glGetUniformLocation(shader, name);
+ glUniform1f(location, value);
+
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_float(honey_shader shader,
- char* float_name,
- float value) {
- honey_shader_use(shader);
- unsigned int float_location = glGetUniformLocation(shader, float_name);
- glUniform1f(float_location, value);
+static void get_array(lua_State* L,
+ unsigned int* location,
+ float** value)
+{
+ if (!honey_lua_validate_types(L, 2, HONEY_INT, HONEY_STRING, HONEY_USERDATA))
+ lua_error(L);
+
+ int shader = lua_tointeger(L, 1);
+ const char* name = lua_tostring(L, 2);
+ *value = lua_touserdata(L, 3);
+
+ glUseProgram(shader);
+ *location = glGetUniformLocation(shader, name);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_vec3(honey_shader shader,
- char* vector_name,
- vec3 value) {
- honey_shader_use(shader);
- unsigned int vector_location = glGetUniformLocation(shader, vector_name);
- glUniform3fv(vector_location, 1, (float*) value);
+int honey_shader_set_vec3(lua_State* L)
+{
+ unsigned int location;
+ float* array;
+ get_array(L, &location, &array);
+
+ glUniform3fv(location, 1, array);
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_mat3(honey_shader shader,
- char* matrix_name,
- mat3 value) {
- glUseProgram(shader);
- unsigned int matrix_location = glGetUniformLocation(shader, matrix_name);
- glUniformMatrix3fv(matrix_location, 1, GL_FALSE, (float*) value);
+int honey_shader_set_vec4(lua_State* L)
+{
+ unsigned int location;
+ float* array;
+ get_array(L, &location, &array);
+
+ glUniform4fv(location, 1, array);
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_mat4(honey_shader shader,
- char* matrix_name,
- mat4 value) {
- glUseProgram(shader);
- unsigned int matrix_location = glGetUniformLocation(shader, matrix_name);
- glUniformMatrix4fv(matrix_location, 1, GL_FALSE, (float*) value);
+int honey_shader_set_mat3(lua_State* L)
+{
+ unsigned int location;
+ float* array;
+ get_array(L, &location, &array);
+
+ glUniformMatrix3fv(location, 1, GL_FALSE, array);
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_point_light(honey_shader shader,
- int point_light_index,
- honey_point_light light) {
- char name[HONEY_MAX_LIGHT_NAME_LENGTH];
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "point_lights[%d].position",
- point_light_index);
- honey_shader_set_vec3(shader, name, light.position);
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "point_lights[%d].color",
- point_light_index);
- honey_shader_set_vec3(shader, name, light.color);
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "point_lights[%d].constant",
- point_light_index);
- honey_shader_set_float(shader, name, light.constant);
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "point_lights[%d].linear",
- point_light_index);
- honey_shader_set_float(shader, name, light.linear);
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "point_lights[%d].quadratic",
- point_light_index);
- honey_shader_set_float(shader, name, light.quadratic);
+int honey_shader_set_mat4(lua_State* L)
+{
+ unsigned int location;
+ float* array;
+ get_array(L, &location, &array);
+
+ glUniformMatrix4fv(location, 1, GL_FALSE, array);
+ return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-void honey_shader_set_directional_light(honey_shader shader,
- int directional_light_index,
- honey_directional_light light) {
- char name[HONEY_MAX_LIGHT_NAME_LENGTH];
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "directional_lights[%d].direction",
- directional_light_index);
- honey_shader_set_vec3(shader, name, light.direction);
-
- snprintf(name,
- HONEY_MAX_LIGHT_NAME_LENGTH,
- "directional_lights[%d].color",
- directional_light_index);
- honey_shader_set_vec3(shader, name, light.color);
-}
+int honey_shader_delete(lua_State* L)
+{
+ if (!honey_lua_validate_types(L, 1, HONEY_INT))
+ lua_error(L);
+
+ int shader = lua_tointeger(L, 1);
-
+ glDeleteProgram(shader);
+ return 0;
+}
diff --git a/src/shader/shader.h b/src/shader/shader.h
index 07cc22d..95956ea 100644
--- a/src/shader/shader.h
+++ b/src/shader/shader.h
@@ -7,111 +7,94 @@
#define HONEY_SHADER_H
#include "../common.h"
-#include "../light/light.h"
-typedef int honey_shader;
+/** @brief Push the shader table to the lua stack.
+ */
+void honey_setup_shader(lua_State* L);
-/** @brief Load a shader.
+/** @brief Create a new shader from source.
*
- * @param[out] shader Pointer to the shader destination
+ * @param[in] vertex_source The GLSL code for the vertex shader.
+ * @param[in] fragment_source The GLSL code for the fragment shader.
*
- * @param[in] vertex_shader_path The path to the vertex shader source code
- * @param[in] fragment_shader_path The path to the fragment shader source code
- *
- * @return The result of the shader load.
+ * @returns OpenGL handle for the compiled shader.
*/
-honey_result honey_shader_load(honey_shader* shader,
- char* vertex_shader_path,
- char* fragment_shader_path);
+int honey_shader_new(lua_State* L);
-/** @brief Create a shader from code strings.
+/** @brief Set a shader as the current OpenGL shader.
*
- * @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
+ * @param[in] shader The OpenGL handle to a shader, as generated by honey.shader.new
*
- * @return The result of the shader creation.
+ * @returns Nothing.
*/
-honey_result honey_shader_new(honey_shader* shader,
- char* vertex_shader_code,
- char* fragment_shader_code);
+int honey_shader_use(lua_State* L);
-/** @brief Set an integer uniform.
+/** @brief Set an integer uniform on a shader.
*
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] int_name The name of the integer uniform
- * @param[in] value The value of the integer uniform
- */
-void honey_shader_set_int(honey_shader shader,
- char* int_name,
- int value);
-
-/** @brief Set a float uniform.
+ * @param[in] shader The OpenGL shader handle.
+ * @param[in] name The name of the shader uniform as a string.
+ * @param[in] value The value to set the uniform to.
*
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] float_name The name of the float uniform
- * @param[in] value The value of the float uniform
+ * @returns Nothing.
*/
-void honey_shader_set_float(honey_shader shader,
- char* float_name,
- float value);
+int honey_shader_set_int(lua_State* L);
-/** @brief Set a vec3 uniform.
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] vector_name The name of the vec3 uniform
- * @param[in] value The value of the vector uniform
- */
-void honey_shader_set_vec3(honey_shader shader,
- char* vector_name,
- vec3 value);
-
-
-/** @brief Set a mat3 uniform.
+/** @brief Set a float uniform on a shader.
+ *
+ * @param[in] shader The OpenGL shader handle.
+ * @param[in] name The name of the shader uniform as a string.
+ * @param[in] value The value to set the uniform to.
*
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] matrix_name The name of the matrix uniform
- * @param[in] value The value of the matrix uniform
+ * @returns Nothing.
*/
-void honey_shader_set_mat3(honey_shader shader,
- char* matrix_name,
- mat3 value);
+int honey_shader_set_float(lua_State* L);
-/** @brief Set a mat4 uniform.
+/** @brief Set a vec3 uniform on a shader.
*
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] matrix_name The name of the matrix uniform
- * @param[in] value The value of the matrix uniform
+ * @param[in] shader The OpenGL shader handle.
+ * @param[in] name The name of the shader uniform as a string.
+ * @param[in] value The value to set the uniform to.
+ *
+ * @returns Nothing.
*/
-void honey_shader_set_mat4(honey_shader shader,
- char* matrix_name,
- mat4 value);
+int honey_shader_set_vec3(lua_State* L);
-/** @brief Set a point_light uniform.
+/** @brief Set a vec4 uniform on a shader.
+ *
+ * @param[in] shader The OpenGL shader handle.
+ * @param[in] name The name of the shader uniform as a string.
+ * @param[in] value The value to set the uniform to.
*
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] point_light_index The index of the light to set
- * @param[in] light The honey_point_light to set
+ * @returns Nothing.
*/
-void honey_shader_set_point_light(honey_shader shader,
- int point_light_index,
- honey_point_light light);
+int honey_shader_set_vec4(lua_State* L);
-/** @brief Set a directional_light uniform.
+/** @brief Set a mat3 uniform on a shader.
*
- * @param[in] shader The shader to which the uniform belongs
- * @param[in] directional_light_index The index of the light to set
- * @param[in] light The honey_directional_light to set
+ * @param[in] shader The OpenGL shader handle.
+ * @param[in] name The name of the shader uniform as a string.
+ * @param[in] value The value to set the uniform to.
+ *
+ * @returns Nothing.
*/
-void honey_shader_set_directional_light(honey_shader shader,
- int directional_light_index,
- honey_directional_light light);
+int honey_shader_set_mat3(lua_State* L);
-/** @brief Use a shader.
+/** @brief Set a mat4 uniform on a shader.
+ *
+ * @param[in] shader The OpenGL shader handle.
+ * @param[in] name The name of the shader uniform as a string.
+ * @param[in] value The value to set the uniform to.
+ *
+ * @returns Nothing.
*/
-#define honey_shader_use glUseProgram
+int honey_shader_set_mat4(lua_State* L);
-/** @brief delete a shader.
+/** @brief Delete a shader.
+ *
+ * @param[in] shader An OpenGL shader handle.
+ *
+ * @returns Nothing.
*/
-#define honey_shader_delete glDeleteProgram
+int honey_shader_delete(lua_State* L);
#endif