5faf474a9cb80f67f2e88abfbb4993ec95a67d6f
[nexus3d] / src / gfx.h
1 #ifndef NEXUS3D_GFX_H_
2 #define NEXUS3D_GFX_H_
3
4 #include <stddef.h>
5
6 enum nex_state_flags {
7         NEX_DEPTH_TEST          = 0x0001,
8         NEX_STENCIL_TEST        = 0x0002,
9         NEX_BLEND                       = 0x0004,
10 };
11
12 enum nex_vattr_type {
13         NEX_FLOAT,
14         NEX_VEC2, NEX_VEC3, NEX_VEC4,
15         NEX_COL3, NEX_COL4
16 };
17
18 enum nex_primitive {
19         NEX_POINTS,
20         NEX_LINES,
21         NEX_LINE_STRIP,
22         NEX_TRIANGLES,
23         NEX_TRIANGLE_STRIP,
24         NEX_TRIANGLE_FAN
25 };
26
27 enum nex_sdr_type {
28         NEX_SDR_VERTEX,
29         NEX_SDR_PIXEL
30 };
31
32 typedef struct nex_buffer nex_buffer;
33 typedef struct nex_geometry nex_geometry;
34 typedef struct nex_shader nex_shader;
35 typedef struct nex_sdrprog nex_sdrprog;
36
37 void nex_clear(void);
38 void nex_clearcolor(float r, float g, float b);
39 void nex_cleardepth(float z);
40 void nex_clearstencil(unsigned int s);
41
42 void nex_viewport(int x, int y, int w, int h);
43
44 /* --- buffers and geometry --- */
45 nex_buffer *nex_alloc_buffer(size_t sz, const void *data);
46 void nex_free_buffer(nex_buffer *buf);
47 nex_geometry *nex_alloc_geometry(void);
48 void nex_free_geometry(nex_geometry *geom);
49
50 void nex_geom_vbuffer(nex_geometry *geom, unsigned int bufid, const nex_buffer *buf,
51                 unsigned int stride);
52 void nex_geom_ibuffer(nex_geometry *geom, const nex_buffer *buf);
53 void nex_geom_vattr(nex_geometry *geom, unsigned int attr,
54                 enum nex_vattr_type type, int bufid, unsigned int offs);
55
56 void nex_draw_geometry(const nex_geometry *geom, enum nex_primitive prim, unsigned int count);
57
58 /* --- shaders --- */
59 nex_shader *nex_alloc_shader(enum nex_sdr_type type);
60 void nex_free_shader(nex_shader *sdr);  /* refcounted */
61
62 nex_sdrprog *nex_alloc_sdrprog(void);
63 void nex_free_sdrprog(nex_sdrprog *prog);
64
65 void nex_sdrname(nex_shader *sdr, const char *name);
66 void nex_sdrsrc(nex_shader *sdr, const char *src);
67 void nex_sdrbin(nex_shader *sdr, void *bin, size_t sz);
68
69 void nex_sdrconst_int(nex_shader *sdr, int id, int val);
70 void nex_sdrconst_float(nex_shader *sdr, int id, float val);
71 int nex_build_shader(nex_shader *sdr);
72
73 void nex_attach_shader(nex_sdrprog *prog, nex_shader *sdr);
74 int nex_build_sdrprog(nex_sdrprog *prog);
75 void nex_bind_sdrprog(nex_sdrprog *prog);
76
77 nex_shader *nex_load_shader(const char *path, enum nex_sdr_type type);
78 nex_sdrprog *nex_load_sdrprog(const char *vpath, const char *ppath);
79
80 #endif  /* NEXUS3D_GFX_H_ */