summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-06-05 18:20:49 -0500
committersanine-a <sanine.not@pm.me>2020-06-05 18:20:49 -0500
commite4dd7978d24f53465c8475bd3a027047b4a53bb8 (patch)
tree5c861830a2f7ad6ed2bcc0f9f04cd504403b3292 /src
parent70784cdb24628e758df27cbe1965ff83102decb0 (diff)
refactor: rename honey_error to honey_result
Diffstat (limited to 'src')
-rw-r--r--src/error.c2
-rw-r--r--src/mesh.c24
-rw-r--r--src/model.c2
-rw-r--r--src/primitives.c58
-rw-r--r--src/shader.c8
5 files changed, 62 insertions, 32 deletions
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) {
diff --git a/src/mesh.c b/src/mesh.c
index 1b0fb1a..f92393c 100644
--- a/src/mesh.c
+++ b/src/mesh.c
@@ -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 */