Skip to content

Commit 8ea2bff

Browse files
committed
Render Textures created larger than the size of the default canvas would be automatically clipped when drawn to in WebGL. They now reset the gl scissor and drawing height property in order to draw to their full size, regardless of the canvas size. Fix phaserjs#4139
1 parent 601c769 commit 8ea2bff

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* `WebGLRenderer.setBlendMode` has a new optional argument `force`, which will force the given blend mode to be set, regardless of the current settings.
2626
* The method `DisplayList.sortGameObjects` has been removed. It has thrown a runtime error since v3.3.0! which no-one even spotted, a good indication of how little the method is used. The display list is automatically sorted anyway, so if you need to sort a small section of it, just use the standard JavaScript Array sort method (thanks ornyth)
2727
* The method `DisplayList.getTopGameObject` has been removed. It has thrown a runtime error since v3.3.0! which no-one even spotted, a good indication of how little the method is used (thanks ornyth)
28+
* `WebGLRenderer.setFramebuffer` has a new optional boolean argument `updateScissor`, which will reset the scissor to match the framebuffer size, or clear it.
2829

2930
### Bug Fixes
3031

@@ -40,6 +41,7 @@
4041
* `Array.Matrix.ReverseColumns` was actually reversing the rows, but now reverses the columns.
4142
* UnityAtlas now sets the correct file type key if using a config file object.
4243
* Starting with version 3.13 in the Canvas Renderer, it was possible for long-running scripts to start to get bogged-down in `fillRect` calls if the game had a background color set. The context is now saved properly to avoid this. Fix #4056 (thanks @Aveyder)
44+
* Render Textures created larger than the size of the default canvas would be automatically clipped when drawn to in WebGL. They now reset the gl scissor and drawing height property in order to draw to their full size, regardless of the canvas size. Fix #4139 (thanks @chaoyang805 @iamchristopher)
4345

4446
### Examples and TypeScript
4547

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ var RenderTexture = new Class({
122122
this.globalAlpha = 1;
123123

124124
/**
125-
* The HTML Canvas Element that the Render Texture is drawing to.
126-
* This is only populated if Phaser is running with the Canvas Renderer.
125+
* The HTML Canvas Element that the Render Texture is drawing to when using the Canvas Renderer.
127126
*
128127
* @name Phaser.GameObjects.RenderTexture#canvas
129128
* @type {HTMLCanvasElement}
@@ -405,15 +404,15 @@ var RenderTexture = new Class({
405404

406405
if (this.gl)
407406
{
408-
this.renderer.setFramebuffer(this.framebuffer);
407+
this.renderer.setFramebuffer(this.framebuffer, true);
409408

410409
var gl = this.gl;
411410

412411
gl.clearColor(ur / 255.0, ug / 255.0, ub / 255.0, alpha);
413412

414413
gl.clear(gl.COLOR_BUFFER_BIT);
415414

416-
this.renderer.setFramebuffer(null);
415+
this.renderer.setFramebuffer(null, true);
417416
}
418417
else
419418
{
@@ -438,15 +437,15 @@ var RenderTexture = new Class({
438437
{
439438
if (this.gl)
440439
{
441-
this.renderer.setFramebuffer(this.framebuffer);
440+
this.renderer.setFramebuffer(this.framebuffer, true);
442441

443442
var gl = this.gl;
444443

445444
gl.clearColor(0, 0, 0, 0);
446445

447446
gl.clear(gl.COLOR_BUFFER_BIT);
448447

449-
this.renderer.setFramebuffer(null);
448+
this.renderer.setFramebuffer(null, true);
450449
}
451450
else
452451
{
@@ -540,7 +539,7 @@ var RenderTexture = new Class({
540539

541540
if (gl)
542541
{
543-
this.renderer.setFramebuffer(this.framebuffer);
542+
this.renderer.setFramebuffer(this.framebuffer, true);
544543

545544
var pipeline = this.pipeline;
546545

@@ -550,7 +549,7 @@ var RenderTexture = new Class({
550549

551550
pipeline.flush();
552551

553-
this.renderer.setFramebuffer(null);
552+
this.renderer.setFramebuffer(null, true);
554553

555554
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
556555
}
@@ -622,8 +621,8 @@ var RenderTexture = new Class({
622621

623622
if (gl)
624623
{
625-
this.renderer.setFramebuffer(this.framebuffer);
626-
624+
this.renderer.setFramebuffer(this.framebuffer, true);
625+
627626
var pipeline = this.pipeline;
628627

629628
pipeline.projOrtho(0, this.width, 0, this.height, -1000.0, 1000.0);
@@ -632,7 +631,7 @@ var RenderTexture = new Class({
632631

633632
pipeline.flush();
634633

635-
this.renderer.setFramebuffer(null);
634+
this.renderer.setFramebuffer(null, true);
636635

637636
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
638637
}

src/renderer/webgl/WebGLRenderer.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,11 +1162,14 @@ var WebGLRenderer = new Class({
11621162
* @since 3.0.0
11631163
*
11641164
* @param {WebGLFramebuffer} framebuffer - The framebuffer that needs to be bound.
1165+
* @param {boolean} [updateScissor=false] - If a framebuffer is given, set the gl scissor to match the frame buffer size? Or, if `null` given, pop the scissor from the stack.
11651166
*
11661167
* @return {this} This WebGLRenderer instance.
11671168
*/
1168-
setFramebuffer: function (framebuffer)
1169+
setFramebuffer: function (framebuffer, updateScissor)
11691170
{
1171+
if (updateScissor === undefined) { updateScissor = false; }
1172+
11701173
var gl = this.gl;
11711174

11721175
var width = this.width;
@@ -1188,6 +1191,22 @@ var WebGLRenderer = new Class({
11881191

11891192
gl.viewport(0, 0, width, height);
11901193

1194+
if (updateScissor)
1195+
{
1196+
if (framebuffer)
1197+
{
1198+
this.drawingBufferHeight = height;
1199+
1200+
this.pushScissor(0, 0, width, height);
1201+
}
1202+
else
1203+
{
1204+
this.drawingBufferHeight = this.height;
1205+
1206+
this.popScissor();
1207+
}
1208+
}
1209+
11911210
this.currentFramebuffer = framebuffer;
11921211
}
11931212

0 commit comments

Comments
 (0)