deepstone

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