Share page creation code
This commit is contained in:
@@ -69,17 +69,6 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
|
|
||||||
private _textureSize: number = 512;
|
private _textureSize: number = 512;
|
||||||
|
|
||||||
/**
|
|
||||||
* Doubles the texture size of new atlas pages if allowed.
|
|
||||||
*/
|
|
||||||
private _increaseTextureSize(): void {
|
|
||||||
// 4096 is the minimum texture size in WebGL, but we still want the texture to be reasonably fast
|
|
||||||
// to upload. We could loosen this limit if it ever becomes a problem.
|
|
||||||
if (this._textureSize < 2048) {
|
|
||||||
this._textureSize *= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly _onAddTextureAtlasCanvas = new EventEmitter<HTMLCanvasElement>();
|
private readonly _onAddTextureAtlasCanvas = new EventEmitter<HTMLCanvasElement>();
|
||||||
public readonly onAddTextureAtlasCanvas = this._onAddTextureAtlasCanvas.event;
|
public readonly onAddTextureAtlasCanvas = this._onAddTextureAtlasCanvas.event;
|
||||||
|
|
||||||
@@ -88,9 +77,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
private readonly _config: ICharAtlasConfig,
|
private readonly _config: ICharAtlasConfig,
|
||||||
private readonly _unicodeService: IUnicodeService
|
private readonly _unicodeService: IUnicodeService
|
||||||
) {
|
) {
|
||||||
const page = new AtlasPage(_document, this._textureSize);
|
this._createNewPage();
|
||||||
this._pages.push(page);
|
|
||||||
this._activePages.push(page);
|
|
||||||
this._tmpCanvas = createCanvas(
|
this._tmpCanvas = createCanvas(
|
||||||
_document,
|
_document,
|
||||||
this._config.deviceCellWidth * 4 + TMP_CANVAS_GLYPH_PADDING * 2,
|
this._config.deviceCellWidth * 4 + TMP_CANVAS_GLYPH_PADDING * 2,
|
||||||
@@ -134,14 +121,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
// TODO: Revisit when a new page gets added, this is only really needed now when there is no
|
// TODO: Revisit when a new page gets added, this is only really needed now when there is no
|
||||||
// room for a new row
|
// room for a new row
|
||||||
if (page.currentRow.y > Math.floor(page.canvas.height * 0.8)) {
|
if (page.currentRow.y > Math.floor(page.canvas.height * 0.8)) {
|
||||||
if (this._pages.length === 4 || this._pages.length === 7) {
|
this._createNewPage();
|
||||||
this._increaseTextureSize();
|
|
||||||
}
|
|
||||||
// TODO: Clear all pages and restart if the maximum page count is reached
|
|
||||||
const newPage = new AtlasPage(this._document, this._textureSize);
|
|
||||||
this._pages.push(newPage);
|
|
||||||
this._activePages.push(newPage);
|
|
||||||
this._onAddTextureAtlasCanvas.fire(newPage.canvas);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -159,6 +139,29 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
this._didWarmUp = false;
|
this._didWarmUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _createNewPage(): AtlasPage {
|
||||||
|
if (this._pages.length === 4 || this._pages.length === 7) {
|
||||||
|
this._increaseTextureSize();
|
||||||
|
}
|
||||||
|
// TODO: Clear all pages and restart if the maximum page count is reached
|
||||||
|
const newPage = new AtlasPage(this._document, this._textureSize);
|
||||||
|
this._pages.push(newPage);
|
||||||
|
this._activePages.push(newPage);
|
||||||
|
this._onAddTextureAtlasCanvas.fire(newPage.canvas);
|
||||||
|
return newPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doubles the texture size of new atlas pages if allowed.
|
||||||
|
*/
|
||||||
|
private _increaseTextureSize(): void {
|
||||||
|
// 4096 is the minimum texture size in WebGL, but we still want the texture to be reasonably fast
|
||||||
|
// to upload. We could loosen this limit if it ever becomes a problem.
|
||||||
|
if (this._textureSize < 2048) {
|
||||||
|
this._textureSize *= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number): IRasterizedGlyph {
|
public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number): IRasterizedGlyph {
|
||||||
return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext);
|
return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext);
|
||||||
}
|
}
|
||||||
@@ -612,7 +615,6 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
return NULL_RASTERIZED_GLYPH;
|
return NULL_RASTERIZED_GLYPH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Ideally this wouldn't pull dimensions off the first canvas
|
|
||||||
const rasterizedGlyph = this._findGlyphBoundingBox(imageData, this._workBoundingBox, allowedWidth, restrictedPowerlineGlyph, customGlyph, padding);
|
const rasterizedGlyph = this._findGlyphBoundingBox(imageData, this._workBoundingBox, allowedWidth, restrictedPowerlineGlyph, customGlyph, padding);
|
||||||
|
|
||||||
// Find the best atlas row to use
|
// Find the best atlas row to use
|
||||||
@@ -661,15 +663,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
}
|
}
|
||||||
if (candidatePage === undefined) {
|
if (candidatePage === undefined) {
|
||||||
// Creating a new page if there is no room
|
// Creating a new page if there is no room
|
||||||
// TODO: Share atlas page creation code
|
const newPage = this._createNewPage();
|
||||||
if (this._pages.length === 4 || this._pages.length === 7) {
|
|
||||||
this._increaseTextureSize();
|
|
||||||
}
|
|
||||||
const newPage = new AtlasPage(this._document, this._textureSize);
|
|
||||||
this._pages.push(newPage);
|
|
||||||
this._activePages.push(newPage);
|
|
||||||
this._onAddTextureAtlasCanvas.fire(newPage.canvas);
|
|
||||||
|
|
||||||
activePage = newPage;
|
activePage = newPage;
|
||||||
activeRow = newPage.currentRow;
|
activeRow = newPage.currentRow;
|
||||||
activeRow.height = rasterizedGlyph.size.y;
|
activeRow.height = rasterizedGlyph.size.y;
|
||||||
|
|||||||
Reference in New Issue
Block a user