added CVAR_SAVE and CVAR_NOTIFY flags to cvar_t structure (at the beginning), updated...
[divverent/darkplaces.git] / gl_poly.h
1
2 extern int R_SetSkyBox(char* sky);
3 extern cvar_t r_skyquality;
4
5 #define TPOLYTYPE_ALPHA 0
6 #define TPOLYTYPE_ADD 1
7
8 extern void transpolyclear(void);
9 extern void transpolyrender(void);
10 extern void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype);
11 extern void transpolyend(void);
12
13 extern void wallpolyclear(void);
14 extern void wallpolyrender(void);
15
16 extern void skypolyclear(void);
17 extern void skypolyrender(void);
18 extern void skypolybegin(void);
19 extern void skypolyvert(float x, float y, float z);
20 extern void skypolyend(void);
21
22 #define MAX_TRANSPOLYS 65536
23 #define MAX_TRANSVERTS (MAX_TRANSPOLYS*4)
24 #define MAX_WALLPOLYS 65536
25 #define MAX_WALLVERTS (MAX_WALLPOLYS*3)
26 #define MAX_SKYPOLYS 2048
27 #define MAX_SKYVERTS (MAX_SKYPOLYS*4)
28
29 typedef struct
30 {
31         vec_t s, t;
32         byte r,g,b,a;
33         vec3_t v;
34 }
35 transvert_t;
36
37 typedef struct
38 {
39 //      vec_t mindistance, maxdistance; // closest and farthest distance along v_forward
40 //      vec_t distance; // distance to center
41 //      vec3_t n; // normal
42 //      vec_t ndist; // distance from origin along that normal
43         unsigned short texnum;
44         unsigned short glowtexnum;
45         unsigned short fogtexnum;
46         unsigned short firstvert;
47         unsigned short verts;
48         unsigned short transpolytype;
49 }
50 transpoly_t;
51
52 // note: must match format of glpoly_t vertices due to a memcpy used in RSurf_DrawWall
53 typedef struct
54 {
55         vec_t vert[VERTEXSIZE]; // xyz st uv
56 }
57 wallvert_t;
58
59 typedef struct
60 {
61         byte r,g,b,a;
62 }
63 wallvertcolor_t;
64
65 typedef struct
66 {
67         unsigned short texnum, lighttexnum, glowtexnum;
68         unsigned short firstvert;
69         unsigned short numverts;
70         unsigned short lit; // doesn't need to be an unsigned short, but to keep the structure consistent...
71 }
72 wallpoly_t;
73
74 typedef struct
75 {
76         float tex[2];
77         float v[4]; // 4th item is only for padding
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 }