Skip to content

Commit 58aa05c

Browse files
authored
Merge pull request #480 from adroitwhiz/usenearest-fix-2
Fix useNearest() to take renderer scale into account, take two
2 parents c6b5824 + ae23bb5 commit 58aa05c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Drawable.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,20 @@ class Drawable {
461461

462462
const localPosition = getLocalPosition(this, vec);
463463

464-
if (this.useNearest) {
464+
// We're not passing in a scale to useNearest, but that's okay because "touching" queries
465+
// happen at the "native" size anyway.
466+
if (this.useNearest()) {
465467
return this.skin.isTouchingNearest(localPosition);
466468
}
467469
return this.skin.isTouchingLinear(localPosition);
468470
}
469471

470472
/**
471473
* Should the drawable use NEAREST NEIGHBOR or LINEAR INTERPOLATION mode
474+
* @param {?Array<Number>} scale Optionally, the screen-space scale of the drawable.
475+
* @return {boolean} True if the drawable should use nearest-neighbor interpolation.
472476
*/
473-
get useNearest () {
477+
useNearest (scale = this.scale) {
474478
// Raster skins (bitmaps) should always prefer nearest neighbor
475479
if (this.skin.isRaster) {
476480
return true;
@@ -492,8 +496,8 @@ class Drawable {
492496
}
493497

494498
// If the scale of the skin is very close to 100 (0.99999 variance is okay I guess)
495-
if (Math.abs(this.scale[0]) > 99 && Math.abs(this.scale[0]) < 101 &&
496-
Math.abs(this.scale[1]) > 99 && Math.abs(this.scale[1]) < 101) {
499+
if (Math.abs(scale[0]) > 99 && Math.abs(scale[0]) < 101 &&
500+
Math.abs(scale[1]) > 99 && Math.abs(scale[1]) < 101) {
497501
return true;
498502
}
499503
return false;
@@ -685,7 +689,7 @@ class Drawable {
685689
}
686690
const textColor =
687691
// commenting out to only use nearest for now
688-
// drawable.useNearest ?
692+
// drawable.useNearest() ?
689693
drawable.skin._silhouette.colorAtNearest(localPosition, dst);
690694
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);
691695
return EffectTransform.transformColor(drawable, textColor, textColor);

src/RenderWebGL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ class RenderWebGL extends EventEmitter {
17331733

17341734
if (uniforms.u_skin) {
17351735
twgl.setTextureParameters(
1736-
gl, uniforms.u_skin, {minMag: drawable.useNearest ? gl.NEAREST : gl.LINEAR}
1736+
gl, uniforms.u_skin, {minMag: drawable.useNearest(drawableScale) ? gl.NEAREST : gl.LINEAR}
17371737
);
17381738
}
17391739

0 commit comments

Comments
 (0)