diff --git a/src/platform/graphics/texture.js b/src/platform/graphics/texture.js index ce0c787e902..34c8efa8ceb 100644 --- a/src/platform/graphics/texture.js +++ b/src/platform/graphics/texture.js @@ -265,7 +265,7 @@ class Texture { if (options.numLevels !== undefined) { this._numLevels = options.numLevels; } - this._updateNumLevel(); + this._updateNumLevels(); this._minFilter = options.minFilter ?? FILTER_LINEAR_MIPMAP_LINEAR; this._magFilter = options.magFilter ?? FILTER_LINEAR; @@ -376,7 +376,7 @@ class Texture { this._width = Math.floor(width); this._height = Math.floor(height); this._depth = Math.floor(depth); - this._updateNumLevel(); + this._updateNumLevels(); // re-create the implementation this.impl = device.createTextureImpl(this); @@ -421,7 +421,7 @@ class Texture { this.renderVersionDirty = this.device.renderVersion; } - _updateNumLevel() { + _updateNumLevels() { const maxLevels = this.mipmaps ? TextureUtils.calcMipLevelsCount(this.width, this.height) : 1; const requestedLevels = this._numLevelsRequested; @@ -673,12 +673,25 @@ class Texture { } else if (isIntegerPixelFormat(this._format)) { Debug.warn('Texture#mipmaps: mipmap property cannot be changed on an integer texture, will remain false', this); } else { + const oldMipmaps = this._mipmaps; + const oldNumLevels = this._numLevels; + this._mipmaps = v; - } + this._updateNumLevels(); - if (v) { - this._needsMipmapsUpload = true; - this.device?.texturesToUpload?.add(this); + // Changing mip count on array textures requires re-creating immutable storage. + if (this.array && this._numLevels !== oldNumLevels) { + this.recreateImpl(); + } else if (this._mipmaps !== oldMipmaps) { + this.propertyChanged(TEXPROPERTY_MIN_FILTER); + + if (this._mipmaps) { + this._needsMipmapsUpload = true; + this.device?.texturesToUpload?.add(this); + } else { + this._needsMipmapsUpload = false; + } + } } } }