Skip to content

Commit

Permalink
POT canvas memory leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tommytee committed May 23, 2017
1 parent 8548820 commit a61af5a
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants';
import { _Math } from '../../math/Math';

var POTCanvas;
function WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, infoMemory ) {

var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
Expand Down Expand Up @@ -43,26 +43,28 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, paramT

}

function makePowerOfTwo( image ) {
function makePowerOfTwo( image ) {

if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {

var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = _Math.nearestPowerOfTwo( image.width );
canvas.height = _Math.nearestPowerOfTwo( image.height );
if ( ! POTCanvas )
POTCanvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );

var context = canvas.getContext( '2d' );
context.drawImage( image, 0, 0, canvas.width, canvas.height );
POTCanvas.width = _Math.nearestPowerOfTwo( image.width );
POTCanvas.height = _Math.nearestPowerOfTwo( image.height );

console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
var context = POTCanvas.getContext( '2d' );
context.drawImage( image, 0, 0, POTCanvas.width, POTCanvas.height );

return canvas;
console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + POTCanvas.width + 'x' + POTCanvas.height, image );

}
return POTCanvas;

return image;
}

}
return image;

}

function textureNeedsPowerOfTwo( texture ) {

Expand Down

0 comments on commit a61af5a

Please sign in to comment.