Skip to content

Commit

Permalink
Optimize code size for 2d module. (#18239)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Jan 23, 2025
1 parent 92d0ee1 commit 1f67480
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
1 change: 1 addition & 0 deletions cocos/2d/assembler/graphics/webgl/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Path {
}
}

/** @mangle */
export class Impl {
public dataOffset = 0;
public updatePathOffset = false;
Expand Down
1 change: 1 addition & 0 deletions cocos/2d/framework/ui-renderer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { assert, js } from '../../core';
import { UIMeshRenderer } from '../components';
import { UIRenderer } from './ui-renderer';

/** @mangle */
export class UIRendererManager {
private _allRenderers: (UIRenderer | UIMeshRenderer)[] = [];
private _dirtyRenderers: (UIRenderer | UIMeshRenderer)[] = [];
Expand Down
1 change: 1 addition & 0 deletions cocos/2d/renderer/render-draw-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export enum RenderDrawInfoType {
SUB_NODE,
}

/** @mangle */
export class RenderDrawInfo {
protected _accId = -1;
protected _bufferId = -1;
Expand Down
1 change: 1 addition & 0 deletions cocos/2d/renderer/render-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export enum MaskMode {
MASK_NODE_INVERTED
}

/** @mangle */
export class RenderEntity {
private _renderEntityType: RenderEntityType = RenderEntityType.STATIC;

Expand Down
53 changes: 33 additions & 20 deletions cocos/2d/renderer/stencil-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,27 @@ export enum StencilSharedBufferView {
count,
}

/** @mangle */
interface StencilPattern {
stencilTest: boolean;
func: ComparisonFunc;
stencilMask: number;
writeMask: number;
failOp: StencilOp;
zFailOp: StencilOp;
passOp: StencilOp;
ref: number;
}

/**
* @en Stencil state manager.
* @zh 模板状态管理器。
* @deprecated since v3.7.0, this is an engine private interface that will be removed in the future.
*/
export class StencilManager {
public static sharedManager: StencilManager | null = null;
private _maskStack: any[] = [];
private _stencilPattern = {
private _maskStack: number[] = [];
private _stencilPattern: StencilPattern = {
stencilTest: true,
func: ComparisonFunc.ALWAYS,
stencilMask: 0xffff,
Expand Down Expand Up @@ -121,7 +133,7 @@ export class StencilManager {
* @zh 添加mask嵌套。
* @deprecated since v3.7.0, this is an engine private interface that will be removed in the future.
*/
public pushMask (mask: any): void {
public pushMask (mask: number): void {
this._maskStack.push(mask);
}

Expand Down Expand Up @@ -248,26 +260,27 @@ export class StencilManager {
return cacheMap.get(key) as DepthStencilState;
}
this.setStateFromStage(stage);
const stencilPattern = this._stencilPattern;
const depthStencilState = new DepthStencilState(
depthTest,
depthWrite,
depthFunc,
this._stencilPattern.stencilTest,
this._stencilPattern.func,
this._stencilPattern.stencilMask,
this._stencilPattern.writeMask,
this._stencilPattern.failOp,
this._stencilPattern.zFailOp,
this._stencilPattern.passOp,
this._stencilPattern.ref,
this._stencilPattern.stencilTest,
this._stencilPattern.func,
this._stencilPattern.stencilMask,
this._stencilPattern.writeMask,
this._stencilPattern.failOp,
this._stencilPattern.zFailOp,
this._stencilPattern.passOp,
this._stencilPattern.ref,
stencilPattern.stencilTest,
stencilPattern.func,
stencilPattern.stencilMask,
stencilPattern.writeMask,
stencilPattern.failOp,
stencilPattern.zFailOp,
stencilPattern.passOp,
stencilPattern.ref,
stencilPattern.stencilTest,
stencilPattern.func,
stencilPattern.stencilMask,
stencilPattern.writeMask,
stencilPattern.failOp,
stencilPattern.zFailOp,
stencilPattern.passOp,
stencilPattern.ref,
);
cacheMap.set(key, depthStencilState);
return depthStencilState;
Expand All @@ -283,7 +296,7 @@ export class StencilManager {
}

// Notice: Only children node in Mask need use this.stage
private setStateFromStage (stage): void {
private setStateFromStage (stage: Stage): void {
const pattern = this._stencilPattern;
if (stage === Stage.DISABLED) {
pattern.stencilTest = false;
Expand Down
39 changes: 22 additions & 17 deletions cocos/2d/renderer/vertex-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
import { AttributeName, Format, FormatInfos, Attribute } from '../../gfx';
import { cclegacy } from '../../core';

const ATTR_POSITION = AttributeName.ATTR_POSITION;
const ATTR_COLOR = AttributeName.ATTR_COLOR;
const ATTR_TEX_COORD = AttributeName.ATTR_TEX_COORD;
const ATTR_COLOR2 = AttributeName.ATTR_COLOR2;

/**
* @en Vertex format with vector 3 position attribute
* @zh 包含三维位置属性的顶点格式
*/
export const vfmt = [
new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F),
new Attribute(ATTR_POSITION, Format.RGB32F),
];

/**
Expand All @@ -42,8 +47,8 @@ export const vfmt = [
* 2. RGBA 颜色属性(Float32)
*/
export const vfmtPosColor = [
new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F),
new Attribute(AttributeName.ATTR_COLOR, Format.RGBA32F),
new Attribute(ATTR_POSITION, Format.RGB32F),
new Attribute(ATTR_COLOR, Format.RGBA32F),
];

/**
Expand All @@ -57,9 +62,9 @@ export const vfmtPosColor = [
* 3. RGBA 颜色属性(Float32)
*/
export const vfmtPosUvColor = [
new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F),
new Attribute(AttributeName.ATTR_TEX_COORD, Format.RG32F),
new Attribute(AttributeName.ATTR_COLOR, Format.RGBA32F),
new Attribute(ATTR_POSITION, Format.RGB32F),
new Attribute(ATTR_TEX_COORD, Format.RG32F),
new Attribute(ATTR_COLOR, Format.RGBA32F),
];

/**
Expand All @@ -73,9 +78,9 @@ export const vfmtPosUvColor = [
* 3. RGBA 颜色属性(Byte)
*/
export const vfmtPosUvColor4B = [
new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F),
new Attribute(AttributeName.ATTR_TEX_COORD, Format.RG32F),
new Attribute(AttributeName.ATTR_COLOR, Format.RGBA8, true),
new Attribute(ATTR_POSITION, Format.RGB32F),
new Attribute(ATTR_TEX_COORD, Format.RG32F),
new Attribute(ATTR_COLOR, Format.RGBA8, true),
];

/**
Expand All @@ -91,10 +96,10 @@ export const vfmtPosUvColor4B = [
* 4. 第二套 RGBA 颜色属性(Float32)
*/
export const vfmtPosUvTwoColor = [
new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F),
new Attribute(AttributeName.ATTR_TEX_COORD, Format.RG32F),
new Attribute(AttributeName.ATTR_COLOR, Format.RGBA32F),
new Attribute(AttributeName.ATTR_COLOR2, Format.RGBA32F),
new Attribute(ATTR_POSITION, Format.RGB32F),
new Attribute(ATTR_TEX_COORD, Format.RG32F),
new Attribute(ATTR_COLOR, Format.RGBA32F),
new Attribute(ATTR_COLOR2, Format.RGBA32F),
];

/**
Expand All @@ -110,10 +115,10 @@ export const vfmtPosUvTwoColor = [
* 4. 第二套 RGBA 颜色属性(Byte)
*/
export const vfmtPosUvTwoColor4B = [
new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F),
new Attribute(AttributeName.ATTR_TEX_COORD, Format.RG32F),
new Attribute(AttributeName.ATTR_COLOR, Format.RGBA8, true),
new Attribute(AttributeName.ATTR_COLOR2, Format.RGBA8, true),
new Attribute(ATTR_POSITION, Format.RGB32F),
new Attribute(ATTR_TEX_COORD, Format.RG32F),
new Attribute(ATTR_COLOR, Format.RGBA8, true),
new Attribute(ATTR_COLOR2, Format.RGBA8, true),
];

/**
Expand Down

0 comments on commit 1f67480

Please sign in to comment.