Skip to content

Commit

Permalink
Merge pull request #641 from jamieallen1234/master
Browse files Browse the repository at this point in the history
Fix for webGL performance on mobile devices and other issues
  • Loading branch information
samme committed Sep 14, 2019
2 parents aef8e05 + b78547c commit bc4ab92
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

### Bug Fixes

* Fix for WebGL being slower than Canvas on iOS and Android (#356)
* Fixed Point.fuzzyEquals and Point.fuzzyEqualsXY (#634).

### Thanks

@Cerlancism, @samme
@jamieallen1234, @Cerlancism, @samme

## Version 2.13.2 - 22 May 2019

Expand Down
6 changes: 6 additions & 0 deletions src/core/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,12 @@ Phaser.Game.prototype = {
}
}

if (this.renderer.type === Phaser.WEBGL)
{
// flush gl to prevent flickering on some android devices
this.renderer.gl.flush();
}

},

/**
Expand Down
4 changes: 3 additions & 1 deletion src/gameobjects/components/LoadTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Phaser.Component.LoadTexture.prototype = {
var cache = this.game.cache;

var setFrame = true;
var smoothed = !this.texture.baseTexture.scaleMode;
var smoothed = this.texture.baseTexture.scaleMode === PIXI.scaleModes.LINEAR;

if (Phaser.RenderTexture && key instanceof Phaser.RenderTexture)
{
Expand Down Expand Up @@ -112,6 +112,8 @@ Phaser.Component.LoadTexture.prototype = {
}
else if (key instanceof PIXI.Texture)
{
smoothed = key.baseTexture.scaleMode === PIXI.scaleModes.LINEAR;

this.setTexture(key);
}
else
Expand Down
9 changes: 5 additions & 4 deletions src/gameobjects/components/Smoothed.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ Phaser.Component.Smoothed.prototype = {
{
if (this.texture)
{
if (this.texture.baseTexture.scaleMode !== 0){
if (this.texture.baseTexture.scaleMode !== 0)
{
this.texture.baseTexture.scaleMode = 0;
this.texture.baseTexture.dirty();
}
}
}
else
if (this.texture)
else if (this.texture)
{
if (this.texture.baseTexture.scaleMode !== 1){
if (this.texture.baseTexture.scaleMode !== 1)
{
this.texture.baseTexture.scaleMode = 1;
this.texture.baseTexture.dirty();
}
Expand Down
2 changes: 1 addition & 1 deletion src/pixi/renderers/webgl/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ PIXI.WebGLRenderer.prototype.updateCompressedTexture = function (texture)
*/
PIXI.WebGLRenderer.prototype.updateTexture = function (texture)
{
if (!texture.hasLoaded)
if (!texture.hasLoaded || !texture.source)
{
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/pixi/renderers/webgl/utils/WebGLFastSpriteBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ PIXI.WebGLFastSpriteBatch.prototype.render = function (spriteBatch)
this.renderSession.blendModeManager.setBlendMode(sprite.blendMode);
}

var textureIndex = this.currentBaseTexture.textureIndex;
var gl = this.gl;

gl.activeTexture(gl.TEXTURE0 + textureIndex);
gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id]);
PIXI.WebGLRenderer.textureArray[textureIndex] = this.currentBaseTexture;

for(var i = 0,j = children.length; i < j; i++)
{
this.renderSprite(children[i]);
Expand Down
20 changes: 1 addition & 19 deletions src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,6 @@ PIXI.WebGLSpriteBatch.prototype.end = function ()
PIXI.WebGLSpriteBatch.prototype.render = function (sprite, matrix)
{
var texture = sprite.texture;
var baseTexture = texture.baseTexture;
var gl = this.gl;
if (PIXI.WebGLRenderer.textureArray[baseTexture.textureIndex] != baseTexture) // eslint-disable-line eqeqeq
{
this.flush();
gl.activeTexture(gl.TEXTURE0 + baseTexture.textureIndex);
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id]);
PIXI.WebGLRenderer.textureArray[baseTexture.textureIndex] = baseTexture;
}

// They provided an alternative rendering matrix, so use it
var wt = sprite.worldTransform;
Expand Down Expand Up @@ -434,16 +425,7 @@ PIXI.WebGLSpriteBatch.prototype.render = function (sprite, matrix)
PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function (sprite)
{
var texture = sprite.tilingTexture;
var baseTexture = texture.baseTexture;
var gl = this.gl;
var textureIndex = sprite.texture.baseTexture.textureIndex;
if (PIXI.WebGLRenderer.textureArray[textureIndex] != baseTexture) // eslint-disable-line eqeqeq
{
this.flush();
gl.activeTexture(gl.TEXTURE0 + textureIndex);
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id]);
PIXI.WebGLRenderer.textureArray[textureIndex] = baseTexture;
}

// check texture..
if (this.currentBatchSize >= this.size)
Expand Down Expand Up @@ -675,7 +657,7 @@ PIXI.WebGLSpriteBatch.prototype.flush = function ()
}

//
if (/* (currentBaseTexture != nextTexture && !skip) || */
if ((currentBaseTexture !== nextTexture && !skip) ||
blendSwap ||
shaderSwap)
{
Expand Down

0 comments on commit bc4ab92

Please sign in to comment.