Debian Codegraph @

code/renderergl1/tr_scene.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #include "tr_local.h"
24
25 int r_firstSceneDrawSurf;
26
27 int r_numdlights;
28 int r_firstSceneDlight;
29
30 int r_numentities;
31 int r_firstSceneEntity;
32
33 int r_numpolys;
34 int r_firstScenePoly;
35
36 int r_numpolyverts;
37
38
39 /*
40 ====================
41 R_InitNextFrame
42
43 ====================
44 */
45 void R_InitNextFrame( void ) {
46 backEndData->commands.used = 0;
47
48 r_firstSceneDrawSurf = 0;
49
50 r_numdlights = 0;
51 r_firstSceneDlight = 0;
52
53 r_numentities = 0;
54 r_firstSceneEntity = 0;
55
56 r_numpolys = 0;
57 r_firstScenePoly = 0;
58
59 r_numpolyverts = 0;
60 }
61
62
63 /*
64 ====================
65 RE_ClearScene
66
67 ====================
68 */
69 void RE_ClearScene( void ) {
70 r_firstSceneDlight = r_numdlights;
71 r_firstSceneEntity = r_numentities;
72 r_firstScenePoly = r_numpolys;
73 }
74
75 /*
76 ===========================================================================
77
78 DISCRETE POLYS
79
80 ===========================================================================
81 */
82
83 /*
84 =====================
85 R_AddPolygonSurfaces
86
87 Adds all the scene's polys into this view's drawsurf list
88 =====================
89 */
90 void R_AddPolygonSurfaces( void ) {
91 int i;
92 shader_t *sh;
93 srfPoly_t *poly;
94
95 tr.currentEntityNum = REFENTITYNUM_WORLD;
96 tr.shiftedEntityNum = tr.currentEntityNum << QSORT_REFENTITYNUM_SHIFT;
97
98 for ( i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys ; i++, poly++ ) {
99 sh = R_GetShaderByHandle( poly->hShader );
100 R_AddDrawSurf( ( void * )poly, sh, poly->fogIndex, qfalse );
101 }
102 }
103
104 /*
105 =====================
106 RE_AddPolyToScene
107
108 =====================
109 */
110 void RE_AddPolyToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts, int numPolys ) {
111 srfPoly_t *poly;
112 int i, j;
113 int fogIndex;
114 fog_t *fog;
115 vec3_t bounds[2];
116
117 if ( !tr.registered ) {
118 return;
119 }
120
121 if ( !hShader ) {
122 ri.Printf( PRINT_WARNING, "WARNING: RE_AddPolyToScene: NULL poly shader\n");
123 return;
124 }
125
126 for ( j = 0; j < numPolys; j++ ) {
127 if ( r_numpolyverts + numVerts > max_polyverts || r_numpolys >= max_polys ) {
128 /*
129 NOTE TTimo this was initially a PRINT_WARNING
130 but it happens a lot with high fighting scenes and particles
131 since we don't plan on changing the const and making for room for those effects
132 simply cut this message to developer only
133 */
134 ri.Printf( PRINT_DEVELOPER, "WARNING: RE_AddPolyToScene: r_max_polys or r_max_polyverts reached\n");
135 return;
136 }
137
138 poly = &backEndData->polys[r_numpolys];
139 poly->surfaceType = SF_POLY;
140 poly->hShader = hShader;
141 poly->numVerts = numVerts;
142 poly->verts = &backEndData->polyVerts[r_numpolyverts];
143
144 Com_Memcpy( poly->verts, &verts[numVerts*j], numVerts * sizeof( *verts ) );
145
146 if ( glConfig.hardwareType == GLHW_RAGEPRO ) {
147 poly->verts->modulate[0] = 255;
148 poly->verts->modulate[1] = 255;
149 poly->verts->modulate[2] = 255;
150 poly->verts->modulate[3] = 255;
151 }
152 // done.
153 r_numpolys++;
154 r_numpolyverts += numVerts;
155
156 // if no world is loaded
157 if ( tr.world == NULL ) {
158 fogIndex = 0;
159 }
160 // see if it is in a fog volume
161 else if ( tr.world->numfogs == 1 ) {
162 fogIndex = 0;
163 } else {
164 // find which fog volume the poly is in
165 VectorCopy( poly->verts[0].xyz, bounds[0] );
166 VectorCopy( poly->verts[0].xyz, bounds[1] );
167 for ( i = 1 ; i < poly->numVerts ; i++ ) {
168 AddPointToBounds( poly->verts[i].xyz, bounds[0], bounds[1] );
169 }
170 for ( fogIndex = 1 ; fogIndex < tr.world->numfogs ; fogIndex++ ) {
171 fog = &tr.world->fogs[fogIndex];
172 if ( bounds[1][0] >= fog->bounds[0][0]
173 && bounds[1][1] >= fog->bounds[0][1]
174 && bounds[1][2] >= fog->bounds[0][2]
175 && bounds[0][0] <= fog->bounds[1][0]
176 && bounds[0][1] <= fog->bounds[1][1]
177 && bounds[0][2] <= fog->bounds[1][2] ) {
178 break;
179 }
180 }
181 if ( fogIndex == tr.world->numfogs ) {
182 fogIndex = 0;
183 }
184 }
185 poly->fogIndex = fogIndex;
186 }
187 }
188
189
190 //=================================================================================
191
192
193 /*
194 =====================
195 RE_AddRefEntityToScene
196
197 =====================
198 */
199 void RE_AddRefEntityToScene( const refEntity_t *ent ) {
200 if ( !tr.registered ) {
201 return;
202 }
203 if ( r_numentities >= MAX_REFENTITIES ) {
204 ri.Printf(PRINT_DEVELOPER, "RE_AddRefEntityToScene: Dropping refEntity, reached MAX_REFENTITIES\n");
205 return;
206 }
207 if ( Q_isnan(ent->origin[0]) || Q_isnan(ent->origin[1]) || Q_isnan(ent->origin[2]) ) {
208 static qboolean firstTime = qtrue;
209 if (firstTime) {
210 firstTime = qfalse;
211 ri.Printf( PRINT_WARNING, "RE_AddRefEntityToScene passed a refEntity which has an origin with a NaN component\n");
212 }
213 return;
214 }
215 if ( (int)ent->reType < 0 || ent->reType >= RT_MAX_REF_ENTITY_TYPE ) {
216 ri.Error( ERR_DROP, "RE_AddRefEntityToScene: bad reType %i", ent->reType );
217 }
218
219 backEndData->entities[r_numentities].e = *ent;
220 backEndData->entities[r_numentities].lightingCalculated = qfalse;
221
222 r_numentities++;
223 }
224
225
226 /*
227 =====================
228 RE_AddDynamicLightToScene
229
230 =====================
231 */
232 void RE_AddDynamicLightToScene( const vec3_t org, float intensity, float r, float g, float b, int additive ) {
233 dlight_t *dl;
234
235 if ( !tr.registered ) {
236 return;
237 }
238 if ( r_numdlights >= MAX_DLIGHTS ) {
239 return;
240 }
241 if ( intensity <= 0 ) {
242 return;
243 }
244 // these cards don't have the correct blend mode
245 if ( glConfig.hardwareType == GLHW_RIVA128 || glConfig.hardwareType == GLHW_PERMEDIA2 ) {
246 return;
247 }
248 dl = &backEndData->dlights[r_numdlights++];
249 VectorCopy (org, dl->origin);
250 dl->radius = intensity;
251 dl->color[0] = r;
252 dl->color[1] = g;
253 dl->color[2] = b;
254 dl->additive = additive;
255 }
256
257 /*
258 =====================
259 RE_AddLightToScene
260
261 =====================
262 */
263 void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b ) {
264 RE_AddDynamicLightToScene( org, intensity, r, g, b, qfalse );
265 }
266
267 /*
268 =====================
269 RE_AddAdditiveLightToScene
270
271 =====================
272 */
273 void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b ) {
274 RE_AddDynamicLightToScene( org, intensity, r, g, b, qtrue );
275 }
276
277 /*
278 @@@@@@@@@@@@@@@@@@@@@
279 RE_RenderScene
280
281 Draw a 3D view into a part of the window, then return
282 to 2D drawing.
283
284 Rendering a scene may require multiple views to be rendered
285 to handle mirrors,
286 @@@@@@@@@@@@@@@@@@@@@
287 */
288 void RE_RenderScene( const refdef_t *fd ) {
289 viewParms_t parms;
290 int startTime;
291
292 if ( !tr.registered ) {
293 return;
294 }
295 GLimp_LogComment( "====== RE_RenderScene =====\n" );
296
297 if ( r_norefresh->integer ) {
298 return;
299 }
300
301 startTime = ri.Milliseconds();
302
303 if (!tr.world && !( fd->rdflags & RDF_NOWORLDMODEL ) ) {
304 ri.Error (ERR_DROP, "R_RenderScene: NULL worldmodel");
305 }
306
307 Com_Memcpy( tr.refdef.text, fd->text, sizeof( tr.refdef.text ) );
308
309 tr.refdef.x = fd->x;
310 tr.refdef.y = fd->y;
311 tr.refdef.width = fd->width;
312 tr.refdef.height = fd->height;
313 tr.refdef.fov_x = fd->fov_x;
314 tr.refdef.fov_y = fd->fov_y;
315
316 VectorCopy( fd->vieworg, tr.refdef.vieworg );
317 VectorCopy( fd->viewaxis[0], tr.refdef.viewaxis[0] );
318 VectorCopy( fd->viewaxis[1], tr.refdef.viewaxis[1] );
319 VectorCopy( fd->viewaxis[2], tr.refdef.viewaxis[2] );
320
321 tr.refdef.time = fd->time;
322 tr.refdef.rdflags = fd->rdflags;
323
324 // copy the areamask data over and note if it has changed, which
325 // will force a reset of the visible leafs even if the view hasn't moved
326 tr.refdef.areamaskModified = qfalse;
327 if ( ! (tr.refdef.rdflags & RDF_NOWORLDMODEL) ) {
328 int areaDiff;
329 int i;
330
331 // compare the area bits
332 areaDiff = 0;
333 for (i = 0 ; i < MAX_MAP_AREA_BYTES/4 ; i++) {
334 areaDiff |= ((int *)tr.refdef.areamask)[i] ^ ((int *)fd->areamask)[i];
335 ((int *)tr.refdef.areamask)[i] = ((int *)fd->areamask)[i];
336 }
337
338 if ( areaDiff ) {
339 // a door just opened or something
340 tr.refdef.areamaskModified = qtrue;
341 }
342 }
343
344
345 // derived info
346
347 tr.refdef.floatTime = tr.refdef.time * 0.001;
348
349 tr.refdef.numDrawSurfs = r_firstSceneDrawSurf;
350 tr.refdef.drawSurfs = backEndData->drawSurfs;
351
352 tr.refdef.num_entities = r_numentities - r_firstSceneEntity;
353 tr.refdef.entities = &backEndData->entities[r_firstSceneEntity];
354
355 tr.refdef.num_dlights = r_numdlights - r_firstSceneDlight;
356 tr.refdef.dlights = &backEndData->dlights[r_firstSceneDlight];
357
358 tr.refdef.numPolys = r_numpolys - r_firstScenePoly;
359 tr.refdef.polys = &backEndData->polys[r_firstScenePoly];
360
361 // turn off dynamic lighting globally by clearing all the
362 // dlights if it needs to be disabled or if vertex lighting is enabled
363 if ( r_dynamiclight->integer == 0 ||
364 r_vertexLight->integer == 1 ||
365 glConfig.hardwareType == GLHW_PERMEDIA2 ) {
366 tr.refdef.num_dlights = 0;
367 }
368
369 // a single frame may have multiple scenes draw inside it --
370 // a 3D game view, 3D status bar renderings, 3D menus, etc.
371 // They need to be distinguished by the light flare code, because
372 // the visibility state for a given surface may be different in
373 // each scene / view.
374 tr.frameSceneNum++;
375 tr.sceneCount++;
376
377 // setup view parms for the initial view
378 //
379 // set up viewport
380 // The refdef takes 0-at-the-top y coordinates, so
381 // convert to GL's 0-at-the-bottom space
382 //
383 Com_Memset( &parms, 0, sizeof( parms ) );
384 parms.viewportX = tr.refdef.x;
385 parms.viewportY = glConfig.vidHeight - ( tr.refdef.y + tr.refdef.height );
386 parms.viewportWidth = tr.refdef.width;
387 parms.viewportHeight = tr.refdef.height;
388 parms.isPortal = qfalse;
389
390 parms.fovX = tr.refdef.fov_x;
391 parms.fovY = tr.refdef.fov_y;
392
393 parms.stereoFrame = tr.refdef.stereoFrame;
394
395 VectorCopy( fd->vieworg, parms.or.origin );
396 VectorCopy( fd->viewaxis[0], parms.or.axis[0] );
397 VectorCopy( fd->viewaxis[1], parms.or.axis[1] );
398 VectorCopy( fd->viewaxis[2], parms.or.axis[2] );
399
400 VectorCopy( fd->vieworg, parms.pvsOrigin );
401
402 R_RenderView( &parms );
403
404 // the next scene rendered in this frame will tack on after this one
405 r_firstSceneDrawSurf = tr.refdef.numDrawSurfs;
406 r_firstSceneEntity = r_numentities;
407 r_firstSceneDlight = r_numdlights;
408 r_firstScenePoly = r_numpolys;
409
410 tr.frontEndMsec += ri.Milliseconds() - startTime;
411 }