@@ -397,10 +397,18 @@ export default class TableCanvas extends SuperComponent<ITableCanvas> {
397397 this . gl . bindTexture ( this . gl . TEXTURE_2D , this . imgProgram . get_texture ( ) ) ;
398398 this . gl . texImage2D ( this . gl . TEXTURE_2D , 0 , this . gl . RGBA , this . gl . RGBA , this . gl . UNSIGNED_BYTE , this . image ) ;
399399
400- if ( ( this . image . width % 2 ) === 0 && ( this . image . height % 2 ) === 0 ) {
400+ if ( this . isPowerOfTwo ( this . image . width ) && this . isPowerOfTwo ( this . image . height ) ) {
401401 this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_MIN_FILTER , this . gl . LINEAR_MIPMAP_NEAREST ) ;
402402 this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_MAG_FILTER , this . gl . NEAREST ) ;
403403 this . gl . generateMipmap ( this . gl . TEXTURE_2D ) ;
404+
405+ const error = this . gl . getError ( ) ;
406+ if ( error !== this . gl . NO_ERROR ) {
407+ this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_WRAP_S , this . gl . CLAMP_TO_EDGE ) ;
408+ this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_WRAP_T , this . gl . CLAMP_TO_EDGE ) ;
409+ this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_MIN_FILTER , this . gl . NEAREST ) ;
410+ this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_MAG_FILTER , this . gl . NEAREST ) ;
411+ }
404412 } else {
405413 this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_WRAP_S , this . gl . CLAMP_TO_EDGE ) ;
406414 this . gl . texParameteri ( this . gl . TEXTURE_2D , this . gl . TEXTURE_WRAP_T , this . gl . CLAMP_TO_EDGE ) ;
@@ -679,5 +687,9 @@ export default class TableCanvas extends SuperComponent<ITableCanvas> {
679687 const clipY = ( y / h ) * 2 - 1 ;
680688 return [ clipX , clipY ] ;
681689 }
690+
691+ private isPowerOfTwo ( value ) {
692+ return ( value & ( value - 1 ) ) === 0 ; // Check if the value is a power of 2
693+ }
682694}
683695env . bind ( "table-canvas" , TableCanvas ) ;
0 commit comments