Skip to content

Commit 8db93c4

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents 8334826 + 9e9b149 commit 8db93c4

3 files changed

Lines changed: 39 additions & 16 deletions

File tree

v3/src/gameobjects/renderpass/RenderPass.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var RenderPass = new Class({
3838
{
3939
GameObject.call(this, scene, 'RenderPass');
4040

41+
var _this = this;
4142
var resourceManager = scene.sys.game.renderer.resourceManager;
4243
var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0);
4344
var gl;
@@ -50,6 +51,11 @@ var RenderPass = new Class({
5051
this.uniforms = {};
5152
this.textures = {};
5253

54+
this.setFlipY(true);
55+
this.setPosition(x, y);
56+
this.setSize(width, height);
57+
this.setOrigin(0, 0);
58+
5359
if (resourceManager !== undefined)
5460
{
5561
gl = scene.sys.game.renderer.gl;
@@ -65,14 +71,10 @@ var RenderPass = new Class({
6571
this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, wrap, wrap, gl.RGBA, null, width, height);
6672
this.passRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null);
6773
scene.sys.game.renderer.currentTexture[0] = null; // force rebinding of prev texture
74+
this.passShader.bind();
75+
this.passShader.setConstantFloat2(this.passShader.getUniformLocation('u_resolution'), width, height);
6876
}
6977

70-
this.flipY = true;
71-
this.setPosition(x, y);
72-
this.setSize(width, height);
73-
this.setOrigin(0, 0);
74-
75-
var _this = this;
7678
scene.sys.game.renderer.addContextRestoredCallback(function (renderer) {
7779
var gl = renderer.gl;
7880
var wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE;
@@ -81,6 +83,8 @@ var RenderPass = new Class({
8183
_this.passRenderTarget = resourceManager.createRenderTarget(_this.width, _this.height, _this.renderTexture, null);
8284
_this.uniforms = {};
8385
_this.textures = {};
86+
_this.passShader.bind();
87+
_this.passShader.setConstantFloat2(_this.passShader.getUniformLocation('u_resolution'), _this.width, _this.height);
8488
scene.sys.game.renderer.currentTexture[0] = null; // force rebinding of prev texture
8589
});
8690
},
@@ -162,7 +166,7 @@ var RenderPass = new Class({
162166
renderer.setRenderer(this.renderer.spriteBatch, null, null);
163167
renderer.spriteBatch.addTileTextureRect(
164168
null, x, y, width, height, 1.0, 0xFFFFFFFF, this.scrollFactorX, this.scrollFactorY,
165-
width, height, 0, 0, width, height, camera, null
169+
this.width, this.height, 0, 0, width, height, camera, null, false, true
166170
);
167171
for (var key in this.textures)
168172
{

v3/src/gameobjects/renderpass/RenderPassCreator.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ GameObjectCreator.register('renderPass', function (config)
1919

2020
BuildGameObject(this.scene, pass, config);
2121

22+
pass.setPosition(x, y);
23+
pass.setSize(width, height);
24+
pass.setOrigin(0, 0);
25+
2226
return pass;
2327
});

v3/src/renderer/webgl/renderers/spritebatch/SpriteBatch.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var SpriteBatch = new Class({
3030
this.currentTexture2D = null;
3131
this.viewMatrixLocation = null;
3232
this.tempMatrix = new TransformMatrix();
33+
this.usingRenderTexture = false;
3334

3435
// All of these settings will be able to be controlled via the Game Config
3536
this.config = {
@@ -369,7 +370,7 @@ var SpriteBatch = new Class({
369370
}
370371
},
371372

372-
addTileTextureRect: function (texture, x, y, width, height, alpha, tint, scrollFactorX, scrollFactorY, textureWidth, textureHeight, rectX, rectY, rectW, rectH, camera, renderTarget)
373+
addTileTextureRect: function (texture, x, y, width, height, alpha, tint, scrollFactorX, scrollFactorY, textureWidth, textureHeight, rectX, rectY, rectW, rectH, camera, renderTarget, flipX, flipY)
373374
{
374375
var vertexDataBuffer = this.vertexDataBuffer;
375376
var vertexBufferObjectF32 = vertexDataBuffer.floatView;
@@ -382,6 +383,14 @@ var SpriteBatch = new Class({
382383
var scrollY = camera.scrollY * scrollFactorY;
383384
var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3;
384385

386+
flipX = flipX ? flipX : false;
387+
flipY = flipY ? flipY : false;
388+
389+
rectW = rectW * (flipX ? -1 : 1);
390+
rectH = rectH * (flipY ? -1 : 1);
391+
rectX = flipX ? -rectW : rectX;
392+
rectY = flipY ? -rectH : rectY;
393+
385394
// Inset UV coordinates by 0.5px to prevent tile bleeding
386395
var u0 = (rectX + 0.5) / textureWidth;
387396
var v0 = (rectY + 0.5) / textureHeight;
@@ -446,16 +455,19 @@ var SpriteBatch = new Class({
446455
var vertexBufferObjectF32 = vertexDataBuffer.floatView;
447456
var vertexBufferObjectU32 = vertexDataBuffer.uintView;
448457
var vertexOffset = 0;
449-
var width = rectWidth * (gameObject.flipX ? -1 : 1);
450-
var height = rectHeight * (gameObject.flipY ? -1 : 1);
458+
var forceFlipY = (texture.isRenderTexture ? true : false);
459+
var flipX = gameObject.flipX;
460+
var flipY = gameObject.flipY ^ forceFlipY;
461+
var width = rectWidth * (flipX ? -1 : 1);
462+
var height = rectHeight * (flipY ? -1 : 1);
451463
var translateX = gameObject.x - camera.scrollX * gameObject.scrollFactorX;
452464
var translateY = gameObject.y - camera.scrollY * gameObject.scrollFactorY;
453465
var scaleX = gameObject.scaleX;
454466
var scaleY = gameObject.scaleY;
455467
var rotation = -gameObject.rotation;
456468
var tempMatrixMatrix = tempMatrix.matrix;
457-
var x = -gameObject.displayOriginX + ((rectWidth) * (gameObject.flipX ? 1 : 0.0));
458-
var y = -gameObject.displayOriginY + ((rectHeight) * (gameObject.flipY ? 1 : 0.0));
469+
var x = -gameObject.displayOriginX + ((rectWidth) * (flipX ? 1 : 0.0));
470+
var y = -gameObject.displayOriginY + ((rectHeight) * (flipY ? 1 : 0.0));
459471
var xw = x + rectWidth;
460472
var yh = y + rectHeight;
461473
var cameraMatrix = camera.matrix.matrix;
@@ -552,16 +564,19 @@ var SpriteBatch = new Class({
552564
var vertexBufferObjectF32 = vertexDataBuffer.floatView;
553565
var vertexBufferObjectU32 = vertexDataBuffer.uintView;
554566
var vertexOffset = 0;
555-
var width = textureWidth * (gameObject.flipX ? -1 : 1);
556-
var height = textureHeight * (gameObject.flipY ? -1 : 1);
567+
var forceFlipY = (texture.isRenderTexture ? true : false);
568+
var flipX = gameObject.flipX;
569+
var flipY = gameObject.flipY ^ forceFlipY;
570+
var width = textureWidth * (flipX ? -1 : 1);
571+
var height = textureHeight * (flipY ? -1 : 1);
557572
var translateX = gameObject.x - camera.scrollX * gameObject.scrollFactorX;
558573
var translateY = gameObject.y - camera.scrollY * gameObject.scrollFactorY;
559574
var scaleX = gameObject.scaleX;
560575
var scaleY = gameObject.scaleY;
561576
var rotation = -gameObject.rotation;
562577
var tempMatrixMatrix = tempMatrix.matrix;
563-
var x = -gameObject.displayOriginX + ((textureWidth) * (gameObject.flipX ? 1 : 0.0));
564-
var y = -gameObject.displayOriginY + ((textureHeight) * (gameObject.flipY ? 1 : 0.0));
578+
var x = -gameObject.displayOriginX + ((textureWidth) * (flipX ? 1 : 0.0));
579+
var y = -gameObject.displayOriginY + ((textureHeight) * (flipY ? 1 : 0.0));
565580
var xw = x + width;
566581
var yh = y + height;
567582
var cameraMatrix = camera.matrix.matrix;

0 commit comments

Comments
 (0)