Skip to content

Commit 2650e6c

Browse files
committed
RetroFont.text would throw WebGL errors due to an issue with Pixi.RenderTexture. Fixed in Phaser and submitted code to Pixi.
RenderTexture.resize would throw WebGL errors due to an issue with Pixi.RenderTexture. Fixed in Phaser and submitted code to Pixi.
1 parent 21011c3 commit 2650e6c

4 files changed

Lines changed: 53 additions & 55 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ Version 2.0.5 - "Tanchico" - in development
125125
* Color.getRGB would return incorrect color components if a color value without alpha was given, now works with both 0xRRGGBB and 0xAARRGGBB.
126126
* Color.getWebRGB now works regardless if you give an 0xRRGGBB or 0xAARRGGBB color value.
127127
* If an object was drag enabled with bringToTop, the onDragStop event wouldn't fire until the mouse was next moved (thanks @alpera, fix #813)
128+
* RetroFont.text would throw WebGL errors due to an issue with Pixi.RenderTexture. Fixed in Phaser and submitted code to Pixi.
129+
* RenderTexture.resize would throw WebGL errors due to an issue with Pixi.RenderTexture. Fixed in Phaser and submitted code to Pixi.
128130

129131

130132
### To Do

src/gameobjects/RenderTexture.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
* @param {string} key - Internal Phaser reference key for the render texture.
1313
* @param {number} [width=100] - The width of the render texture.
1414
* @param {number} [height=100] - The height of the render texture.
15+
* @param {string} [key=''] - The key of the RenderTexture in the Cache, if stored there.
16+
* @param {number} [scaleMode=Phaser.scaleModes.DEFAULT] - One of the Phaser.scaleModes consts.
1517
*/
16-
Phaser.RenderTexture = function (game, width, height, key) {
18+
Phaser.RenderTexture = function (game, width, height, key, scaleMode) {
19+
20+
if (typeof key === 'undefined') { key = ''; }
21+
if (typeof scaleMode === 'undefined') { scaleMode = Phaser.scaleModes.DEFAULT; }
1722

1823
/**
1924
* @property {Phaser.Game} game - A reference to the currently running game.
@@ -36,7 +41,7 @@ Phaser.RenderTexture = function (game, width, height, key) {
3641
*/
3742
this._temp = new Phaser.Point();
3843

39-
PIXI.RenderTexture.call(this, width, height);
44+
PIXI.RenderTexture.call(this, width, height, scaleMode);
4045

4146
};
4247

src/gameobjects/RetroFont.js

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -311,41 +311,6 @@ Phaser.RetroFont.prototype.setText = function (content, multiLine, characterSpac
311311

312312
};
313313

314-
/**
315-
* Over rides the default PIXI.RenderTexture resize event as we need our baseTexture resized as well.
316-
*
317-
* @method Phaser.RetroFont#resize
318-
* @memberof Phaser.RetroFont
319-
*/
320-
Phaser.RetroFont.prototype.resize = function (width, height) {
321-
322-
this.width = width;
323-
this.height = height;
324-
325-
this.frame.width = this.width;
326-
this.frame.height = this.height;
327-
328-
this.baseTexture.width = this.width;
329-
this.baseTexture.height = this.height;
330-
331-
if (this.renderer.type === PIXI.WEBGL_RENDERER)
332-
{
333-
this.projection.x = this.width / 2;
334-
this.projection.y = -this.height / 2;
335-
336-
var gl = this.renderer.gl;
337-
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTextures[gl.id]);
338-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
339-
}
340-
else
341-
{
342-
this.textureBuffer.resize(this.width, this.height);
343-
}
344-
345-
PIXI.Texture.frameUpdates.push(this);
346-
347-
};
348-
349314
/**
350315
* Updates the BitmapData of the Sprite with the text
351316
*
@@ -357,21 +322,21 @@ Phaser.RetroFont.prototype.buildRetroFontText = function () {
357322
var cx = 0;
358323
var cy = 0;
359324

325+
this.clear();
326+
360327
if (this.multiLine)
361328
{
362329
var lines = this._text.split("\n");
363330

364331
if (this.fixedWidth > 0)
365332
{
366-
this.resize(this.fixedWidth, (lines.length * (this.characterHeight + this.customSpacingY)) - this.customSpacingY);
333+
this.resize(this.fixedWidth, (lines.length * (this.characterHeight + this.customSpacingY)) - this.customSpacingY, true);
367334
}
368335
else
369336
{
370-
this.resize(this.getLongestLine() * (this.characterWidth + this.customSpacingX), (lines.length * (this.characterHeight + this.customSpacingY)) - this.customSpacingY);
337+
this.resize(this.getLongestLine() * (this.characterWidth + this.customSpacingX), (lines.length * (this.characterHeight + this.customSpacingY)) - this.customSpacingY, true);
371338
}
372339

373-
this.textureBuffer.clear();
374-
375340
// Loop through each line of text
376341
for (var i = 0; i < lines.length; i++)
377342
{
@@ -407,15 +372,13 @@ Phaser.RetroFont.prototype.buildRetroFontText = function () {
407372
{
408373
if (this.fixedWidth > 0)
409374
{
410-
this.resize(this.fixedWidth, this.characterHeight);
375+
this.resize(this.fixedWidth, this.characterHeight, true);
411376
}
412377
else
413378
{
414-
this.resize(this._text.length * (this.characterWidth + this.customSpacingX), this.characterHeight);
379+
this.resize(this._text.length * (this.characterWidth + this.customSpacingX), this.characterHeight, true);
415380
}
416381

417-
this.textureBuffer.clear();
418-
419382
switch (this.align)
420383
{
421384
case Phaser.RetroFont.ALIGN_LEFT:
@@ -432,6 +395,8 @@ Phaser.RetroFont.prototype.buildRetroFontText = function () {
432395
break;
433396
}
434397

398+
this.textureBuffer.clear();
399+
435400
this.pasteLine(this._text, cx, 0, this.customSpacingX);
436401
}
437402

src/pixi/textures/RenderTexture.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,55 @@ PIXI.RenderTexture = function(width, height, renderer, scaleMode)
101101
PIXI.RenderTexture.prototype = Object.create(PIXI.Texture.prototype);
102102
PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture;
103103

104-
PIXI.RenderTexture.prototype.resize = function(width, height)
104+
/**
105+
* Resize the RenderTexture.
106+
*
107+
* @method resize
108+
* @param width {Number} The width to resize to.
109+
* @param height {Number} The height to resize to.
110+
* @param updateBase {Boolean} Should the baseTexture.width and height values be resized as well?
111+
*/
112+
PIXI.RenderTexture.prototype.resize = function(width, height, updateBase)
105113
{
114+
if (width === this.width && height === this.height)
115+
{
116+
return;
117+
}
118+
106119
this.width = width;
107120
this.height = height;
108121

109122
this.frame.width = this.width;
110123
this.frame.height = this.height;
111124

112-
if(this.renderer.type === PIXI.WEBGL_RENDERER)
125+
if (updateBase)
126+
{
127+
this.baseTexture.width = this.width;
128+
this.baseTexture.height = this.height;
129+
}
130+
131+
if (this.renderer.type === PIXI.WEBGL_RENDERER)
113132
{
114133
this.projection.x = this.width / 2;
115134
this.projection.y = -this.height / 2;
116-
117-
var gl = this.renderer.gl;
118-
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTextures[gl.id]);
119-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
120135
}
121-
else
136+
137+
this.textureBuffer.resize(this.width, this.height);
138+
};
139+
140+
/**
141+
* Clears the RenderTexture.
142+
*
143+
* @method clear
144+
*/
145+
PIXI.RenderTexture.prototype.clear = function()
146+
{
147+
if (this.renderer.type === PIXI.WEBGL_RENDERER)
122148
{
123-
this.textureBuffer.resize(this.width, this.height);
149+
this.renderer.gl.bindFramebuffer(this.renderer.gl.FRAMEBUFFER, this.textureBuffer.frameBuffer);
124150
}
125-
126-
PIXI.Texture.frameUpdates.push(this);
151+
152+
this.textureBuffer.clear();
127153
};
128154

129155
/**

0 commit comments

Comments
 (0)