Skip to content

Commit b2d9a30

Browse files
committed
Updated builds.
1 parent 9164153 commit b2d9a30

File tree

2 files changed

+165
-123
lines changed

2 files changed

+165
-123
lines changed

build/three.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6847,6 +6847,12 @@ THREE.Math = {
68476847

68486848
},
68496849

6850+
nearestPowerOfTwo: function ( value ) {
6851+
6852+
return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
6853+
6854+
},
6855+
68506856
nextPowerOfTwo: function ( value ) {
68516857

68526858
value --;
@@ -22341,7 +22347,7 @@ THREE.WebGLRenderer = function ( parameters ) {
2234122347
if ( renderTarget ) {
2234222348

2234322349
var texture = renderTarget.texture;
22344-
var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
22350+
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
2234522351
if ( texture.generateMipmaps && isTargetPowerOfTwo && texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
2234622352

2234722353
updateRenderTargetMipmap( renderTarget );
@@ -23897,8 +23903,14 @@ THREE.WebGLRenderer = function ( parameters ) {
2389723903

2389823904
texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
2389923905

23906+
if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false ) {
23907+
23908+
texture.image = makePowerOfTwo( texture.image );
23909+
23910+
}
23911+
2390023912
var image = texture.image,
23901-
isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
23913+
isImagePowerOfTwo = isPowerOfTwo( image ), // TODO: Always true at this step?
2390223914
glFormat = paramThreeToGL( texture.format ),
2390323915
glType = paramThreeToGL( texture.type );
2390423916

@@ -24048,6 +24060,36 @@ THREE.WebGLRenderer = function ( parameters ) {
2404824060

2404924061
}
2405024062

24063+
function isPowerOfTwo( image ) {
24064+
24065+
return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
24066+
24067+
}
24068+
24069+
function textureNeedsPowerOfTwo( texture ) {
24070+
24071+
if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
24072+
if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
24073+
24074+
return false;
24075+
24076+
}
24077+
24078+
function makePowerOfTwo( image ) {
24079+
24080+
var canvas = document.createElement( 'canvas' );
24081+
canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
24082+
canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
24083+
24084+
var context = canvas.getContext( '2d' );
24085+
context.drawImage( image, 0, 0, canvas.width, canvas.height );
24086+
24087+
console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
24088+
24089+
return canvas;
24090+
24091+
}
24092+
2405124093
function setCubeTexture ( texture, slot ) {
2405224094

2405324095
var textureProperties = properties.get( texture );
@@ -24091,7 +24133,7 @@ THREE.WebGLRenderer = function ( parameters ) {
2409124133
}
2409224134

2409324135
var image = cubeImage[ 0 ],
24094-
isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
24136+
isImagePowerOfTwo = isPowerOfTwo( image ),
2409524137
glFormat = paramThreeToGL( texture.format ),
2409624138
glType = paramThreeToGL( texture.type );
2409724139

@@ -24229,7 +24271,7 @@ THREE.WebGLRenderer = function ( parameters ) {
2422924271

2423024272
// Setup texture, create render and frame buffers
2423124273

24232-
var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
24274+
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget ),
2423324275
glFormat = paramThreeToGL( renderTarget.texture.format ),
2423424276
glType = paramThreeToGL( renderTarget.texture.type );
2423524277

0 commit comments

Comments
 (0)