added newmap function to render modules (so explosions and other things are reset...
[xonotic/darkplaces.git] / gl_poly.h
1
2 extern float fog_density, fog_red, fog_green, fog_blue;
3
4 #define TPOLYTYPE_ALPHA 0
5 #define TPOLYTYPE_ADD 1
6
7 extern void transpolyclear();
8 extern void transpolyrender();
9 extern void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype);
10 extern void transpolyend();
11
12 extern void wallpolyclear();
13 extern void wallpolyrender();
14
15 extern void skypolyclear();
16 extern void skypolyrender();
17 extern void skypolybegin();
18 extern void skypolyvert(float x, float y, float z);
19 extern void skypolyend();
20
21 #define MAX_TRANSPOLYS 65536
22 #define MAX_TRANSVERTS (MAX_TRANSPOLYS*4)
23 #define MAX_WALLPOLYS 65536
24 #define MAX_WALLVERTS (MAX_WALLPOLYS*3)
25 #define MAX_SKYPOLYS 2048
26 #define MAX_SKYVERTS (MAX_SKYPOLYS*4)
27
28 typedef struct
29 {
30         vec_t s, t;
31         byte r,g,b,a;
32         vec3_t v;
33 }
34 transvert_t;
35
36 typedef struct
37 {
38 //      vec_t mindistance, maxdistance; // closest and farthest distance along v_forward
39 //      vec_t distance; // distance to center
40 //      vec3_t n; // normal
41 //      vec_t ndist; // distance from origin along that normal
42         unsigned short texnum;
43         unsigned short glowtexnum;
44         unsigned short fogtexnum;
45         unsigned short firstvert;
46         unsigned short verts;
47         unsigned short transpolytype;
48 }
49 transpoly_t;
50
51 // note: must match format of glpoly_t vertices due to a memcpy used in RSurf_DrawWall
52 typedef struct
53 {
54         vec_t vert[VERTEXSIZE]; // xyz st uv
55 }
56 wallvert_t;
57
58 typedef struct
59 {
60         byte r,g,b,a;
61 }
62 wallvertcolor_t;
63
64 typedef struct
65 {
66         unsigned short texnum, lighttexnum, glowtexnum;
67         unsigned short firstvert;
68         unsigned short numverts;
69         unsigned short lit; // doesn't need to be an unsigned short, but to keep the structure consistent...
70 }
71 wallpoly_t;
72
73 typedef struct
74 {
75         // the order and type of these is crucial to the vertex array based rendering 
76         vec2_t tex;
77         vec3_t v;
78 }
79 skyvert_t;
80
81 typedef struct
82 {
83         unsigned short firstvert;
84         unsigned short verts;
85 }
86 skypoly_t;
87
88 extern transvert_t *transvert;
89 extern transpoly_t *transpoly;
90 extern unsigned short *transpolyindex;
91 extern wallvert_t *wallvert;
92 extern wallvertcolor_t *wallvertcolor;
93 extern wallpoly_t *wallpoly;
94 extern skyvert_t *skyvert;
95 extern skypoly_t *skypoly;
96
97 extern int currenttranspoly;
98 extern int currenttransvert;
99 extern int currentwallpoly;
100 extern int currentwallvert;
101 extern int currentskypoly;
102 extern int currentskyvert;
103
104 #define transpolybegin(ttexnum, tglowtexnum, tfogtexnum, ttranspolytype)\
105 {\
106         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
107         {\
108                 transpoly[currenttranspoly].texnum = (unsigned short) (ttexnum);\
109                 transpoly[currenttranspoly].glowtexnum = (unsigned short) (tglowtexnum);\
110                 transpoly[currenttranspoly].fogtexnum = (unsigned short) (tfogtexnum);\
111                 transpoly[currenttranspoly].transpolytype = (unsigned short) (ttranspolytype);\
112                 transpoly[currenttranspoly].firstvert = currenttransvert;\
113                 transpoly[currenttranspoly].verts = 0;\
114         }\
115 }
116
117 #define transpolyvert(vx,vy,vz,vs,vt,vr,vg,vb,va) \
118 {\
119         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
120         {\
121                 transvert[currenttransvert].s = (vs);\
122                 transvert[currenttransvert].t = (vt);\
123                 if (lighthalf)\
124                 {\
125                         transvert[currenttransvert].r = (byte) (bound(0, (int) (vr) >> 1, 255));\
126                         transvert[currenttransvert].g = (byte) (bound(0, (int) (vg) >> 1, 255));\
127                         transvert[currenttransvert].b = (byte) (bound(0, (int) (vb) >> 1, 255));\
128                 }\
129                 else\
130                 {\
131                         transvert[currenttransvert].r = (byte) (bound(0, (int) (vr), 255));\
132                         transvert[currenttransvert].g = (byte) (bound(0, (int) (vg), 255));\
133                         transvert[currenttransvert].b = (byte) (bound(0, (int) (vb), 255));\
134                 }\
135                 transvert[currenttransvert].a = (byte) (bound(0, (int) (va), 255));\
136                 transvert[currenttransvert].v[0] = (vx);\
137                 transvert[currenttransvert].v[1] = (vy);\
138                 transvert[currenttransvert].v[2] = (vz);\
139                 currenttransvert++;\
140                 transpoly[currenttranspoly].verts++;\
141         }\
142 }
143
144 #define transpolyvertub(vx,vy,vz,vs,vt,vr,vg,vb,va) \
145 {\
146         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
147         {\
148                 transvert[currenttransvert].s = (vs);\
149                 transvert[currenttransvert].t = (vt);\
150                 if (lighthalf)\
151                 {\
152                         transvert[currenttransvert].r = (vr) >> 1;\
153                         transvert[currenttransvert].g = (vg) >> 1;\
154                         transvert[currenttransvert].b = (vb) >> 1;\
155                 }\
156                 else\
157                 {\
158                         transvert[currenttransvert].r = (vr);\
159                         transvert[currenttransvert].g = (vg);\
160                         transvert[currenttransvert].b = (vb);\
161                 }\
162                 transvert[currenttransvert].a = (va);\
163                 transvert[currenttransvert].v[0] = (vx);\
164                 transvert[currenttransvert].v[1] = (vy);\
165                 transvert[currenttransvert].v[2] = (vz);\
166                 currenttransvert++;\
167                 transpoly[currenttranspoly].verts++;\
168         }\
169 }