@@ -299,32 +299,37 @@ export class GlyphRenderer {
299299 return this . _colors . ansi [ idx ] ;
300300 }
301301
302- public onResize ( ) : void {
302+ public clear ( force ?: boolean ) : void {
303303 const terminal = this . _terminal ;
304- const gl = this . _gl ;
305-
306- gl . viewport ( 0 , 0 , gl . canvas . width , gl . canvas . height ) ;
307-
308- // Update vertices
309304 const newCount = terminal . cols * terminal . rows * INDICES_PER_CELL ;
310- if ( this . _vertices . count !== newCount ) {
311- this . _vertices . count = newCount ;
312- this . _vertices . attributes = new Float32Array ( newCount ) ;
313- for ( let i = 0 ; i < this . _vertices . attributesBuffers . length ; i ++ ) {
314- this . _vertices . attributesBuffers [ i ] = new Float32Array ( newCount ) ;
315- }
316305
317- let i = 0 ;
318- for ( let y = 0 ; y < terminal . rows ; y ++ ) {
319- for ( let x = 0 ; x < terminal . cols ; x ++ ) {
320- this . _vertices . attributes [ i + 8 ] = x / terminal . cols ;
321- this . _vertices . attributes [ i + 9 ] = y / terminal . rows ;
322- i += INDICES_PER_CELL ;
323- }
306+ // Don't clear if not forced and the array length is correct
307+ if ( ! force && this . _vertices . count === newCount ) {
308+ return ;
309+ }
310+
311+ // Clear vertices
312+ this . _vertices . count = newCount ;
313+ this . _vertices . attributes = new Float32Array ( newCount ) ;
314+ for ( let i = 0 ; i < this . _vertices . attributesBuffers . length ; i ++ ) {
315+ this . _vertices . attributesBuffers [ i ] = new Float32Array ( newCount ) ;
316+ }
317+ let i = 0 ;
318+ for ( let y = 0 ; y < terminal . rows ; y ++ ) {
319+ for ( let x = 0 ; x < terminal . cols ; x ++ ) {
320+ this . _vertices . attributes [ i + 8 ] = x / terminal . cols ;
321+ this . _vertices . attributes [ i + 9 ] = y / terminal . rows ;
322+ i += INDICES_PER_CELL ;
324323 }
325324 }
326325 }
327326
327+ public onResize ( ) : void {
328+ const gl = this . _gl ;
329+ gl . viewport ( 0 , 0 , gl . canvas . width , gl . canvas . height ) ;
330+ this . clear ( ) ;
331+ }
332+
328333 public setColors ( ) : void {
329334 }
330335
0 commit comments