deepstone

view src/mglimpl.h @ 40:1fa939507d8b

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