Skip to content

Commit b3cff83

Browse files
willeastcottcursoragentCopilot
authored
[FIX] Refresh texture state when toggling mipmaps (playcanvas#8455)
* [FIX] Refresh texture state when mipmaps toggles Update Texture#mipmaps to recalculate mip levels and mark min filter parameters dirty when toggled, so runtime mipmap changes apply immediately without requiring unrelated texture edits. Co-authored-by: Cursor <cursoragent@cursor.com> * Update src/platform/graphics/texture.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * [FIX] Handle mipmaps toggle edge cases Base mip upload scheduling on effective mipmap state after _updateNumLevel, and recreate array texture storage when mip level count changes to keep immutable GPU allocation in sync. Co-authored-by: Cursor <cursoragent@cursor.com> * Add s to _updateNumLevel --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 711eb0f commit b3cff83

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/platform/graphics/texture.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class Texture {
265265
if (options.numLevels !== undefined) {
266266
this._numLevels = options.numLevels;
267267
}
268-
this._updateNumLevel();
268+
this._updateNumLevels();
269269

270270
this._minFilter = options.minFilter ?? FILTER_LINEAR_MIPMAP_LINEAR;
271271
this._magFilter = options.magFilter ?? FILTER_LINEAR;
@@ -376,7 +376,7 @@ class Texture {
376376
this._width = Math.floor(width);
377377
this._height = Math.floor(height);
378378
this._depth = Math.floor(depth);
379-
this._updateNumLevel();
379+
this._updateNumLevels();
380380

381381
// re-create the implementation
382382
this.impl = device.createTextureImpl(this);
@@ -421,7 +421,7 @@ class Texture {
421421
this.renderVersionDirty = this.device.renderVersion;
422422
}
423423

424-
_updateNumLevel() {
424+
_updateNumLevels() {
425425

426426
const maxLevels = this.mipmaps ? TextureUtils.calcMipLevelsCount(this.width, this.height) : 1;
427427
const requestedLevels = this._numLevelsRequested;
@@ -673,12 +673,25 @@ class Texture {
673673
} else if (isIntegerPixelFormat(this._format)) {
674674
Debug.warn('Texture#mipmaps: mipmap property cannot be changed on an integer texture, will remain false', this);
675675
} else {
676+
const oldMipmaps = this._mipmaps;
677+
const oldNumLevels = this._numLevels;
678+
676679
this._mipmaps = v;
677-
}
680+
this._updateNumLevels();
678681

679-
if (v) {
680-
this._needsMipmapsUpload = true;
681-
this.device?.texturesToUpload?.add(this);
682+
// Changing mip count on array textures requires re-creating immutable storage.
683+
if (this.array && this._numLevels !== oldNumLevels) {
684+
this.recreateImpl();
685+
} else if (this._mipmaps !== oldMipmaps) {
686+
this.propertyChanged(TEXPROPERTY_MIN_FILTER);
687+
688+
if (this._mipmaps) {
689+
this._needsMipmapsUpload = true;
690+
this.device?.texturesToUpload?.add(this);
691+
} else {
692+
this._needsMipmapsUpload = false;
693+
}
694+
}
682695
}
683696
}
684697
}

0 commit comments

Comments
 (0)