Browse Source

Fix non power-of-2 textures being flipped when resized

Merwan Achibet 6 years ago
parent
commit
b2e7559a96
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/renderers/webgl/WebGLTextures.js

+ 12 - 1
src/renderers/webgl/WebGLTextures.js

@@ -12,7 +12,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 	//
 
-	var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
+	var useOffscreenCanvas = typeof document === 'undefined';
 
 	function createCanvas( width, height ) {
 
@@ -59,6 +59,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 				canvas.height = height;
 
 				var context = canvas.getContext( '2d' );
+
+				// ImageBitmap is flipped vertically
+
+				if ( useOffscreenCanvas )
+				{
+
+					context.translate( 0, height );
+					context.scale( 1, -1 );
+
+				}
+
 				context.drawImage( image, 0, 0, width, height );
 
 				console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );