TGE1.5.1 particle system optimization breaks it
by Jeff Faust · in Torque Game Engine · 04/06/2007 (4:34 pm) · 1 replies
There is a change in the TGE1.5.1 particle system rendering that tries to speed it up by limiting calls to glBindTexture(). Unfortunately this code change ignores the fact that ParticleEmitter supports multiple independent Particle styles in a single emitter and actually breaks this feature.
Here's the code... the additions are in bold.
This code change ignores the fact that "particle" is changing everytime around the loop and "texNum" is calculated from values of a specific particle. If the emitter is using multiple particles, then one cannot assume any correlation of "texNum" between different particles. Instead it ends up forcing all particles to use whatever texture the first one had.
There may be an opportunity to optimize the glBindTexture() calls here, but this change is overly simplistic and should be removed. If these texture changes are really causing problems then the single-texture-per-emitter optimization in TGEA 1.01 should be back-ported here to TGE.
Here's the code... the additions are in bold.
[b]S32 boundTexture = -1; // used to limit calls to glBindTexture[/b]
for (U32 i = 0; i < orderedVecSize; i++)
{
const Particle* particle = orderedVector[i].p;
// Set our blend mode, where appropriate.
if (particle->dataBlock->useInvAlpha != prevInvAlpha)
{
if (particle->dataBlock->useInvAlpha)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
prevInvAlpha = particle->dataBlock->useInvAlpha;
}
if( particle->dataBlock->animateTexture )
{
U32 texNum = (U32)(particle->currentAge * (1.0f/1000.0f) * particle->dataBlock->framesPerSec);
texNum %= particle->dataBlock->numFrames;
[b]if ( boundTexture != texNum )
{[/b]
glBindTexture(GL_TEXTURE_2D, particle->dataBlock->textureList[texNum].getGLName());
[b]boundTexture = texNum;
}[/b]
}
else
{
[b]if ( boundTexture != 0 )
{[/b]
glBindTexture(GL_TEXTURE_2D, particle->dataBlock->textureList[0].getGLName());
[b]boundTexture = 0;
}[/b]
}
if( mDataBlock->orientParticles )
{
renderOrientedParticle( *particle, state->getCameraPosition() );
}
else
{
renderBillboardParticle( *particle, basePoints, camView, spinFactor );
}
} This code change ignores the fact that "particle" is changing everytime around the loop and "texNum" is calculated from values of a specific particle. If the emitter is using multiple particles, then one cannot assume any correlation of "texNum" between different particles. Instead it ends up forcing all particles to use whatever texture the first one had.
There may be an opportunity to optimize the glBindTexture() calls here, but this change is overly simplistic and should be removed. If these texture changes are really causing problems then the single-texture-per-emitter optimization in TGEA 1.01 should be back-ported here to TGE.
About the author
Jeff Faust creates special effects indie middleware and games for Faust Logic. --- Blog: Effectronica.com --- Twitter: @FaustLogic
Torque Owner asmaloney (Andy)
Default Studio Name
Thanks Jeff.