deepstone

view src/mglimpl.h @ 37:e5e01cd2c995

changed the VC project file to use the non-dll versions of msvcrt
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Sep 2013 08:06:04 +0300
parents 5ff8ce78059a
children 1fa939507d8b
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
8 #define MAX_CLIP_PLANES 6
10 #define ZTILE_SIZE 16384
11 #define ZTILE_SHIFT 14
12 #define ZTILE_MASK 0x3fff
14 #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT)
15 #define ZTILE_OFFS(x) ((x) & ZTILE_MASK)
17 #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)
20 typedef float mat4_t[16];
22 struct vertex {
23 vec4_t pos;
24 vec3_t norm;
25 vec2_t tc;
26 float energy;
27 int cidx;
28 };
30 struct fixed_vertex {
31 vec4x_t pos;
32 vec4x_t norm;
33 vec2x_t tc;
34 fixed energy;
35 int cidx;
36 };
38 struct plane {
39 vec3_t pt;
40 vec3_t normal;
41 };
43 struct texture {
44 int width, height;
45 int xshift, yshift;
46 unsigned int xmask, ymask;
47 unsigned char *pixels;
48 };
50 struct state {
51 unsigned int flags;
52 int ord, frontface, cullface;
53 int mmode, mtop[2];
54 mat4_t matrix[2][MATRIX_STACK_SIZE];
55 int prim;
56 struct vertex curv, v[6];
57 int vidx;
58 int vp[4]; /* viewport */
59 int col_range; /* color interpolation range */
60 vec4_t lpos[MAX_LIGHTS];
61 float lint[MAX_LIGHTS];
62 float ambient;
64 struct plane clip_planes[MAX_CLIP_PLANES + 1];
66 struct texture tex;
67 };
69 struct framebuffer {
70 int width, height;
71 unsigned char *pixels;
72 unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */
73 int num_ztiles;
74 };
76 #define IS_ENABLED(f, x) ((f) & (1 << (x)))
78 #define vertex_to_fixedvertex(v, vx) \
79 do { \
80 vec4_to_fixed4((v).pos, (vx).pos); \
81 vec3_to_fixed3((v).norm, (vx).norm); \
82 vec2_to_fixed2((v).tc, (vx).tc); \
83 (vx).energy = fixedf((v).energy); \
84 (vx).cidx = (v).cidx; \
85 } while(0)
87 #define fixedvertex_to_vertex(vx, v) \
88 do { \
89 fixed4_to_vec4((vx).pos, (v).pos); \
90 fixed3_to_vec3((vx).norm, (v).norm); \
91 fixed2_to_vec2((vx).tc, (v).tc); \
92 (v).energy = fixed_float((vx).energy); \
93 (v).cidx = (vx).cidx; \
94 } while(0)
97 int mgl_rast_init(struct state *state, struct framebuffer *fbuf);
98 void mgl_rast_cleanup(void);
99 void mgl_rast_prepare(void);
100 void mgl_draw_point(struct vertex *v);
101 void mgl_draw_line(struct vertex *v0, struct vertex *v1);
102 void mgl_draw_poly(struct vertex *v, int numv);
104 int mgl_clip_init(struct state *state);
105 int mgl_clip_poly(struct vertex *v, int vnum);
107 #endif /* MGL_IMPL_H_ */