summaryrefslogtreecommitdiff
path: root/micro/renderer.h
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-04-06 17:04:05 -0400
committeriamcheeseman <[email protected]>2026-04-06 17:06:53 -0400
commit957c64c7b8b5e98d8a03dd84c7e27e7991fb9dbc (patch)
treef5fc230703791cee8d8e7851fb87eaef07ae63a2 /micro/renderer.h
Initial commit
Diffstat (limited to 'micro/renderer.h')
-rw-r--r--micro/renderer.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/micro/renderer.h b/micro/renderer.h
new file mode 100644
index 0000000..7ddddf5
--- /dev/null
+++ b/micro/renderer.h
@@ -0,0 +1,77 @@
+#ifndef __MICRO_RENDERER_H__
+#define __MICRO_RENDERER_H__
+
+#include "common.h"
+#include "mat4.h"
+#include "tex.h"
+
+#define MAX_BOUND_TEX 16
+
+enum blend_mode {
+ BLEND_ALPHA,
+ BLEND_ADD,
+};
+
+struct color {
+ float r;
+ float g;
+ float b;
+ float a;
+};
+
+struct vec3 {
+ float x;
+ float y;
+ float z;
+};
+
+struct vec2 {
+ float x;
+ float y;
+};
+
+struct vertex {
+ struct vec3 xyz;
+ struct vec2 uv;
+ struct color col;
+};
+
+struct draw_call {
+ struct texture textures[MAX_BOUND_TEX];
+ int next_tex_bind;
+ int cur_tex_bind;
+ int mesh_start;
+ int vert_count;
+ enum blend_mode blend_mode;
+
+ struct vec3 *xyz;
+ struct vec2 *uv;
+ struct color *col;
+ int *tex;
+
+ u16 *indices;
+};
+
+struct renderer {
+ struct ctx *ctx;
+ struct texture white_1x1;
+ struct draw_call dc;
+ struct color cur_col;
+ u32 shader_program;
+
+ mat4 projection;
+};
+
+void init_renderer(struct renderer *r, struct ctx *ctx);
+void deinit_renderer(struct renderer *r);
+void flush_pending(struct renderer *r);
+
+void draw_clear(struct color col);
+void draw_rect(struct renderer *r, float x, float y, float w, float h);
+void draw_texture(struct renderer *r, struct texture tex, float x, float y);
+void set_blend_mode(struct renderer *r, enum blend_mode mode);
+// NULL to unbind
+void bind_render_texture(struct renderer *r, struct render_texture *rtex);
+void end_draw(struct renderer *r);
+
+#endif // __MICRO_RENDERER_H__