mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
ui batch marge for stencil (#7540)
This commit is contained in:
@@ -210,6 +210,31 @@ export class UIRenderable extends RenderableComponent {
|
||||
protected _uiMaterialDirty = false;
|
||||
protected _uiMatInsDirty = false;
|
||||
|
||||
// materialInstance only for Stencil // Will remove at v3.0
|
||||
protected _materialInstanceForStencil;
|
||||
public getMaterialInstanceForStencil () {
|
||||
if (!this._materialInstanceForStencil) {
|
||||
let patentMaterial;
|
||||
if (this.getRenderMaterial(0)) {
|
||||
patentMaterial = this.getMaterial(0);
|
||||
} else {
|
||||
patentMaterial = this._uiMaterial;
|
||||
}
|
||||
_matInsInfo.owner = this;
|
||||
_matInsInfo.parent = patentMaterial;
|
||||
this._materialInstanceForStencil = new MaterialInstance(_matInsInfo);
|
||||
}
|
||||
return this._materialInstanceForStencil;
|
||||
}
|
||||
|
||||
protected _onMaterialModified (idx: number, material: Material | null) {
|
||||
if (this._materialInstanceForStencil) {
|
||||
const inst = this._materialInstanceForStencil;
|
||||
inst.destroy();
|
||||
this._materialInstanceForStencil = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The user customized material, if not set, it will use builtin material resources, and will show nothing on inspector field.
|
||||
* @zh 用户自定义材质,如果没有设置过,那么将使用引擎内置的材质资源,在面板上也不会显示。
|
||||
@@ -475,6 +500,12 @@ export class UIRenderable extends RenderableComponent {
|
||||
}
|
||||
this._uiMaterialDirty = false;
|
||||
if(!init) {this._uiMatInsDirty = true;}
|
||||
// materialInstance only for Stencil // Will remove at v3.0
|
||||
if(this._materialInstanceForStencil) {
|
||||
const inst = this._materialInstanceForStencil;
|
||||
inst.destroy();
|
||||
this._materialInstanceForStencil = null;
|
||||
}
|
||||
return this._uiMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,6 +387,7 @@ export class UI {
|
||||
mat = renderComp._updateBlendFunc();
|
||||
}
|
||||
|
||||
// use material judgment merge is increasingly impossible, change to hash is more possible
|
||||
if (this._currMaterial !== mat ||
|
||||
this._currTexture !== texture || this._currSampler !== samp
|
||||
) {
|
||||
@@ -505,11 +506,7 @@ export class UI {
|
||||
}
|
||||
|
||||
if (renderComp && StencilManager.sharedManager!.handleMaterial(mat)) {
|
||||
if (renderComp.getUIRenderMaterial()) {
|
||||
this._currMaterial = mat = renderComp.getUIMaterialInstance();
|
||||
} else {
|
||||
this._currMaterial = mat = renderComp.material!;
|
||||
}
|
||||
this._currMaterial = mat = renderComp.getMaterialInstanceForStencil();
|
||||
const state = StencilManager.sharedManager!.pattern;
|
||||
mat.overridePipelineStates({
|
||||
depthStencilState: {
|
||||
|
||||
Reference in New Issue
Block a user