From 92865d88dad7eff9fb2462f97ec8b10d75505e20 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 18 May 2018 15:01:38 +0800 Subject: [PATCH 1/2] Add Texture premultiply alpha serialization support --- cocos2d/core/assets/CCTexture2D.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/assets/CCTexture2D.js b/cocos2d/core/assets/CCTexture2D.js index 30f59e71b5..7340d7e35c 100644 --- a/cocos2d/core/assets/CCTexture2D.js +++ b/cocos2d/core/assets/CCTexture2D.js @@ -657,7 +657,10 @@ var Texture2D = cc.Class({ } } } - let asset = "" + extId + "," + this._minFilter + "," + this._magFilter + "," + this._wrapS + "," + this._wrapT; + let asset = "" + extId + "," + + this._minFilter + "," + this._magFilter + "," + + this._wrapS + "," + this._wrapT + "," + + (this._premultiplyAlpha ? 1 : 0); return asset; }, @@ -687,6 +690,8 @@ var Texture2D = cc.Class({ // decode wraps this._wrapS = parseInt(fields[3]); this._wrapT = parseInt(fields[4]); + // decode premultiply alpha + this._premultiplyAlpha = !!parseInt(fields[5]); } } }); From 950a68d1640f227fed55511c44191dca95e50a77 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 21 May 2018 15:14:46 +0800 Subject: [PATCH 2/2] Improve texture2d deserialize --- cocos2d/core/assets/CCTexture2D.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cocos2d/core/assets/CCTexture2D.js b/cocos2d/core/assets/CCTexture2D.js index 7340d7e35c..5dfd768857 100644 --- a/cocos2d/core/assets/CCTexture2D.js +++ b/cocos2d/core/assets/CCTexture2D.js @@ -42,6 +42,9 @@ const GL_REPEAT = 10497; // gl.REPEAT const GL_CLAMP_TO_EDGE = 33071; // gl.CLAMP_TO_EDGE const GL_MIRRORED_REPEAT = 33648; // gl.MIRRORED_REPEAT +const CHAR_CODE_0 = 48; // '0' +const CHAR_CODE_1 = 49; // '1' + var idGenerater = new (require('../platform/id-generater'))('Tex'); /** @@ -665,25 +668,24 @@ var Texture2D = cc.Class({ }, _deserialize: function (data, handle) { - var fields = data.split(','); + let fields = data.split(','); // decode extname var extIdStr = fields[0]; if (extIdStr) { - const CHAR_CODE_0 = 48; // '0' - var extId = extIdStr.charCodeAt(0) - CHAR_CODE_0; - var ext = Texture2D.extnames[extId]; + let extId = extIdStr.charCodeAt(0) - CHAR_CODE_0; + let ext = Texture2D.extnames[extId]; this._setRawAsset(ext || extIdStr); // preset uuid to get correct nativeUrl - var loadingItem = handle.customEnv; - var uuid = loadingItem && loadingItem.uuid; + let loadingItem = handle.customEnv; + let uuid = loadingItem && loadingItem.uuid; if (uuid) { this._uuid = uuid; var url = this.nativeUrl; this.url = url; } } - if (fields.length >= 5) { + if (fields.length === 6) { // decode filters this._minFilter = parseInt(fields[1]); this._magFilter = parseInt(fields[2]); @@ -691,7 +693,7 @@ var Texture2D = cc.Class({ this._wrapS = parseInt(fields[3]); this._wrapT = parseInt(fields[4]); // decode premultiply alpha - this._premultiplyAlpha = !!parseInt(fields[5]); + this._premultiplyAlpha = fields[5].charCodeAt(0) === CHAR_CODE_1; } } });