@@ -353,12 +353,14 @@ const ImageGLRenderable = Base => {
353353 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . LINEAR ) ;
354354 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
355355 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
356- if ( ! isPowerOfTwo ( image . width ) || ! isPowerOfTwo ( image . height ) ) {
356+ const genMipmap = this . layer . options [ 'mipmapTexture' ] ;
357+ if ( genMipmap && ( ! isPowerOfTwo ( image . width ) || ! isPowerOfTwo ( image . height ) ) ) {
357358 image = resize ( image ) ;
358359 }
359360 gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , image ) ;
360- gl . generateMipmap ( gl . TEXTURE_2D ) ;
361-
361+ if ( genMipmap ) {
362+ gl . generateMipmap ( gl . TEXTURE_2D ) ;
363+ }
362364 return texture ;
363365 }
364366
@@ -396,12 +398,14 @@ const ImageGLRenderable = Base => {
396398 image . texture = texture ;
397399 }
398400 gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
399- if ( map . isMoving ( ) && map . getRenderer ( ) . isViewChanged ( ) ) {
400- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR_MIPMAP_LINEAR ) ;
401- } else {
402- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR ) ;
401+ const genMipmap = this . layer . options [ 'mipmapTexture' ] ;
402+ if ( genMipmap ) {
403+ if ( map . isMoving ( ) && map . getRenderer ( ) . isViewChanged ( ) ) {
404+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR_MIPMAP_LINEAR ) ;
405+ } else {
406+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR ) ;
407+ }
403408 }
404-
405409 return texture ;
406410 }
407411
@@ -636,15 +640,17 @@ function resize(image) {
636640 let width = image . width ;
637641 let height = image . height ;
638642 if ( ! isPowerOfTwo ( width ) ) {
639- width = floorPowerOfTwo ( width ) ;
643+ width = ceilPowerOfTwo ( width ) ;
640644 }
641645 if ( ! isPowerOfTwo ( height ) ) {
642- height = floorPowerOfTwo ( height ) ;
646+ height = ceilPowerOfTwo ( height ) ;
643647 }
644648 const canvas = document . createElement ( 'canvas' ) ;
645649 canvas . width = width ;
646650 canvas . height = height ;
647- canvas . getContext ( '2d' ) . drawImage ( image , 0 , 0 , width , height ) ;
651+ const ctx = canvas . getContext ( '2d' ) ;
652+ ctx . imageSmoothingEnabled = false ;
653+ ctx . drawImage ( image , 0 , 0 , width , height ) ;
648654 return canvas ;
649655}
650656
@@ -655,3 +661,7 @@ export function isPowerOfTwo(value) {
655661export function floorPowerOfTwo ( value ) {
656662 return Math . pow ( 2 , Math . floor ( Math . log ( value ) / Math . LN2 ) ) ;
657663}
664+
665+ function ceilPowerOfTwo ( value ) {
666+ return Math . pow ( 2 , Math . ceil ( Math . log ( value ) / Math . LN2 ) ) ;
667+ }
0 commit comments