Skip to content

Commit 754fc4f

Browse files
committed
RenderTexture.resize wouldn't correctly resize the texture under WebGL. Fix phaserjs#4034
1 parent 9aaa640 commit 754fc4f

3 files changed

Lines changed: 46 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Doing this gives you the ability to modify the texture before this happens, allo
108108
* The Cameras `setScene` method, which is called automatically when a new Camera is created, will now call `updateSystem` which correctly increases the custom viewport counter. This fixes an issue with mini-cams inside of larger cameras not clipping their contents properly. If a Camera is moved to another Scene it also now correctly shrinks the total custom viewport counter.
109109
* Due to the two fixes above another bug was fixed: The ability for you to swap between Cameras with and without `setRenderToTexture` enabled with custom shaders. Previously if you used this with a custom shader then only the first Camera using the shader would render, the rest would appear black. Now, all Cameras using the custom shader work correctly. As a result all of the 'experimental' Camera rendering properties from 3.12 have been moved to stable.
110110
* If you destroyed a Game Object that had a custom cursor set during one of its input events the cursor didn't correctly reset. Fix #4033 (thanks @pantoninho)
111+
* `RenderTexture.resize` wouldn't correctly resize the texture under WebGL. Fix #4034 (thanks @jbpuryear)
111112

112113
### Examples, Documentation and TypeScript
113114

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ var UUID = require('../../utils/string/UUID');
1717
/**
1818
* @classdesc
1919
* A Render Texture.
20+
*
21+
* A Render Texture is a special texture that allows any number of Game Objects to be drawn to it. You can take many complex objects and
22+
* draw them all to this one texture, which can they be used as the texture for other Game Object's. It's a way to generate dynamic
23+
* textures at run-time that are WebGL friendly and don't invoke expensive GPU uploads.
2024
*
2125
* @class RenderTexture
2226
* @extends Phaser.GameObjects.GameObject
@@ -156,12 +160,32 @@ var RenderTexture = new Class({
156160
*/
157161
this._crop = this.resetCropObject();
158162

159-
// Create a Texture for this Text object
163+
/**
164+
* The Texture corresponding to this Render Texture.
165+
*
166+
* @name Phaser.GameObjects.RenderTexture#texture
167+
* @type {Phaser.Textures.Texture}
168+
* @since 3.12.0
169+
*/
160170
this.texture = scene.sys.textures.addCanvas(UUID(), this.canvas);
161171

162-
// Get the frame
172+
/**
173+
* The Frame corresponding to this Render Texture.
174+
*
175+
* @name Phaser.GameObjects.RenderTexture#frame
176+
* @type {Phaser.Textures.Frame}
177+
* @since 3.12.0
178+
*/
163179
this.frame = this.texture.get();
164180

181+
/**
182+
* Internal saved texture flag.
183+
*
184+
* @name Phaser.GameObjects.RenderTexture#_saved
185+
* @type {boolean}
186+
* @private
187+
* @since 3.12.0
188+
*/
165189
this._saved = false;
166190

167191
/**
@@ -185,7 +209,7 @@ var RenderTexture = new Class({
185209
this.dirty = false;
186210

187211
/**
188-
* [description]
212+
* A reference to the WebGL Rendering Context.
189213
*
190214
* @name Phaser.GameObjects.RenderTexture#gl
191215
* @type {WebGLRenderingContext}
@@ -256,25 +280,27 @@ var RenderTexture = new Class({
256280

257281
if (width !== this.width || height !== this.height)
258282
{
259-
if (this.canvas)
260-
{
261-
this.canvas.width = width;
262-
this.canvas.height = height;
263-
}
264-
else
283+
this.canvas.width = width;
284+
this.canvas.height = height;
285+
286+
if (this.gl)
265287
{
266288
var gl = this.gl;
267289

268290
this.renderer.deleteTexture(this.frame.source.glTexture);
269291
this.renderer.deleteFramebuffer(this.framebuffer);
270292

271293
this.frame.source.glTexture = this.renderer.createTexture2D(0, gl.NEAREST, gl.NEAREST, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE, gl.RGBA, null, width, height, false);
272-
this.framebuffer = this.renderer.createFramebuffer(width, height, this.texture, false);
294+
this.framebuffer = this.renderer.createFramebuffer(width, height, this.frame.source.glTexture, false);
273295

274296
this.frame.glTexture = this.frame.source.glTexture;
275297
}
276298

299+
this.frame.source.width = width;
300+
this.frame.source.height = height;
301+
277302
this.camera.setSize(width, height);
303+
278304
this.frame.setSize(width, height);
279305

280306
this.width = width;
@@ -829,18 +855,15 @@ var RenderTexture = new Class({
829855
*/
830856
preDestroy: function ()
831857
{
832-
if (this.canvas && !this._saved)
858+
if (!this._saved)
833859
{
834860
CanvasPool.remove(this.canvas);
835-
}
836861

837-
if (this.gl)
838-
{
839-
this.renderer.deleteFramebuffer(this.framebuffer);
840-
}
862+
if (this.gl)
863+
{
864+
this.renderer.deleteFramebuffer(this.framebuffer);
865+
}
841866

842-
if (!this._saved)
843-
{
844867
this.texture.destroy();
845868
}
846869
}

src/gameobjects/rendertexture/RenderTextureFactory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ var RenderTexture = require('./RenderTexture');
1111
* Creates a new Render Texture Game Object and adds it to the Scene.
1212
*
1313
* Note: This method will only be available if the Render Texture Game Object has been built into Phaser.
14+
*
15+
* A Render Texture is a special texture that allows any number of Game Objects to be drawn to it. You can take many complex objects and
16+
* draw them all to this one texture, which can they be used as the texture for other Game Object's. It's a way to generate dynamic
17+
* textures at run-time that are WebGL friendly and don't invoke expensive GPU uploads.
1418
*
1519
* @method Phaser.GameObjects.GameObjectFactory#renderTexture
1620
* @since 3.2.0

0 commit comments

Comments
 (0)