Skip to content

Commit 16d4d11

Browse files
committed
Final fixes to blitFrame
1 parent 1cb6d52 commit 16d4d11

2 files changed

Lines changed: 38 additions & 56 deletions

File tree

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ var RenderTexture = new Class({
545545

546546
if (renderTarget)
547547
{
548-
renderTarget.bind();
548+
renderTarget.bind(true);
549549

550550
var pipeline = this.pipeline;
551551

@@ -1072,6 +1072,8 @@ var RenderTexture = new Class({
10721072
var util = renderer.pipelines.setUtility();
10731073

10741074
util.blitFrame(canvasTarget, renderTarget, 1, false);
1075+
1076+
renderer.resetViewport();
10751077
}
10761078
else
10771079
{

src/renderer/webgl/pipelines/UtilityPipeline.js

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,19 @@ var UtilityPipeline = new Class({
402402
gl.activeTexture(gl.TEXTURE0);
403403
gl.bindTexture(gl.TEXTURE_2D, source.texture);
404404

405-
gl.viewport(0, 0, source.width, source.height);
405+
if (source.height >= target.height)
406+
{
407+
gl.viewport(0, 0, source.width, source.height);
408+
409+
this.setVerticesFromTarget(source, target);
410+
}
411+
else
412+
{
413+
var diff = target.height - source.height;
414+
415+
gl.viewport(0, diff, source.width, source.height);
416+
}
417+
406418
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
407419
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
408420

@@ -420,15 +432,15 @@ var UtilityPipeline = new Class({
420432
gl.clear(gl.COLOR_BUFFER_BIT);
421433
}
422434

423-
this.setVerticesFromTarget(source, target);
435+
gl.disable(gl.SCISSOR_TEST);
424436

425437
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
426438
gl.drawArrays(gl.TRIANGLES, 0, 6);
427439

428440
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
429441
gl.bindTexture(gl.TEXTURE_2D, null);
430442

431-
this.resetVertices();
443+
this.resetUVs();
432444
},
433445

434446
/**
@@ -692,19 +704,6 @@ var UtilityPipeline = new Class({
692704
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
693705
},
694706

695-
/**
696-
* Resets the quad vertices to their default values.
697-
*
698-
* The quad is used by all shaders of the Utility Pipeline.
699-
*
700-
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#resetVertices
701-
* @since 3.50.0
702-
*/
703-
resetVertices: function ()
704-
{
705-
this.vertexViewF32.set([ -1, -1, 0, 0, -1, 1, 0, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, 1, 1, 1, -1, 1, 0 ]);
706-
},
707-
708707
/**
709708
* Set the UV values for the 6 vertices that make up the quad used by the shaders
710709
* in the Utility Pipeline.
@@ -766,16 +765,7 @@ var UtilityPipeline = new Class({
766765
diff = 0.5 + (0.5 - diff);
767766
}
768767

769-
console.log('setVerticesFromTarget UVs', 'game', source.height, 'rt', target.height, diff);
770-
771768
this.setUVs(0, diff, 0, 1 + diff, 1, 1 + diff, 1, diff);
772-
773-
if (target.height >= source.height)
774-
{
775-
console.log('Adjusting Quad Y position');
776-
777-
778-
}
779769
},
780770

781771
/**
@@ -806,40 +796,30 @@ var UtilityPipeline = new Class({
806796
this.setUVs(0, 1, 0, 0, 1, 0, 1, 1);
807797
},
808798

809-
setAPos: function (x, y)
810-
{
811-
var vertexViewF32 = this.vertexViewF32;
812-
813-
vertexViewF32[0] = x;
814-
vertexViewF32[1] = y;
815-
vertexViewF32[12] = x;
816-
vertexViewF32[13] = y;
817-
},
818-
819-
setBPos: function (x, y)
820-
{
821-
var vertexViewF32 = this.vertexViewF32;
822-
823-
vertexViewF32[4] = x;
824-
vertexViewF32[5] = y;
825-
},
826-
827-
setCPos: function (x, y)
799+
/**
800+
* Resets the quad vertices to their default values.
801+
*
802+
* The quad is used by all shaders of the Utility Pipeline.
803+
*
804+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#resetVertices
805+
* @since 3.50.0
806+
*/
807+
resetVertices: function ()
828808
{
829-
var vertexViewF32 = this.vertexViewF32;
830-
831-
vertexViewF32[8] = x;
832-
vertexViewF32[9] = y;
833-
vertexViewF32[16] = x;
834-
vertexViewF32[17] = y;
809+
this.vertexViewF32.set([ -1, -1, 0, 0, -1, 1, 0, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, 1, 1, 1, -1, 1, 0 ]);
835810
},
836811

837-
setDPos: function (x, y)
812+
/**
813+
* Resets the quad vertice UV values to their default settings.
814+
*
815+
* The quad is used by all shaders of the Utility Pipeline.
816+
*
817+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#resetUVs
818+
* @since 3.50.0
819+
*/
820+
resetUVs: function ()
838821
{
839-
var vertexViewF32 = this.vertexViewF32;
840-
841-
vertexViewF32[20] = x;
842-
vertexViewF32[21] = y;
822+
this.setUVs(0, 0, 0, 1, 1, 1, 1, 0);
843823
}
844824

845825
});

0 commit comments

Comments
 (0)