-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support compress texture #3039
support compress texture #3039
Conversation
cocos2d/core/assets/CCTexture2D.js
Outdated
} | ||
let asset = "" + extId + "," + | ||
this._minFilter + "," + this._magFilter + "," + | ||
this._wrapS + "," + this._wrapT + "," + | ||
(this._premultiplyAlpha ? 1 : 0); | ||
(this._premultiplyAlpha ? 1 : 0) + ',' + this.width + ',' + this.height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
压缩纹理后大小会被改变,需要记录之前 texture 的大小
cocos2d/core/assets/CCTexture2D.js
Outdated
@@ -285,6 +320,8 @@ var Texture2D = cc.Class({ | |||
this.height = 0; | |||
|
|||
this._texture = null; | |||
|
|||
this._compressed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉有 _format 就行了,没必要专门存一个 _compressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要方便判断的话,考虑封装一个静态方法,cc.Texture2D._isCompressed(texture) ?
cocos2d/core/platform/CCMacro.js
Outdated
let SupportTextureFormats = ['.webp', '.jpg', '.jpeg', '.bmp', '.png']; | ||
if (cc.sys.isMobile) { | ||
if (cc.sys.os === cc.sys.OS_IOS) { | ||
SupportTextureFormats = ['.pvr'].join(SupportTextureFormats); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 join 是不是写错了?这样得到的值也只是 '.pvr'
cocos2d/core/platform/CCMacro.js
Outdated
// } | ||
} | ||
|
||
cc.macro.SupportTextureFormats = SupportTextureFormats; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要不要统一用 SUPPORT_TEXTURE_FORMATS
try { | ||
var ext = gl.getExtension(vendorPrefixes[j] + name); | ||
if (ext) { | ||
this$1._extensions[name] = ext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里加一个 break; 会好点
cocos2d/core/assets/CCTexture2D.js
Outdated
@@ -687,7 +765,7 @@ var Texture2D = cc.Class({ | |||
this.url = url; | |||
} | |||
} | |||
if (fields.length === 6) { | |||
if (fields.length === 8) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这个判断是多余的。如果这个判断有必要留着,那就应该兼容 .length === 6 和 8 两种情况
cocos2d/core/assets/CCTexture2D.js
Outdated
extId = ext; | ||
} | ||
let natives = this._native; | ||
if (!Array.isArray(natives)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里拿的是 ext,不会是 arrary 吧?下面 this._setRawAsset(ext);
时,传入的也不是 array
cocos2d/core/assets/CCTexture2D.js
Outdated
let extFormat = extIds[i].split('@'); | ||
let tmpExt = extFormat[0]; | ||
tmpExt = tmpExt.charCodeAt(0) - CHAR_CODE_0; | ||
tmpExt = Texture2D.extnames[tmpExt]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要判断一下 tmpExt 拿不到的情况,例如 tmpExt = Texture2D.extnames[tmpExt] || extFormat;
。如果后缀是其它类型(比如 gif?),就没办法从 extnames 数组里拿到。
cocos2d/core/assets/CCTexture2D.js
Outdated
let extId = ""; | ||
if (ext) { | ||
// ext@format | ||
let extFormat = ext.split('@'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 native 里面的 @,是在哪里生成的呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
压缩纹理的时候生成的
cocos2d/core/load-pipeline/loader.js
Outdated
@@ -119,6 +208,8 @@ var defaultMap = { | |||
'tiff' : loadImage, | |||
'webp' : loadImage, | |||
'image' : loadImage, | |||
'pvr' : loadPVR, | |||
'etc' : loadPVR, | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
etc怎么也用loadpvr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cocos2d/core/assets/CCTexture2D.js
Outdated
RGB_PVRTC_2BPPV1: gfx.TEXTURE_FMT_RGB_PVRTC_2BPPV1, | ||
/** | ||
* rgba 2 bpp pvrtc | ||
* @property RGB_PVRTC_2BPPV1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RGBA_PVRTC_2BPPV1
cocos2d/core/assets/CCTexture2D.js
Outdated
RGBA_PVRTC_2BPPV1: gfx.TEXTURE_FMT_RGBA_PVRTC_2BPPV1, | ||
/** | ||
* rgb 4 bpp pvrtc | ||
* @property RGB_PVRTC_2BPPV1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RGB_PVRTC_4BPPV1
cocos2d/core/assets/CCTexture2D.js
Outdated
RGB_PVRTC_4BPPV1: gfx.TEXTURE_FMT_RGB_PVRTC_4BPPV1, | ||
/** | ||
* rgba 4 bpp pvrtc | ||
* @property RGB_PVRTC_2BPPV1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RGBA_PVRTC_4BPPV1
cocos2d/core/assets/CCTexture2D.js
Outdated
@@ -217,8 +246,13 @@ var Texture2D = cc.Class({ | |||
// maybe returned to pool in webgl | |||
return this._image; | |||
}, | |||
set (image) { | |||
this.initWithElement(image); | |||
set (asset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该叫 asset 吧,这个对象不是 asset 类型,是一个 raw data 类型,直接用 data 吧
cocos2d/core/assets/CCTexture2D.js
Outdated
@@ -285,6 +323,8 @@ var Texture2D = cc.Class({ | |||
this.height = 0; | |||
|
|||
this._texture = null; | |||
|
|||
this._exportedExts = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用 CC_EDITOR 限定一下吧
cocos2d/core/load-pipeline/loader.js
Outdated
|
||
// ETC1 format, from: | ||
// http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc1/ | ||
const COMPRESSED_RGB_ETC1_WEBGL = 0x8D64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面这几个加上 GL_ 前缀
cocos2d/core/load-pipeline/loader.js
Outdated
|
||
case PVR_FORMAT_ETC1: | ||
internalFormat = COMPRESSED_RGB_ETC1_WEBGL; | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些 internalFormat 好像没有用啊?是不是只是用来判断支持格式的?如果是的话,不需要 internalFormat 参数吧?只要把 case 连起来,保证这些 case 不走 errorCallback 就好了把
cocos2d/core/platform/CCMacro.js
Outdated
// } | ||
} | ||
|
||
cc.macro.SUPPORT_TEXTURE_FORMATS = SUPPORT_TEXTURE_FORMATS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一下 API 注释,说明目前的格式和平台支持情况
var ext = gl.getExtension(name); | ||
if (ext) { | ||
this$1._extensions[name] = ext; | ||
var vendorPrefixes = ["", "WEBKIT_", "MOZ_"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哪些情况会出现这些前缀?目前格式还不统一?
var ext = gl.getExtension(name); | ||
if (ext) { | ||
this$1._extensions[name] = ext; | ||
var vendorPrefixes = ["", "WEBKIT_", "MOZ_"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哪些情况会出现这些前缀?目前格式还不统一?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ios safari 是 WEBKIT_
前缀,MOZ_
还不知道,ios 的火狐?
https://github.com/toji/texture-tester/blob/master/js/webgl-texture-util.js#L337
Re: cocos-creator/fireball#7906
Changelog: