Skip to content

Commit 835bc37

Browse files
committed
Optimized TextureTintPipeline.drawBlitter so it skips bobs that have alpha of zero and only calls setTexture2D if the bob sourceIndex has changed, previously it called it for every single bob.
1 parent 7df0488 commit 835bc37

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* WebGLRenderer.config has a new property `maxTextures` which is derived from `gl.MAX_TEXTURE_IMAGE_UNITS`, you can get it via the new method `getMaxTextures()`.
1010
* WebGLRenderer.config has a new property `maxTextureSize` which is derived from `gl.MAX_TEXTURE_SIZE`, you can get it via the new method `getMaxTextureSize()`
1111
* WebGLRenderer has a new property `compression` which holds the browser / devices compressed texture support gl extensions, which is populated during `init`.
12+
* Optimized TextureTintPipeline.drawBlitter so it skips bobs that have alpha of zero and only calls `setTexture2D` if the bob sourceIndex has changed, previously it called it for every single bob.
1213

1314
### Bug Fixes
1415

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ var TextureTintPipeline = new Class({
664664
var blitterX = blitter.x - cameraScrollX;
665665
var blitterY = blitter.y - cameraScrollY;
666666

667+
var prevTextureSourceIndex;
668+
667669
for (var batchIndex = 0; batchIndex < batchCount; ++batchIndex)
668670
{
669671
var batchSize = Math.min(length, this.maxQuads);
@@ -673,6 +675,13 @@ var TextureTintPipeline = new Class({
673675
var bob = list[batchOffset + index];
674676
var frame = bob.frame;
675677
var alpha = bob.alpha;
678+
679+
if (alpha === 0)
680+
{
681+
// Nothing to see here, moving on ...
682+
continue;
683+
}
684+
676685
var tint = getTint(0xffffff, alpha);
677686
var uvs = frame.uvs;
678687
var flipX = bob.flipX;
@@ -688,10 +697,13 @@ var TextureTintPipeline = new Class({
688697
var tx1 = xw * a + yh * c + e;
689698
var ty1 = xw * b + yh * d + f;
690699

691-
// Bind Texture if texture wasn't bound.
692-
// This needs to be here because of multiple
693-
// texture atlas.
694-
this.setTexture2D(frame.texture.source[frame.sourceIndex].glTexture, 0);
700+
// Bind texture only if the Texture Source is different from before
701+
if (frame.sourceIndex !== prevTextureSourceIndex)
702+
{
703+
this.setTexture2D(frame.texture.source[frame.sourceIndex].glTexture, 0);
704+
705+
prevTextureSourceIndex = frame.sourceIndex;
706+
}
695707

696708
var vertexOffset = this.vertexCount * this.vertexComponentCount;
697709

@@ -739,6 +751,8 @@ var TextureTintPipeline = new Class({
739751
if (this.vertexCount >= this.vertexCapacity)
740752
{
741753
this.flush();
754+
755+
prevTextureSourceIndex = -1;
742756
}
743757
}
744758

0 commit comments

Comments
 (0)