deepstone

annotate src/mglimpl.h @ 30:a8d42276b5ad

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