3dgfx code, untested
[metatoy] / src / 3dgfx / 3dgfx.h
1 #ifndef THREEDGFX_H_
2 #define THREEDGFX_H_
3
4 #include <inttypes.h>
5
6 typedef unsigned char g3d_pixel;
7
8
9 struct g3d_vertex {
10         float x, y, z, w;
11         float nx, ny, nz;
12         float u, v;
13         unsigned char l, a;
14 };
15
16 enum {
17         G3D_POINTS = 1,
18         G3D_LINES = 2,
19         G3D_TRIANGLES = 3,
20         G3D_QUADS = 4
21 };
22
23 /* g3d_enable/g3d_disable bits */
24 enum {
25         G3D_CULL_FACE   = 0x000001,
26         G3D_DEPTH_TEST  = 0x000002,
27         G3D_LIGHTING    = 0x000004,
28         G3D_LIGHT0              = 0x000008,
29         G3D_LIGHT1              = 0x000010,
30         G3D_LIGHT2              = 0x000020,
31         G3D_LIGHT3              = 0x000040,
32         G3D_TEXTURE_2D  = 0x000080,
33         G3D_ALPHA_BLEND = 0x000100,
34         G3D_TEXTURE_GEN = 0x000200,
35         G3D_CLIP_FRUSTUM = 0x000800,/* when disabled, don't clip against the frustum */
36         G3D_CLIP_PLANE0 = 0x001000,     /* user-defined 3D clipping planes XXX not impl. */
37         G3D_CLIP_PLANE1 = 0x002000,
38         G3D_CLIP_PLANE2 = 0x004000,
39         G3D_CLIP_PLANE3 = 0x008000,
40
41         G3D_TEXTURE_MAT = 0x010000,
42         G3D_SPECULAR    = 0x020000,
43
44         G3D_ADD_BLEND   = 0x040000,
45
46         G3D_ALL = 0x7fffffff
47 };
48
49 /* arg to g3d_front_face */
50 enum { G3D_CCW, G3D_CW };
51
52 /* arg to g3d_polygon_mode */
53 enum {
54         G3D_WIRE,
55         G3D_FLAT,
56         G3D_GOURAUD
57 };
58
59 /* matrix stacks */
60 enum {
61         G3D_MODELVIEW,
62         G3D_PROJECTION,
63         G3D_TEXTURE,
64
65         G3D_NUM_MATRICES
66 };
67
68 /* clear bits */
69 enum {
70         G3D_COLOR_BUFFER_BIT = 1,
71         G3D_DEPTH_BUFFER_BIT = 2
72 };
73
74 int g3d_init(void);
75 void g3d_destroy(void);
76 void g3d_reset(void);
77
78 void g3d_framebuffer(int width, int height, void *pixels);
79 void g3d_framebuffer_addr(void *pixels);
80 void g3d_viewport(int x, int y, int w, int h);
81
82 void g3d_clear_color(unsigned char r, unsigned char g, unsigned char b);
83 void g3d_clear_depth(float z);
84 void g3d_clear(unsigned int mask);
85
86 void g3d_enable(unsigned int opt);
87 void g3d_disable(unsigned int opt);
88 void g3d_setopt(unsigned int opt, unsigned int mask);
89 unsigned int g3d_getopt(unsigned int mask);
90
91 void g3d_front_face(unsigned int order);
92 void g3d_polygon_mode(int pmode);
93 int g3d_get_polygon_mode(void);
94
95 void g3d_matrix_mode(int mmode);
96
97 void g3d_load_identity(void);
98 void g3d_load_matrix(const float *m);
99 void g3d_mult_matrix(const float *m);
100 void g3d_push_matrix(void);
101 void g3d_pop_matrix(void);
102
103 void g3d_translate(float x, float y, float z);
104 void g3d_rotate(float angle, float x, float y, float z);
105 void g3d_scale(float x, float y, float z);
106 void g3d_ortho(float left, float right, float bottom, float top, float znear, float zfar);
107 void g3d_frustum(float left, float right, float bottom, float top, float znear, float zfar);
108 void g3d_perspective(float vfov, float aspect, float znear, float zfar);
109
110 /* returns pointer to the *internal* matrix, and if argument m is not null,
111  * also copies the internal matrix there. */
112 const float *g3d_get_matrix(int which, float *m);
113
114 void g3d_light_pos(int idx, float x, float y, float z);
115 void g3d_light_dir(int idx, float x, float y, float z);
116 void g3d_light_energy(int idx, float val);
117
118 void g3d_light_ambient(float val);
119
120 void g3d_mtl_diffuse(float diffuse);
121 void g3d_mtl_specular(float spec);
122 void g3d_mtl_shininess(float shin);
123
124 void g3d_set_texture(int xsz, int ysz, void *pixels);
125
126 void g3d_draw(int prim, const struct g3d_vertex *varr, int varr_size);
127 void g3d_draw_indexed(int prim, const struct g3d_vertex *varr, int varr_size,
128                 const uint16_t *iarr, int iarr_size);
129
130 void g3d_begin(int prim);
131 void g3d_end(void);
132 void g3d_vertex(float x, float y, float z);
133 void g3d_normal(float x, float y, float z);
134 void g3d_color1b(unsigned char lum);
135 void g3d_color2b(unsigned char lum, unsigned char a);
136 void g3d_color1f(float lum);
137 void g3d_color2f(float lum, float a);
138 void g3d_texcoord(float u, float v);
139
140 #endif  /* THREEDGFX_H_ */