Moved canvas to texture on Text to TExtWebGLRenderer

This commit is contained in:
Felipe Alfonso 2017-03-21 18:06:36 -03:00
parent 58e4912633
commit 84bc90f7ba
2 changed files with 14 additions and 10 deletions

View file

@ -68,6 +68,7 @@ var Text = new Class({
this.canvasTexture = null; this.canvasTexture = null;
this.prevWidth = this.canvas.width; this.prevWidth = this.canvas.width;
this.prevHeight = this.canvas.height; this.prevHeight = this.canvas.height;
this.dirty = false;
if (text !== '') if (text !== '')
{ {
@ -258,16 +259,7 @@ var Text = new Class({
} }
} }
if (this.state.game.config.renderType === Phaser.WEBGL) this.dirty = true;
{
this.canvasTexture = this.state.game.renderer.uploadCanvasToGPU(
this.canvas,
this.canvasTexture,
!(this.prevWidth < canvas.width || this.prevHeight < canvas.height)
);
this.prevWidth = canvas.width;
this.prevHeight = canvas.height;
}
return this; return this;
}, },

View file

@ -5,6 +5,18 @@ var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera
return; return;
} }
if (src.dirty)
{
src.canvasTexture = renderer.uploadCanvasToGPU(
src.canvas,
src.canvasTexture,
!(src.prevWidth < src.canvas.width || src.prevHeight < src.canvas.height)
);
src.prevWidth = src.canvas.width;
src.prevHeight = src.canvas.height;
src.dirty = false;
}
renderer.spriteBatch.addSpriteTexture(src, camera, src.canvasTexture, src.prevWidth, src.prevHeight); renderer.spriteBatch.addSpriteTexture(src, camera, src.canvasTexture, src.prevWidth, src.prevHeight);
}; };