|
@@ -357,104 +357,110 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function setTextureCube( texture, slot ) {
|
|
|
|
|
|
+ if ( texture.image.length !== 6 ) return;
|
|
|
+
|
|
|
var textureProperties = properties.get( texture );
|
|
|
|
|
|
- if ( texture.image.length === 6 ) {
|
|
|
+ if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
|
|
|
- if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
+ initTexture( textureProperties, texture );
|
|
|
|
|
|
- initTexture( textureProperties, texture );
|
|
|
+ state.activeTexture( _gl.TEXTURE0 + slot );
|
|
|
+ state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
|
|
|
|
- state.activeTexture( _gl.TEXTURE0 + slot );
|
|
|
- state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
|
+ _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
|
|
|
|
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
|
+ var isCompressed = ( texture && texture.isCompressedTexture );
|
|
|
+ var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
|
|
|
|
|
|
- var isCompressed = ( texture && texture.isCompressedTexture );
|
|
|
- var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
|
|
|
+ var cubeImage = [];
|
|
|
|
|
|
- var cubeImage = [];
|
|
|
+ for ( var i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ if ( ! isCompressed && ! isDataTexture ) {
|
|
|
|
|
|
- if ( ! isCompressed && ! isDataTexture ) {
|
|
|
+ cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
|
|
|
|
|
|
- cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
|
|
|
|
|
|
- cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ var image = cubeImage[ 0 ],
|
|
|
+ supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
|
|
|
+ glFormat = utils.convert( texture.format ),
|
|
|
+ glType = utils.convert( texture.type ),
|
|
|
+ glInternalFormat = getInternalFormat( glFormat, glType );
|
|
|
|
|
|
- var image = cubeImage[ 0 ],
|
|
|
- supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
|
|
|
- glFormat = utils.convert( texture.format ),
|
|
|
- glType = utils.convert( texture.type ),
|
|
|
- glInternalFormat = getInternalFormat( glFormat, glType );
|
|
|
+ setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
|
|
|
|
|
|
- setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
|
|
|
+ var mipmaps;
|
|
|
|
|
|
- var mipmaps = texture.mipmaps;
|
|
|
+ if ( isCompressed ) {
|
|
|
|
|
|
for ( var i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
- if ( ! isCompressed ) {
|
|
|
+ mipmaps = cubeImage[ i ].mipmaps;
|
|
|
+
|
|
|
+ for ( var j = 0; j < mipmaps.length; j ++ ) {
|
|
|
|
|
|
- if ( isDataTexture ) {
|
|
|
+ var mipmap = mipmaps[ j ];
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
|
|
|
+ if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
|
|
|
|
|
|
- for ( var j = 0; j < mipmaps.length; ++ j ) {
|
|
|
+ if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
|
|
|
|
|
|
- var mipmap = mipmaps[ j ];
|
|
|
- var mipmapImage = mipmap.image[ i ].image;
|
|
|
+ state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
|
|
|
|
|
|
- for ( var j = 0; j < mipmaps.length; ++ j ) {
|
|
|
+ }
|
|
|
|
|
|
- var mipmap = mipmaps[ j ];
|
|
|
+ }
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ textureProperties.__maxMipLevel = mipmaps.length - 1;
|
|
|
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ mipmaps = texture.mipmaps;
|
|
|
|
|
|
- mipmaps = cubeImage[ i ].mipmaps;
|
|
|
+ for ( var i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
- for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
|
|
|
+ if ( isDataTexture ) {
|
|
|
|
|
|
- var mipmap = mipmaps[ j ];
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
|
|
|
|
|
|
- if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
|
|
|
+ for ( var j = 0; j < mipmaps.length; j ++ ) {
|
|
|
|
|
|
- if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
|
|
|
+ var mipmap = mipmaps[ j ];
|
|
|
+ var mipmapImage = mipmap.image[ i ].image;
|
|
|
|
|
|
- state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
|
|
|
|
|
|
- } else {
|
|
|
+ for ( var j = 0; j < mipmaps.length; j ++ ) {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
|
|
|
+ var mipmap = mipmaps[ j ];
|
|
|
|
|
|
- }
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -462,25 +468,25 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- textureProperties.__maxMipLevel = isCompressed ? mipmaps.length - 1 : mipmaps.length;
|
|
|
+ textureProperties.__maxMipLevel = mipmaps.length;
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
+ }
|
|
|
|
|
|
- // We assume images for cube map have the same size.
|
|
|
- generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
- }
|
|
|
+ // We assume images for cube map have the same size.
|
|
|
+ generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
|
|
|
|
|
|
- textureProperties.__version = texture.version;
|
|
|
+ }
|
|
|
|
|
|
- if ( texture.onUpdate ) texture.onUpdate( texture );
|
|
|
+ textureProperties.__version = texture.version;
|
|
|
|
|
|
- } else {
|
|
|
+ if ( texture.onUpdate ) texture.onUpdate( texture );
|
|
|
|
|
|
- state.activeTexture( _gl.TEXTURE0 + slot );
|
|
|
- state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ state.activeTexture( _gl.TEXTURE0 + slot );
|
|
|
+ state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
|
|
|
|
}
|
|
|
|