doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
draw_nv10.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #include "../idlib/precompiled.h"
29 #pragma hdrstop
30 
31 #include "tr_local.h"
32 
33 
34 /*
35 ==================
36 RB_RenderInteraction
37 
38 backEnd.vLight
39 backEnd.lightScale
40 
41 
42 backEnd.depthFunc must be equal for alpha tested surfaces to work right,
43 it is set to lessThan for blended transparent surfaces
44 
45 This expects a bumpmap stage before a diffuse stage before a specular stage
46 The material code is responsible for guaranteeing that, but conditional stages
47 can still make it invalid.
48 
49 you can't blend two bumpmaps, but you can change bump maps between
50 blended diffuse / specular maps to get the same effect
51 
52 
53 ==================
54 */
55 static void RB_RenderInteraction( const drawSurf_t *surf ) {
56  const idMaterial *surfaceShader = surf->material;
57  const float *surfaceRegs = surf->shaderRegisters;
58  const viewLight_t *vLight = backEnd.vLight;
59  const idMaterial *lightShader = vLight->lightShader;
60  const float *lightRegs = vLight->shaderRegisters;
61  static idPlane lightProject[4]; // reused across function calls
62  const srfTriangles_t *tri = surf->geo;
63  const shaderStage_t *lastBumpStage = NULL;
64 
65  RB_LogComment( "---------- RB_RenderInteraction %s on %s ----------\n",
66  lightShader->GetName(), surfaceShader->GetName() );
67 
68  // change the matrix and light projection vectors if needed
69  if ( surf->space != backEnd.currentSpace ) {
70  backEnd.currentSpace = surf->space;
72 
73  for ( int i = 0 ; i < 4 ; i++ ) {
74  R_GlobalPlaneToLocal( surf->space->modelMatrix, backEnd.vLight->lightProject[i], lightProject[i] );
75  }
76  }
77 
78  // change the scissor if needed
85  }
86 
87  // hack depth range if needed
88  if ( surf->space->weaponDepthHack ) {
90  }
91 
92  if ( surf->space->modelDepthHack != 0.0f ) {
94  }
95 
96 
97  // set the vertex arrays, which may not all be enabled on a given pass
99  qglVertexPointer( 3, GL_FLOAT, sizeof( idDrawVert ), ac->xyz.ToFloatPtr() );
100  GL_SelectTexture( 0 );
101  qglTexCoordPointer( 2, GL_FLOAT, sizeof( idDrawVert ), ac->st.ToFloatPtr() );
102  qglColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( idDrawVert ), ac->color );
103 
104 
105  // go through the individual stages
106  for ( int i = 0 ; i < surfaceShader->GetNumStages() ; i++ ) {
107  const shaderStage_t *surfaceStage = surfaceShader->GetStage( i );
108 
109  // ignore ambient stages while drawing interactions
110  if ( surfaceStage->lighting == SL_AMBIENT ) {
111  continue;
112  }
113 
114  // ignore stages that fail the condition
115  if ( !surfaceRegs[ surfaceStage->conditionRegister ] ) {
116  continue;
117  }
118 
119  //-----------------------------------------------------
120  //
121  // bump / falloff
122  //
123  //-----------------------------------------------------
124  if ( surfaceStage->lighting == SL_BUMP ) {
125  // render light falloff * bumpmap lighting
126 
127  if ( surfaceStage->vertexColor != SVC_IGNORE ) {
128  common->Printf( "shader %s: vertexColor on a bump stage\n",
129  surfaceShader->GetName() );
130  }
131 
132  // check for RGBA modulations in the stage, which are also illegal?
133 
134  // save the bump map stage for the specular calculation and diffuse
135  // error checking
136  lastBumpStage = surfaceStage;
137 
138  //
139  // ambient lights combine non-directional bump and falloff
140  // and write to the alpha channel
141  //
142  if ( lightShader->IsAmbientLight() ) {
144 
145  // texture 0 will be the per-surface bump map
146  GL_SelectTexture( 0 );
147  qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
148 
149  RB_BindStageTexture( surfaceRegs, &surfaceStage->texture, surf );
150  // development aid
151  if ( r_skipBump.GetBool() ) {
153  }
154 
155  // texture 1 will be the light falloff
156  GL_SelectTexture( 1 );
157 
158  qglEnable( GL_TEXTURE_GEN_S );
159  qglTexGenfv( GL_S, GL_OBJECT_PLANE, lightProject[3].ToFloatPtr() );
160  qglTexCoord2f( 0, 0.5 );
161  vLight->falloffImage->Bind();
162 
163  qglCombinerParameteriNV( GL_NUM_GENERAL_COMBINERS_NV, 2 );
164 
165  // set the constant color to a bit of an angle
166  qglCombinerParameterfvNV( GL_CONSTANT_COLOR0_NV, tr.ambientLightVector.ToFloatPtr() );
167 
168  // stage 0 sets primary_color = bump dot constant color
169  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV,
171  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
173  qglCombinerOutputNV( GL_COMBINER0_NV, GL_RGB,
175  GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE );
176 
177  // stage 1 alpha sets primary_color = primary_color * falloff
178  qglCombinerInputNV( GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_A_NV,
180  qglCombinerInputNV( GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_B_NV,
182  qglCombinerOutputNV( GL_COMBINER1_NV, GL_ALPHA,
184  GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE );
185 
186  // final combiner takes the result for the alpha channel
187  qglFinalCombinerInputNV( GL_VARIABLE_A_NV, GL_ZERO,
188  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
189  qglFinalCombinerInputNV( GL_VARIABLE_B_NV, GL_ZERO,
190  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
191  qglFinalCombinerInputNV( GL_VARIABLE_C_NV, GL_ZERO,
192  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
193  qglFinalCombinerInputNV( GL_VARIABLE_D_NV, GL_ZERO,
194  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
195  qglFinalCombinerInputNV( GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV,
196  GL_UNSIGNED_IDENTITY_NV, GL_ALPHA );
197 
198  // draw it
200 
202  qglDisable( GL_TEXTURE_GEN_S );
203 
204  GL_SelectTexture( 0 );
205  RB_FinishStageTexture( &surfaceStage->texture, surf );
206  continue;
207  }
208 
209  //
210  // draw light falloff to the alpha channel
211  //
213  qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
214  qglDisableClientState( GL_COLOR_ARRAY );
215  qglEnable( GL_TEXTURE_GEN_S );
216  qglTexGenfv( GL_S, GL_OBJECT_PLANE, lightProject[3].ToFloatPtr() );
217  qglTexCoord2f( 0, 0.5 );
218  vLight->falloffImage->Bind();
219 
220  // make sure a combiner output doesn't step on the texture
221  qglCombinerParameteriNV( GL_NUM_GENERAL_COMBINERS_NV, 1 );
222  qglCombinerOutputNV( GL_COMBINER0_NV, GL_ALPHA,
224  GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE );
225 
226  // final combiner
227  qglFinalCombinerInputNV( GL_VARIABLE_A_NV, GL_ZERO,
228  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
229  qglFinalCombinerInputNV( GL_VARIABLE_B_NV, GL_ZERO,
230  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
231  qglFinalCombinerInputNV( GL_VARIABLE_C_NV, GL_ZERO,
232  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
233  qglFinalCombinerInputNV( GL_VARIABLE_D_NV, GL_ZERO,
234  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
235  qglFinalCombinerInputNV( GL_VARIABLE_G_NV, GL_TEXTURE0_ARB,
236  GL_UNSIGNED_IDENTITY_NV, GL_ALPHA );
237 
238  // draw it
240 
241  qglDisable( GL_TEXTURE_GEN_S );
242 
243  //
244  // draw the bump map result onto the alpha channel
245  //
247  | backEnd.depthFunc );
248 
249  // texture 0 will be the per-surface bump map
250  GL_SelectTexture( 0 );
251  qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
252  RB_BindStageTexture( surfaceRegs, &surfaceStage->texture, surf );
253 
254  // texture 1 is the normalization cube map
255  // the texccords are the non-normalized vector towards the light origin
256  GL_SelectTexture( 1 );
258  qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
259  qglTexCoordPointer( 3, GL_FLOAT, sizeof( lightingCache_t ), ((lightingCache_t *)vertexCache.Position(tri->lightingCache))->localLightVector.ToFloatPtr() );
260 
261  qglDisableClientState( GL_COLOR_ARRAY );
262 
263  // program the nvidia register combiners
264  // I just want alpha = Dot( texture0, texture1 )
265  qglCombinerParameteriNV( GL_NUM_GENERAL_COMBINERS_NV, 1 );
266 
267  // stage 0 rgb performs the dot product
268  // SPARE0 = TEXTURE0 dot TEXTURE1
269  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV,
271  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
273  qglCombinerOutputNV( GL_COMBINER0_NV, GL_RGB,
275  GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE );
276 
277  // final combiner just takes the dot result and puts it in alpha
278  qglFinalCombinerInputNV( GL_VARIABLE_G_NV, GL_SPARE0_NV,
279  GL_UNSIGNED_IDENTITY_NV, GL_BLUE );
280 
281  // draw it
283 
285  qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
286 
287  GL_SelectTexture( 0 );
288  RB_FinishStageTexture( &surfaceStage->texture, surf );
289  continue;
290  }
291 
292  if ( surfaceStage->lighting == SL_DIFFUSE ) {
293  if ( !lastBumpStage ) {
294  common->Printf( "shader %s: diffuse stage without a preceeding bumpmap stage\n",
295  surfaceShader->GetName() );
296  continue;
297  }
298  }
299 
300  //-----------------------------------------------------
301  //
302  // specular exponent modification of the bump / falloff
303  //
304  //-----------------------------------------------------
305  if ( surfaceStage->lighting == SL_SPECULAR ) {
306  // put specular bump map into alpha channel, then treat as a diffuse
307 
308  // allow the specular to be skipped as a user speed optimization
309  if ( r_skipSpecular.GetBool() ) {
310  continue;
311  }
312 
313  // ambient lights don't have specular
314  if ( lightShader->IsAmbientLight() ) {
315  continue;
316  }
317 
318  if ( !lastBumpStage ) {
319  common->Printf( "shader %s: specular stage without a preceeding bumpmap stage\n",
320  surfaceShader->GetName() );
321  continue;
322  }
323 
325  | backEnd.depthFunc );
326 
327  // texture 0 will be the per-surface bump map
328  GL_SelectTexture( 0 );
329  qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
330  RB_BindStageTexture( surfaceRegs, &lastBumpStage->texture, surf );
331 
332  // development aid
333  if ( r_skipBump.GetBool() ) {
335  }
336 
337  // texture 1 is the normalization cube map
338  // indexed by the dynamic halfangle texcoords
339  GL_SelectTexture( 1 );
341  qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
342  qglTexCoordPointer( 4, GL_FLOAT, 0, vertexCache.Position( surf->dynamicTexCoords ) );
343 
344  // program the nvidia register combiners
345  qglCombinerParameteriNV( GL_NUM_GENERAL_COMBINERS_NV, 2 );
346 
347  // stage 0 rgb performs the dot product
348  // GL_PRIMARY_COLOR_NV = ( TEXTURE0 dot TEXTURE1 - 0.5 ) * 2
349  // the scale and bias steepen the specular curve
350  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV,
352  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
354  qglCombinerOutputNV( GL_COMBINER0_NV, GL_RGB,
356  GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_TRUE, GL_FALSE, GL_FALSE );
357 
358  // stage 0 alpha does nothing
359  qglCombinerOutputNV( GL_COMBINER0_NV, GL_ALPHA,
361  GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE );
362 
363  // stage 1 rgb does nothing
364  qglCombinerOutputNV( GL_COMBINER1_NV, GL_RGB,
366  GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE );
367 
368  // stage 1 alpha takes bump * bump
369  // PRIMARY_COLOR = ( GL_PRIMARY_COLOR_NV * GL_PRIMARY_COLOR_NV - 0.5 ) * 2
370  // the scale and bias steepen the specular curve
371  qglCombinerInputNV( GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_A_NV,
373  qglCombinerInputNV( GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_B_NV,
375  qglCombinerOutputNV( GL_COMBINER1_NV, GL_ALPHA,
377  GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE );
378 
379  // final combiner
380  qglFinalCombinerInputNV( GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV,
381  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
382  qglFinalCombinerInputNV( GL_VARIABLE_A_NV, GL_ZERO,
383  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
384  qglFinalCombinerInputNV( GL_VARIABLE_B_NV, GL_ZERO,
385  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
386  qglFinalCombinerInputNV( GL_VARIABLE_C_NV, GL_ZERO,
387  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
388  qglFinalCombinerInputNV( GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV,
389  GL_UNSIGNED_IDENTITY_NV, GL_ALPHA );
390 
391  // draw it
393 
395  qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
396 
397  GL_SelectTexture( 0 );
398 
399  RB_FinishStageTexture( &lastBumpStage->texture, surf );
400 
401  // the bump map in the alpha channel is now corrupted, so a normal diffuse
402  // map can't be drawn unless a new bumpmap is put down
403  lastBumpStage = NULL;
404 
405  // fall through to the common handling of diffuse and specular projected lighting
406  }
407 
408  //-----------------------------------------------------
409  //
410  // projected light / surface color for diffuse and specular maps
411  //
412  //-----------------------------------------------------
413  if ( surfaceStage->lighting == SL_DIFFUSE || surfaceStage->lighting == SL_SPECULAR ) {
414  // don't trash alpha
416  | backEnd.depthFunc );
417 
418  // texture 0 will get the surface color texture
419  GL_SelectTexture( 0 );
420  qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
421  RB_BindStageTexture( surfaceRegs, &surfaceStage->texture, surf );
422 
423  // development aid
424  if ( ( surfaceStage->lighting == SL_DIFFUSE && r_skipDiffuse.GetBool() )
425  || ( surfaceStage->lighting == SL_SPECULAR && r_skipSpecular.GetBool() ) ) {
427  }
428 
429  // texture 1 will get the light projected texture
430  GL_SelectTexture( 1 );
431  qglDisableClientState( GL_TEXTURE_COORD_ARRAY );
432  qglEnable( GL_TEXTURE_GEN_S );
433  qglEnable( GL_TEXTURE_GEN_T );
434  qglEnable( GL_TEXTURE_GEN_Q );
435  qglTexGenfv( GL_S, GL_OBJECT_PLANE, lightProject[0].ToFloatPtr() );
436  qglTexGenfv( GL_T, GL_OBJECT_PLANE, lightProject[1].ToFloatPtr() );
437  qglTexGenfv( GL_Q, GL_OBJECT_PLANE, lightProject[2].ToFloatPtr() );
438 
439  // texture0 * texture1 * primaryColor * constantColor
440  qglCombinerParameteriNV( GL_NUM_GENERAL_COMBINERS_NV, 1 );
441 
442  // SPARE0 = TEXTURE0 * PRIMARY_COLOR
443  // SPARE1 = TEXTURE1 * CONSTANT_COLOR
444  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV,
446  // variable B will be overriden based on the stage vertexColor option
447  if ( surfaceStage->vertexColor == SVC_MODULATE ) {
448  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
450  qglEnableClientState( GL_COLOR_ARRAY );
451  } else if ( surfaceStage->vertexColor == SVC_INVERSE_MODULATE ) {
452  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
454  qglEnableClientState( GL_COLOR_ARRAY );
455  } else { // SVC_IGNORE
456  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
457  GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB );
458  qglDisableClientState( GL_COLOR_ARRAY );
459  }
460  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV,
462  qglCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV,
464  qglCombinerOutputNV( GL_COMBINER0_NV, GL_RGB,
466  GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE );
467 
468  // final combiner
469  qglFinalCombinerInputNV( GL_VARIABLE_A_NV, GL_SPARE1_NV,
470  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
471  qglFinalCombinerInputNV( GL_VARIABLE_B_NV, GL_SPARE0_NV,
472  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
473  qglFinalCombinerInputNV( GL_VARIABLE_C_NV, GL_ZERO,
474  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
475  qglFinalCombinerInputNV( GL_VARIABLE_D_NV, GL_ZERO,
476  GL_UNSIGNED_IDENTITY_NV, GL_RGB );
477  qglFinalCombinerInputNV( GL_VARIABLE_G_NV, GL_ZERO,
478  GL_UNSIGNED_IDENTITY_NV, GL_ALPHA );
479 
480  // for all light stages, multiply the projected color by the surface
481  // color, and blend with the framebuffer
482  for ( int j = 0 ; j < lightShader->GetNumStages() ; j++ ) {
483  const shaderStage_t *lightStage = lightShader->GetStage( j );
484  float color[4];
485 
486  // ignore stages that fail the condition
487  if ( !lightRegs[ lightStage->conditionRegister ] ) {
488  continue;
489  }
490 
491  // set the color to the light color times the surface color
492  color[0] = backEnd.lightScale
493  * lightRegs[ lightStage->color.registers[0] ]
494  * surfaceRegs[ surfaceStage->color.registers[0] ];
495  color[1] = backEnd.lightScale
496  * lightRegs[ lightStage->color.registers[1] ]
497  * surfaceRegs[ surfaceStage->color.registers[1] ];
498  color[2] = backEnd.lightScale
499  * lightRegs[ lightStage->color.registers[2] ]
500  * surfaceRegs[ surfaceStage->color.registers[2] ];
501  color[3] = 1;
502 
503  // don't draw if it would be all black
504  if ( color[0] == 0 && color[1] == 0 && color[2] == 0 ) {
505  continue;
506  }
507 
508  qglCombinerParameterfvNV( GL_CONSTANT_COLOR1_NV, color );
509 
510  RB_BindStageTexture( lightRegs, &lightStage->texture, surf );
511 
513 
514  RB_FinishStageTexture( &lightStage->texture, surf );
515  }
516 
517  if ( surfaceStage->vertexColor != SVC_IGNORE ) {
518  qglDisableClientState( GL_COLOR_ARRAY );
519  }
520 
521  qglDisable( GL_TEXTURE_GEN_S );
522  qglDisable( GL_TEXTURE_GEN_T );
523  qglDisable( GL_TEXTURE_GEN_Q );
524 
526  GL_SelectTexture( 0 );
527  RB_FinishStageTexture( &surfaceStage->texture, surf );
528 
529  continue;
530  }
531 
532  }
533  // unhack depth range if needed
534  if ( surf->space->weaponDepthHack || surf->space->modelDepthHack != 0.0f ) {
536  }
537 }
538 
539 /*
540 ==================
541 RB_RenderInteractionList
542 ==================
543 */
544 static void RB_RenderInteractionList( const drawSurf_t *surf ) {
545  if ( !surf ) {
546  return;
547  }
548 
550 
551  // force a space calculation for light vectors
553 
554  for ( const drawSurf_t *s = surf ; s ; s = s->nextOnLight ) {
555  RB_RenderInteraction( s );
556  }
557 
559 }
560 
561 
562 
563 /*
564 ==================
565 RB_RenderViewLight
566 
567 ==================
568 */
569 static void RB_RenderViewLight( viewLight_t *vLight ) {
570  backEnd.vLight = vLight;
571 
572  // do fogging later
573  if ( vLight->lightShader->IsFogLight() ) {
574  return;
575  }
576  if ( vLight->lightShader->IsBlendLight() ) {
577  return;
578  }
579 
580  RB_LogComment( "---------- RB_RenderViewLight 0x%p ----------\n", vLight );
581 
582  // clear the stencil buffer if needed
583  if ( vLight->globalShadows || vLight->localShadows ) {
585  if ( r_useScissor.GetBool() ) {
590  }
591  qglClear( GL_STENCIL_BUFFER_BIT );
592  } else {
593  // no shadows, so no need to read or write the stencil buffer
594  // we might in theory want to use GL_ALWAYS instead of disabling
595  // completely, to satisfy the invarience rules
596  qglStencilFunc( GL_ALWAYS, 128, 255 );
597  }
598 
601  RB_RenderInteractionList( vLight->localInteractions );
603  RB_RenderInteractionList( vLight->globalInteractions );
604 
605  if ( r_skipTranslucent.GetBool() ) {
606  return;
607  }
608 
609  // disable stencil testing for translucent interactions, because
610  // the shadow isn't calculated at their point, and the shadow
611  // behind them may be depth fighting with a back side, so there
612  // isn't any reasonable thing to do
613  qglStencilFunc( GL_ALWAYS, 128, 255 );
615  RB_RenderInteractionList( vLight->translucentInteractions );
616 }
617 
618 
619 /*
620 ==================
621 RB_NV10_DrawInteractions
622 ==================
623 */
625  qglEnable( GL_STENCIL_TEST );
626 
627  for ( viewLight_t *vLight = backEnd.viewDef->viewLights ; vLight ; vLight = vLight->next ) {
628  RB_RenderViewLight( vLight );
629  }
630 }
631 
632 
633 /*
634 ==================
635 R_NV10_Init
636 
637 ==================
638 */
639 void R_NV10_Init( void ) {
640  glConfig.allowNV10Path = false;
641 
643  return;
644  }
645 
646  glConfig.allowNV10Path = true;
647 }
const int GLS_DSTBLEND_ONE
Definition: tr_local.h:1017
bool weaponDepthHack
Definition: tr_local.h:357
byte color[4]
Definition: MegaTexture.cpp:54
#define qglTexCoordPointer
Definition: qgl_linked.h:318
#define qglLoadMatrixf
Definition: qgl_linked.h:188
const srfTriangles_t * geo
Definition: tr_local.h:112
const int GLS_DEPTHFUNC_LESS
Definition: tr_local.h:1040
#define qglScissor
Definition: qgl_linked.h:280
idImage * falloffImage
Definition: tr_local.h:328
#define qglEnableClientState
Definition: qgl_linked.h:102
#define GL_VARIABLE_A_NV
Definition: glext.h:1784
#define qglDisable
Definition: qgl_linked.h:92
#define qglDisableClientState
Definition: qgl_linked.h:93
short x2
Definition: tr_local.h:55
#define GL_UNSIGNED_INVERT_NV
Definition: glext.h:1801
#define GL_DISCARD_NV
Definition: glext.h:1797
const int GetNumStages(void) const
Definition: Material.h:365
#define GL_TEXTURE1_ARB
Definition: glext.h:378
int conditionRegister
Definition: Material.h:204
idCVar r_skipTranslucent("r_skipTranslucent","0", CVAR_RENDERER|CVAR_BOOL,"skip the translucent interaction rendering")
const float * ToFloatPtr(void) const
Definition: Vector.h:719
idScreenRect scissorRect
Definition: tr_local.h:307
const int GLS_ALPHAMASK
Definition: tr_local.h:1033
const int GLS_COLORMASK
Definition: tr_local.h:1034
idVec3 xyz
Definition: DrawVert.h:42
idCVar r_skipSpecular("r_skipSpecular","0", CVAR_RENDERER|CVAR_BOOL|CVAR_CHEAT|CVAR_ARCHIVE,"use black for specular1")
const int GLS_DSTBLEND_SRC_ALPHA
Definition: tr_local.h:1020
stageLighting_t lighting
Definition: Material.h:205
idScreenRect scissorRect
Definition: tr_local.h:118
const struct drawSurf_s * localShadows
Definition: tr_local.h:332
const char * GetName(void) const
Definition: DeclManager.h:140
idScreenRect viewport
Definition: tr_local.h:398
#define GL_VARIABLE_G_NV
Definition: glext.h:1790
const struct drawSurf_s * globalInteractions
Definition: tr_local.h:333
bool IsBlendLight() const
Definition: Material.h:461
float lightScale
Definition: tr_local.h:653
short x1
Definition: tr_local.h:55
void R_NV10_Init(void)
Definition: draw_nv10.cpp:639
void RB_EnterWeaponDepthHack()
Definition: tr_render.cpp:176
void RB_EnterModelDepthHack(float depth)
Definition: tr_render.cpp:195
float modelDepthHack
Definition: tr_local.h:358
GLdouble s
Definition: glext.h:2935
const struct viewEntity_s * space
Definition: tr_local.h:113
struct vertCache_s * ambientCache
Definition: Model.h:137
int i
Definition: process.py:33
#define GL_SPARE0_NV
Definition: glext.h:1795
const idMaterial * material
Definition: tr_local.h:114
bool IsAmbientLight() const
Definition: Material.h:464
#define qglEnable
Definition: qgl_linked.h:101
const viewEntity_t * currentSpace
Definition: tr_local.h:644
void RB_LeaveDepthHack()
Definition: tr_render.cpp:214
const idMaterial * lightShader
Definition: tr_local.h:326
idImage * flatNormalMap
Definition: Image.h:393
#define GL_VARIABLE_D_NV
Definition: glext.h:1787
backEndState_t backEnd
Definition: tr_backend.cpp:35
const int GLS_DEPTHFUNC_EQUAL
Definition: tr_local.h:1039
struct viewLight_s * next
Definition: tr_local.h:299
struct viewLight_s * viewLights
Definition: tr_local.h:415
idVec2 st
Definition: DrawVert.h:43
#define qglStencilFunc
Definition: qgl_linked.h:283
int registers[4]
Definition: Material.h:145
viewLight_t * vLight
Definition: tr_local.h:648
#define GL_NUM_GENERAL_COMBINERS_NV
Definition: glext.h:1824
idImage * normalCubeMapImage
Definition: Image.h:400
const shaderStage_t * GetStage(const int index) const
Definition: Material.h:368
#define qglTexGenfv
Definition: qgl_linked.h:326
idCVar r_skipBump("r_skipBump","0", CVAR_RENDERER|CVAR_BOOL|CVAR_ARCHIVE,"uses a flat surface instead of the bump map")
idCommon * common
Definition: Common.cpp:206
#define GL_PRIMARY_COLOR_NV
Definition: glext.h:1793
#define NULL
Definition: Lib.h:88
struct vertCache_s * dynamicTexCoords
Definition: tr_local.h:120
#define qglTexCoord2f
Definition: qgl_linked.h:296
#define GL_CONSTANT_COLOR0_NV
Definition: glext.h:1791
idImageManager * globalImages
Definition: Image_init.cpp:74
Definition: Plane.h:71
#define GL_CONSTANT_COLOR1_NV
Definition: glext.h:1792
struct vertCache_s * lightingCache
Definition: Model.h:138
colorStage_t color
Definition: Material.h:207
const struct drawSurf_s * translucentInteractions
Definition: tr_local.h:334
idImage * blackImage
Definition: Image.h:399
bool registerCombinersAvailable
Definition: RenderSystem.h:68
virtual void Printf(const char *fmt,...) id_attribute((format(printf
#define GL_REGISTER_COMBINERS_NV
Definition: glext.h:1783
float modelMatrix[16]
Definition: tr_local.h:360
void RB_DrawElementsWithCounters(const srfTriangles_t *tri)
Definition: tr_render.cpp:78
const float * ToFloatPtr(void) const
Definition: Vector.h:1051
const int GLS_SRCBLEND_DST_ALPHA
Definition: tr_local.h:1011
#define GL_SCALE_BY_TWO_NV
Definition: glext.h:1808
bool allowNV10Path
Definition: RenderSystem.h:94
const int GLS_DSTBLEND_ZERO
Definition: tr_local.h:1016
const float * shaderRegisters
Definition: tr_local.h:327
#define GL_SPARE1_NV
Definition: glext.h:1796
void RB_LogComment(const char *comment,...)
Definition: tr_backend.cpp:112
#define qglColorPointer
Definition: qgl_linked.h:80
bool GetBool(void) const
Definition: CVarSystem.h:142
glconfig_t glConfig
void RB_NV10_DrawInteractions(void)
Definition: draw_nv10.cpp:624
const struct drawSurf_s * globalShadows
Definition: tr_local.h:330
textureStage_t texture
Definition: Material.h:210
const struct drawSurf_s * localInteractions
Definition: tr_local.h:331
const float * ToFloatPtr(void) const
Definition: Vector.h:301
#define GL_VARIABLE_C_NV
Definition: glext.h:1786
void * Position(vertCache_t *buffer)
#define qglClear
Definition: qgl_linked.h:39
float modelViewMatrix[16]
Definition: tr_local.h:361
byte color[4]
Definition: DrawVert.h:46
#define GL_COMBINER0_NV
Definition: glext.h:1826
#define GL_EXPAND_NORMAL_NV
Definition: glext.h:1802
stageVertexColor_t vertexColor
Definition: Material.h:211
#define GL_VARIABLE_B_NV
Definition: glext.h:1785
bool IsFogLight() const
Definition: Material.h:458
void RB_FinishStageTexture(const textureStage_t *texture, const drawSurf_t *surf)
Definition: tr_render.cpp:451
idVertexCache vertexCache
Definition: VertexCache.cpp:41
idRenderSystemLocal tr
#define GL_COMBINER1_NV
Definition: glext.h:1827
#define GL_TEXTURE0_ARB
Definition: glext.h:377
idPlane lightProject[4]
Definition: tr_local.h:323
void GL_State(int stateBits)
Definition: tr_backend.cpp:239
void RB_StencilShadowPass(const drawSurf_t *drawSurfs)
#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV
Definition: glext.h:1811
short y1
Definition: tr_local.h:55
GLint j
Definition: qgl.h:264
idCVar r_useScissor("r_useScissor","1", CVAR_RENDERER|CVAR_BOOL,"scissor clip as portals and lights are processed")
void GL_SelectTexture(int unit)
Definition: tr_backend.cpp:135
#define GL_UNSIGNED_IDENTITY_NV
Definition: glext.h:1800
short y2
Definition: tr_local.h:55
idCVar r_skipDiffuse("r_skipDiffuse","0", CVAR_RENDERER|CVAR_BOOL,"use black for diffuse")
void RB_BindStageTexture(const float *shaderRegisters, const textureStage_t *texture, const drawSurf_t *surf)
Definition: tr_render.cpp:410
void Bind()
idVec4 ambientLightVector
Definition: tr_local.h:768
idScreenRect currentScissor
Definition: tr_local.h:645
#define qglVertexPointer
Definition: qgl_linked.h:363
void R_GlobalPlaneToLocal(const float modelMatrix[16], const idPlane &in, idPlane &out)
Definition: tr_main.cpp:547
const float * shaderRegisters
Definition: tr_local.h:116
const int GLS_DEPTHMASK
Definition: tr_local.h:1029
bool Equals(const idScreenRect &rect) const
Definition: tr_main.cpp:133
const viewDef_t * viewDef
Definition: tr_local.h:641