|
@@ -20067,6 +20067,18 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
+ var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
|
|
|
|
+
|
|
|
|
+ function createCanvas( width, height ) {
|
|
|
|
+
|
|
|
|
+ // Use OffscreenCanvas when available. Specially needed in web workers
|
|
|
|
+
|
|
|
|
+ return useOffscreenCanvas ?
|
|
|
|
+ new OffscreenCanvas( width, height ) :
|
|
|
|
+ document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
|
|
function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
|
|
|
|
|
|
var scale = 1;
|
|
var scale = 1;
|
|
@@ -20085,25 +20097,28 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
// only perform resize for certain image types
|
|
// only perform resize for certain image types
|
|
|
|
|
|
- if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
|
|
|
|
|
|
+ if ( image instanceof ImageBitmap || image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
|
|
|
|
|
|
- if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
|
|
|
|
|
|
+ var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
|
|
|
|
|
|
- // cube textures can't reuse the same canvas
|
|
|
|
|
|
+ var width = floor( scale * image.width );
|
|
|
|
+ var height = floor( scale * image.height );
|
|
|
|
|
|
- var canvas = needsNewCanvas ? document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ) : _canvas;
|
|
|
|
|
|
+ if ( _canvas === undefined ) _canvas = createCanvas( width, height );
|
|
|
|
|
|
- var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
|
|
|
|
|
|
+ // cube textures can't reuse the same canvas
|
|
|
|
|
|
- canvas.width = floor( scale * image.width );
|
|
|
|
- canvas.height = floor( scale * image.height );
|
|
|
|
|
|
+ var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
|
|
|
|
+
|
|
|
|
+ canvas.width = width;
|
|
|
|
+ canvas.height = height;
|
|
|
|
|
|
var context = canvas.getContext( '2d' );
|
|
var context = canvas.getContext( '2d' );
|
|
- context.drawImage( image, 0, 0, canvas.width, canvas.height );
|
|
|
|
|
|
+ context.drawImage( image, 0, 0, width, height );
|
|
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + canvas.width + 'x' + canvas.height + ').' );
|
|
|
|
|
|
+ console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
|
|
|
|
|
|
- return canvas;
|
|
|
|
|
|
+ return useOffscreenCanvas ? canvas.transferToImageBitmap() : canvas;
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
@@ -38969,6 +38984,8 @@ ImageBitmapLoader.prototype = {
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
+ scope.manager.itemStart( url );
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
setCrossOrigin: function ( /* value */ ) {
|
|
setCrossOrigin: function ( /* value */ ) {
|