Skip to content

Commit 9dc53d1

Browse files
committed
The WebGLRenderer method canvasToTexture has a new optional argument noRepeat which will stop it from using gl.REPEAT entirely. This is now used by the Text object to avoid it potentially switching between a REPEAT and CLAMP texture, causing texture black-outs
1 parent 4beffe8 commit 9dc53d1

4 files changed

Lines changed: 35 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
* `TileSprite.setFrame` has had both the `updateSize` and `updateOrigin` arguments removed as they didn't do anything for TileSprites and were misleading.
1616
* `CameraManager.remove` has a new argument `runDestroy` which, if set, will automatically call `Camera.destroy` on the Cameras removed from the Camera Manager. You should nearly always allow this to happen (thanks jamespierce)
1717
* Device.OS has been restructured to allow fake UAs from Chrome dev tools to register iOS devices.
18-
* Texture batching during the batch flush has been implemented in the TextureTintPipeline which resolves the issues of very low frame rates, especially on iOS devices, when using non-batched textures such as those used by Text or TileSprites. Fix #4110 #4086 (thanks @ivan @sachinhosmani @maximtsai @alexeymolchan)
18+
* Texture batching during the batch flush has been implemented in the TextureTintPipeline which resolves the issues of very low frame rates, especially on iOS devices, when using non-batched textures such as those used by Text or TileSprites. Fix #4110 #4086 (thanks @ivanpopelyshev @sachinhosmani @maximtsai @alexeymolchan)
19+
* The WebGLRenderer method `canvasToTexture` has a new optional argument `noRepeat` which will stop it from using `gl.REPEAT` entirely. This is now used by the Text object to avoid it potentially switching between a REPEAT and CLAMP texture, causing texture black-outs (thanks @ivanpopelyshev)
1920

2021
### Bug Fixes
2122

2223
* Fixed a bug in the canvas rendering of both the Static and Dynamic Tilemap Layers where the camera matrix was being multiplied twice with the layer, causing the scale and placement to be off (thanks galerijanamar)
2324
* If you set `pixelArt` to true in your game config (or `antialias` to false) then TileSprites will now respect this when using the Canvas Renderer and disable smoothing on the internal fill canvas.
2425
* TileSprites that were set to be interactive before they had rendered once wouldn't receive a valid input hit area, causing input to fail. They now define their size immediately, allowing them to be made interactive without having rendered. Fix #4085 (thanks @DotTheGreat)
2526
* The Particle Emitter Manager has been given a NOOP method called `setBlendMode` to stop warnings from being thrown if you added an emitter to a Container in the Canvas renderer. Fix #4083 (thanks @maximtsai)
26-
*
2727

2828
### Examples and TypeScript
2929

src/gameobjects/text/static/Text.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ var Text = new Class({
253253
// Set the resolution
254254
this.frame.source.resolution = this.style.resolution;
255255

256+
if (this.renderer && this.renderer.gl)
257+
{
258+
// Clear the default 1x1 glTexture, as we override it later
259+
this.renderer.deleteTexture(this.frame.source.glTexture);
260+
261+
this.frame.source.glTexture = null;
262+
}
263+
256264
this.initRTL();
257265

258266
if (style && style.padding)
@@ -1168,7 +1176,7 @@ var Text = new Class({
11681176

11691177
if (this.renderer.gl)
11701178
{
1171-
this.frame.source.glTexture = this.renderer.canvasToTexture(canvas, this.frame.source.glTexture);
1179+
this.frame.source.glTexture = this.renderer.canvasToTexture(canvas, this.frame.source.glTexture, true);
11721180

11731181
this.frame.glTexture = this.frame.source.glTexture;
11741182
}

src/renderer/webgl/WebGLRenderer.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,28 +1824,40 @@ var WebGLRenderer = new Class({
18241824
*
18251825
* @param {HTMLCanvasElement} srcCanvas - The Canvas element that will be used to populate the texture.
18261826
* @param {WebGLTexture} [dstTexture] - Is this going to replace an existing texture? If so, pass it here.
1827+
* @param {boolean} [noRepeat=false] - Should this canvas never be allowed to set REPEAT? (such as for Text objects)
18271828
*
18281829
* @return {WebGLTexture} The newly created WebGL Texture.
18291830
*/
1830-
canvasToTexture: function (srcCanvas, dstTexture)
1831+
canvasToTexture: function (srcCanvas, dstTexture, noRepeat)
18311832
{
1832-
var gl = this.gl;
1833+
if (noRepeat === undefined) { noRepeat = false; }
18331834

1834-
var wrapping = gl.CLAMP_TO_EDGE;
1835+
var gl = this.gl;
18351836

1836-
if (IsSizePowerOfTwo(srcCanvas.width, srcCanvas.height))
1837+
if (!dstTexture)
18371838
{
1838-
wrapping = gl.REPEAT;
1839-
}
1839+
var wrapping = gl.CLAMP_TO_EDGE;
18401840

1841-
var newTexture = this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true);
1841+
if (!noRepeat && IsSizePowerOfTwo(srcCanvas.width, srcCanvas.height))
1842+
{
1843+
wrapping = gl.REPEAT;
1844+
}
18421845

1843-
if (newTexture && dstTexture)
1846+
dstTexture = this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true);
1847+
}
1848+
else
18441849
{
1845-
this.deleteTexture(dstTexture);
1850+
this.setTexture2D(dstTexture, 0);
1851+
1852+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
1853+
1854+
dstTexture.width = srcCanvas.width;
1855+
dstTexture.height = srcCanvas.height;
1856+
1857+
this.setTexture2D(null, 0);
18461858
}
18471859

1848-
return newTexture;
1860+
return dstTexture;
18491861
},
18501862

18511863
/**

src/textures/TextureSource.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ var TextureSource = new Class({
238238

239239
// Update all the Frames using this TextureSource
240240

241+
/*
241242
var index = this.texture.getTextureSourceIndex(this);
242243
243244
var frames = this.texture.getFramesFromTextureSource(index, true);
@@ -246,6 +247,7 @@ var TextureSource = new Class({
246247
{
247248
frames[i].glTexture = this.glTexture;
248249
}
250+
*/
249251
}
250252
},
251253

0 commit comments

Comments
 (0)