Removed double rounding to pixel on rendering routines.

Fixed rounding pixel issue when camera is shaking
This commit is contained in:
Felipe Alfonso 2018-02-19 17:38:40 -03:00
parent cdc4359fd7
commit 50c79c14af
3 changed files with 19 additions and 152 deletions

View file

@ -1323,6 +1323,12 @@ var Camera = new Class({
{
this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom;
this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom;
if (this.roundPixels)
{
this._shakeOffsetX |= 0;
this._shakeOffsetY |= 0;
}
}
}
},

View file

@ -196,9 +196,8 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
@ -236,18 +235,6 @@ var FlatTintPipeline = new Class({
var ty3 = xw * b + y * d + f;
var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha);
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewU32[vertexOffset + 2] = tint;
@ -296,9 +283,8 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
@ -332,16 +318,6 @@ var FlatTintPipeline = new Class({
var ty2 = x2 * b + y2 * d + f;
var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha);
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewU32[vertexOffset + 2] = tint;
@ -382,9 +358,8 @@ var FlatTintPipeline = new Class({
* @param {float} e - [description]
* @param {float} f - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix, roundPixels)
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix)
{
var tempTriangle = this.tempTriangle;
@ -414,8 +389,7 @@ var FlatTintPipeline = new Class({
tempTriangle, lineWidth, lineColor, lineAlpha,
a, b, c, d, e, f,
false,
currentMatrix,
roundPixels
currentMatrix
);
},
@ -440,9 +414,8 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
@ -508,16 +481,6 @@ var FlatTintPipeline = new Class({
tx2 = x2 * a + y2 * c + e;
ty2 = x2 * b + y2 * d + f;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewU32[vertexOffset + 2] = tint;
@ -557,9 +520,8 @@ var FlatTintPipeline = new Class({
* @param {float} f - [description]
* @param {boolean} isLastPath - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix, roundPixels)
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix)
{
this.renderer.setPipeline(this);
@ -585,8 +547,7 @@ var FlatTintPipeline = new Class({
point0.width / 2, point1.width / 2,
point0.rgb, point1.rgb, lineAlpha,
a, b, c, d, e, f,
currentMatrix,
roundPixels
currentMatrix
);
polylines.push(line);
@ -656,9 +617,8 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
@ -711,18 +671,6 @@ var FlatTintPipeline = new Class({
var bTint = getTint(bLineColor, lineAlpha);
var vertexOffset = this.vertexCount * this.vertexComponentCount;
if (roundPixels)
{
x0 = ((x0 * resolution)|0) / resolution;
y0 = ((y0 * resolution)|0) / resolution;
x1 = ((x1 * resolution)|0) / resolution;
y1 = ((y1 * resolution)|0) / resolution;
x2 = ((x2 * resolution)|0) / resolution;
y2 = ((y2 * resolution)|0) / resolution;
x3 = ((x3 * resolution)|0) / resolution;
y3 = ((y3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = x0;
vertexViewF32[vertexOffset + 1] = y0;
vertexViewU32[vertexOffset + 2] = bTint;
@ -816,7 +764,6 @@ var FlatTintPipeline = new Class({
var mvd = src * cmb + srd * cmd;
var mve = sre * cma + srf * cmc + cme;
var mvf = sre * cmb + srf * cmd + cmf;
var roundPixels = camera.roundPixels;
var pathArrayIndex;
var pathArrayLength;
@ -911,8 +858,7 @@ var FlatTintPipeline = new Class({
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
}
break;
@ -937,8 +883,7 @@ var FlatTintPipeline = new Class({
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
path === this._lastPath,
currentMatrix,
roundPixels
currentMatrix
);
}
break;
@ -959,8 +904,7 @@ var FlatTintPipeline = new Class({
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
cmdIndex += 4;
@ -984,8 +928,7 @@ var FlatTintPipeline = new Class({
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
cmdIndex += 6;
@ -1010,8 +953,7 @@ var FlatTintPipeline = new Class({
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
cmdIndex += 6;

View file

@ -378,7 +378,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var maxQuads = this.maxQuads;
var cameraScrollX = camera.scrollX;
@ -465,18 +464,6 @@ var TextureTintPipeline = new Class({
var ty3 = xw * mvb + y * mvd + mvf;
var vertexOffset = this.vertexCount * vertexComponentCount;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewF32[vertexOffset + 2] = uvs.x0;
@ -540,7 +527,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var list = blitter.getRenderList();
var length = list.length;
@ -581,14 +567,6 @@ var TextureTintPipeline = new Class({
var ty0 = x * b + y * d + f;
var tx1 = xw * a + yh * c + e;
var ty1 = xw * b + yh * d + f;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
}
// Bind Texture if texture wasn't bound.
// This needs to be here because of multiple
@ -668,7 +646,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var cameraMatrix = camera.matrix.matrix;
var frame = sprite.frame;
@ -734,18 +711,6 @@ var TextureTintPipeline = new Class({
vertexOffset = this.vertexCount * this.vertexComponentCount;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewF32[vertexOffset + 2] = uvs.x0;
@ -809,7 +774,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var cameraMatrix = camera.matrix.matrix;
var frame = mesh.frame;
@ -852,12 +816,6 @@ var TextureTintPipeline = new Class({
var tx = x * mva + y * mvc + mve;
var ty = x * mvb + y * mvd + mvf;
if (roundPixels)
{
tx = ((tx * resolution)|0) / resolution;
tx = ((tx * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx;
vertexViewF32[vertexOffset + 1] = ty;
vertexViewF32[vertexOffset + 2] = uvs[index + 0];
@ -895,7 +853,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var cameraMatrix = camera.matrix.matrix;
var cameraWidth = camera.width + 50;
@ -1057,18 +1014,6 @@ var TextureTintPipeline = new Class({
vertexOffset = this.vertexCount * this.vertexComponentCount;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewF32[vertexOffset + 2] = umin;
@ -1129,7 +1074,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var cameraMatrix = camera.matrix.matrix;
var frame = bitmapText.frame;
@ -1360,18 +1304,6 @@ var TextureTintPipeline = new Class({
vertexOffset = this.vertexCount * this.vertexComponentCount;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewF32[vertexOffset + 2] = umin;
@ -1601,7 +1533,6 @@ var TextureTintPipeline = new Class({
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var renderer = this.renderer;
var roundPixels = camera.roundPixels;
var resolution = renderer.config.resolution;
var cameraMatrix = camera.matrix.matrix;
var width = srcWidth * (flipX ? -1.0 : 1.0);
@ -1650,18 +1581,6 @@ var TextureTintPipeline = new Class({
vertexOffset = this.vertexCount * this.vertexComponentCount;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewF32[vertexOffset + 2] = u0;