mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
Merge pull request #2260 from pandamicro/next
Fix SpriteFrame and Texture2D merge issue
This commit is contained in:
@@ -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();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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 }
|
||||
];
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data. <br/>
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user