[engine] service pack 命名空间、多纹理渲染基础

This commit is contained in:
SmallMain
2022-06-25 00:29:47 +08:00
parent f31cb598e3
commit 7d0519ed68
8 changed files with 432 additions and 2 deletions

View File

@@ -470,6 +470,9 @@ var Texture2D = cc.Class({
if (CC_EDITOR) {
this._exportedExts = null;
}
// multi batcher
this._multiMaterial = null;
},
/**
@@ -688,6 +691,8 @@ var Texture2D = cc.Class({
}
this._packable && cc.dynamicAtlasManager && cc.dynamicAtlasManager.deleteAtlasTexture(this);
this.unlinkMaterial();
this._image = null;
this._texture && this._texture.destroy();
this._super();
@@ -1054,7 +1059,43 @@ var Texture2D = cc.Class({
else {
cb();
}
}
},
linkMaterial(material, index) {
const handler = material.getMultiHandler();
if (handler) {
if (index == null) {
if (handler.autoSetTexture(this) === -1) {
return false;
}
} else {
handler.setTexture(index, this);
}
this.unlinkMaterial();
this._multiMaterial = material;
return true;
} else {
return false;
}
},
unlinkMaterial() {
if (this._multiMaterial) {
const handler = this._multiMaterial.getMultiHandler();
const _texture = this.getImpl();
handler.removeTexture(_texture);
this._multiMaterial = null;
}
},
getLinkedMaterial() {
return this._multiMaterial;
},
hasLinkedMaterial() {
return !!this._multiMaterial;
},
});
/**

View File

@@ -72,6 +72,7 @@ let Material = cc.Class({
this._manualHash = false;
this._dirty = true;
this._effect = null;
this._multiHandler = null;
},
properties: {
@@ -124,6 +125,8 @@ let Material = cc.Class({
}
this._effect = this._effectAsset.getInstantiatedEffect();
this.updateMultiSupport();
}
},
@@ -140,6 +143,7 @@ let Material = cc.Class({
set (v) {
this._techniqueIndex = v;
this._effect.switchTechnique(v);
this.updateMultiSupport();
}
}
},
@@ -401,7 +405,39 @@ let Material = cc.Class({
}
}
this.updateMultiSupport();
if (this._multiHandler) this._multiHandler.syncTextures();
},
updateMultiSupport() {
const passes = this._effect.technique.passes;
if (passes.length > 0 && passes[0].getDefine("USE_MULTI_TEXTURE")) {
this.setMultiSupport(true);
} else {
this.setMultiSupport(false);
}
},
isMultiSupport() {
return !!this._multiHandler;
},
setMultiSupport(bool) {
if (bool) {
if (this._multiHandler) {
this._multiHandler.syncTextures();
} else {
this._multiHandler = new cc.sp.MultiHandler(this);
}
} else if (!bool) {
this._multiHandler = null;
}
},
getMultiHandler() {
return this._multiHandler;
},
});
export default Material;