Skip to content

Commit c882b52

Browse files
committed
Fixed an issue where changing the viewport or size of a Camera belonging to a RenderTexture, it wouldn't impact the rendering and objects will still render outside of the viewport range. It's now converted to a proper gl scissor rect by the renderer, meaning you can limit the area rendered to by adjusting the internal Render Texture cameras viewport. Fix phaserjs#4243
1 parent 4b1ea8d commit c882b52

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ var RenderTexture = new Class({
414414
var g = ((rgb >> 8) | 0) & 0xff;
415415
var b = (rgb | 0) & 0xff;
416416

417-
if (this.gl)
417+
var gl = this.gl;
418+
419+
if (gl)
418420
{
419421
var renderer = this.renderer;
420422

@@ -451,17 +453,18 @@ var RenderTexture = new Class({
451453
{
452454
if (this.dirty)
453455
{
454-
if (this.gl)
456+
var gl = this.gl;
457+
458+
if (gl)
455459
{
456-
this.renderer.setFramebuffer(this.framebuffer, true);
460+
var renderer = this.renderer;
457461

458-
var gl = this.gl;
459-
462+
renderer.setFramebuffer(this.framebuffer, true);
463+
460464
gl.clearColor(0, 0, 0, 0);
461-
462465
gl.clear(gl.COLOR_BUFFER_BIT);
463-
464-
this.renderer.setFramebuffer(null, true);
466+
467+
renderer.setFramebuffer(null, true);
465468
}
466469
else
467470
{
@@ -619,7 +622,14 @@ var RenderTexture = new Class({
619622

620623
if (gl)
621624
{
622-
this.renderer.setFramebuffer(this.framebuffer, true);
625+
var cx = this.camera._cx;
626+
var cy = this.camera._cy;
627+
var cw = this.camera._cw;
628+
var ch = this.camera._ch;
629+
630+
this.renderer.setFramebuffer(this.framebuffer, false);
631+
632+
this.renderer.pushScissor(cx, cy, cw, ch, ch);
623633

624634
var pipeline = this.pipeline;
625635

@@ -629,7 +639,9 @@ var RenderTexture = new Class({
629639

630640
pipeline.flush();
631641

632-
this.renderer.setFramebuffer(null, true);
642+
this.renderer.setFramebuffer(null, false);
643+
644+
this.renderer.popScissor();
633645

634646
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
635647
}
@@ -697,12 +709,19 @@ var RenderTexture = new Class({
697709

698710
if (textureFrame)
699711
{
700-
this.camera.preRender(1, 1, 1);
712+
this.camera.preRender(1, 1);
701713

702714
if (gl)
703715
{
704-
this.renderer.setFramebuffer(this.framebuffer, true);
705-
716+
var cx = this.camera._cx;
717+
var cy = this.camera._cy;
718+
var cw = this.camera._cw;
719+
var ch = this.camera._ch;
720+
721+
this.renderer.setFramebuffer(this.framebuffer, false);
722+
723+
this.renderer.pushScissor(cx, cy, cw, ch, ch);
724+
706725
var pipeline = this.pipeline;
707726

708727
pipeline.projOrtho(0, this.width, 0, this.height, -1000.0, 1000.0);
@@ -711,8 +730,10 @@ var RenderTexture = new Class({
711730

712731
pipeline.flush();
713732

714-
this.renderer.setFramebuffer(null, true);
715-
733+
this.renderer.setFramebuffer(null, false);
734+
735+
this.renderer.popScissor();
736+
716737
pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
717738
}
718739
else

0 commit comments

Comments
 (0)