Fix shared atlas page invalidation per renderer

This commit is contained in:
Anthony Kim
2026-07-04 14:44:23 -07:00
parent 780cbef3cf
commit 6fe6fe1af3
3 changed files with 18 additions and 14 deletions
+10 -1
View File
@@ -100,6 +100,7 @@ export class GlyphRenderer extends Disposable {
private readonly _attributesBuffer: WebGLBuffer; private readonly _attributesBuffer: WebGLBuffer;
private _atlas: ITextureAtlas | undefined; private _atlas: ITextureAtlas | undefined;
private _lastAtlasPagesVersion: number = -1;
private _activeBuffer: number = 0; private _activeBuffer: number = 0;
private readonly _vertices: IVertices = { private readonly _vertices: IVertices = {
count: 0, count: 0,
@@ -214,7 +215,14 @@ export class GlyphRenderer extends Disposable {
} }
public beginFrame(): boolean { public beginFrame(): boolean {
return this._atlas ? this._atlas.beginFrame() : true; if (!this._atlas) {
return true;
}
if (this._atlas.pagesVersion !== this._lastAtlasPagesVersion) {
this._lastAtlasPagesVersion = this._atlas.pagesVersion;
return true;
}
return false;
} }
public updateCell(x: number, y: number, code: number, bg: number, fg: number, ext: number, chars: string, width: number, lastBg: number): void { public updateCell(x: number, y: number, code: number, bg: number, fg: number, ext: number, chars: string, width: number, lastBg: number): void {
@@ -375,6 +383,7 @@ export class GlyphRenderer extends Disposable {
public setAtlas(atlas: ITextureAtlas): void { public setAtlas(atlas: ITextureAtlas): void {
this._atlas = atlas; this._atlas = atlas;
this._lastAtlasPagesVersion = -1;
this.invalidateAtlasTextures(); this.invalidateAtlasTextures();
} }
+6 -10
View File
@@ -132,12 +132,8 @@ export class TextureAtlas implements ITextureAtlas {
} }
} }
private _requestClearModel = false; private _pagesVersion = 0;
public beginFrame(): boolean { public get pagesVersion(): number { return this._pagesVersion; }
const result = this._requestClearModel;
this._requestClearModel = false;
return result;
}
public clearTexture(): void { public clearTexture(): void {
if (this._pages[0].currentRow.x === 0 && this._pages[0].currentRow.y === 0) { if (this._pages[0].currentRow.x === 0 && this._pages[0].currentRow.y === 0) {
@@ -206,8 +202,8 @@ export class TextureAtlas implements ITextureAtlas {
// Add the new merged page to the end // Add the new merged page to the end
this.pages.push(mergedPage); this.pages.push(mergedPage);
// Request the model to be cleared to refresh all texture pages. // Invalidate renderer models so all texture pages are refreshed.
this._requestClearModel = true; this._pagesVersion++;
this._onAddTextureAtlasCanvas.fire(mergedPage.canvas); this._onAddTextureAtlasCanvas.fire(mergedPage.canvas);
} }
@@ -818,8 +814,8 @@ export class TextureAtlas implements ITextureAtlas {
this._overflowSizePage = new AtlasPage(this._document, this._config.deviceMaxTextureSize); this._overflowSizePage = new AtlasPage(this._document, this._config.deviceMaxTextureSize);
this.pages.push(this._overflowSizePage); this.pages.push(this._overflowSizePage);
// Request the model to be cleared to refresh all texture pages. // Invalidate renderer models so all texture pages are refreshed.
this._requestClearModel = true; this._pagesVersion++;
this._onAddTextureAtlasCanvas.fire(this._overflowSizePage.canvas); this._onAddTextureAtlasCanvas.fire(this._overflowSizePage.canvas);
} }
activePage = this._overflowSizePage; activePage = this._overflowSizePage;
+2 -3
View File
@@ -68,10 +68,9 @@ export interface ITextureAtlas extends IDisposable {
warmUp(): void; warmUp(): void;
/** /**
* Call when a frame is being drawn, this will return true if the atlas was cleared to make room * Incremented whenever texture page indexes or coordinates cached by renderers may be stale.
* for a new set of glyphs.
*/ */
beginFrame(): boolean; readonly pagesVersion: number;
/** /**
* Clear all glyphs from the texture atlas. * Clear all glyphs from the texture atlas.