1 /*
2 Copyright (C) 2001-2002 Charles Hollemeersch
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 PENTA: the whole file is freakin penta...
20
21 Abstracts the different paths that exist for different 3d-cards.
22
23 Idea: Write a new R_DrawLightEntitys* and do whatever you want in it.
24 adapt R_DrawLightEntitys to call your new code if the requirements are met.
25 */
26
27 /*
28 DrawLightEntities, draws lit bumpmapped entities, calls apropriate function for the user's 3d card.
29
30 NOTE: This should not draw sprites, sprites are drawn separately.
31
32 */
33
34 #include "quakedef.h"
35
36 /* Some material definitions. */
37 float gl_Light_Ambience2[4] = {0.03,0.03,0.03,0.03};
38 float gl_Light_Diffuse2[4] = {0.03,0.03,0.03,0.03};
39 float gl_Light_Specular2[4] = {0,0,0,0};
40 float gl_Material_Color2[4] = {0.9, 0.9, 0.9, 0.9};
41
42 void R_DrawLightEntitiesGF3 (shadowlight_t *l);
43 void R_DrawLightEntitiesGF (shadowlight_t *l);
44 void R_DrawLightEntitiesGEN (shadowlight_t *l);
45 void R_DrawLightEntitiesRadeon (shadowlight_t *l); //PA:
46 void R_DrawLightEntitiesParhelia (shadowlight_t *l); //PA:
47 void R_DrawLightEntitiesARB (shadowlight_t *l); //PA:
48
R_DrawWorldBumped()49 void R_DrawWorldBumped (/* shadowlight_t *l */) // <AWE> Function should not have parameters.
50 {
51 switch(gl_cardtype )
52 {
53 case GEFORCE3:
54 R_DrawWorldBumpedGF3(/* l */); // <AWE> Function has no parameters.
55 break;
56
57 case GEFORCE:
58 R_DrawWorldBumpedGF(/* l */); // <AWE> Function has no parameters.
59 break;
60
61 case RADEON:
62 R_DrawWorldBumpedRadeon(/* l */);
63 break;
64 #ifndef __glx__
65 case PARHELIA:
66 R_DrawWorldBumpedParhelia(/* l */);
67 break;
68 #endif
69 case ARB:
70 R_DrawWorldBumpedARB(/* l */);
71 break;
72 default:
73 R_DrawWorldBumpedGEN(/* l */);
74 break;
75 }
76 }
77
R_DrawLightEntities(shadowlight_t * l)78 void R_DrawLightEntities (shadowlight_t *l)
79 {
80 switch(gl_cardtype )
81 {
82 case GEFORCE3:
83 R_DrawLightEntitiesGF3( l );
84 break;
85
86 case GEFORCE:
87 R_DrawLightEntitiesGF( l );
88 break;
89
90 case RADEON:
91 R_DrawLightEntitiesRadeon( l );
92 break;
93 #ifndef __glx__
94 case PARHELIA:
95 R_DrawLightEntitiesParhelia( l );
96 break;
97 #endif
98 case ARB:
99 R_DrawLightEntitiesARB( l );
100 break;
101 default:
102 R_DrawLightEntitiesGEN( l );
103 break;
104 }
105 }
106
107
R_DrawLightEntitiesGF(shadowlight_t * l)108 void R_DrawLightEntitiesGF (shadowlight_t *l)
109 {
110 int i;
111 float pos[4];
112 if (!r_drawentities.value)
113 return;
114
115 if (!currentshadowlight->visible)
116 return;
117
118 glDepthMask (0);
119 glShadeModel (GL_SMOOTH);
120
121 //Meshes: Atten & selfshadow via vertex ligting
122
123 glEnable(GL_LIGHT0);
124 glEnable(GL_NORMALIZE);
125
126 pos[0] = l->origin[0];
127 pos[1] = l->origin[1];
128 pos[2] = l->origin[2];
129 pos[3] = 1;
130
131 glLightfv(GL_LIGHT0, GL_POSITION,&pos[0]);
132 glLightfv(GL_LIGHT0, GL_DIFFUSE, &l->color[0]);
133 glLightfv(GL_LIGHT0, GL_AMBIENT, &gl_Light_Ambience2[0]);
134 glLightfv(GL_LIGHT0, GL_SPECULAR, &gl_Light_Specular2[0]);
135 glEnable(GL_COLOR_MATERIAL);
136
137
138 for (i=0 ; i<cl_numlightvisedicts ; i++)
139 {
140 currententity = cl_lightvisedicts[i];
141
142 if (currententity->model->type == mod_alias)
143 {
144 //these models are full bright
145 if (currententity->model->flags & EF_FULLBRIGHT) continue;
146 if (!currententity->aliasframeinstant) continue;
147 if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
148
149 R_DrawAliasObjectLight(currententity, R_DrawAliasBumped);
150 }
151 }
152
153 if (R_ShouldDrawViewModel())
154 {
155 R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumped);
156 }
157
158
159 glDisable(GL_COLOR_MATERIAL);
160 glDisable(GL_LIGHTING);
161 glDisable(GL_LIGHT0);
162
163 /*
164 Brushes: we use the same thecnique as the world
165 */
166
167 //glEnable(GL_TEXTURE_2D);
168 //GL_Bind(glow_texture_object);
169 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
170 //glShadeModel (GL_SMOOTH);
171 //glEnable(GL_ALPHA_TEST);
172 //glAlphaFunc(GL_GREATER,0.2);
173 for (i=0 ; i<cl_numlightvisedicts ; i++)
174 {
175 currententity = cl_lightvisedicts[i];
176
177 if (currententity->model->type == mod_brush)
178 {
179 if (!currententity->brushlightinstant) continue;
180 if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
181 R_DrawBrushObjectLight(currententity, R_DrawBrushBumped);
182 }
183
184 }
185
186 //reset gl state
187
188 //glAlphaFunc(GL_GREATER,0.666);//Satan!
189 //glDisable(GL_ALPHA_TEST);
190 glColor3f (1,1,1);
191 glDepthMask (1);
192 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
193 glDisable (GL_BLEND);
194 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
195 }
196
R_DrawLightEntitiesGEN(shadowlight_t * l)197 void R_DrawLightEntitiesGEN (shadowlight_t *l)
198 {
199 //Currently this is merged with the geforce2 path
200 R_DrawLightEntitiesGF(l);
201 }
202
R_DrawLightEntitiesGF3(shadowlight_t * l)203 void R_DrawLightEntitiesGF3 (shadowlight_t *l)
204 {
205 int i;
206
207 if (!r_drawentities.value)
208 return;
209
210 if (!currentshadowlight->visible)
211 return;
212
213 glDepthMask (0);
214 glShadeModel (GL_SMOOTH);
215
216 //Alias models
217
218 for (i=0 ; i<cl_numlightvisedicts ; i++)
219 {
220 currententity = cl_lightvisedicts[i];
221
222 if (currententity->model->type == mod_alias)
223 {
224 //these models are full bright
225 if (currententity->model->flags & EF_FULLBRIGHT) continue;
226 if (!currententity->aliasframeinstant) continue;
227 if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
228
229 R_DrawAliasObjectLight(currententity, R_DrawAliasBumpedGF3);
230 }
231 }
232
233 if (R_ShouldDrawViewModel()) {
234 R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumpedGF3);
235 }
236
237 //Brush models
238 for (i=0 ; i<cl_numlightvisedicts ; i++)
239 {
240 currententity = cl_lightvisedicts[i];
241
242 if (currententity->model->type == mod_brush)
243 {
244 if (!currententity->brushlightinstant) continue;
245 if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
246 R_DrawBrushObjectLight(currententity, R_DrawBrushBumpedGF3);
247 }
248
249 }
250
251 //Cleanup state
252 glColor3f (1,1,1);
253 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
254 glDisable (GL_BLEND);
255 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
256 glDepthMask (1);
257 }
258
259 //PA:
R_DrawLightEntitiesRadeon(shadowlight_t * l)260 void R_DrawLightEntitiesRadeon (shadowlight_t *l)
261 {
262 int i;
263
264 if (!r_drawentities.value)
265 return;
266
267 if (!currentshadowlight->visible)
268 return;
269
270 glDepthMask (0);
271 glShadeModel (GL_SMOOTH);
272
273 //Alias models
274
275 for (i=0 ; i<cl_numlightvisedicts ; i++)
276 {
277 currententity = cl_lightvisedicts[i];
278
279 if (currententity->model->type == mod_alias)
280 {
281 //these models are full bright
282 if (currententity->model->flags & EF_FULLBRIGHT) continue;
283 if (!currententity->aliasframeinstant) continue;
284 if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
285
286 R_DrawAliasObjectLight(currententity, R_DrawAliasBumpedRadeon);
287 }
288 }
289
290 if (R_ShouldDrawViewModel()) {
291 R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumpedRadeon);
292 }
293
294 //Brush models
295 for (i=0 ; i<cl_numlightvisedicts ; i++)
296 {
297 currententity = cl_lightvisedicts[i];
298
299 if (currententity->model->type == mod_brush)
300 {
301 if (!currententity->brushlightinstant) continue;
302 if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
303 R_DrawBrushObjectLight(currententity, R_DrawBrushBumpedRadeon);
304 }
305
306 }
307
308 //Cleanup state
309 glColor3f (1,1,1);
310 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
311 glDisable (GL_BLEND);
312 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
313 glDepthMask (1);
314 }
315
316 #ifndef __glx__
317
318 //PA:
R_DrawLightEntitiesParhelia(shadowlight_t * l)319 void R_DrawLightEntitiesParhelia (shadowlight_t *l)
320 {
321 int i;
322
323 if (!r_drawentities.value)
324 return;
325
326 if (!currentshadowlight->visible)
327 return;
328
329 glDepthMask (0);
330 glShadeModel (GL_SMOOTH);
331
332 //Alias models
333
334 for (i=0 ; i<cl_numlightvisedicts ; i++)
335 {
336 currententity = cl_lightvisedicts[i];
337
338 if (currententity->model->type == mod_alias)
339 {
340 //these models are full bright
341 if (currententity->model->flags & EF_FULLBRIGHT) continue;
342 if (!currententity->aliasframeinstant) continue;
343 if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
344
345 R_DrawAliasObjectLight(currententity, R_DrawAliasBumpedParhelia);
346 }
347 }
348
349 if (R_ShouldDrawViewModel())
350 {
351 R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumpedParhelia);
352 }
353
354 //Brush models
355 for (i=0 ; i<cl_numlightvisedicts ; i++)
356 {
357 currententity = cl_lightvisedicts[i];
358
359 if (currententity->model->type == mod_brush)
360 {
361 if (!currententity->brushlightinstant) continue;
362 if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
363 R_DrawBrushObjectLight(currententity, R_DrawBrushBumpedParhelia);
364 }
365
366 }
367
368 //Cleanup state
369 glColor3f (1,1,1);
370 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
371 glDisable (GL_BLEND);
372 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
373 glDepthMask (1);
374 }
375
376 #endif
377
R_DrawLightEntitiesARB(shadowlight_t * l)378 void R_DrawLightEntitiesARB (shadowlight_t *l)
379 {
380 int i;
381
382 if (!r_drawentities.value)
383 return;
384
385 if (!currentshadowlight->visible)
386 return;
387
388 glDepthMask (0);
389 glShadeModel (GL_SMOOTH);
390
391 //Alias models
392
393 for (i=0 ; i<cl_numlightvisedicts ; i++)
394 {
395 currententity = cl_lightvisedicts[i];
396
397 if (currententity->model->type == mod_alias)
398 {
399 //these models are full bright
400 if (currententity->model->flags & EF_FULLBRIGHT) continue;
401 if (!currententity->aliasframeinstant) continue;
402 if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
403
404 R_DrawAliasObjectLight(currententity, R_DrawAliasBumpedARB);
405 }
406 }
407
408 if (R_ShouldDrawViewModel())
409 {
410 R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumpedARB);
411 }
412
413 //Brush models
414 for (i=0 ; i<cl_numlightvisedicts ; i++)
415 {
416 currententity = cl_lightvisedicts[i];
417
418 if (currententity->model->type == mod_brush)
419 {
420 if (!currententity->brushlightinstant) continue;
421 if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
422 R_DrawBrushObjectLight(currententity, R_DrawBrushBumpedARB);
423 }
424
425 }
426
427 //Cleanup state
428 glColor3f (1,1,1);
429 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
430 glDisable (GL_BLEND);
431 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
432 glDepthMask (1);
433 }
434