Fix texture update issues

This commit is contained in:
pandamicro
2017-10-14 08:52:48 +02:00
parent 6f60a4e211
commit 510d57ab1d
2 changed files with 22 additions and 7 deletions
+7 -4
View File
@@ -215,6 +215,11 @@ var Sprite = cc.Class({
}
}
this._spriteFrame = value;
if (lastSprite && lastSprite.getTexture() !== value.getTexture()) {
// Drop previous material, because texture have changed
this._material = null;
this._customMaterial = false;
}
this._applySpriteFrame(lastSprite);
if (CC_EDITOR) {
this.node.emit('spriteframe-changed', this);
@@ -496,6 +501,7 @@ var Sprite = cc.Class({
switch (this.type) {
case SpriteType.SIMPLE:
this._model = SpriteModel.alloc();
this._model.trimmed = this._isTrimmedMode;
break;
case SpriteType.SLICED:
this._model = SlicedModel.alloc();
@@ -595,9 +601,6 @@ var Sprite = cc.Class({
if (!this.isValid) {
return;
}
// Drop previous material, because texture have changed
this._material = null;
this._customMaterial = false;
// Reattach material to model
this._activateModel();
this._applySpriteSize();
@@ -611,7 +614,7 @@ var Sprite = cc.Class({
var spriteFrame = this._spriteFrame;
if (spriteFrame) {
if (spriteFrame.textureLoaded()) {
if (spriteFrame.textureLoaded) {
this._onTextureLoaded(null);
}
else {
+15 -3
View File
@@ -218,17 +218,18 @@ let _sharedOpts = {
mipmap: undefined,
images: undefined,
image: undefined,
flipY: undefined,
premultiplyAlpha: undefined
};
function _getSharedOptions () {
for (var key in _sharedOpts) {
_sharedOpts[key] = undefined;
}
_sharedOpts.flipY = false;
return _sharedOpts;
}
var Texture2D = cc.Class({
name: 'cc.Texture2D',
extends: require('../assets/CCRawAsset'),
mixins: [EventTarget],
@@ -287,7 +288,7 @@ var Texture2D = cc.Class({
*/
this.height = 0;
this._texture = new TextureImpl(renderer.device, _emptyOpts);
this._texture = null;
},
getImpl () {
@@ -454,6 +455,11 @@ var Texture2D = cc.Class({
this.height = this._image.height;
let opts = _getSharedOptions();
opts.image = this._image;
if (renderMode.supportWebGL) {
// webgl texture 2d uses images
opts.images = [opts.image];
}
opts.flipY = false;
opts.width = this.width;
opts.height = this.height;
opts.hasMipmap = this._hasMipmap;
@@ -463,7 +469,13 @@ var Texture2D = cc.Class({
opts.magFilter = FilterIndex[this._magFilter];
opts.wrapS = this._wrapS;
opts.wrapT = this._wrapT;
this._texture.update(opts);
if (!this._texture) {
this._texture = new TextureImpl(renderer.device, opts);
}
else {
this._texture.update(opts);
}
//dispatch load event to listener.
this.loaded = true;