Merge pull request from adroitwhiz/usenearest-fix-2

Fix useNearest() to take renderer scale into account, take two
This commit is contained in:
DD Liu 2019-11-06 15:43:06 -05:00 committed by GitHub
commit 58aa05c0a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -461,7 +461,9 @@ class Drawable {
const localPosition = getLocalPosition(this, vec);
if (this.useNearest) {
// We're not passing in a scale to useNearest, but that's okay because "touching" queries
// happen at the "native" size anyway.
if (this.useNearest()) {
return this.skin.isTouchingNearest(localPosition);
}
return this.skin.isTouchingLinear(localPosition);
@ -469,8 +471,10 @@ class Drawable {
/**
* Should the drawable use NEAREST NEIGHBOR or LINEAR INTERPOLATION mode
* @param {?Array<Number>} scale Optionally, the screen-space scale of the drawable.
* @return {boolean} True if the drawable should use nearest-neighbor interpolation.
*/
get useNearest () {
useNearest (scale = this.scale) {
// Raster skins (bitmaps) should always prefer nearest neighbor
if (this.skin.isRaster) {
return true;
@ -492,8 +496,8 @@ class Drawable {
}
// If the scale of the skin is very close to 100 (0.99999 variance is okay I guess)
if (Math.abs(this.scale[0]) > 99 && Math.abs(this.scale[0]) < 101 &&
Math.abs(this.scale[1]) > 99 && Math.abs(this.scale[1]) < 101) {
if (Math.abs(scale[0]) > 99 && Math.abs(scale[0]) < 101 &&
Math.abs(scale[1]) > 99 && Math.abs(scale[1]) < 101) {
return true;
}
return false;
@ -685,7 +689,7 @@ class Drawable {
}
const textColor =
// commenting out to only use nearest for now
// drawable.useNearest ?
// drawable.useNearest() ?
drawable.skin._silhouette.colorAtNearest(localPosition, dst);
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);
return EffectTransform.transformColor(drawable, textColor, textColor);

View file

@ -1733,7 +1733,7 @@ class RenderWebGL extends EventEmitter {
if (uniforms.u_skin) {
twgl.setTextureParameters(
gl, uniforms.u_skin, {minMag: drawable.useNearest ? gl.NEAREST : gl.LINEAR}
gl, uniforms.u_skin, {minMag: drawable.useNearest(drawableScale) ? gl.NEAREST : gl.LINEAR}
);
}