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

egret使用tint替代color filter减少drawcall #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion DragonBones/src/dragonBones/factory/BaseFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,15 @@ namespace dragonBones {
* @version DragonBones 3.0
* @language zh_CN
*/
public buildArmature(armatureName: string, dragonBonesName: string = "", skinName: string = "", textureAtlasName: string = ""): Armature | null {
public buildArmature(armatureName: string, dragonBonesName: string = "", skinName: string = "", textureAtlasName: string = "", isUseTint: boolean = false): Armature | null {
const dataPackage: BuildArmaturePackage = new BuildArmaturePackage();
if (!this._fillBuildArmaturePackage(dataPackage, dragonBonesName || "", armatureName, skinName || "", textureAtlasName || "")) {
console.warn("No armature data: " + armatureName + ", " + (dragonBonesName !== null ? dragonBonesName : ""));
return null;
}

const armature = this._buildArmature(dataPackage);
armature.display.isUseTint = isUseTint;
this._buildBones(dataPackage, armature);
this._buildSlots(dataPackage, armature);
this._buildConstraints(dataPackage, armature);
Expand Down
9 changes: 9 additions & 0 deletions Egret/4.x/src/dragonBones/egret/EgretArmatureDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ namespace dragonBones {
*/
export class EgretArmatureDisplay extends egret.DisplayObjectContainer implements IArmatureProxy {
private static _cleanBeforeRender(): void { }
/**
* Whether to use tint instead of color filter
* @language en_US
*/
/**
* 是否使用 tint 优化 color filter
* @language zh_CN
*/
public isUseTint: boolean = false;
/**
* @private
*/
Expand Down
4 changes: 2 additions & 2 deletions Egret/4.x/src/dragonBones/egret/EgretFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ namespace dragonBones {
* </pre>
* @language zh_CN
*/
public buildArmatureDisplay(armatureName: string, dragonBonesName: string = "", skinName: string = "", textureAtlasName: string = ""): EgretArmatureDisplay | null {
const armature = this.buildArmature(armatureName, dragonBonesName || "", skinName || "", textureAtlasName || "");
public buildArmatureDisplay(armatureName: string, dragonBonesName: string = "", skinName: string = "", textureAtlasName: string = "", isUseTint: boolean = false): EgretArmatureDisplay | null {
const armature = this.buildArmature(armatureName, dragonBonesName || "", skinName || "", textureAtlasName || "", isUseTint);
if (armature !== null) {
this._dragonBones.clock.add(armature);

Expand Down
29 changes: 29 additions & 0 deletions Egret/4.x/src/dragonBones/egret/EgretSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,33 @@ namespace dragonBones {
this._colorTransform.blueOffset !== 0 ||
this._colorTransform.alphaOffset !== 0
) {
if (
this._armatureDisplay.isUseTint &&
this._colorTransform.redOffset === 0 &&
this._colorTransform.greenOffset === 0 &&
this._colorTransform.blueOffset === 0 &&
this._colorTransform.alphaOffset === 0
) {
// 当不使用offset时,可以用 tint+alpha 代替 filter
const red = (this._colorTransform.redMultiplier * 0xFF + 0.5 | 0) << 16;
const green = (this._colorTransform.greenMultiplier * 0xFF + 0.5 | 0) << 8;
const blue = this._colorTransform.blueMultiplier * 0xFF + 0.5 | 0;
const tintColor = red + green + blue;
if (this._armatureDisplay._batchEnabled) {
const node = this._renderDisplay.$renderNode as (egret.sys.BitmapNode);
if ('tint' in node) {
// 需要egret引擎BitmapNode与MeshNode支持tint属性
node.tint = tintColor;
node.alpha = alpha;
return;
}
} else {
this._renderDisplay.tint = tintColor;
this._renderDisplay.alpha = alpha;
return;
}
}

if (this._colorFilter === null) {
this._colorFilter = new egret.ColorMatrixFilter();
}
Expand Down Expand Up @@ -257,10 +284,12 @@ namespace dragonBones {
const node = this._renderDisplay.$renderNode as (egret.sys.BitmapNode);
node.filter = null as any;
node.alpha = alpha;
if ('tint' in node) node.tint = 0xFFFFFF;
}

this._renderDisplay.filters = null as any;
this._renderDisplay.alpha = alpha;
this._renderDisplay.tint = 0xFFFFFF;
}
}

Expand Down