deepstone
view src/mglimpl.h @ 25:5ff8ce78059a
first pass at converting the rasterizer to fixed point
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Sep 2013 02:21:30 +0300 |
parents | 4ad71b558ab2 |
children | 11d14f688485 |
line source
1 #ifndef MGL_IMPL_H_
2 #define MGL_IMPL_H_
4 #include "vmath.h"
6 #define MATRIX_STACK_SIZE 8
7 #define MAX_LIGHTS 4
9 #define ZTILE_SIZE 16384
10 #define ZTILE_SHIFT 14
11 #define ZTILE_MASK 0x3fff
13 #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT)
14 #define ZTILE_OFFS(x) ((x) & ZTILE_MASK)
16 #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)
19 typedef float mat4_t[16];
21 struct vertex {
22 vec4_t pos;
23 vec3_t norm;
24 vec2_t tc;
25 float energy;
26 int cidx;
27 };
29 struct fixed_vertex {
30 vec4x_t pos;
31 vec4x_t norm;
32 vec2x_t tc;
33 fixed energy;
34 int cidx;
35 };
37 struct texture {
38 int width, height;
39 int xshift, yshift;
40 unsigned int xmask, ymask;
41 unsigned char *pixels;
42 };
44 struct state {
45 unsigned int flags;
46 int ord, frontface, cullface;
47 int mmode, mtop[2];
48 mat4_t matrix[2][MATRIX_STACK_SIZE];
49 int prim;
50 struct vertex curv, v[4];
51 int vidx;
52 int vp[4]; /* viewport */
53 int col_range; /* color interpolation range */
54 vec4_t lpos[MAX_LIGHTS];
55 float lint[MAX_LIGHTS];
57 struct texture tex;
58 };
60 struct framebuffer {
61 int width, height;
62 unsigned char *pixels;
63 unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */
64 int num_ztiles;
65 };
68 #define vertex_to_fixedvertex(v, vx) \
69 do { \
70 vec4_to_fixed4((v).pos, (vx).pos); \
71 vec3_to_fixed3((v).norm, (vx).norm); \
72 vec2_to_fixed2((v).tc, (vx).tc); \
73 (vx).energy = fixedf((v).energy); \
74 (vx).cidx = (v).cidx; \
75 } while(0)
77 #define fixedvertex_to_vertex(vx, v) \
78 do { \
79 fixed4_to_vec4((vx).pos, (v).pos); \
80 fixed3_to_vec3((vx).norm, (v).norm); \
81 fixed2_to_vec2((vx).tc, (v).tc); \
82 (v).energy = fixed_float((vx).energy); \
83 (v).cidx = (vx).cidx; \
84 } while(0)
87 int mgl_rast_init(struct state *state, struct framebuffer *fbuf);
88 void mgl_rast_cleanup(void);
89 void mgl_rast_prepare(void);
90 void mgl_draw_point(struct vertex *v);
91 void mgl_draw_line(struct vertex *v0, struct vertex *v1);
92 void mgl_draw_poly(struct vertex *v, int numv);
94 #endif /* MGL_IMPL_H_ */