|
@@ -17,21 +17,35 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( image.width > maxSize || image.height > maxSize ) {
|
|
|
|
|
|
- // Warning: Scaling through the canvas will only work with images that use
|
|
|
- // premultiplied alpha.
|
|
|
-
|
|
|
var scale = maxSize / Math.max( image.width, image.height );
|
|
|
|
|
|
- var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
|
|
|
- canvas.width = Math.floor( image.width * scale );
|
|
|
- canvas.height = Math.floor( image.height * scale );
|
|
|
+ if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
|
|
|
+
|
|
|
+ // Warning: Scaling through the canvas will only work with images that use
|
|
|
+ // premultiplied alpha.
|
|
|
+
|
|
|
+ var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
|
|
|
+ canvas.width = Math.max( Math.floor( image.width * scale ), 1 );
|
|
|
+ canvas.height = Math.max( Math.floor( image.height * scale ), 1 );
|
|
|
+
|
|
|
+ var context = canvas.getContext( '2d' );
|
|
|
+ context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
|
|
|
+
|
|
|
+ console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
|
|
|
|
|
|
- var context = canvas.getContext( '2d' );
|
|
|
- context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
|
|
|
+ return canvas;
|
|
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ var width = Math.max( Math.floor( image.width * scale ), 1 );
|
|
|
+ var height = Math.max( Math.floor( image.height * scale ), 1 );
|
|
|
+
|
|
|
+ console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + width + 'x' + height, image );
|
|
|
|
|
|
- return canvas;
|
|
|
+ image.width = width;
|
|
|
+ image.height = height;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|