workaround for %33 texture memory bug

本文探讨了在iOS应用中使用纹理时产生的额外内存消耗问题,并介绍了如何通过创建NPOT(非PowerOfTwo)纹理来降低内存使用。包括检查纹理是否为POT或NPOT的方法,以及在不同版本的Cocos2d-v1.0/v1.1/v2.0中如何启用NPOT支持。

原帖链接:http://www.cocos2d-iphone.org/forum/topic/29121

PS:

为什么要关心 NPOT 呢?

因为苹果的OpenGL驱动有一个bug,导致如果使用 POT 的纹理,则会产生额外33%的内存消耗。

So,

If you didn't know, when you create a texture, iOS will allocate 33% more memory, presumably to have enough room in case mipmaps are needed.
http://www.cocos2d-iphone.org/forum/topic/23887#post-129097 )

But it is worth noting that this bug is only present on POT (Power Of Two) textures ( Mipmapping is only supported on POT textures ).
So, in order to reduce memory, what you have to do is two create NPOT textures.

eg:
If you are using a 2048x2048 textures, convert it into a 2048x2047 textures (and you will save 33% memory).
In case you can't make it smaller, then make it bigger. eg:
If you have a 2048x1024 texture, create a 2048x1025 texture.

If you are using cocos2d v1.0, then you have to edit ccConfig.h with:

#define CC_TEXTURE_NPOT_SUPPORT 1

If you are using v1.1 or v2.0, then you are OK, since they already support NPOT textures by default.

Ways to know if you are using POT / NPOT textures:
A) Parse your PNG, GIF, BMP, JPEG files with file:

$ find . -name "*.png" -print0 | xargs -0 file

B) Run this line of code and see your debug console:

[[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];

Further info:
https://devforums.apple.com/thread/113889?start=0&tstart=0

Important: NPOT textures can't have mipmaps, and also they only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}

Important 2: PVRTC (2bpp and 4bpp) textures can't be converted to NPOT


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值