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