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