Ver Fonte

WebGLRenderer: Check image type in makePowerOfTwo.

Mr.doob há 9 anos atrás
pai
commit
1eb3ffced6
1 ficheiros alterados com 14 adições e 8 exclusões
  1. 14 8
      src/renderers/WebGLRenderer.js

+ 14 - 8
src/renderers/WebGLRenderer.js

@@ -2731,7 +2731,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		}
 
 		var image = texture.image,
-		isImagePowerOfTwo = isPowerOfTwo( image ), // TODO: Always true at this step?
+		isImagePowerOfTwo = isPowerOfTwo( image ),
 		glFormat = paramThreeToGL( texture.format ),
 		glType = paramThreeToGL( texture.type );
 
@@ -2898,16 +2898,22 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	function makePowerOfTwo( image ) {
 
-		var canvas = document.createElement( 'canvas' );
-		canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
-		canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
+		if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
 
-		var context = canvas.getContext( '2d' );
-		context.drawImage( image, 0, 0, canvas.width, canvas.height );
+			var canvas = document.createElement( 'canvas' );
+			canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
+			canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
+
+			var context = canvas.getContext( '2d' );
+			context.drawImage( image, 0, 0, canvas.width, canvas.height );
+
+			console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
 
-		console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
+			return canvas;
+
+		}
 
-		return canvas;
+		return image;
 
 	}