Skip to content
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

Merged
merged 8 commits into from
Aug 6, 2018
Merged

Conversation

2youyou2
Copy link
Contributor

@2youyou2 2youyou2 commented Aug 1, 2018

Re: cocos-creator/fireball#7906

Changelog:

  • support compress texture

}
let asset = "" + extId + "," +
this._minFilter + "," + this._magFilter + "," +
this._wrapS + "," + this._wrapT + "," +
(this._premultiplyAlpha ? 1 : 0);
(this._premultiplyAlpha ? 1 : 0) + ',' + this.width + ',' + this.height;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

压缩纹理后大小会被改变,需要记录之前 texture 的大小

@@ -285,6 +320,8 @@ var Texture2D = cc.Class({
this.height = 0;

this._texture = null;

this._compressed = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉有 _format 就行了,没必要专门存一个 _compressed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要方便判断的话,考虑封装一个静态方法,cc.Texture2D._isCompressed(texture) ?

let SupportTextureFormats = ['.webp', '.jpg', '.jpeg', '.bmp', '.png'];
if (cc.sys.isMobile) {
if (cc.sys.os === cc.sys.OS_IOS) {
SupportTextureFormats = ['.pvr'].join(SupportTextureFormats);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 join 是不是写错了?这样得到的值也只是 '.pvr'

// }
}

cc.macro.SupportTextureFormats = SupportTextureFormats;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里加一个 break; 会好点

@@ -687,7 +765,7 @@ var Texture2D = cc.Class({
this.url = url;
}
}
if (fields.length === 6) {
if (fields.length === 8) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这个判断是多余的。如果这个判断有必要留着,那就应该兼容 .length === 6 和 8 两种情况

extId = ext;
}
let natives = this._native;
if (!Array.isArray(natives)) {
Copy link
Contributor

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

let extFormat = extIds[i].split('@');
let tmpExt = extFormat[0];
tmpExt = tmpExt.charCodeAt(0) - CHAR_CODE_0;
tmpExt = Texture2D.extnames[tmpExt];
Copy link
Contributor

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 数组里拿到。

let extId = "";
if (ext) {
// ext@format
let extFormat = ext.split('@');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 native 里面的 @,是在哪里生成的呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

压缩纹理的时候生成的

@@ -119,6 +208,8 @@ var defaultMap = {
'tiff' : loadImage,
'webp' : loadImage,
'image' : loadImage,
'pvr' : loadPVR,
'etc' : loadPVR,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etc怎么也用loadpvr?

Copy link
Contributor Author

@2youyou2 2youyou2 Aug 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGB_PVRTC_2BPPV1: gfx.TEXTURE_FMT_RGB_PVRTC_2BPPV1,
/**
* rgba 2 bpp pvrtc
* @property RGB_PVRTC_2BPPV1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGBA_PVRTC_2BPPV1

RGBA_PVRTC_2BPPV1: gfx.TEXTURE_FMT_RGBA_PVRTC_2BPPV1,
/**
* rgb 4 bpp pvrtc
* @property RGB_PVRTC_2BPPV1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGB_PVRTC_4BPPV1

RGB_PVRTC_4BPPV1: gfx.TEXTURE_FMT_RGB_PVRTC_4BPPV1,
/**
* rgba 4 bpp pvrtc
* @property RGB_PVRTC_2BPPV1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGBA_PVRTC_4BPPV1

@@ -217,8 +246,13 @@ var Texture2D = cc.Class({
// maybe returned to pool in webgl
return this._image;
},
set (image) {
this.initWithElement(image);
set (asset) {
Copy link
Contributor

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 吧

@@ -285,6 +323,8 @@ var Texture2D = cc.Class({
this.height = 0;

this._texture = null;

this._exportedExts = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 CC_EDITOR 限定一下吧


// ETC1 format, from:
// http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc1/
const COMPRESSED_RGB_ETC1_WEBGL = 0x8D64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面这几个加上 GL_ 前缀


case PVR_FORMAT_ETC1:
internalFormat = COMPRESSED_RGB_ETC1_WEBGL;
break;
Copy link
Contributor

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 就好了把

// }
}

cc.macro.SUPPORT_TEXTURE_FORMATS = SUPPORT_TEXTURE_FORMATS;
Copy link
Contributor

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_"];
Copy link
Contributor

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_"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哪些情况会出现这些前缀?目前格式还不统一?

Copy link
Contributor Author

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

@pandamicro pandamicro merged commit 44d068b into cocos:next Aug 6, 2018
@2youyou2 2youyou2 deleted the next-compress-texture branch September 20, 2018 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants