Skip to content

Commit 0b95ed0

Browse files
committed
Fixed scissors when using a small cam with render texture
1 parent 79b4f07 commit 0b95ed0

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ var Camera = new Class({
261261
/**
262262
* Sets the Camera to render to a texture instead of to the main display.
263263
*
264+
* Make sure that you resize the camera first if you're going to use this feature.
265+
*
264266
* This is an experimental feature and should be expected to change in the future.
265267
*
266268
* @method Phaser.Cameras.Scene2D.Camera#setRenderToTexture

src/renderer/webgl/WebGLRenderer.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,14 +1530,14 @@ var WebGLRenderer = new Class({
15301530
var cw = camera._cw;
15311531
var ch = camera._ch;
15321532

1533-
this.pushScissor(cx, cy, cw, ch);
1534-
15351533
var TextureTintPipeline = this.pipelines.TextureTintPipeline;
15361534

15371535
var color = camera.backgroundColor;
15381536

15391537
if (camera.renderToTexture)
15401538
{
1539+
this.pushScissor(cx, cy, cw, -ch);
1540+
15411541
this.setFramebuffer(camera.framebuffer);
15421542

15431543
var gl = this.gl;
@@ -1546,25 +1546,31 @@ var WebGLRenderer = new Class({
15461546

15471547
gl.clear(gl.COLOR_BUFFER_BIT);
15481548

1549-
TextureTintPipeline.projOrtho(0, camera.width, 0, camera.height, -1000, 1000);
1549+
TextureTintPipeline.projOrtho(cx, cw + cx, cy, ch + cy, -1000, 1000);
15501550

15511551
if (color.alphaGL > 0)
15521552
{
15531553
TextureTintPipeline.drawFillRect(
1554-
cx, cy, cw, ch,
1554+
0, 0, cw + cx, ch + cy,
15551555
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1),
15561556
color.alphaGL
15571557
);
15581558
}
15591559
}
15601560
else if (color.alphaGL > 0)
15611561
{
1562+
this.pushScissor(cx, cy, cw, ch);
1563+
15621564
TextureTintPipeline.drawFillRect(
1563-
cx, cy, cw, ch,
1565+
0, 0, cw + cx, ch + cy,
15641566
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1),
15651567
color.alphaGL
15661568
);
15671569
}
1570+
else
1571+
{
1572+
this.pushScissor(cx, cy, cw, ch);
1573+
}
15681574
},
15691575

15701576
/**

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,6 @@ var TextureTintPipeline = new Class({
733733
var width = srcWidth;
734734
var height = srcHeight;
735735

736-
// var x = -displayOriginX + frameX;
737-
// var y = -displayOriginY + frameY;
738-
739736
var x = -displayOriginX;
740737
var y = -displayOriginY;
741738

@@ -789,13 +786,6 @@ var TextureTintPipeline = new Class({
789786
y += srcHeight;
790787
}
791788

792-
// Do we need this? (doubt it)
793-
// if (camera.roundPixels)
794-
// {
795-
// x |= 0;
796-
// y |= 0;
797-
// }
798-
799789
var xw = x + width;
800790
var yh = y + height;
801791

0 commit comments

Comments
 (0)