Skip to content

Commit b1b8a74

Browse files
committed
RenderTexture.fill would fail to fill the correct area under WebGL if the RenderTexture wasn't the same size as the Canvas. It now fills the given region properly.
1 parent c89b619 commit b1b8a74

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var ProjectOrtho = require('../../renderer/webgl/mvp/ProjectOrtho');
1717
var Render = require('./RenderTextureRender');
1818
var Utils = require('../../renderer/webgl/Utils');
1919
var UUID = require('../../utils/string/UUID');
20+
const Clamp = require('../../math/Clamp');
2021

2122
/**
2223
* @classdesc
@@ -517,21 +518,22 @@ var RenderTexture = new Class({
517518
*/
518519
fill: function (rgb, alpha, x, y, width, height)
519520
{
521+
var gl = this.gl;
522+
var frame = this.frame;
523+
var texture = this.texture;
524+
var camera = this.camera;
525+
var renderer = this.renderer;
526+
520527
if (alpha === undefined) { alpha = 1; }
521528
if (x === undefined) { x = 0; }
522529
if (y === undefined) { y = 0; }
523-
if (width === undefined) { width = this.frame.cutWidth; }
524-
if (height === undefined) { height = this.frame.cutHeight; }
530+
if (width === undefined) { width = frame.cutWidth; }
531+
if (height === undefined) { height = frame.cutHeight; }
525532

526533
var r = ((rgb >> 16) | 0) & 0xff;
527534
var g = ((rgb >> 8) | 0) & 0xff;
528535
var b = (rgb | 0) & 0xff;
529536

530-
var gl = this.gl;
531-
var frame = this.frame;
532-
var camera = this.camera;
533-
var renderer = this.renderer;
534-
535537
camera.preRender(1, 1);
536538

537539
if (gl)
@@ -543,16 +545,23 @@ var RenderTexture = new Class({
543545

544546
renderer.resetTextures(true);
545547

546-
renderer.setFramebuffer(this.framebuffer, false);
548+
renderer.pushScissor(cx, cy, cw, -ch);
547549

548-
renderer.pushScissor(cx, cy, cw, ch, ch);
550+
renderer.setFramebuffer(this.framebuffer, false);
549551

550552
var pipeline = this.pipeline;
551553

552-
ProjectOrtho(pipeline, 0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
554+
var tw = texture.width;
555+
var th = texture.height;
556+
557+
var rw = pipeline.width;
558+
var rh = pipeline.height;
559+
560+
var sx = rw / tw;
561+
var sy = rh / th;
553562

554563
pipeline.drawFillRect(
555-
x, y, width, height,
564+
x * sx, (th - height - y) * sy, width * sx, height * sy,
556565
Utils.getTintFromFloats(r / 255, g / 255, b / 255, 1),
557566
alpha
558567
);
@@ -562,15 +571,15 @@ var RenderTexture = new Class({
562571
renderer.setFramebuffer(null, false);
563572

564573
renderer.popScissor();
565-
566-
ProjectOrtho(pipeline, 0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0);
567574
}
568575
else
569576
{
570-
renderer.setContext(this.context);
577+
var ctx = this.context;
578+
579+
renderer.setContext(ctx);
571580

572-
this.context.fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')';
573-
this.context.fillRect(x + frame.cutX, y + frame.cutY, width, height);
581+
ctx.fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')';
582+
ctx.fillRect(x + frame.cutX, y + frame.cutY, width, height);
574583

575584
renderer.setContext();
576585
}

0 commit comments

Comments
 (0)