summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-01-11 22:09:48 -0500
committerrealtradam <[email protected]>2023-01-11 22:09:48 -0500
commitb172c2a6b22796dc16c059979d2ec6108b0402e4 (patch)
tree9eda4db6d584b4c0415d30c9b5295aaf541f938b /src
parentb4bc89485ab18ccdc2e381e3e3f2c3bb5e346e1e (diff)
downloadRodeoKit-b172c2a6b22796dc16c059979d2ec6108b0402e4.tar.gz
RodeoKit-b172c2a6b22796dc16c059979d2ec6108b0402e4.zip
isolated dependencies into seperate compilation unit, added basic logging
Diffstat (limited to 'src')
-rw-r--r--src/private/rodeo_error.h20
-rw-r--r--src/private/rodeo_internal.h7
-rw-r--r--src/private/rodeo_internal_types.h35
-rw-r--r--src/rodeo.c83
-rw-r--r--src/rodeo_error.c48
-rw-r--r--src/rodeo_math.c4
-rw-r--r--src/rodeo_types.c34
7 files changed, 215 insertions, 16 deletions
diff --git a/src/private/rodeo_error.h b/src/private/rodeo_error.h
new file mode 100644
index 0000000..d1b9eb5
--- /dev/null
+++ b/src/private/rodeo_error.h
@@ -0,0 +1,20 @@
+
+#define RODEO__EMPTY_ERROR_MESSAGE NULL
+
+typedef
+enum
+{
+ RODEO__ERROR__UNREACHABLE_REACHED,
+ RODEO__ERROR__UNINITIALIZED_STATE
+}
+Rodeo__\
+error;
+
+void
+Rodeo__\
+error_exit(
+ Rodeo__error error,
+ const char *function,
+ int line_number,
+ const char *extra_info
+);
diff --git a/src/private/rodeo_internal.h b/src/private/rodeo_internal.h
new file mode 100644
index 0000000..f01ac87
--- /dev/null
+++ b/src/private/rodeo_internal.h
@@ -0,0 +1,7 @@
+
+// private internal
+#include "private/rodeo_internal_types.h"
+
+bgfx_shader_handle_t
+_Rodeo__\
+load_shader(const char* path);
diff --git a/src/private/rodeo_internal_types.h b/src/private/rodeo_internal_types.h
new file mode 100644
index 0000000..1dfa485
--- /dev/null
+++ b/src/private/rodeo_internal_types.h
@@ -0,0 +1,35 @@
+#pragma once
+
+// public internal
+#include "rodeo_config.h"
+#include "rodeo_types.h"
+
+// system
+#include "SDL2/SDL.h"
+#include "SDL2/SDL_syswm.h"
+#include "bgfx/c99/bgfx.h"
+
+struct
+Rodeo__\
+data
+{
+ SDL_Window* window;
+ SDL_Surface* screen_surface;
+ SDL_SysWMinfo wmi;
+ int screen_width;
+ int screen_height;
+ SDL_Event sdl_event;
+ bool quit;
+
+ bgfx_vertex_layout_t vertex_layout;
+ bgfx_dynamic_vertex_buffer_handle_t vertex_buffer_handle;
+ bgfx_dynamic_index_buffer_handle_t index_buffer_handle;
+ uint16_t vertex_size;
+ Rodeo__position_color_vertex_t batched_vertices[RODEO__MAX_VERTEX_SIZE];
+ uint16_t index_count;
+ uint16_t index_size;
+ uint16_t batched_indices[(RODEO__MAX_VERTEX_SIZE / 4) * 6];
+ bgfx_shader_handle_t vertex_shader;
+ bgfx_shader_handle_t fragment_shader;
+ bgfx_program_handle_t program_shader;
+} Rodeo__data_t;
diff --git a/src/rodeo.c b/src/rodeo.c
index 3f946ea..e50debb 100644
--- a/src/rodeo.c
+++ b/src/rodeo.c
@@ -1,23 +1,42 @@
+
+// public internal
+#include "rodeo.h"
+#include "rodeo_math.h"
+#include "rodeo_types.h"
+// private internal
+#include "private/rodeo_internal.h"
+#include "private/rodeo_internal_types.h"
+#include "private/rodeo_error.h"
+
+// external
#include "SDL2/SDL.h"
#include "SDL2/SDL_syswm.h"
#include "bgfx/c99/bgfx.h"
//#define CGLM_FORCE_LEFT_HANDED
-//#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#define CGLM_CLIPSPACE_INCLUDE_ALL
+#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
+//#define CGLM_CLIPSPACE_INCLUDE_ALL
#include "cglm/cglm.h"
-#include "rodeo.h"
-#include "rodeo_math.h"
-
void
Rodeo__\
init_window(
- Rodeo__data_t* state,
+ Rodeo__data_p *state_p,
int screen_height,
int screen_width,
char* title
)
{
+ *state_p = (Rodeo__data_p)malloc(sizeof(Rodeo__data_t));
+ Rodeo__data_p state = *state_p;
+ if(!state)
+ {
+ Rodeo__error_exit(
+ RODEO__ERROR__UNINITIALIZED_STATE,
+ __FUNCTION__,
+ __LINE__,
+ "Malloc failed to initialize state."
+ );
+ }
state->window = NULL;
state->screen_surface = NULL;
state->screen_height = screen_height;
@@ -97,8 +116,8 @@ init_window(
state->index_buffer_handle = bgfx_create_dynamic_index_buffer((RODEO__MAX_VERTEX_SIZE / 4) * 6, BGFX_BUFFER_NONE);
// load shaders
- state->vertex_shader = Rodeo__load_shader("./external/RodeoEngine/build_dir/simple.vertex.bin");
- state->fragment_shader = Rodeo__load_shader("./external/RodeoEngine/build_dir/simple.fragment.bin");
+ state->vertex_shader = _Rodeo__load_shader("./external/RodeoEngine/build_dir/simple.vertex.bin");
+ state->fragment_shader = _Rodeo__load_shader("./external/RodeoEngine/build_dir/simple.fragment.bin");
state->program_shader = bgfx_create_program(
state->vertex_shader,
state->fragment_shader,
@@ -108,8 +127,17 @@ init_window(
void
Rodeo__\
-deinit_window(Rodeo__data_t* state)
+deinit_window(Rodeo__data_p state)
{
+ if(!state)
+ {
+ Rodeo__error_exit(
+ RODEO__ERROR__UNINITIALIZED_STATE,
+ __FUNCTION__,
+ __LINE__,
+ RODEO__EMPTY_ERROR_MESSAGE
+ );
+ }
bgfx_destroy_dynamic_index_buffer(state->index_buffer_handle);
bgfx_destroy_dynamic_vertex_buffer(state->vertex_buffer_handle);
bgfx_destroy_program(state->program_shader);
@@ -126,8 +154,17 @@ quit()
void
Rodeo__\
-begin(Rodeo__data_t* state)
+begin(Rodeo__data_p state)
{
+ if(!state)
+ {
+ Rodeo__error_exit(
+ RODEO__ERROR__UNINITIALIZED_STATE,
+ __FUNCTION__,
+ __LINE__,
+ RODEO__EMPTY_ERROR_MESSAGE
+ );
+ }
//vec3 eye = {0.0f, 0.0f, -35.0f};
//vec3 center = {0.0f, 0.0f, 0.0f};
//vec3 up = {0, 1, 0};
@@ -158,8 +195,17 @@ begin(Rodeo__data_t* state)
void
Rodeo__\
-end(Rodeo__data_t* state)
+end(Rodeo__data_p state)
{
+ if(!state)
+ {
+ Rodeo__error_exit(
+ RODEO__ERROR__UNINITIALIZED_STATE,
+ __FUNCTION__,
+ __LINE__,
+ RODEO__EMPTY_ERROR_MESSAGE
+ );
+ }
Rodeo__flush_batch(state);
bgfx_frame(false);
@@ -173,6 +219,13 @@ end(Rodeo__data_t* state)
}
}
+bool
+Rodeo__\
+should_quit(Rodeo__data_p state)
+{
+ return state->quit;
+}
+
void
Rodeo__\
draw_debug_text(u_int16_t x, u_int16_t y, const char *format, ...)
@@ -192,7 +245,7 @@ get_renderer_name_as_string()
void
Rodeo__\
-flush_batch(Rodeo__data_t *state)
+flush_batch(Rodeo__data_p state)
{
if(state->vertex_size > 0)
{
@@ -229,12 +282,12 @@ flush_batch(Rodeo__data_t *state)
void
Rodeo__\
draw_rectangle(
- Rodeo__data_t *state,
+ Rodeo__data_p state,
u_int16_t x,
u_int16_t y,
u_int16_t width,
u_int16_t height,
- struct Rodeo__color_rgba_t color
+ Rodeo__color_rgba_t color
)
{
const uint32_t abgr = Rodeo__Math__color_rgba_to_uint32(color);
@@ -294,7 +347,7 @@ draw_rectangle(
}
bgfx_shader_handle_t
-Rodeo__\
+_Rodeo__\
load_shader(const char* path)
{
bgfx_shader_handle_t invalid = BGFX_INVALID_HANDLE;
diff --git a/src/rodeo_error.c b/src/rodeo_error.c
new file mode 100644
index 0000000..1b5b03d
--- /dev/null
+++ b/src/rodeo_error.c
@@ -0,0 +1,48 @@
+
+// private internal
+#include "private/rodeo_error.h"
+
+// system
+#include <stdlib.h>
+#include <stdio.h>
+
+void
+Rodeo__\
+error_exit(
+ Rodeo__error error,
+ const char *function,
+ int line_number,
+ const char *extra_info
+)
+{
+ switch(error)
+ {
+ case RODEO__ERROR__UNREACHABLE_REACHED:
+ printf("[ERROR] RODEO: \n\t(func: %s, line: %d)\n", function, line_number);
+ printf("\tUnreachable code reached.\n");
+ if(extra_info)
+ {
+ printf("\t%s\n", extra_info);
+ }
+ fflush(stdout);
+ break;
+ case RODEO__ERROR__UNINITIALIZED_STATE:
+ printf("RODEO ERROR: \n\t(func: %s, line: %d)\n", function, line_number);
+ printf("\tUninitialized State.\n");
+ if(extra_info)
+ {
+ printf("\t%s\n", extra_info);
+ }
+ fflush(stdout);
+ break;
+ default:
+ Rodeo__error_exit(
+ RODEO__ERROR__UNREACHABLE_REACHED,
+ __FUNCTION__,
+ __LINE__,
+ "Unhandled error code."
+ );
+ }
+ exit(EXIT_FAILURE);
+}
+
diff --git a/src/rodeo_math.c b/src/rodeo_math.c
index 99f61af..248e600 100644
--- a/src/rodeo_math.c
+++ b/src/rodeo_math.c
@@ -1,10 +1,12 @@
+
+// public internal
#include "rodeo.h"
#include "rodeo_math.h"
uint32_t
Rodeo__\
Math__\
-color_rgba_to_uint32(const struct Rodeo__color_rgba_t color)
+color_rgba_to_uint32(const Rodeo__color_rgba_t color)
{
return
((uint32_t)(uint8_t)(color.red * 255))
diff --git a/src/rodeo_types.c b/src/rodeo_types.c
new file mode 100644
index 0000000..d2c56aa
--- /dev/null
+++ b/src/rodeo_types.c
@@ -0,0 +1,34 @@
+
+// public internal
+#include "rodeo_types.h"
+#include "rodeo_config.h"
+
+// external
+#include "SDL2/SDL.h"
+#include "SDL2/SDL_syswm.h"
+#include "bgfx/c99/bgfx.h"
+
+struct
+Rodeo__\
+data_t
+{
+ SDL_Window* window;
+ SDL_Surface* screen_surface;
+ SDL_SysWMinfo wmi;
+ int screen_width;
+ int screen_height;
+ SDL_Event sdl_event;
+ bool quit;
+
+ bgfx_vertex_layout_t vertex_layout;
+ bgfx_dynamic_vertex_buffer_handle_t vertex_buffer_handle;
+ bgfx_dynamic_index_buffer_handle_t index_buffer_handle;
+ uint16_t vertex_size;
+ Rodeo__position_color_vertex_t batched_vertices[RODEO__MAX_VERTEX_SIZE];
+ uint16_t index_count;
+ uint16_t index_size;
+ uint16_t batched_indices[(RODEO__MAX_VERTEX_SIZE / 4) * 6];
+ bgfx_shader_handle_t vertex_shader;
+ bgfx_shader_handle_t fragment_shader;
+ bgfx_program_handle_t program_shader;
+};