[engine] 修复 Effect 被修改后其变体的 hash 错误问题

This commit is contained in:
SmallMain 2022-06-25 00:27:59 +08:00
parent e4e59b0305
commit f31cb598e3
3 changed files with 25 additions and 18 deletions

View File

@ -75,7 +75,7 @@ export default class EffectVariant extends EffectBase {
let effect = this._effect; let effect = this._effect;
if (effect) { if (effect) {
hash += utils.serializePasses(effect.passes); hash += effect._id;
} }
this._hash = murmurhash2(hash, 666); this._hash = murmurhash2(hash, 666);

View File

@ -7,6 +7,8 @@ export default class Effect extends EffectBase {
_techniques: Technique[] = []; _techniques: Technique[] = [];
_asset = null; _asset = null;
static id = 0;
_id = '';
get technique () { get technique () {
return this._technique; return this._technique;
@ -22,6 +24,7 @@ export default class Effect extends EffectBase {
constructor (name, techniques, techniqueIndex, asset) { constructor (name, techniques, techniqueIndex, asset) {
super(); super();
this.init(name, techniques, techniqueIndex, asset, true); this.init(name, techniques, techniqueIndex, asset, true);
this._id = '|' + Effect.id++;
} }
init (name, techniques, techniqueIndex, asset, createNative) { init (name, techniques, techniqueIndex, asset, createNative) {

View File

@ -18,12 +18,14 @@ import enums from '../../../renderer/enums';
const hashArray = []; const hashArray = [];
function serializeDefines (defines, names) { function serializeDefines (defines, names) {
const len = names.length; let i = 0;
for (let i = 0; i < len; i++) { for (const name in defines) {
const name = names[i]; if (Object.hasOwnProperty.call(defines, name)) {
hashArray[i] = name + defines[name]; hashArray[i] = name + defines[name];
i++;
} }
hashArray.length = len; }
hashArray.length = i;
return hashArray.join(''); return hashArray.join('');
} }
@ -63,8 +65,9 @@ function serializePasses (passes) {
function serializeUniforms (uniforms, names) { function serializeUniforms (uniforms, names) {
let index = 0; let index = 0;
for (let i = 0, len = names.length; i < len; i++) { for (const name in uniforms) {
let param = uniforms[names[i]]; if (Object.hasOwnProperty.call(uniforms, name)) {
const param = uniforms[name];
let prop = param.value; let prop = param.value;
if (!prop) { if (!prop) {
@ -77,7 +80,8 @@ function serializeUniforms (uniforms, names) {
else { else {
hashArray[index] = prop.toString(); hashArray[index] = prop.toString();
} }
index++ index++;
}
} }
hashArray.length = index; hashArray.length = index;
return hashArray.join(';'); return hashArray.join(';');