From 895b0e04f3f6bec163c38ddd6cce1ee6618d6129 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 16 Jan 2018 18:25:31 +0800 Subject: [PATCH] Fix SpriteFrame and Texture2D merge issue --- cocos2d/core/sprites/CCSpriteFrame.js | 9 +-- cocos2d/core/textures/CCTexture2D.js | 80 ++++++--------------------- 2 files changed, 21 insertions(+), 68 deletions(-) diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index 0e07a3201a..c3fb02d080 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -272,7 +272,8 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ var w = texture.width, h = texture.height; if (self._rotated && cc._renderType === cc.game.RENDER_TYPE_CANVAS) { - self._texture = _ccsg.Sprite.CanvasRenderCmd._createRotatedTexture(texture, self.getRect()); + // TODO: rotate texture for canvas + // self._texture = _ccsg.Sprite.CanvasRenderCmd._createRotatedTexture(texture, self.getRect()); self._rotated = false; w = self._texture.width; h = self._texture.height; @@ -382,7 +383,8 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ // loading texture var texture = textureOrTextureFile; if (typeof texture === 'string' && texture) { - texture = cc.textureCache.addImage(texture); + this._textureFilename = texture; + this._loadTexture(); } if (texture instanceof cc.Texture2D && this._texture !== texture) { this._refreshTexture(texture); @@ -426,8 +428,7 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ } else if (this._textureFilename) { // load new texture - var texture = cc.textureCache.addImage(this._textureFilename); - this._refreshTexture(texture); + this._loadTexture(); } }, diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index 050d4d07be..263d09e32f 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -36,44 +36,12 @@ const gfx = renderEngine.gfx; const TextureImpl = renderEngine.Texture2D; const renderMode = renderEngine.renderMode; -const GL_ALPHA = 6406; // gl.ALPHA -const GL_RGB = 6407; // gl.RGB -const GL_RGBA = 6408; // gl.RGBA -const GL_LUMINANCE = 6409; // gl.LUMINANCE -const GL_LUMINANCE_ALPHA = 6410; // gl.LUMINANCE_ALPHA -const GL_UNSIGNED_BYTE = 5121; // gl.UNSIGNED_BYTE -const GL_UNSIGNED_SHORT = 5123; // gl.UNSIGNED_SHORT -const GL_UNSIGNED_INT = 5125; // gl.UNSIGNED_INT -const GL_FLOAT = 5126; // gl.FLOAT -const GL_UNSIGNED_SHORT_5_6_5 = 33635; // gl.UNSIGNED_SHORT_5_6_5 -const GL_UNSIGNED_SHORT_4_4_4_4 = 32819; // gl.UNSIGNED_SHORT_4_4_4_4 -const GL_UNSIGNED_SHORT_5_5_5_1 = 32820; // gl.UNSIGNED_SHORT_5_5_5_1 - const GL_NEAREST = 9728; // gl.NEAREST const GL_LINEAR = 9729; // gl.LINEAR 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 _textureFmtGL = [ - // R5_G6_B5: 0 - { format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_UNSIGNED_SHORT_5_6_5 }, - // R5_G5_B5_A1: 1 - { format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_SHORT_5_5_5_1 }, - // R4_G4_B4_A4: 2 - { format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_SHORT_4_4_4_4 }, - // RGB8: 3 - { format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_UNSIGNED_BYTE }, - // RGBA8: 4 - { format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_BYTE }, - // A8: 5 - { format: GL_ALPHA, internalFormat: GL_ALPHA, pixelType: GL_UNSIGNED_BYTE }, - // L8: 6 - { format: GL_LUMINANCE, internalFormat: GL_LUMINANCE, pixelType: GL_UNSIGNED_BYTE }, - // L8_A8: 7 - { format: GL_LUMINANCE_ALPHA, internalFormat: GL_LUMINANCE_ALPHA, pixelType: GL_UNSIGNED_BYTE } -]; - /** *

* This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data.
@@ -243,6 +211,17 @@ var Texture2D = cc.Class({ mixins: [EventTarget], properties: { + _nativeAsset: { + get () { + // maybe returned to pool in webgl + return this._image; + }, + set (image) { + this.initWithElement(image); + this.handleLoadedTexture(); + }, + override: true + }, _hasMipmap: false, _format: PixelFormat.RGBA8888, _premultiplyAlpha: false, @@ -255,7 +234,9 @@ var Texture2D = cc.Class({ statics: { PixelFormat: PixelFormat, WrapMode: WrapMode, - Filter: Filter + Filter: Filter, + // predefined most common extnames + extnames: ['.png', '.jpg', '.jpeg', '.bmp', '.webp'] }, ctor () { @@ -305,36 +286,6 @@ var Texture2D = cc.Class({ return this._texture; }, - properties: { - _nativeAsset: { - get () { - // maybe returned to pool in webgl - return this._image; - }, - set (image) { - this.initWithElement(image); - this.handleLoadedTexture(); - }, - override: true - }, - _hasMipmap: false, - _format: PixelFormat.RGBA8888, - _compressed: false, - _premultiplyAlpha: false, - _minFilter: Filter.LINEAR, - _magFilter: Filter.LINEAR, - _wrapS: WrapMode.CLAMP_TO_EDGE, - _wrapT: WrapMode.CLAMP_TO_EDGE - }, - - statics: { - WrapMode: WrapMode, - PixelFormat: PixelFormat, - Filter: Filter, - // predefined most common extnames - extnames: ['.png', '.jpg', '.jpeg', '.bmp', '.webp'] - }, - /** * Update texture options, not available in Canvas render mode. * image, format, premultiplyAlpha can not be updated in native. @@ -549,8 +500,9 @@ var Texture2D = cc.Class({ }, /** - * Release texture. + * Release texture, please use destroy instead. * @method releaseTexture + * @deprecated */ releaseTexture () { this._image = null;