Permalink
Browse files

Fix light flares.

The vistests were run on the empty BACK framebuffer, so the flares
were considered always visible.
  • Loading branch information...
gimhael committed Feb 12, 2016
1 parent ddc6b4a commit 054570d03c70fbcdbe7545974b42def377f24539
@@ -2626,6 +2626,138 @@ static void RB_RenderInteractionsShadowMapped()
}
}
/*
=============
RB_RunVisTests
=============
*/
void RB_RunVisTests( )
{
int i;
// finish any 2D drawing if needed
if ( tess.numIndexes )
{
Tess_End();
}
for ( i = 0; i < backEnd.refdef.numVisTests; i++ )
{
vec3_t diff;
vec3_t center, left, up;
visTestResult_t *test = &backEnd.refdef.visTests[ i ];
visTestQueries_t *testState = &backEnd.visTestQueries[ test->visTestHandle - 1 ];
if ( testState->running && !test->discardExisting )
{
GLint available;
GLuint result, resultRef;
glGetQueryObjectiv( testState->hQuery,
GL_QUERY_RESULT_AVAILABLE,
&available );
if( !available )
{
continue;
}
glGetQueryObjectiv( testState->hQueryRef,
GL_QUERY_RESULT_AVAILABLE,
&available );
if ( !available )
{
continue;
}
glGetQueryObjectuiv( testState->hQueryRef, GL_QUERY_RESULT,
&resultRef );
glGetQueryObjectuiv( testState->hQuery, GL_QUERY_RESULT,
&result );
if ( resultRef > 0 )
{
test->lastResult = (float)result / (float)resultRef;
}
else
{
test->lastResult = 0.0f;
}
testState->running = false;
}
Tess_MapVBOs( false );
VectorSubtract( backEnd.orientation.viewOrigin,
test->position, diff );
VectorNormalize( diff );
VectorMA( test->position, test->depthAdjust, diff, center );
VectorScale( backEnd.viewParms.orientation.axis[ 1 ],
test->area, left );
VectorScale( backEnd.viewParms.orientation.axis[ 2 ],
test->area, up );
tess.verts[ 0 ].xyz[ 0 ] = center[ 0 ] + left[ 0 ] + up[ 0 ];
tess.verts[ 0 ].xyz[ 1 ] = center[ 1 ] + left[ 1 ] + up[ 1 ];
tess.verts[ 0 ].xyz[ 2 ] = center[ 2 ] + left[ 2 ] + up[ 2 ];
tess.verts[ 1 ].xyz[ 0 ] = center[ 0 ] - left[ 0 ] + up[ 0 ];
tess.verts[ 1 ].xyz[ 1 ] = center[ 1 ] - left[ 1 ] + up[ 1 ];
tess.verts[ 1 ].xyz[ 2 ] = center[ 2 ] - left[ 2 ] + up[ 2 ];
tess.verts[ 2 ].xyz[ 0 ] = center[ 0 ] - left[ 0 ] - up[ 0 ];
tess.verts[ 2 ].xyz[ 1 ] = center[ 1 ] - left[ 1 ] - up[ 1 ];
tess.verts[ 2 ].xyz[ 2 ] = center[ 2 ] - left[ 2 ] - up[ 2 ];
tess.verts[ 3 ].xyz[ 0 ] = center[ 0 ] + left[ 0 ] - up[ 0 ];
tess.verts[ 3 ].xyz[ 1 ] = center[ 1 ] + left[ 1 ] - up[ 1 ];
tess.verts[ 3 ].xyz[ 2 ] = center[ 2 ] + left[ 2 ] - up[ 2 ];
tess.numVertexes = 4;
tess.indexes[ 0 ] = 0;
tess.indexes[ 1 ] = 1;
tess.indexes[ 2 ] = 2;
tess.indexes[ 3 ] = 0;
tess.indexes[ 4 ] = 2;
tess.indexes[ 5 ] = 3;
tess.numIndexes = 6;
Tess_UpdateVBOs( );
GL_VertexAttribsState( ATTR_POSITION );
gl_genericShader->DisableVertexSkinning();
gl_genericShader->DisableVertexAnimation();
gl_genericShader->DisableTCGenEnvironment();
gl_genericShader->DisableTCGenLightmap();
gl_genericShader->BindProgram( 0 );
gl_genericShader->SetUniform_AlphaTest( GLS_ATEST_NONE );
gl_genericShader->SetUniform_Color( Color::White );
gl_genericShader->SetUniform_ColorModulate( colorGen_t::CGEN_CONST, alphaGen_t::AGEN_CONST );
gl_genericShader->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
gl_genericShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[ glState.stackIndex ] );
// bind u_ColorMap
GL_BindToTMU( 0, tr.whiteImage );
gl_genericShader->SetUniform_ColorTextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] );
GL_State( GLS_DEPTHTEST_DISABLE | GLS_COLORMASK_BITS );
glBeginQuery( GL_SAMPLES_PASSED, testState->hQueryRef );
Tess_DrawElements();
glEndQuery( GL_SAMPLES_PASSED );
GL_State( GLS_COLORMASK_BITS );
glBeginQuery( GL_SAMPLES_PASSED, testState->hQuery );
Tess_DrawElements();
glEndQuery( GL_SAMPLES_PASSED );
tess.numIndexes = 0;
tess.numVertexes = 0;
tess.multiDrawPrimitives = 0;
testState->running = true;
}
}
void RB_RenderPostDepth()
{
static vec4_t quadVerts[4] = {
@@ -4493,6 +4625,7 @@ static void RB_RenderView()
}
RB_RenderDrawSurfaces( shaderSort_t::SS_DEPTH, shaderSort_t::SS_DEPTH, DRAWSURFACES_ALL );
RB_RunVisTests();
RB_RenderPostDepth();
if( tr.refdef.blurVec[0] != 0.0f ||
@@ -5351,147 +5484,6 @@ const void *RB_DrawView( const void *data )
return ( const void * )( cmd + 1 );
}
/*
=============
RB_RunVisTests
=============
*/
const void *RB_RunVisTests( const void *data )
{
const runVisTestsCommand_t *cmd;
int i;
// finish any 2D drawing if needed
if ( tess.numIndexes )
{
Tess_End();
}
cmd = ( const runVisTestsCommand_t * ) data;
backEnd.refdef = cmd->refdef;
backEnd.viewParms = cmd->viewParms;
for ( i = 0; i < backEnd.refdef.numVisTests; i++ )
{
vec3_t diff;
vec3_t center, left, up;
visTestResult_t *test = &backEnd.refdef.visTests[ i ];
visTestQueries_t *testState = &backEnd.visTestQueries[ test->visTestHandle - 1 ];
if ( testState->running && !test->discardExisting )
{
GLint available;
GLuint result, resultRef;
glGetQueryObjectiv( testState->hQuery,
GL_QUERY_RESULT_AVAILABLE,
&available );
if( !available )
{
continue;
}
glGetQueryObjectiv( testState->hQueryRef,
GL_QUERY_RESULT_AVAILABLE,
&available );
if ( !available )
{
continue;
}
glGetQueryObjectuiv( testState->hQueryRef, GL_QUERY_RESULT,
&resultRef );
glGetQueryObjectuiv( testState->hQuery, GL_QUERY_RESULT,
&result );
if ( resultRef > 0 )
{
test->lastResult = (float)result / (float)resultRef;
}
else
{
test->lastResult = 0.0f;
}
testState->running = false;
}
Tess_MapVBOs( false );
VectorSubtract( backEnd.orientation.viewOrigin,
test->position, diff );
VectorNormalize( diff );
VectorMA( test->position, test->depthAdjust, diff, center );
VectorScale( backEnd.viewParms.orientation.axis[ 1 ],
test->area, left );
VectorScale( backEnd.viewParms.orientation.axis[ 2 ],
test->area, up );
tess.verts[ 0 ].xyz[ 0 ] = center[ 0 ] + left[ 0 ] + up[ 0 ];
tess.verts[ 0 ].xyz[ 1 ] = center[ 1 ] + left[ 1 ] + up[ 1 ];
tess.verts[ 0 ].xyz[ 2 ] = center[ 2 ] + left[ 2 ] + up[ 2 ];
tess.verts[ 1 ].xyz[ 0 ] = center[ 0 ] - left[ 0 ] + up[ 0 ];
tess.verts[ 1 ].xyz[ 1 ] = center[ 1 ] - left[ 1 ] + up[ 1 ];
tess.verts[ 1 ].xyz[ 2 ] = center[ 2 ] - left[ 2 ] + up[ 2 ];
tess.verts[ 2 ].xyz[ 0 ] = center[ 0 ] - left[ 0 ] - up[ 0 ];
tess.verts[ 2 ].xyz[ 1 ] = center[ 1 ] - left[ 1 ] - up[ 1 ];
tess.verts[ 2 ].xyz[ 2 ] = center[ 2 ] - left[ 2 ] - up[ 2 ];
tess.verts[ 3 ].xyz[ 0 ] = center[ 0 ] + left[ 0 ] - up[ 0 ];
tess.verts[ 3 ].xyz[ 1 ] = center[ 1 ] + left[ 1 ] - up[ 1 ];
tess.verts[ 3 ].xyz[ 2 ] = center[ 2 ] + left[ 2 ] - up[ 2 ];
tess.numVertexes = 4;
tess.indexes[ 0 ] = 0;
tess.indexes[ 1 ] = 1;
tess.indexes[ 2 ] = 2;
tess.indexes[ 3 ] = 0;
tess.indexes[ 4 ] = 2;
tess.indexes[ 5 ] = 3;
tess.numIndexes = 6;
Tess_UpdateVBOs( );
GL_VertexAttribsState( ATTR_POSITION );
gl_genericShader->DisableVertexSkinning();
gl_genericShader->DisableVertexAnimation();
gl_genericShader->DisableTCGenEnvironment();
gl_genericShader->DisableTCGenLightmap();
gl_genericShader->BindProgram( 0 );
gl_genericShader->SetUniform_AlphaTest( GLS_ATEST_NONE );
gl_genericShader->SetUniform_Color( Color::White );
gl_genericShader->SetUniform_ColorModulate( colorGen_t::CGEN_CONST, alphaGen_t::AGEN_CONST );
gl_genericShader->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
gl_genericShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[ glState.stackIndex ] );
// bind u_ColorMap
GL_BindToTMU( 0, tr.whiteImage );
gl_genericShader->SetUniform_ColorTextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] );
GL_State( GLS_DEPTHTEST_DISABLE | GLS_COLORMASK_BITS );
glBeginQuery( GL_SAMPLES_PASSED, testState->hQueryRef );
Tess_DrawElements();
glEndQuery( GL_SAMPLES_PASSED );
GL_State( GLS_COLORMASK_BITS );
glBeginQuery( GL_SAMPLES_PASSED, testState->hQuery );
Tess_DrawElements();
glEndQuery( GL_SAMPLES_PASSED );
tess.numIndexes = 0;
tess.numVertexes = 0;
tess.multiDrawPrimitives = 0;
testState->running = true;
}
return ( const void * )( cmd + 1 );
}
/*
=============
RB_DrawBuffer
@@ -5749,10 +5741,6 @@ void RB_ExecuteRenderCommands( const void *data )
data = RB_DrawView( data );
break;
case Util::ordinal(renderCommand_t::RC_RUN_VISTESTS):
data = RB_RunVisTests( data );
break;
case Util::ordinal(renderCommand_t::RC_DRAW_BUFFER):
data = RB_DrawBuffer( data );
break;
@@ -291,29 +291,6 @@ void R_AddDrawViewCmd()
cmd->viewParms = tr.viewParms;
}
/*
=============
R_AddRunVisTestsCmd
=============
*/
void R_AddRunVisTestsCmd()
{
runVisTestsCommand_t *cmd;
cmd = ( runVisTestsCommand_t * ) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd )
{
return;
}
cmd->commandId = renderCommand_t::RC_RUN_VISTESTS;
cmd->refdef = tr.refdef;
cmd->viewParms = tr.viewParms;
}
/*
=============
RE_SetColor
@@ -3744,7 +3744,6 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
RC_SETUP_LIGHTS,
RC_DRAW_VIEW,
RC_DRAW_BUFFER,
RC_RUN_VISTESTS,
RC_SWAP_BUFFERS,
RC_SCREENSHOT,
RC_VIDEOFRAME,
@@ -3934,7 +3933,6 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
void R_AddDrawViewCmd();
void RE_SetColor( const Color::Color& rgba );
void R_AddRunVisTestsCmd();
void RE_SetClipRegion( const float *region );
void RE_StretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader );
void RE_RotatedPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader, float angle ); // NERVE - SMF
@@ -2508,8 +2508,6 @@ void R_RenderView( viewParms_t *parms )
R_SortDrawSurfs();
R_AddRunVisTestsCmd();
// draw main system development information (surface outlines, etc)
R_DebugGraphics();
}

0 comments on commit 054570d

Please sign in to comment.