speedups to R_WorldNode, and some shrinkage on the surface struct
[divverent/darkplaces.git] / gl_poly.h
1
2 #define TPOLYTYPE_ALPHA 0
3 #define TPOLYTYPE_ADD 1
4
5 extern void transpolyclear();
6 extern void transpolyrender();
7 extern void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype);
8 extern void transpolyend();
9
10 extern void wallpolyclear();
11 extern void wallpolyrender();
12
13 extern void skypolyclear();
14 extern void skypolyrender();
15 extern void skypolybegin();
16 extern void skypolyvert(float x, float y, float z);
17 extern void skypolyend();
18
19 #define MAX_TRANSPOLYS 8192
20 #define MAX_TRANSVERTS (MAX_TRANSPOLYS*4)
21 #define MAX_WALLPOLYS 65536
22 #define MAX_WALLVERTS (MAX_WALLPOLYS*3)
23 #define MAX_SKYPOLYS 2048
24 #define MAX_SKYVERTS (MAX_SKYPOLYS*4)
25
26 typedef struct
27 {
28         vec_t s, t;
29         byte r,g,b,a;
30         vec3_t v;
31 } transvert_t;
32
33 typedef struct
34 {
35 //      vec_t mindistance, maxdistance; // closest and farthest distance along v_forward
36 //      vec_t distance; // distance to center
37 //      vec3_t n; // normal
38 //      vec_t ndist; // distance from origin along that normal
39         unsigned short texnum;
40         unsigned short glowtexnum;
41         unsigned short fogtexnum;
42         unsigned short firstvert;
43         unsigned short verts;
44         unsigned short transpolytype;
45 } transpoly_t;
46
47 typedef struct
48 {
49         vec3_t vert;
50         vec_t s, t, u, v;
51         byte r,g,b,a;
52 } wallvert_t;
53
54 typedef struct
55 {
56         unsigned short texnum, lighttexnum, glowtexnum;
57         unsigned short firstvert;
58         unsigned short numverts;
59         unsigned short lit; // doesn't need to be an unsigned short, but to keep the structure consistent...
60 } wallpoly_t;
61
62 typedef struct
63 {
64         vec3_t v;
65 } skyvert_t;
66
67 typedef struct
68 {
69         unsigned short firstvert;
70         unsigned short verts;
71 } skypoly_t;
72
73 extern transvert_t *transvert;
74 extern transpoly_t *transpoly;
75 extern unsigned short *transpolyindex;
76 extern wallvert_t *wallvert;
77 extern wallpoly_t *wallpoly;
78 extern skyvert_t *skyvert;
79 extern skypoly_t *skypoly;
80
81 extern unsigned short currenttranspoly;
82 extern unsigned short currenttransvert;
83 extern unsigned short currentwallpoly;
84 extern unsigned short currentwallvert;
85 extern unsigned short currentskypoly;
86 extern unsigned short currentskyvert;
87
88 #define transpolybegin(ttexnum, tglowtexnum, tfogtexnum, ttranspolytype)\
89 {\
90         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
91         {\
92                 transpoly[currenttranspoly].texnum = (unsigned short) (ttexnum);\
93                 transpoly[currenttranspoly].glowtexnum = (unsigned short) (tglowtexnum);\
94                 transpoly[currenttranspoly].fogtexnum = (unsigned short) (tfogtexnum);\
95                 transpoly[currenttranspoly].transpolytype = (unsigned short) (ttranspolytype);\
96                 transpoly[currenttranspoly].firstvert = currenttransvert;\
97                 transpoly[currenttranspoly].verts = 0;\
98         }\
99 }
100
101 #define transpolyvert(vx,vy,vz,vs,vt,vr,vg,vb,va) \
102 {\
103         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
104         {\
105                 transvert[currenttransvert].s = (vs);\
106                 transvert[currenttransvert].t = (vt);\
107                 if (lighthalf)\
108                 {\
109                         transvert[currenttransvert].r = (byte) (bound(0, (int) (vr) >> 1, 255));\
110                         transvert[currenttransvert].g = (byte) (bound(0, (int) (vg) >> 1, 255));\
111                         transvert[currenttransvert].b = (byte) (bound(0, (int) (vb) >> 1, 255));\
112                 }\
113                 else\
114                 {\
115                         transvert[currenttransvert].r = (byte) (bound(0, (int) (vr), 255));\
116                         transvert[currenttransvert].g = (byte) (bound(0, (int) (vg), 255));\
117                         transvert[currenttransvert].b = (byte) (bound(0, (int) (vb), 255));\
118                 }\
119                 transvert[currenttransvert].a = (byte) (bound(0, (int) (va), 255));\
120                 transvert[currenttransvert].v[0] = (vx);\
121                 transvert[currenttransvert].v[1] = (vy);\
122                 transvert[currenttransvert].v[2] = (vz);\
123                 currenttransvert++;\
124                 transpoly[currenttranspoly].verts++;\
125         }\
126 }