nuclear@0: #ifndef MGL_IMPL_H_ nuclear@0: #define MGL_IMPL_H_ nuclear@0: nuclear@14: #include "vmath.h" nuclear@14: nuclear@0: #define MATRIX_STACK_SIZE 8 nuclear@0: #define MAX_LIGHTS 4 nuclear@0: nuclear@9: #define ZTILE_SIZE 16384 nuclear@9: #define ZTILE_SHIFT 14 nuclear@9: #define ZTILE_MASK 0x3fff nuclear@9: nuclear@9: #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT) nuclear@9: #define ZTILE_OFFS(x) ((x) & ZTILE_MASK) nuclear@9: nuclear@0: #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5) nuclear@0: nuclear@0: nuclear@0: typedef float mat4_t[16]; nuclear@0: nuclear@0: struct vertex { nuclear@0: vec4_t pos; nuclear@0: vec3_t norm; nuclear@0: vec2_t tc; nuclear@0: float energy; nuclear@0: int cidx; nuclear@0: }; nuclear@0: nuclear@25: struct fixed_vertex { nuclear@25: vec4x_t pos; nuclear@25: vec4x_t norm; nuclear@25: vec2x_t tc; nuclear@25: fixed energy; nuclear@25: int cidx; nuclear@25: }; nuclear@25: nuclear@3: struct texture { nuclear@3: int width, height; nuclear@3: int xshift, yshift; nuclear@3: unsigned int xmask, ymask; nuclear@3: unsigned char *pixels; nuclear@3: }; nuclear@3: nuclear@0: struct state { nuclear@0: unsigned int flags; nuclear@0: int ord, frontface, cullface; nuclear@0: int mmode, mtop[2]; nuclear@0: mat4_t matrix[2][MATRIX_STACK_SIZE]; nuclear@0: int prim; nuclear@0: struct vertex curv, v[4]; nuclear@0: int vidx; nuclear@0: int vp[4]; /* viewport */ nuclear@0: int col_range; /* color interpolation range */ nuclear@11: vec4_t lpos[MAX_LIGHTS]; nuclear@0: float lint[MAX_LIGHTS]; nuclear@3: nuclear@3: struct texture tex; nuclear@0: }; nuclear@0: nuclear@0: struct framebuffer { nuclear@0: int width, height; nuclear@0: unsigned char *pixels; nuclear@9: unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */ nuclear@9: int num_ztiles; nuclear@0: }; nuclear@0: nuclear@3: nuclear@25: #define vertex_to_fixedvertex(v, vx) \ nuclear@25: do { \ nuclear@25: vec4_to_fixed4((v).pos, (vx).pos); \ nuclear@25: vec3_to_fixed3((v).norm, (vx).norm); \ nuclear@25: vec2_to_fixed2((v).tc, (vx).tc); \ nuclear@25: (vx).energy = fixedf((v).energy); \ nuclear@25: (vx).cidx = (v).cidx; \ nuclear@25: } while(0) nuclear@25: nuclear@25: #define fixedvertex_to_vertex(vx, v) \ nuclear@25: do { \ nuclear@25: fixed4_to_vec4((vx).pos, (v).pos); \ nuclear@25: fixed3_to_vec3((vx).norm, (v).norm); \ nuclear@25: fixed2_to_vec2((vx).tc, (v).tc); \ nuclear@25: (v).energy = fixed_float((vx).energy); \ nuclear@25: (v).cidx = (vx).cidx; \ nuclear@25: } while(0) nuclear@25: nuclear@25: nuclear@0: int mgl_rast_init(struct state *state, struct framebuffer *fbuf); nuclear@0: void mgl_rast_cleanup(void); nuclear@0: void mgl_rast_prepare(void); nuclear@0: void mgl_draw_point(struct vertex *v); nuclear@0: void mgl_draw_line(struct vertex *v0, struct vertex *v1); nuclear@0: void mgl_draw_poly(struct vertex *v, int numv); nuclear@0: nuclear@0: #endif /* MGL_IMPL_H_ */