-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSWzbuffer.h
67 lines (53 loc) · 2.72 KB
/
SWzbuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef SW_ZBUFFER_H
#define SW_ZBUFFER_H
#include "SWcore.h"
typedef struct SWzrange {
SWfloat min, max;
} SWzrange;
typedef struct SWzbuffer {
SWint w, h;
SWfloat *depth;
SWint tile_w, tile_h;
SWzrange *tiles;
SWfloat zmax;
} SWzbuffer;
typedef enum SWoccresult { SW_OCCLUDED = 0, SW_NONOCCLUDED, SW_PARTIAL } SWoccresult;
void swZbufInit(SWzbuffer *zb, SWint w, SWint h, SWfloat zmax);
void swZbufDestroy(SWzbuffer *zb);
void swZbufClearDepth(SWzbuffer *zb, SWfloat val);
#define swZbufSetDepth(zb, x, y, val) (zb)->depth[(y) * (zb)->w + (x)] = (val)
#define swZbufGetDepth(zb, x, y) (zb)->depth[(y) * (zb)->w + (x)]
#define swZbufTestDepth(zb, x, y, z) ((z) <= (zb)->depth[(y) * (zb)->w + (x)])
#define swZbufSetTileRange(zb, x, y, zmin, zmax) \
{ \
SWzrange *_zr = \
&(zb)->tiles[((y) / SW_TILE_SIZE) * (zb)->tile_w + ((x) / SW_TILE_SIZE)]; \
_zr->min = (zmin); \
_zr->max = (zmax); \
}
#define swZbufUpdateTileRange(zb, x, y, zmin, zmax) \
{ \
SWzrange *_zr = \
&(zb)->tiles[((y) / SW_TILE_SIZE) * (zb)->tile_w + ((x) / SW_TILE_SIZE)]; \
_zr->min = sw_min((zmin), _zr->min); \
_zr->max = sw_max((zmax), _zr->max); \
}
sw_inline SWoccresult swZbufTestTileRange(const SWzbuffer *zb, SWint x, SWint y,
SWfloat min, SWfloat max) {
SWzrange *zr = &zb->tiles[(y / SW_TILE_SIZE) * zb->tile_w + (x / SW_TILE_SIZE)];
if (max < zr->min) {
return SW_NONOCCLUDED;
} else if (min > zr->max) {
return SW_OCCLUDED;
} else {
return SW_PARTIAL;
}
}
sw_inline SWzrange *swZbufGetTileRange(const SWzbuffer *zb, SWint x, SWint y) {
return &zb->tiles[(y / SW_TILE_SIZE) * zb->tile_w + (x / SW_TILE_SIZE)];
}
void swZbufSetDepth_(SWzbuffer *zb, SWint x, SWint y, SWfloat val);
SWint swZbufTestDepth_(SWzbuffer *zb, SWint x, SWint y, SWfloat z);
SWoccresult swZbufTriTestDepth(SWzbuffer *zb, SWint min[2], SWint max[2], SWfloat *attrs1,
SWfloat *attrs2, SWfloat *attrs3);
#endif /* SW_ZBUFFER_H */