Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
function textureNeedsGenerateMipmaps( texture, supportsMips ) {

return texture.generateMipmaps && isPowerOfTwo &&
return texture.generateMipmaps && supportsMips &&
texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;

}
Expand Down Expand Up @@ -355,12 +355,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}

var image = cubeImage[ 0 ],
isPowerOfTwoImage = isPowerOfTwo( image ),
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, isPowerOfTwoImage );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );

for ( var i = 0; i < 6; i ++ ) {

Expand Down Expand Up @@ -418,7 +418,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {

// We assume images for cube map have the same size.
generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
Expand Down Expand Up @@ -447,11 +447,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
function setTextureParameters( textureType, texture, supportsMips ) {

var extension;

if ( isPowerOfTwoImage ) {
if ( supportsMips ) {

_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
Expand Down Expand Up @@ -539,12 +539,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );

var isPowerOfTwoImage = isPowerOfTwo( image ),
var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
glFormat = utils.convert( texture.format ),
glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( glFormat, glType );

setTextureParameters( textureType, texture, isPowerOfTwoImage );
setTextureParameters( textureType, texture, supportsMips );

var mipmap, mipmaps = texture.mipmaps;

Expand Down Expand Up @@ -610,7 +610,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// if there are no manual mipmaps
// set 0 level mipmap and then use GL to generate other mipmap levels

if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
if ( mipmaps.length > 0 && supportsMips ) {

for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {

Expand Down Expand Up @@ -670,7 +670,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// if there are no manual mipmaps
// set 0 level mipmap and then use GL to generate other mipmap levels

if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
if ( mipmaps.length > 0 && supportsMips ) {

for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {

Expand All @@ -691,7 +691,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {

generateMipmap( _gl.TEXTURE_2D, texture, image.width, image.height );

Expand Down Expand Up @@ -880,7 +880,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;

// Setup framebuffer

Expand Down Expand Up @@ -941,15 +941,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( isCube ) {

state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, supportsMips );

for ( var i = 0; i < 6; i ++ ) {

setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );

}

if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {

generateMipmap( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, renderTarget.width, renderTarget.height );

Expand All @@ -960,10 +960,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} else {

state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, supportsMips );
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );

if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {

generateMipmap( _gl.TEXTURE_2D, renderTarget.texture, renderTarget.width, renderTarget.height );

Expand All @@ -986,9 +986,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function updateRenderTargetMipmap( renderTarget ) {

var texture = renderTarget.texture;
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;

if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {

var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
var webglTexture = properties.get( texture ).__webglTexture;
Expand Down