Skip to content

Commit 326bdd5

Browse files
committed
Fixed camera effects
1 parent 12a1ef3 commit 326bdd5

2 files changed

Lines changed: 68 additions & 36 deletions

File tree

src/renderer/webgl/WebGLRenderer.js

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var Class = require('../../utils/Class');
22
var CONST = require('../../const');
33
var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
44
var IsSizePowerOfTwo = require('../../math/pow2/IsSizePowerOfTwo');
5+
var Utils = require('./Utils');
56

67
// Default Pipelines
78
var TextureTintPipeline = require('./pipelines/TextureTintPipeline');
@@ -233,13 +234,19 @@ var WebGLRenderer = new Class({
233234
var gl = this.gl;
234235
var scissorState = this.currentScissorState;
235236

236-
if (!x !== 0 || y !== 0 || width !== gl.canvas.width || height !== gl.canvas.height)
237+
if (x == 0 &&
238+
y == 0 &&
239+
width == gl.canvas.width &&
240+
height == gl.canvas.height &&
241+
width > 0 &&
242+
height > 0)
237243
{
238-
return;
244+
return;
239245
}
240246

241247
if (!scissorState.enabled)
242248
{
249+
this.flush();
243250
gl.enable(gl.SCISSOR_TEST);
244251
scissorState.enabled = true;
245252
}
@@ -259,6 +266,7 @@ var WebGLRenderer = new Class({
259266
if (scissorState.enabled)
260267
{
261268
gl.disable(gl.SCISSOR_TEST);
269+
scissorState.enabled = false;
262270
}
263271
},
264272

@@ -549,6 +557,60 @@ var WebGLRenderer = new Class({
549557
},
550558

551559
/* Rendering Functions */
560+
preRenderCamera: function (camera)
561+
{
562+
this.beginScissor(camera.x, camera.y, camera.width, camera.height);
563+
564+
if (camera.backgroundColor.alphaGL > 0)
565+
{
566+
var color = camera.backgroundColor;
567+
var FlatTintPipeline = this.pipelines.FlatTintPipeline;
568+
569+
FlatTintPipeline.batchFillRect(
570+
0, 0, 1, 1, 0,
571+
camera.x, camera.y, camera.width, camera.height,
572+
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0),
573+
color.alphaGL,
574+
1, 0, 0, 1, 0, 0,
575+
[1, 0, 0, 1, 0, 0]
576+
);
577+
578+
FlatTintPipeline.flush();
579+
}
580+
},
581+
582+
postRenderCamera: function (camera)
583+
{
584+
if (camera._fadeAlpha > 0 || camera._flashAlpha > 0)
585+
{
586+
var FlatTintPipeline = this.pipelines.FlatTintPipeline;
587+
588+
// Fade
589+
FlatTintPipeline.batchFillRect(
590+
0, 0, 1, 1, 0,
591+
camera.x, camera.y, camera.width, camera.height,
592+
Utils.getTintFromFloats(camera._fadeRed, camera._fadeGreen, camera._fadeBlue, 1.0),
593+
camera._fadeAlpha,
594+
1, 0, 0, 1, 0, 0,
595+
[1, 0, 0, 1, 0, 0]
596+
);
597+
598+
// Flash
599+
FlatTintPipeline.batchFillRect(
600+
0, 0, 1, 1, 0,
601+
camera.x, camera.y, camera.width, camera.height,
602+
Utils.getTintFromFloats(camera._flashRed, camera._flashGreen, camera._flashBlue, 1.0),
603+
camera._flashAlpha,
604+
1, 0, 0, 1, 0, 0,
605+
[1, 0, 0, 1, 0, 0]
606+
);
607+
608+
FlatTintPipeline.flush();
609+
}
610+
611+
this.endScissor();
612+
},
613+
552614
preRender: function ()
553615
{
554616
if (this.contextLost) return;
@@ -569,7 +631,7 @@ var WebGLRenderer = new Class({
569631
var list = children.list;
570632
var childCount = list.length;
571633

572-
this.beginScissor(camera.x, camera.y, camera.width, camera.height);
634+
this.preRenderCamera(camera);
573635

574636
for (var index = 0; index < childCount; ++index)
575637
{
@@ -599,7 +661,8 @@ var WebGLRenderer = new Class({
599661
}
600662

601663
this.flush();
602-
this.endScissor();
664+
this.setBlendMode(CONST.BlendModes.NORMAL);
665+
this.postRenderCamera(camera);
603666
},
604667

605668
postRender: function ()

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,7 @@ var TextureTintPipeline = new Class({
144144
var ty0 = x * b + y * d + f;
145145
var tx1 = xw * a + yh * c + e;
146146
var ty1 = xw * b + yh * d + f;
147-
148-
if ((tx0 < cameraX || tx0 > cameraWidth || ty0 < cameraX || ty0 > cameraHeight) &&
149-
(tx1 < cameraY || tx1 > cameraWidth || ty1 < cameraY || ty1 > cameraHeight))
150-
{
151-
continue;
152-
}
153-
147+
154148
// Bind Texture if texture wasn't bound.
155149
// This needs to be here because of multiple
156150
// texture atlas.
@@ -270,15 +264,6 @@ var TextureTintPipeline = new Class({
270264
var tx3 = xw * mva + y * mvc + mve;
271265
var ty3 = xw * mvb + y * mvd + mvf;
272266
var vertexOffset = 0;
273-
274-
if ((tx0 < cameraX || tx0 > cameraWidth || ty0 < cameraY || ty0 > cameraHeight) &&
275-
(tx1 < cameraX || tx1 > cameraWidth || ty1 < cameraY || ty1 > cameraHeight) &&
276-
(tx2 < cameraX || tx2 > cameraWidth || ty2 < cameraY || ty2 > cameraHeight) &&
277-
(tx3 < cameraX || tx3 > cameraWidth || ty3 < cameraY || ty3 > cameraHeight))
278-
{
279-
return;
280-
}
281-
282267
var u0 = frameX / texture.width;
283268
var v0 = frameY / texture.height;
284269
var u1 = frameX / texture.width;
@@ -403,14 +388,6 @@ var TextureTintPipeline = new Class({
403388
var tint3 = getTint(tintBR, alphaBR);
404389
var vertexOffset = 0;
405390

406-
if ((tx0 < cameraX || tx0 > cameraWidth || ty0 < cameraY || ty0 > cameraHeight) &&
407-
(tx1 < cameraX || tx1 > cameraWidth || ty1 < cameraY || ty1 > cameraHeight) &&
408-
(tx2 < cameraX || tx2 > cameraWidth || ty2 < cameraY || ty2 > cameraHeight) &&
409-
(tx3 < cameraX || tx3 > cameraWidth || ty3 < cameraY || ty3 > cameraHeight))
410-
{
411-
return;
412-
}
413-
414391
renderer.setTexture2D(texture, 0);
415392

416393
vertexOffset = this.vertexCount * this.vertexComponentCount;
@@ -675,14 +652,6 @@ var TextureTintPipeline = new Class({
675652
vmin = glyphY / textureHeight;
676653
vmax = (glyphY + glyphH) / textureHeight;
677654

678-
if ((tx0 < cameraX || tx0 > cameraWidth || ty0 < cameraY || ty0 > cameraHeight) &&
679-
(tx1 < cameraX || tx1 > cameraWidth || ty1 < cameraY || ty1 > cameraHeight) &&
680-
(tx2 < cameraX || tx2 > cameraWidth || ty2 < cameraY || ty2 > cameraHeight) &&
681-
(tx3 < cameraX || tx3 > cameraWidth || ty3 < cameraY || ty3 > cameraHeight))
682-
{
683-
continue;
684-
}
685-
686655
if (this.vertexCount + 6 > this.vertexCapacity)
687656
{
688657
this.flush();

0 commit comments

Comments
 (0)