Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use char cache mode for TextRenderer #837

Merged
merged 58 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
869552f
feat(text): add FontAtlas
singlecoder Jun 6, 2022
d4c3b28
feat(text): opt api name
singlecoder Jun 6, 2022
05f3803
feat(text): add assembler for 2d renderer
singlecoder Jun 7, 2022
5c056da
fix(text): fix conflicts
singlecoder Jun 7, 2022
ef915d3
feat(text): temp version
singlecoder Jun 9, 2022
2b266d5
feat(text): preliminary version for render text use char cache
singlecoder Jun 10, 2022
40473e1
feat(text): opt code
singlecoder Jun 14, 2022
3bdd773
feat(text): opt code
singlecoder Jun 14, 2022
1a4a697
feat(text): opt code and fix bounds
singlecoder Jun 15, 2022
fe6029b
feat(text): render text for char cache
singlecoder Jun 16, 2022
16b5502
Merge branch 'dev/0.8' of https://github.com/oasis-engine/engine into…
singlecoder Jun 16, 2022
721d8bf
feat(text): fix conflicts
singlecoder Jul 4, 2022
47f2fc4
feat(text): opt code for pixelsPerUnit
singlecoder Jul 4, 2022
9441d16
feat(text): opt code
singlecoder Jul 4, 2022
67e86b8
feat(text): change pixelsPerUnit value
singlecoder Jul 4, 2022
833e4af
feat(text): add internal
singlecoder Jul 4, 2022
1a096e7
feat(text): opt code
singlecoder Jul 4, 2022
884f821
feat(text): useCharCache default value is true
singlecoder Jul 4, 2022
304f7be
feat(text): delete debugger
singlecoder Jul 4, 2022
c142744
feat(text): fix useCharCache clone bug
singlecoder Jul 4, 2022
91ec415
feat(text): opt code
singlecoder Jul 4, 2022
2ac80da
feat(text): opt code
singlecoder Jul 5, 2022
36f4def
feat(text): change CharDef to CharInfo
singlecoder Jul 6, 2022
3bce132
feat(text): opt code
singlecoder Jul 6, 2022
ecf9d7a
feat(text): opt code
singlecoder Jul 6, 2022
944946e
feat(text): opt code
singlecoder Jul 6, 2022
01a81c9
feat(text): add resource destroy
singlecoder Jul 6, 2022
26ea7c4
feat(text): opt code
singlecoder Jul 6, 2022
5a7943e
feat(text): opt code
singlecoder Jul 6, 2022
c58e2b7
feat(text): opt code
singlecoder Jul 6, 2022
18685d4
feat(text): opt code
singlecoder Jul 6, 2022
22749c5
feat(text): opt code
singlecoder Jul 6, 2022
ae8a296
feat(text): opt code
singlecoder Jul 6, 2022
15afe31
feat(text): opt code
singlecoder Jul 6, 2022
85bab5d
feat(text): opt code
singlecoder Jul 6, 2022
90ca73d
feat(text): fix text assembler position error
singlecoder Jul 7, 2022
ed69c4e
feat(text): opt code
singlecoder Jul 7, 2022
fa8cea1
feat(text): opt code
singlecoder Jul 7, 2022
1e0f0df
feat(text): opt code
singlecoder Jul 7, 2022
5d721b5
feat(text): delete text assembler
singlecoder Jul 7, 2022
1ed8a8a
feat(text): delete text char mode
singlecoder Jul 7, 2022
44f9b1d
feat(text): opt code
singlecoder Jul 7, 2022
e968315
feat(text): opt code
singlecoder Jul 7, 2022
8ef6212
feat(text): opt code
singlecoder Jul 7, 2022
12c1b17
feat(text): opt code
singlecoder Jul 7, 2022
c4f2293
feat(text): opt code
singlecoder Jul 7, 2022
c36c19c
feat(text): opt code
singlecoder Jul 7, 2022
a78d42c
feat(text): opt code
singlecoder Jul 7, 2022
4239723
feat(text): opt code
singlecoder Jul 7, 2022
403f302
feat(text): fix bounds error
singlecoder Jul 7, 2022
fd0c4ca
feat(text): delete char assembler
singlecoder Jul 8, 2022
d7e8e19
feat(text): opt code
singlecoder Jul 8, 2022
eaf6d76
feat(text): opt code
singlecoder Jul 8, 2022
a3e2308
feat(text): opt code
singlecoder Jul 8, 2022
99de1ff
feat(text): opt code
singlecoder Jul 8, 2022
b6ddd96
feat(text): opt code
singlecoder Jul 8, 2022
a011477
feat(text): opt code
singlecoder Jul 8, 2022
5f013ec
feat(text): opt code
singlecoder Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/core/src/2d/assembler/IAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Renderer } from "../../Renderer";

/**
* @internal
*/
export interface IAssembler {
resetData(renderer: Renderer): void;
updateData(renderer: Renderer): void;
updatePositions(renderer: Renderer): void;
updateUVs(renderer: Renderer): void;
updatePositions?(renderer: Renderer): void;
updateUVs?(renderer: Renderer): void;
}
2 changes: 1 addition & 1 deletion packages/core/src/2d/assembler/SimpleSpriteAssembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { SpriteRenderer } from "../sprite/SpriteRenderer";
import { IAssembler } from "./IAssembler";
import { StaticInterfaceImplement } from "./StaticInterfaceImplement";

@StaticInterfaceImplement<IAssembler>()
/**
* @internal
*/
@StaticInterfaceImplement<IAssembler>()
export class SimpleSpriteAssembler {
static _rectangleTriangles: number[] = [0, 1, 2, 2, 1, 3];
static _worldMatrix: Matrix = new Matrix();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/2d/assembler/SlicedSpriteAssembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { SpriteRenderer } from "../sprite/SpriteRenderer";
import { IAssembler } from "./IAssembler";
import { StaticInterfaceImplement } from "./StaticInterfaceImplement";

@StaticInterfaceImplement<IAssembler>()
/**
* @internal
*/
@StaticInterfaceImplement<IAssembler>()
export class SlicedSpriteAssembler {
static _worldMatrix: Matrix = new Matrix();
static resetData(renderer: SpriteRenderer | SpriteMask): void {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/2d/assembler/StaticInterfaceImplement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Static interface implement decorator.
* https://stackoverflow.com/questions/13955157/how-to-define-static-property-in-typescript-interface
*/
export function StaticInterfaceImplement<T>() {
return <U extends T>(constructor: U) => {
constructor;
};
}
export function StaticInterfaceImplement<T>() {
return <U extends T>(constructor: U) => {
constructor;
};
}

93 changes: 93 additions & 0 deletions packages/core/src/2d/atlas/FontAtlas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { RefObject } from "../../asset/RefObject";
import { Engine } from "../../Engine";
import { Texture2D } from "../../texture/Texture2D";
import { CharInfo } from "../text/CharInfo";

/**
* @internal
* Font Atlas.
*/
export class FontAtlas extends RefObject {
private _charInfoMap: Record<number, CharInfo> = {};
private _texture: Texture2D;
private _space: number = 1;
private _curX: number = 1;
private _curY: number = 1;
private _nextY: number = 1;

get texture(): Texture2D {
return this._texture;
}

set texture(value: Texture2D) {
this._texture = value;
}

/**
* Constructor a FontAtlas.
* @param engine - Engine to which the FontAtlas belongs
*/
constructor(engine: Engine) {
super(engine);
}

/**
* @override
*/
_onDestroy(): void {
this._texture.destroy();
this._texture = null;
this._charInfoMap = {};
}

uploadCharTexture(charInfo: CharInfo, imageSource: TexImageSource | OffscreenCanvas): boolean {
const { w: width, h: height } = charInfo;
const { _space: space, texture } = this;
const textureSize = texture.width;
const offsetWidth = width + space;
const offsetHeight = height + space;
if ((1 + offsetWidth) >= textureSize || (1 + offsetHeight) >= textureSize) {
throw Error("The char fontSize is too large.");
}

const endX = this._curX + offsetWidth;
if (endX >= textureSize) {
this._curX = space;
this._curY = this._nextY + space;
}
const endY = this._curY + offsetHeight;
if (endY > this._nextY) {
this._nextY = endY;
}
if (endY >= textureSize) {
return false;
}

if (width > 0 && height > 0) {
texture.setImageSource(imageSource, 0, false, false, this._curX, this._curY);
texture.generateMipmaps();
}

const textureSizeReciprocal = 1.0 / textureSize;
const x = this._curX;
const y = this._curY;
const w = width;
const h = height;
charInfo.x = x;
charInfo.y = y;
charInfo.u0 = x * textureSizeReciprocal;
charInfo.u1 = (x + w) * textureSizeReciprocal;
charInfo.v0 = y * textureSizeReciprocal;
charInfo.v1 = (y + h) * textureSizeReciprocal;
this._curX += offsetWidth + space;
return true;
}

addCharInfo(char: string, charInfo: CharInfo) {
this._charInfoMap[char.charCodeAt(0)] = charInfo;
}

getCharInfo(char: string): CharInfo {
return this._charInfoMap[char.charCodeAt(0)];
}
}
95 changes: 0 additions & 95 deletions packages/core/src/2d/dynamic-atlas/DynamicTextAtlas.ts

This file was deleted.

126 changes: 0 additions & 126 deletions packages/core/src/2d/dynamic-atlas/DynamicTextAtlasManager.ts

This file was deleted.

Loading