fc9816a988752b9dc121b8c73cf27f8fba55eaf4
[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 enum nex_tex_type {
34         NEX_TEX1D,
35         NEX_TEX2D,
36         NEX_TEX3D,
37         NEX_TEXCUBE
38 };
39
40 enum nex_cube_face {
41         NEX_CUBE_PX, NEX_CUBE_NX,
42         NEX_CUBE_PY, NEX_CUBE_NY,
43         NEX_CUBE_PZ, NEX_CUBE_NZ
44 };
45
46 typedef struct nex_buffer nex_buffer;
47 typedef struct nex_geometry nex_geometry;
48 typedef struct nex_shader nex_shader;
49 typedef struct nex_sdrprog nex_sdrprog;
50 typedef struct nex_texture nex_texture;
51
52 void nex_clear(void);
53 void nex_clearcolor(float r, float g, float b);
54 void nex_cleardepth(float z);
55 void nex_clearstencil(unsigned int s);
56
57 void nex_viewport(int x, int y, int w, int h);
58
59 void nex_enable(enum nex_state_opt opt);
60 void nex_disable(enum nex_state_opt opt);
61 int nex_is_enabled(enum nex_state_opt opt);
62
63 /* --- buffers and geometry --- */
64 nex_buffer *nex_alloc_buffer(size_t sz, const void *data);
65 void nex_free_buffer(nex_buffer *buf);
66 nex_geometry *nex_alloc_geometry(void);
67 void nex_free_geometry(nex_geometry *geom);
68
69 void nex_geom_vbuffer(nex_geometry *geom, unsigned int bufid, const nex_buffer *buf,
70                 unsigned int stride);
71 void nex_geom_ibuffer(nex_geometry *geom, const nex_buffer *buf);
72 void nex_geom_vattr(nex_geometry *geom, unsigned int attr,
73                 enum nex_vattr_type type, int bufid, unsigned int offs);
74
75 void nex_draw_geometry(const nex_geometry *geom, enum nex_primitive prim, unsigned int count);
76
77 /* --- shaders --- */
78 nex_shader *nex_alloc_shader(enum nex_sdr_type type);
79 void nex_free_shader(nex_shader *sdr);  /* refcounted */
80
81 nex_sdrprog *nex_alloc_sdrprog(void);
82 void nex_free_sdrprog(nex_sdrprog *prog);
83
84 void nex_sdrname(nex_shader *sdr, const char *name);
85 void nex_sdrsrc(nex_shader *sdr, const char *src);
86 void nex_sdrbin(nex_shader *sdr, void *bin, size_t sz);
87
88 void nex_sdrconst_int(nex_shader *sdr, int id, int val);
89 void nex_sdrconst_float(nex_shader *sdr, int id, float val);
90 int nex_build_shader(nex_shader *sdr);
91
92 void nex_attach_shader(nex_sdrprog *prog, nex_shader *sdr);
93 int nex_build_sdrprog(nex_sdrprog *prog);
94 void nex_bind_sdrprog(nex_sdrprog *prog);
95
96 int nex_find_uniform(nex_sdrprog *prog, const char *name);
97 void nex_uniform_mat4(nex_sdrprog *prog, int loc, const float *mat);
98 void nex_uniform_mat4_name(nex_sdrprog *prog, const char *name, const float *mat);
99
100 nex_shader *nex_load_shader(const char *path, enum nex_sdr_type type);
101 nex_sdrprog *nex_load_sdrprog(const char *vpath, const char *ppath);
102
103 /* --- textures --- */
104 nex_texture *nex_alloc_texture(enum nex_tex_type type);
105 void nex_free_texture(nex_texture *tex);
106
107 #endif  /* NEXUS3D_GFX_H_ */