Skip to content

Commit 1eb3ffc

Browse files
committed
WebGLRenderer: Check image type in makePowerOfTwo.
1 parent b2d9a30 commit 1eb3ffc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/renderers/WebGLRenderer.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,7 +2731,7 @@ THREE.WebGLRenderer = function ( parameters ) {
27312731
}
27322732

27332733
var image = texture.image,
2734-
isImagePowerOfTwo = isPowerOfTwo( image ), // TODO: Always true at this step?
2734+
isImagePowerOfTwo = isPowerOfTwo( image ),
27352735
glFormat = paramThreeToGL( texture.format ),
27362736
glType = paramThreeToGL( texture.type );
27372737

@@ -2898,16 +2898,22 @@ THREE.WebGLRenderer = function ( parameters ) {
28982898

28992899
function makePowerOfTwo( image ) {
29002900

2901-
var canvas = document.createElement( 'canvas' );
2902-
canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
2903-
canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
2901+
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
29042902

2905-
var context = canvas.getContext( '2d' );
2906-
context.drawImage( image, 0, 0, canvas.width, canvas.height );
2903+
var canvas = document.createElement( 'canvas' );
2904+
canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
2905+
canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
2906+
2907+
var context = canvas.getContext( '2d' );
2908+
context.drawImage( image, 0, 0, canvas.width, canvas.height );
2909+
2910+
console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
29072911

2908-
console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
2912+
return canvas;
2913+
2914+
}
29092915

2910-
return canvas;
2916+
return image;
29112917

29122918
}
29132919

0 commit comments

Comments
 (0)