Skip to content

Commit eaddfaf

Browse files
committed
Snap stamp bounds after applying renderQuality
Fixes lines between tiles in projects such as https://scratch.mit.edu/projects/322341152
1 parent 14debd2 commit eaddfaf

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/RenderWebGL.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,18 @@ class RenderWebGL extends EventEmitter {
14861486
return bounds;
14871487
}
14881488

1489+
_unsnappedTouchingBounds (drawableID) {
1490+
// _touchingBounds with the snapToint call removed.
1491+
const drawable = this._allDrawables[drawableID];
1492+
if (!drawable.skin || !drawable.skin.getTexture([100, 100])) return null;
1493+
const bounds = drawable.getFastBounds();
1494+
bounds.clamp(this._xLeft, this._xRight, this._yBottom, this._yTop);
1495+
if (bounds.width === 0 || bounds.height === 0) {
1496+
return null;
1497+
}
1498+
return bounds;
1499+
}
1500+
14891501
/**
14901502
* Filter a list of candidates for a touching query into only those that
14911503
* could possibly intersect the given bounds.
@@ -1737,7 +1749,8 @@ class RenderWebGL extends EventEmitter {
17371749
return;
17381750
}
17391751

1740-
const bounds = this._touchingBounds(stampID);
1752+
// tw: snapping occurs later
1753+
const bounds = this._unsnappedTouchingBounds(stampID);
17411754
if (!bounds) {
17421755
return;
17431756
}
@@ -1750,13 +1763,21 @@ class RenderWebGL extends EventEmitter {
17501763
twgl.bindFramebufferInfo(gl, skin._framebuffer);
17511764

17521765
// Limit size of viewport to the bounds around the stamp Drawable and create the projection matrix for the draw.
1753-
gl.viewport(
1754-
// tw: account for renderQuality
1755-
((this._nativeSize[0] * 0.5) + bounds.left) * skin.renderQuality,
1756-
((this._nativeSize[1] * 0.5) - bounds.top) * skin.renderQuality,
1757-
bounds.width * skin.renderQuality,
1758-
bounds.height * skin.renderQuality
1759-
);
1766+
// tw: scale for high quality render
1767+
if (!this.useHighQualityRender) {
1768+
bounds.snapToInt();
1769+
}
1770+
let x = (this._nativeSize[0] * 0.5) + bounds.left;
1771+
let y = (this._nativeSize[1] * 0.5) - bounds.top;
1772+
let width = bounds.width;
1773+
let height = bounds.height;
1774+
if (this.useHighQualityRender) {
1775+
x = Math.floor(x * skin.renderQuality);
1776+
y = Math.floor(y * skin.renderQuality);
1777+
width = Math.ceil(width * skin.renderQuality);
1778+
height = Math.ceil(height * skin.renderQuality);
1779+
}
1780+
gl.viewport(x, y, width, height);
17601781
const projection = twgl.m4.ortho(bounds.left, bounds.right, bounds.top, bounds.bottom, -1, 1);
17611782

17621783
// Draw the stamped sprite onto the PenSkin's framebuffer.

0 commit comments

Comments
 (0)