summaryrefslogtreecommitdiff
path: root/micro/renderer.h
blob: 7ddddf57c6e12c89430ac0229ef7783126c8b300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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__