Skip to content

Commit cc2bc3d

Browse files
committed
Also pass in drawable to useNearest
This makes the code messier but I'm not sure what else to do since the texture filtering method to be used depends on the drawable's properties (e.g. transform, enabled effects).
1 parent 71b1e0f commit cc2bc3d

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/Drawable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class Drawable {
467467

468468
// "touching" queries always occur at the "native" size, so it's fine to just pass in this._scale with no
469469
// screen-space scaling factors.
470-
if (this.skin.useNearest(this._scale)) {
470+
if (this.skin.useNearest(this._scale, this)) {
471471
return this.skin.isTouchingNearest(localPosition);
472472
}
473473
return this.skin.isTouchingLinear(localPosition);
@@ -678,7 +678,7 @@ class Drawable {
678678
}
679679
const textColor =
680680
// commenting out to only use nearest for now
681-
// drawable.skin.useNearest(drawable._scale) ?
681+
// drawable.skin.useNearest(drawable._scale, drawable) ?
682682
drawable.skin._silhouette.colorAtNearest(localPosition, dst);
683683
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);
684684

src/RenderWebGL.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,9 @@ class RenderWebGL extends EventEmitter {
17821782

17831783
if (uniforms.u_skin) {
17841784
twgl.setTextureParameters(
1785-
gl, uniforms.u_skin, {minMag: drawable.skin.useNearest(drawableScale) ? gl.NEAREST : gl.LINEAR}
1785+
gl, uniforms.u_skin, {
1786+
minMag: drawable.skin.useNearest(drawableScale, drawable) ? gl.NEAREST : gl.LINEAR
1787+
}
17861788
);
17871789
}
17881790

src/SVGSkin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class SVGSkin extends Skin {
5959
return this._svgRenderer.size;
6060
}
6161

62-
useNearest (scale) {
62+
useNearest (scale, drawable) {
6363
// If the effect bits for mosaic, pixelate, whirl, or fisheye are set, use linear
64-
if ((this.enabledEffects & (
64+
if ((drawable.enabledEffects & (
6565
ShaderManager.EFFECT_INFO.fisheye.mask |
6666
ShaderManager.EFFECT_INFO.whirl.mask |
6767
ShaderManager.EFFECT_INFO.pixelate.mask |
@@ -71,7 +71,7 @@ class SVGSkin extends Skin {
7171
}
7272

7373
// We can't use nearest neighbor unless we are a multiple of 90 rotation
74-
if (this._direction % 90 !== 0) {
74+
if (drawable._direction % 90 !== 0) {
7575
return false;
7676
}
7777

src/Skin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ class Skin extends EventEmitter {
8585
* Should this skin's texture be filtered with nearest-neighbor or linear interpolation at the given scale?
8686
* @param {?Array<Number>} scale The screen-space X and Y scaling factors at which this skin's texture will be
8787
* displayed, as percentages (100 means 1 "native size" unit is 1 screen pixel; 200 means 2 screen pixels, etc).
88+
* @param {Drawable} drawable The drawable that this skin's texture will be applied to.
8889
* @return {boolean} True if this skin's texture, as returned by {@link getTexture}, should be filtered with
8990
* nearest-neighbor interpolation.
9091
*/
9192
// eslint-disable-next-line no-unused-vars
92-
useNearest (scale) {
93+
useNearest (scale, drawable) {
9394
return true;
9495
}
9596

0 commit comments

Comments
 (0)