diff options
author | sanine-a <sanine.not@pm.me> | 2020-06-05 18:20:49 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-06-05 18:20:49 -0500 |
commit | e4dd7978d24f53465c8475bd3a027047b4a53bb8 (patch) | |
tree | 5c861830a2f7ad6ed2bcc0f9f04cd504403b3292 | |
parent | 70784cdb24628e758df27cbe1965ff83102decb0 (diff) |
refactor: rename honey_error to honey_result
-rw-r--r-- | include/common.h | 4 | ||||
-rw-r--r-- | include/mesh.h | 21 | ||||
-rw-r--r-- | include/model.h | 2 | ||||
-rw-r--r-- | include/primitives.h | 31 | ||||
-rw-r--r-- | include/scene.h | 27 | ||||
-rw-r--r-- | include/shader.h | 4 | ||||
-rw-r--r-- | src/error.c | 2 | ||||
-rw-r--r-- | src/mesh.c | 24 | ||||
-rw-r--r-- | src/model.c | 2 | ||||
-rw-r--r-- | src/primitives.c | 58 | ||||
-rw-r--r-- | src/shader.c | 8 |
11 files changed, 124 insertions, 59 deletions
diff --git a/include/common.h b/include/common.h index 680f097..56c1634 100644 --- a/include/common.h +++ b/include/common.h @@ -40,7 +40,7 @@ typedef enum { /* model errors */ HONEY_MODEL_LOAD_ERROR, - HONEY_N_ERRORS } honey_error; + HONEY_N_ERRORS } honey_result; #define HONEY_ERROR_DATA_STRING_LENGTH 4096 @@ -58,6 +58,6 @@ void honey_error_set_string2(char* string); * @param[out] error_string A string with at least 3*HONEY_ERROR_DATA_STRING_LENGTH characters to store the result * @param[in] error The error to generate a message for */ -void honey_human_readable_error(char* error_string, honey_error error); +void honey_human_readable_error(char* error_string, honey_result error); #endif diff --git a/include/mesh.h b/include/mesh.h index e3b5c39..de2370f 100644 --- a/include/mesh.h +++ b/include/mesh.h @@ -11,13 +11,6 @@ #include "common.h" #include "shader.h" -enum honey_mesh_result { - MESH_OK, - MEMORY_ERROR, - BAD_VERTEX_DATA, - BAD_INDEX_DATA, - N_MESH_RESULTS }; - typedef struct { float* vertices; unsigned int n_vertices; @@ -39,13 +32,13 @@ typedef struct { * @param[in] indices Array of vertex indices * @param[in] n_indices The number of elements in the index array */ -enum honey_mesh_result honey_mesh_new(honey_mesh* mesh, - float* vertices, - unsigned int n_vertices, - unsigned int n_attributes, - unsigned int* attribute_sizes, - unsigned int* indices, - unsigned int n_indices); +honey_result honey_mesh_new(honey_mesh* mesh, + float* vertices, + unsigned int n_vertices, + unsigned int n_attributes, + unsigned int* attribute_sizes, + unsigned int* indices, + unsigned int n_indices); /** @brief Draw a mesh on screen. * diff --git a/include/model.h b/include/model.h index 00d20b7..d210792 100644 --- a/include/model.h +++ b/include/model.h @@ -22,7 +22,7 @@ typedef struct { * @param[out] model Pointer to the destination honey_model struct. * @param[in] path Path of the model to be loaded. */ -honey_error honey_model_load(honey_model* model, char* path); +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); diff --git a/include/primitives.h b/include/primitives.h index a7e4ccb..58e9dd3 100644 --- a/include/primitives.h +++ b/include/primitives.h @@ -9,6 +9,21 @@ #include "common.h" #include "mesh.h" +/** @brief Create a textured plane. + * + * This function creates a plane with vertex positions in attribute 0, + * vertex normals in attribute 1, and UV coordinates in attribute 2. + * + * @param[out] mesh Pointer to the destination mesh + * @param[in] width Desired width of the plane (x-axis) + * @param[in] height Desired height of the plane (y-axis) + * + * @return 0 (HONEY_OK) on success, and an error code otherwise. + */ +honey_result honey_mesh_new_textured_plane(honey_mesh* mesh, + float width, + float height); + /** @brief Create a cube. * * This function creates a cube with vertex positions in attribute 0. @@ -20,10 +35,10 @@ * * @return Success or failure code */ -enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh, - float width, - float height, - float depth); +honey_result honey_mesh_new_cube(honey_mesh* mesh, + float width, + float height, + float depth); /** @brief Create a textured cube. * * This function creates a cube with vertex positions in attribute 0, @@ -36,9 +51,9 @@ enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh, * * @return Success or failure code */ -enum honey_mesh_result honey_mesh_new_textured_cube(honey_mesh* mesh, - float width, - float height, - float depth); +honey_result honey_mesh_new_textured_cube(honey_mesh* mesh, + float width, + float height, + float depth); #endif diff --git a/include/scene.h b/include/scene.h new file mode 100644 index 0000000..c998af9 --- /dev/null +++ b/include/scene.h @@ -0,0 +1,27 @@ +#ifndef HONEY_SCENE_H +#define HONEY_SCENE_H + +#include "common.h" +#include "light.h" +#include "model.h" +#include "texture.h" + +#define HONEY_SCENE_MAX_POINT_LIGHTS 8 +#define HONEY_SCENE_MAX_DIRECTIONAL_LIGHTS 8 +#define HONEY_SCENE_MAX_MODELS 8 +#define HONEY_SCENE_MAX_TEXTURES 8 + +typedef struct { + honey_point_light point_lights[HONEY_SCENE_MAX_POINT_LIGHTS]; + unsigned int n_point_lights; + + honey_directional_light directional_lights[HONEY_SCENE_MAX_DIRECTIONAL_LIGHTS]; + unsigned int n_directional_lights; + + honey_mode models[HONEY_SCENE_MAX_MODELS]; + unsigned int n_models; +} honey_scene; + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +#endif diff --git a/include/shader.h b/include/shader.h index b502137..cca8ab9 100644 --- a/include/shader.h +++ b/include/shader.h @@ -20,7 +20,7 @@ typedef int honey_shader; * * @return The result of the shader load. */ -honey_error honey_shader_load(honey_shader* shader, +honey_result honey_shader_load(honey_shader* shader, char* vertex_shader_path, char* fragment_shader_path); @@ -32,7 +32,7 @@ honey_error honey_shader_load(honey_shader* shader, * * @return The result of the shader creation. */ -honey_error honey_shader_new(honey_shader* shader, +honey_result honey_shader_new(honey_shader* shader, char* vertex_shader_code, char* fragment_shader_code); diff --git a/src/error.c b/src/error.c index 4e60301..c5fa5b1 100644 --- a/src/error.c +++ b/src/error.c @@ -27,7 +27,7 @@ void honey_error_set_string2(char* string) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void honey_human_readable_error(char* error_string, honey_error error) { +void honey_human_readable_error(char* error_string, honey_result error) { size_t string_size = sizeof(char)*3*HONEY_ERROR_DATA_STRING_LENGTH; switch(error) { @@ -1,17 +1,17 @@ #include "include/mesh.h" -enum honey_mesh_result honey_mesh_new(honey_mesh* mesh, - float* vertices, - unsigned int n_vertices, - unsigned int n_attributes, - unsigned int* attribute_sizes, - unsigned int* indices, - unsigned int n_indices) { +honey_result honey_mesh_new(honey_mesh* mesh, + float* vertices, + unsigned int n_vertices, + unsigned int n_attributes, + unsigned int* attribute_sizes, + unsigned int* indices, + unsigned int n_indices) { if (vertices == NULL || n_vertices == 0) { - return BAD_VERTEX_DATA; + return HONEY_MESH_BAD_VERTEX_DATA; } if (indices == NULL || n_indices == 0) { - return BAD_INDEX_DATA; + return HONEY_MESH_BAD_INDEX_DATA; } unsigned int vertex_size = 0; @@ -21,13 +21,13 @@ enum honey_mesh_result honey_mesh_new(honey_mesh* mesh, (*mesh).vertices = malloc(vertex_size*n_vertices * sizeof(float)); if ((*mesh).vertices == NULL) { - return MEMORY_ERROR; + return HONEY_MEMORY_ALLOCATION_ERROR; } memcpy((*mesh).vertices, vertices, vertex_size*n_vertices*sizeof(float)); (*mesh).indices = malloc(n_indices * sizeof(unsigned int)); if ((*mesh).indices == NULL) { - return MEMORY_ERROR; + return HONEY_MEMORY_ALLOCATION_ERROR; } memcpy((*mesh).indices, indices, n_indices * sizeof(unsigned int)); @@ -61,7 +61,7 @@ enum honey_mesh_result honey_mesh_new(honey_mesh* mesh, glBindVertexArray(0); - return MESH_OK; + return HONEY_OK; } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ diff --git a/src/model.c b/src/model.c index 00837f7..48f6653 100644 --- a/src/model.c +++ b/src/model.c @@ -81,7 +81,7 @@ static void process_assimp_node(honey_model* model, struct aiNode* node, struct /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -honey_error honey_model_load(honey_model* model, +honey_result honey_model_load(honey_model* model, char* path) { model->n_meshes = 0; diff --git a/src/primitives.c b/src/primitives.c index 4e6d93b..37d549b 100644 --- a/src/primitives.c +++ b/src/primitives.c @@ -1,9 +1,39 @@ #include "include/primitives.h" -enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh, +honey_result honey_mesh_new_textured_plane(honey_mesh* mesh, float width, - float height, - float depth) { + float height) { + float x0 = 0; + float y0 = 0; + float x1 = width; + float y1 = height; + + float vertices[] = { + /* position normal uv */ + x0, y0, 0, 0, 0, 1, 0, 0, + x1, y0, 0, 0, 0, 1, 1, 0, + x0, y1, 0, 0, 0, 1, 0, 1, + x1, y1, 0, 0, 0, 1, 1, 1 }; + + unsigned int indices[] = { + 0, 1, 2, + 1, 2, 3 }; + + unsigned int attrib_sizes[] = { 3, 3, 2 }; + + honey_result result = honey_mesh_new(mesh, + vertices, 4, + 3, attrib_sizes, + indices, 6); + return result; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +honey_result honey_mesh_new_cube(honey_mesh* mesh, + float width, + float height, + float depth) { float x0 = 0; float y0 = 0; float z0 = 0; @@ -50,7 +80,7 @@ enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh, x0, y1, z1, 0, 1, 0, x1, y1, z1, 0, 1, 0 }; - unsigned int indices[] = { + unsigned int indices[] = { 0, 1, 2, 1, 2, 3, 4, 5, 6, @@ -66,20 +96,20 @@ enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh, unsigned int attrib_sizes[] = { 3, 3 }; - enum honey_mesh_result result = honey_mesh_new(mesh, - vertices, 24, - 2, attrib_sizes, - indices, 36); + honey_result result = honey_mesh_new(mesh, + vertices, 24, + 2, attrib_sizes, + indices, 36); return result; } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -enum honey_mesh_result honey_mesh_new_textured_cube(honey_mesh* mesh, - float width, - float height, - float depth) { +honey_result honey_mesh_new_textured_cube(honey_mesh* mesh, + float width, + float height, + float depth) { float x0 = 0; float y0 = 0; float z0 = 0; @@ -88,7 +118,7 @@ enum honey_mesh_result honey_mesh_new_textured_cube(honey_mesh* mesh, float y1 = height; float z1 = depth; - float vertices[] = { + float vertices[] = { /* position normal tex coord */ /* back face */ x0, y0, z0, 0, 0, -1, 0, 0, @@ -142,7 +172,7 @@ enum honey_mesh_result honey_mesh_new_textured_cube(honey_mesh* mesh, unsigned int attrib_sizes[] = { 3, 3, 2 }; - enum honey_mesh_result result; + honey_result result; result = honey_mesh_new(mesh, vertices, 24, 3, attrib_sizes, indices, 36); diff --git a/src/shader.c b/src/shader.c index d570f52..898a7fc 100644 --- a/src/shader.c +++ b/src/shader.c @@ -2,7 +2,7 @@ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static honey_error read_file(char** destination, char* file_path) { +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); @@ -27,12 +27,12 @@ static honey_error read_file(char** destination, char* file_path) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -honey_error honey_shader_load(honey_shader* shader, +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_error result = read_file(&vertex_shader_code, + honey_result result = read_file(&vertex_shader_code, vertex_shader_path); if (result != HONEY_OK) return result; @@ -62,7 +62,7 @@ honey_error honey_shader_load(honey_shader* shader, /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -honey_error honey_shader_new(honey_shader* shader, +honey_result honey_shader_new(honey_shader* shader, char* vertex_shader_code, char* fragment_shader_code) { /* compile shaders */ |