|
@@ -5630,6 +5630,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
|
|
|
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
|
|
|
|
+ texture.image = clampToMaxSize( texture.image, _maxTextureSize );
|
|
|
+
|
|
|
var image = texture.image,
|
|
|
isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
|
|
|
glFormat = paramThreeToGL( texture.format ),
|
|
@@ -5726,27 +5728,27 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
function clampToMaxSize ( image, maxSize ) {
|
|
|
|
|
|
- if ( image.width <= maxSize && image.height <= maxSize ) {
|
|
|
+ if ( image.width > maxSize || image.height > maxSize ) {
|
|
|
|
|
|
- return image;
|
|
|
+ // Warning: Scaling through the canvas will only work with images that use
|
|
|
+ // premultiplied alpha.
|
|
|
|
|
|
- }
|
|
|
+ var scale = maxSize / Math.max( image.width, image.height );
|
|
|
|
|
|
- // Warning: Scaling through the canvas will only work with images that use
|
|
|
- // premultiplied alpha.
|
|
|
+ var canvas = document.createElement( 'canvas' );
|
|
|
+ canvas.width = Math.floor( image.width * scale );
|
|
|
+ canvas.height = Math.floor( image.height * scale );
|
|
|
|
|
|
- var maxDimension = Math.max( image.width, image.height );
|
|
|
- var newWidth = Math.floor( image.width * maxSize / maxDimension );
|
|
|
- var newHeight = Math.floor( image.height * maxSize / maxDimension );
|
|
|
+ var context = canvas.getContext( '2d' );
|
|
|
+ context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
|
|
|
|
|
|
- var canvas = document.createElement( 'canvas' );
|
|
|
- canvas.width = newWidth;
|
|
|
- canvas.height = newHeight;
|
|
|
+ console.log( 'THREE.WebGLRenderer:', image, 'is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height + '.' );
|
|
|
|
|
|
- var ctx = canvas.getContext( '2d' );
|
|
|
- ctx.drawImage( image, 0, 0, image.width, image.height, 0, 0, newWidth, newHeight );
|
|
|
+ return canvas;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- return canvas;
|
|
|
+ return image;
|
|
|
|
|
|
}
|
|
|
|