rev |
line source |
nuclear@0
|
1 #ifndef MGL_IMPL_H_
|
nuclear@0
|
2 #define MGL_IMPL_H_
|
nuclear@0
|
3
|
nuclear@14
|
4 #include "vmath.h"
|
nuclear@14
|
5
|
nuclear@0
|
6 #define MATRIX_STACK_SIZE 8
|
nuclear@0
|
7 #define MAX_LIGHTS 4
|
nuclear@28
|
8 #define MAX_CLIP_PLANES 6
|
nuclear@0
|
9
|
nuclear@9
|
10 #define ZTILE_SIZE 16384
|
nuclear@9
|
11 #define ZTILE_SHIFT 14
|
nuclear@9
|
12 #define ZTILE_MASK 0x3fff
|
nuclear@9
|
13
|
nuclear@9
|
14 #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT)
|
nuclear@9
|
15 #define ZTILE_OFFS(x) ((x) & ZTILE_MASK)
|
nuclear@9
|
16
|
nuclear@40
|
17 /*#define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)*/
|
nuclear@40
|
18 #define ROUND(x) cround64(x)
|
nuclear@0
|
19
|
nuclear@0
|
20
|
nuclear@0
|
21 typedef float mat4_t[16];
|
nuclear@0
|
22
|
nuclear@0
|
23 struct vertex {
|
nuclear@0
|
24 vec4_t pos;
|
nuclear@0
|
25 vec3_t norm;
|
nuclear@0
|
26 vec2_t tc;
|
nuclear@0
|
27 float energy;
|
nuclear@0
|
28 int cidx;
|
nuclear@0
|
29 };
|
nuclear@0
|
30
|
nuclear@25
|
31 struct fixed_vertex {
|
nuclear@25
|
32 vec4x_t pos;
|
nuclear@25
|
33 vec4x_t norm;
|
nuclear@25
|
34 vec2x_t tc;
|
nuclear@25
|
35 fixed energy;
|
nuclear@25
|
36 int cidx;
|
nuclear@25
|
37 };
|
nuclear@25
|
38
|
nuclear@28
|
39 struct plane {
|
nuclear@28
|
40 vec3_t pt;
|
nuclear@28
|
41 vec3_t normal;
|
nuclear@28
|
42 };
|
nuclear@28
|
43
|
nuclear@3
|
44 struct texture {
|
nuclear@3
|
45 int width, height;
|
nuclear@3
|
46 int xshift, yshift;
|
nuclear@3
|
47 unsigned int xmask, ymask;
|
nuclear@3
|
48 unsigned char *pixels;
|
nuclear@3
|
49 };
|
nuclear@3
|
50
|
nuclear@0
|
51 struct state {
|
nuclear@0
|
52 unsigned int flags;
|
nuclear@0
|
53 int ord, frontface, cullface;
|
nuclear@0
|
54 int mmode, mtop[2];
|
nuclear@0
|
55 mat4_t matrix[2][MATRIX_STACK_SIZE];
|
nuclear@0
|
56 int prim;
|
nuclear@28
|
57 struct vertex curv, v[6];
|
nuclear@0
|
58 int vidx;
|
nuclear@0
|
59 int vp[4]; /* viewport */
|
nuclear@0
|
60 int col_range; /* color interpolation range */
|
nuclear@11
|
61 vec4_t lpos[MAX_LIGHTS];
|
nuclear@0
|
62 float lint[MAX_LIGHTS];
|
nuclear@28
|
63 float ambient;
|
nuclear@28
|
64
|
nuclear@28
|
65 struct plane clip_planes[MAX_CLIP_PLANES + 1];
|
nuclear@3
|
66
|
nuclear@3
|
67 struct texture tex;
|
nuclear@0
|
68 };
|
nuclear@0
|
69
|
nuclear@0
|
70 struct framebuffer {
|
nuclear@0
|
71 int width, height;
|
nuclear@0
|
72 unsigned char *pixels;
|
nuclear@9
|
73 unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */
|
nuclear@9
|
74 int num_ztiles;
|
nuclear@0
|
75 };
|
nuclear@0
|
76
|
nuclear@28
|
77 #define IS_ENABLED(f, x) ((f) & (1 << (x)))
|
nuclear@3
|
78
|
nuclear@25
|
79 #define vertex_to_fixedvertex(v, vx) \
|
nuclear@25
|
80 do { \
|
nuclear@25
|
81 vec4_to_fixed4((v).pos, (vx).pos); \
|
nuclear@25
|
82 vec3_to_fixed3((v).norm, (vx).norm); \
|
nuclear@25
|
83 vec2_to_fixed2((v).tc, (vx).tc); \
|
nuclear@25
|
84 (vx).energy = fixedf((v).energy); \
|
nuclear@25
|
85 (vx).cidx = (v).cidx; \
|
nuclear@25
|
86 } while(0)
|
nuclear@25
|
87
|
nuclear@25
|
88 #define fixedvertex_to_vertex(vx, v) \
|
nuclear@25
|
89 do { \
|
nuclear@25
|
90 fixed4_to_vec4((vx).pos, (v).pos); \
|
nuclear@25
|
91 fixed3_to_vec3((vx).norm, (v).norm); \
|
nuclear@25
|
92 fixed2_to_vec2((vx).tc, (v).tc); \
|
nuclear@25
|
93 (v).energy = fixed_float((vx).energy); \
|
nuclear@25
|
94 (v).cidx = (vx).cidx; \
|
nuclear@25
|
95 } while(0)
|
nuclear@25
|
96
|
nuclear@25
|
97
|
nuclear@0
|
98 int mgl_rast_init(struct state *state, struct framebuffer *fbuf);
|
nuclear@0
|
99 void mgl_rast_cleanup(void);
|
nuclear@0
|
100 void mgl_rast_prepare(void);
|
nuclear@0
|
101 void mgl_draw_point(struct vertex *v);
|
nuclear@0
|
102 void mgl_draw_line(struct vertex *v0, struct vertex *v1);
|
nuclear@0
|
103 void mgl_draw_poly(struct vertex *v, int numv);
|
nuclear@0
|
104
|
nuclear@28
|
105 int mgl_clip_init(struct state *state);
|
nuclear@28
|
106 int mgl_clip_poly(struct vertex *v, int vnum);
|
nuclear@28
|
107
|
nuclear@0
|
108 #endif /* MGL_IMPL_H_ */
|