workaround for %33 texture memory bug

原帖链接: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


原文地址:https://www.cnblogs.com/java20130723/p/3212056.html