two-layer sky rendering now uses GL_ARB_texture_env_combine if available to render...
[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 tex2[2];
78         float v[4]; // 4th item is only for padding
79 }
80 skyvert_t;
81
82 typedef struct
83 {
84         unsigned short firstvert;
85         unsigned short verts;
86 }
87 skypoly_t;
88
89 extern transvert_t *transvert;
90 extern transpoly_t *transpoly;
91 extern unsigned short *transpolyindex;
92 extern wallvert_t *wallvert;
93 extern wallvertcolor_t *wallvertcolor;
94 extern wallpoly_t *wallpoly;
95 extern skyvert_t *skyvert;
96 extern skypoly_t *skypoly;
97
98 extern int currenttranspoly;
99 extern int currenttransvert;
100 extern int currentwallpoly;
101 extern int currentwallvert;
102 extern int currentskypoly;
103 extern int currentskyvert;
104
105 #define transpolybegin(ttexnum, tglowtexnum, tfogtexnum, ttranspolytype)\
106 {\
107         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
108         {\
109                 transpoly[currenttranspoly].texnum = (unsigned short) (ttexnum);\
110                 transpoly[currenttranspoly].glowtexnum = (unsigned short) (tglowtexnum);\
111                 transpoly[currenttranspoly].fogtexnum = (unsigned short) (tfogtexnum);\
112                 transpoly[currenttranspoly].transpolytype = (unsigned short) (ttranspolytype);\
113                 transpoly[currenttranspoly].firstvert = currenttransvert;\
114                 transpoly[currenttranspoly].verts = 0;\
115         }\
116 }
117
118 #define transpolyvert(vx,vy,vz,vs,vt,vr,vg,vb,va) \
119 {\
120         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
121         {\
122                 transvert[currenttransvert].s = (vs);\
123                 transvert[currenttransvert].t = (vt);\
124                 if (lighthalf)\
125                 {\
126                         transvert[currenttransvert].r = (byte) (bound(0, (int) (vr) >> 1, 255));\
127                         transvert[currenttransvert].g = (byte) (bound(0, (int) (vg) >> 1, 255));\
128                         transvert[currenttransvert].b = (byte) (bound(0, (int) (vb) >> 1, 255));\
129                 }\
130                 else\
131                 {\
132                         transvert[currenttransvert].r = (byte) (bound(0, (int) (vr), 255));\
133                         transvert[currenttransvert].g = (byte) (bound(0, (int) (vg), 255));\
134                         transvert[currenttransvert].b = (byte) (bound(0, (int) (vb), 255));\
135                 }\
136                 transvert[currenttransvert].a = (byte) (bound(0, (int) (va), 255));\
137                 transvert[currenttransvert].v[0] = (vx);\
138                 transvert[currenttransvert].v[1] = (vy);\
139                 transvert[currenttransvert].v[2] = (vz);\
140                 currenttransvert++;\
141                 transpoly[currenttranspoly].verts++;\
142         }\
143 }
144
145 #define transpolyvertub(vx,vy,vz,vs,vt,vr,vg,vb,va) \
146 {\
147         if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\
148         {\
149                 transvert[currenttransvert].s = (vs);\
150                 transvert[currenttransvert].t = (vt);\
151                 if (lighthalf)\
152                 {\
153                         transvert[currenttransvert].r = (vr) >> 1;\
154                         transvert[currenttransvert].g = (vg) >> 1;\
155                         transvert[currenttransvert].b = (vb) >> 1;\
156                 }\
157                 else\
158                 {\
159                         transvert[currenttransvert].r = (vr);\
160                         transvert[currenttransvert].g = (vg);\
161                         transvert[currenttransvert].b = (vb);\
162                 }\
163                 transvert[currenttransvert].a = (va);\
164                 transvert[currenttransvert].v[0] = (vx);\
165                 transvert[currenttransvert].v[1] = (vy);\
166                 transvert[currenttransvert].v[2] = (vz);\
167                 currenttransvert++;\
168                 transpoly[currenttranspoly].verts++;\
169         }\
170 }