Skip to content

Commit 50c79c1

Browse files
committed
Removed double rounding to pixel on rendering routines.
Fixed rounding pixel issue when camera is shaking
1 parent cdc4359 commit 50c79c1

3 files changed

Lines changed: 19 additions & 152 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,12 @@ var Camera = new Class({
13231323
{
13241324
this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom;
13251325
this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom;
1326+
1327+
if (this.roundPixels)
1328+
{
1329+
this._shakeOffsetX |= 0;
1330+
this._shakeOffsetY |= 0;
1331+
}
13261332
}
13271333
}
13281334
},

src/renderer/webgl/pipelines/FlatTintPipeline.js

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,8 @@ var FlatTintPipeline = new Class({
196196
* @param {float} e1 - [description]
197197
* @param {float} f1 - [description]
198198
* @param {Float32Array} currentMatrix - [description]
199-
* @param {boolean} roundPixels - [description]
200199
*/
201-
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
200+
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
202201
{
203202
this.renderer.setPipeline(this);
204203

@@ -236,18 +235,6 @@ var FlatTintPipeline = new Class({
236235
var ty3 = xw * b + y * d + f;
237236
var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha);
238237

239-
if (roundPixels)
240-
{
241-
tx0 = ((tx0 * resolution)|0) / resolution;
242-
ty0 = ((ty0 * resolution)|0) / resolution;
243-
tx1 = ((tx1 * resolution)|0) / resolution;
244-
ty1 = ((ty1 * resolution)|0) / resolution;
245-
tx2 = ((tx2 * resolution)|0) / resolution;
246-
ty2 = ((ty2 * resolution)|0) / resolution;
247-
tx3 = ((tx3 * resolution)|0) / resolution;
248-
ty3 = ((ty3 * resolution)|0) / resolution;
249-
}
250-
251238
vertexViewF32[vertexOffset + 0] = tx0;
252239
vertexViewF32[vertexOffset + 1] = ty0;
253240
vertexViewU32[vertexOffset + 2] = tint;
@@ -296,9 +283,8 @@ var FlatTintPipeline = new Class({
296283
* @param {float} e1 - [description]
297284
* @param {float} f1 - [description]
298285
* @param {Float32Array} currentMatrix - [description]
299-
* @param {boolean} roundPixels - [description]
300286
*/
301-
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
287+
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
302288
{
303289
this.renderer.setPipeline(this);
304290

@@ -332,16 +318,6 @@ var FlatTintPipeline = new Class({
332318
var ty2 = x2 * b + y2 * d + f;
333319
var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha);
334320

335-
if (roundPixels)
336-
{
337-
tx0 = ((tx0 * resolution)|0) / resolution;
338-
ty0 = ((ty0 * resolution)|0) / resolution;
339-
tx1 = ((tx1 * resolution)|0) / resolution;
340-
ty1 = ((ty1 * resolution)|0) / resolution;
341-
tx2 = ((tx2 * resolution)|0) / resolution;
342-
ty2 = ((ty2 * resolution)|0) / resolution;
343-
}
344-
345321
vertexViewF32[vertexOffset + 0] = tx0;
346322
vertexViewF32[vertexOffset + 1] = ty0;
347323
vertexViewU32[vertexOffset + 2] = tint;
@@ -382,9 +358,8 @@ var FlatTintPipeline = new Class({
382358
* @param {float} e - [description]
383359
* @param {float} f - [description]
384360
* @param {Float32Array} currentMatrix - [description]
385-
* @param {boolean} roundPixels - [description]
386361
*/
387-
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix, roundPixels)
362+
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix)
388363
{
389364
var tempTriangle = this.tempTriangle;
390365

@@ -414,8 +389,7 @@ var FlatTintPipeline = new Class({
414389
tempTriangle, lineWidth, lineColor, lineAlpha,
415390
a, b, c, d, e, f,
416391
false,
417-
currentMatrix,
418-
roundPixels
392+
currentMatrix
419393
);
420394
},
421395

@@ -440,9 +414,8 @@ var FlatTintPipeline = new Class({
440414
* @param {float} e1 - [description]
441415
* @param {float} f1 - [description]
442416
* @param {Float32Array} currentMatrix - [description]
443-
* @param {boolean} roundPixels - [description]
444417
*/
445-
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
418+
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
446419
{
447420
this.renderer.setPipeline(this);
448421

@@ -508,16 +481,6 @@ var FlatTintPipeline = new Class({
508481
tx2 = x2 * a + y2 * c + e;
509482
ty2 = x2 * b + y2 * d + f;
510483

511-
if (roundPixels)
512-
{
513-
tx0 = ((tx0 * resolution)|0) / resolution;
514-
ty0 = ((ty0 * resolution)|0) / resolution;
515-
tx1 = ((tx1 * resolution)|0) / resolution;
516-
ty1 = ((ty1 * resolution)|0) / resolution;
517-
tx2 = ((tx2 * resolution)|0) / resolution;
518-
ty2 = ((ty2 * resolution)|0) / resolution;
519-
}
520-
521484
vertexViewF32[vertexOffset + 0] = tx0;
522485
vertexViewF32[vertexOffset + 1] = ty0;
523486
vertexViewU32[vertexOffset + 2] = tint;
@@ -557,9 +520,8 @@ var FlatTintPipeline = new Class({
557520
* @param {float} f - [description]
558521
* @param {boolean} isLastPath - [description]
559522
* @param {Float32Array} currentMatrix - [description]
560-
* @param {boolean} roundPixels - [description]
561523
*/
562-
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix, roundPixels)
524+
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix)
563525
{
564526
this.renderer.setPipeline(this);
565527

@@ -585,8 +547,7 @@ var FlatTintPipeline = new Class({
585547
point0.width / 2, point1.width / 2,
586548
point0.rgb, point1.rgb, lineAlpha,
587549
a, b, c, d, e, f,
588-
currentMatrix,
589-
roundPixels
550+
currentMatrix
590551
);
591552

592553
polylines.push(line);
@@ -656,9 +617,8 @@ var FlatTintPipeline = new Class({
656617
* @param {float} e1 - [description]
657618
* @param {float} f1 - [description]
658619
* @param {Float32Array} currentMatrix - [description]
659-
* @param {boolean} roundPixels - [description]
660620
*/
661-
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
621+
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
662622
{
663623
this.renderer.setPipeline(this);
664624

@@ -711,18 +671,6 @@ var FlatTintPipeline = new Class({
711671
var bTint = getTint(bLineColor, lineAlpha);
712672
var vertexOffset = this.vertexCount * this.vertexComponentCount;
713673

714-
if (roundPixels)
715-
{
716-
x0 = ((x0 * resolution)|0) / resolution;
717-
y0 = ((y0 * resolution)|0) / resolution;
718-
x1 = ((x1 * resolution)|0) / resolution;
719-
y1 = ((y1 * resolution)|0) / resolution;
720-
x2 = ((x2 * resolution)|0) / resolution;
721-
y2 = ((y2 * resolution)|0) / resolution;
722-
x3 = ((x3 * resolution)|0) / resolution;
723-
y3 = ((y3 * resolution)|0) / resolution;
724-
}
725-
726674
vertexViewF32[vertexOffset + 0] = x0;
727675
vertexViewF32[vertexOffset + 1] = y0;
728676
vertexViewU32[vertexOffset + 2] = bTint;
@@ -816,7 +764,6 @@ var FlatTintPipeline = new Class({
816764
var mvd = src * cmb + srd * cmd;
817765
var mve = sre * cma + srf * cmc + cme;
818766
var mvf = sre * cmb + srf * cmd + cmf;
819-
var roundPixels = camera.roundPixels;
820767

821768
var pathArrayIndex;
822769
var pathArrayLength;
@@ -911,8 +858,7 @@ var FlatTintPipeline = new Class({
911858

912859
/* Transform */
913860
mva, mvb, mvc, mvd, mve, mvf,
914-
currentMatrix,
915-
roundPixels
861+
currentMatrix
916862
);
917863
}
918864
break;
@@ -937,8 +883,7 @@ var FlatTintPipeline = new Class({
937883
/* Transform */
938884
mva, mvb, mvc, mvd, mve, mvf,
939885
path === this._lastPath,
940-
currentMatrix,
941-
roundPixels
886+
currentMatrix
942887
);
943888
}
944889
break;
@@ -959,8 +904,7 @@ var FlatTintPipeline = new Class({
959904

960905
/* Transform */
961906
mva, mvb, mvc, mvd, mve, mvf,
962-
currentMatrix,
963-
roundPixels
907+
currentMatrix
964908
);
965909

966910
cmdIndex += 4;
@@ -984,8 +928,7 @@ var FlatTintPipeline = new Class({
984928

985929
/* Transform */
986930
mva, mvb, mvc, mvd, mve, mvf,
987-
currentMatrix,
988-
roundPixels
931+
currentMatrix
989932
);
990933

991934
cmdIndex += 6;
@@ -1010,8 +953,7 @@ var FlatTintPipeline = new Class({
1010953

1011954
/* Transform */
1012955
mva, mvb, mvc, mvd, mve, mvf,
1013-
currentMatrix,
1014-
roundPixels
956+
currentMatrix
1015957
);
1016958

1017959
cmdIndex += 6;

0 commit comments

Comments
 (0)