1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-14 16:55:28 +00:00

simplify particle render

Less special cases for non-rotated and non-flipped particles,
but since these are rare and the rest of the quad rendering code
has already gotten improvements there's not really any reason to keep
the specialized modes around.
The gains in GL calls were negligible and the new quad render code avoids
glVertex3f() entirely, which is a much better gain imho.
This commit is contained in:
fgenesis 2025-02-05 05:30:46 +01:00
parent 68c29a3fc9
commit 947f55f10b
3 changed files with 21 additions and 100 deletions

View file

@ -64,7 +64,6 @@ Emitter::Emitter(ParticleEffect *pe) : Quad(), pe(pe)
{ {
//HACK: //HACK:
cull = false; cull = false;
hasRot = false;
} }
void Emitter::destroy() void Emitter::destroy()
@ -250,115 +249,40 @@ void Emitter::onRender(const RenderState& rs) const
core->setupRenderPositionAndScale(); core->setupRenderPositionAndScale();
} }
float w2 = width*0.5f;
float h2 = height*0.5f;
if (texture) if (texture)
texture->apply(); texture->apply();
Vector colorMult = rs.color;
if(data.inheritColor)
colorMult *= pe->color;
float alphaMult = rs.alpha;
if(data.inheritAlpha)
alphaMult *= pe->alpha.x;
const RenderGrid * const rquad = core->getDefaultQuadGrid();
const bool flip = data.flipH != (data.copyParentFlip && pe->isfhr()); const bool flip = data.flipH != (data.copyParentFlip && pe->isfhr());
if (flip || hasRot)
for (Particles::const_iterator i = particles.begin(); i != particles.end(); i++)
{ {
Vector colorMult = data.inheritColor ? pe->color : Vector(1, 1, 1); Particle *p = *i;
float alphaMult = data.inheritAlpha ? pe->alpha.x : 1; if (p->active)
for (Particles::const_iterator i = particles.begin(); i != particles.end(); i++)
{ {
Particle *p = *i; const Vector col = p->color * colorMult;
if (p->active) glColor4f(col.x, col.y, col.z, p->alpha.x * alphaMult);
{
const float dx = w2 * p->scale.x;
const float dy = h2 * p->scale.y;
Vector col = p->color * colorMult; glPushMatrix();
glColor4f(col.x, col.y, col.z, p->alpha.x * alphaMult);
glTranslatef(p->pos.x, p->pos.y,0);
glScalef(width * p->scale.x, height * p->scale.y, 0);
if (flip || p->rot.z != 0 || p->rot.isInterpolating()) glRotatef(p->rot.z, 0, 0, 1);
{
glPushMatrix();
glTranslatef(p->pos.x, p->pos.y,0); if (flip)
glRotatef(180, 0, 1, 0);
glRotatef(p->rot.z, 0, 0, 1); rquad->render(rs);
if (flip) glPopMatrix();
{
glRotatef(180, 0, 1, 0);
}
glBegin(GL_QUADS);
glTexCoord2f(0,1);
glVertex2f(-dx, +dy);
glTexCoord2f(1,1);
glVertex2f(+dx, +dy);
glTexCoord2f(1,0);
glVertex2f(+dx, -dy);
glTexCoord2f(0,0);
glVertex2f(-dx, -dy);
glEnd();
glPopMatrix();
}
else
{
const float x = p->pos.x;
const float y = p->pos.y;
glBegin(GL_QUADS);
glTexCoord2f(0,1);
glVertex2f(x-dx, y+dy);
glTexCoord2f(1,1);
glVertex2f(x+dx, y+dy);
glTexCoord2f(1,0);
glVertex2f(x+dx, y-dy);
glTexCoord2f(0,0);
glVertex2f(x-dx, y-dy);
glEnd();
}
}
} }
} }
else
{
glBegin(GL_QUADS);
for (Particles::const_iterator i = particles.begin(); i != particles.end(); i++)
{
Particle *p = *i;
if (p->active)
{
const float x = p->pos.x;
const float y = p->pos.y;
const float dx = w2 * p->scale.x;
const float dy = h2 * p->scale.y;
glColor4f(p->color.x, p->color.y, p->color.z, p->alpha.x);
glTexCoord2f(0,1);
glVertex2f(x-dx, y+dy);
glTexCoord2f(1,1);
glVertex2f(x+dx, y+dy);
glTexCoord2f(1,0);
glVertex2f(x+dx, y-dy);
glTexCoord2f(0,0);
glVertex2f(x-dx, y-dy);
}
}
glEnd();
}
} }

View file

@ -146,8 +146,6 @@ void ParticleManager::updateParticle(Particle *p, float dt)
p->vel += dir * dt; p->vel += dir * dt;
} }
} }
if (p->rot.z != 0 || p->rot.isInterpolating())
p->emitter->hasRot = true;
} }
if (p->life <= 0) if (p->life <= 0)

View file

@ -116,7 +116,6 @@ public:
Vector getSpawnPosition(); Vector getSpawnPosition();
bool hasRot; // FIXME: this should be removed eventually
protected: protected:
Vector lastSpawn; Vector lastSpawn;
float lastDTDifference; float lastDTDifference;