backport cont.
[dosdemo] / src / 3dgfx / 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,
48         G3D_ALPHA_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_ADD_BLEND   = 0x040000,
60
61         G3D_ALL = 0x7fffffff
62 };
63
64 /* arg to g3d_front_face */
65 enum { G3D_CCW, G3D_CW };
66
67 /* arg to g3d_polygon_mode */
68 enum {
69         G3D_WIRE,
70         G3D_FLAT,
71         G3D_GOURAUD
72 };
73
74 /* matrix stacks */
75 enum {
76         G3D_MODELVIEW,
77         G3D_PROJECTION,
78         G3D_TEXTURE,
79
80         G3D_NUM_MATRICES
81 };
82
83 int g3d_init(void);
84 void g3d_destroy(void);
85 void g3d_reset(void);
86
87 void g3d_framebuffer(int width, int height, void *pixels);
88 void g3d_framebuffer_addr(void *pixels);
89 void g3d_viewport(int x, int y, int w, int h);
90
91 void g3d_enable(unsigned int opt);
92 void g3d_disable(unsigned int opt);
93 void g3d_setopt(unsigned int opt, unsigned int mask);
94 unsigned int g3d_getopt(unsigned int mask);
95
96 void g3d_front_face(unsigned int order);
97 void g3d_polygon_mode(int pmode);
98 int g3d_get_polygon_mode(void);
99
100 void g3d_matrix_mode(int mmode);
101
102 void g3d_load_identity(void);
103 void g3d_load_matrix(const float *m);
104 void g3d_mult_matrix(const float *m);
105 void g3d_push_matrix(void);
106 void g3d_pop_matrix(void);
107
108 void g3d_translate(float x, float y, float z);
109 void g3d_rotate(float angle, float x, float y, float z);
110 void g3d_scale(float x, float y, float z);
111 void g3d_ortho(float left, float right, float bottom, float top, float znear, float zfar);
112 void g3d_frustum(float left, float right, float bottom, float top, float znear, float zfar);
113 void g3d_perspective(float vfov, float aspect, float znear, float zfar);
114
115 /* returns pointer to the *internal* matrix, and if argument m is not null,
116  * also copies the internal matrix there. */
117 const float *g3d_get_matrix(int which, float *m);
118
119 void g3d_light_pos(int idx, float x, float y, float z);
120 void g3d_light_dir(int idx, float x, float y, float z);
121 void g3d_light_color(int idx, float r, float g, float b);
122
123 void g3d_light_ambient(float r, float g, float b);
124
125 void g3d_mtl_diffuse(float r, float g, float b);
126 void g3d_mtl_specular(float r, float g, float b);
127 void g3d_mtl_shininess(float shin);
128
129 void g3d_set_texture(int xsz, int ysz, void *pixels);
130
131 void g3d_draw(int prim, const struct g3d_vertex *varr, int varr_size);
132 void g3d_draw_indexed(int prim, const struct g3d_vertex *varr, int varr_size,
133                 const uint16_t *iarr, int iarr_size);
134
135 void g3d_begin(int prim);
136 void g3d_end(void);
137 void g3d_vertex(float x, float y, float z);
138 void g3d_normal(float x, float y, float z);
139 void g3d_color3b(unsigned char r, unsigned char g, unsigned char b);
140 void g3d_color4b(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
141 void g3d_color3f(float r, float g, float b);
142 void g3d_color4f(float r, float g, float b, float a);
143 void g3d_texcoord(float u, float v);
144
145 #endif  /* THREEDGFX_H_ */