From 957c64c7b8b5e98d8a03dd84c7e27e7991fb9dbc Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Mon, 6 Apr 2026 17:04:05 -0400 Subject: Initial commit --- micro/renderer.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 micro/renderer.h (limited to 'micro/renderer.h') 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__ -- cgit v1.3-2-g0d8e