summaryrefslogtreecommitdiff
path: root/src/draw.h
blob: 12825638ed075a440d2e5af258b8e6b9434e16ed (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
#ifndef ANIMTOOL_DRAW_H_
#define ANIMTOOL_DRAW_H_

#include "util/container.h"

typedef void *rgba_data;
typedef uint64_t texture_id;
typedef uint64_t mesh_id;

#define PRItexture_id PRIu64
#define PRImesh_id PRIu64

enum texture_type
{
    TEXTURE_2D,
    TEXTURE_CUBEMAP,
};

struct draw_vertex
{
    float pos[3];
    float tex[2];
    // float normal[3];
};

struct draw_surface
{
    option(texture_id) texture;
    float color[3];
};

struct draw_call
{
    mesh_id mesh;
    struct draw_surface surface;
    float model[4][4];
};

struct draw_frame
{
    option(struct draw_surface) bg;
    array(struct draw_call) calls;
    float view_proj[4][4];
};

struct draw_backend
{
    void (*init)(unsigned int size[2]);
    bool (*create_mesh)(size_t n_verts, const struct draw_vertex verts[n_verts], mesh_id *id);
    bool (*create_texture)(enum texture_type type, unsigned int size[2], const rgba_data faces[], texture_id *id);
    void (*draw_frame)(struct draw_frame *frame, rgba_data out_data);
    void (*cleanup)();
};

#endif