The ParticleEmitterWebGLRenderer has been refactored so that the particle.frame is used as the source of the glTexture used in the batch and also if a new texture unit is required. This fixes issues where a Particle Emitter would fail to use the correct frame from a multi-atlas texture. Fix #6515

This commit is contained in:
Richard Davey 2023-09-07 16:14:06 +01:00
parent 522b3a05e2
commit 533ed6e47d

View file

@ -53,7 +53,6 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
var getTint = Utils.getTintAppendFloatAlpha; var getTint = Utils.getTintAppendFloatAlpha;
var camerAlpha = camera.alpha; var camerAlpha = camera.alpha;
var emitterAlpha = emitter.alpha; var emitterAlpha = emitter.alpha;
var texture = emitter.frame.glTexture;
renderer.pipelines.preBatch(emitter); renderer.pipelines.preBatch(emitter);
@ -71,8 +70,6 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
emitter.depthSort(); emitter.depthSort();
} }
var textureUnit = pipeline.setGameObject(emitter, emitter.frame);
camera.addToRenderList(emitter); camera.addToRenderList(emitter);
camMatrix.copyFrom(camera.matrix); camMatrix.copyFrom(camera.matrix);
@ -89,6 +86,8 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
} }
var tintEffect = emitter.tintFill; var tintEffect = emitter.tintFill;
var textureUnit;
var glTexture;
for (var i = 0; i < particleCount; i++) for (var i = 0; i < particleCount; i++)
{ {
@ -112,6 +111,13 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
var frame = particle.frame; var frame = particle.frame;
if (frame.glTexture !== glTexture)
{
glTexture = frame.glTexture;
textureUnit = pipeline.setGameObject(emitter, frame);
}
var x = -frame.halfWidth; var x = -frame.halfWidth;
var y = -frame.halfHeight; var y = -frame.halfHeight;
@ -122,10 +128,19 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
if (pipeline.shouldFlush(6)) if (pipeline.shouldFlush(6))
{ {
pipeline.flush(); pipeline.flush();
textureUnit = pipeline.setGameObject(emitter, emitter.frame);
textureUnit = pipeline.setGameObject(emitter, frame);
} }
pipeline.batchQuad(emitter, quad[0], quad[1], quad[2], quad[3], quad[4], quad[5], quad[6], quad[7], frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, tintEffect, texture, textureUnit); pipeline.batchQuad(
emitter,
quad[0], quad[1], quad[2], quad[3], quad[4], quad[5], quad[6], quad[7],
frame.u0, frame.v0, frame.u1, frame.v1,
tint, tint, tint, tint,
tintEffect,
glTexture,
textureUnit
);
} }
if (emitter.mask) if (emitter.mask)