I got this error when I try to load a PVR image on device. It works in iPhone 5s, 5, 4s and iPad well, but in 4 it doesn't work. My PVR image size is: width = 4096
and height = 2048
.
Cocos2d: cocos2d: TexturePVR: Error uploading compressed texture level: 0 . glError: 0x0501
Cocos2d: cocos2d: Couldn't load PVR image /var/mobile/Applications/7CF6C347-8B63-4C1E-857A-41F48C8ACBEF/Race.app/Images/BackGround/bg1.pvr.ccz
Cocos2d: cocos2d: Couldn't add PVRImage:Images/BackGround/bg1.pvr.ccz in CCTextureCache
I got this form this link:
Supported sizes are: iPhone 3gs / iPhone 4 / iPad 1 / iPod 3 / 4 : 2048x2048 iPad 2 / 3 / 4 / Mini / iPhone 4S / 5 / iPod 5 : 4096x4096
Btw, you can import texture at 4096x4096 and turn mip maps on, this would automatically use smaller resolution texture on older devices.
But how to turn on the mip-maps .. and what does this do?
// support mipmap filtering
sprite->getTexture()->generateMipmap();
ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
sprite->getTexture()->setTexParameters(&texParams);
Well, you try to create a texture bigger than GL_MAX_TEXTURE_SIZE
, so it will fail. There is no way around that.
Btw, you can import texture at 4096x4096 and turn mip maps on, this would automatically use smaller resolution texture on older devices.
No, you can not. That is not what mipmaps are for. They are used when sampling the texture to avoid artifacts due to sparse sampling when the texture is shown smaller. You are still trying to create a 4096x4096 texure, which simply will not work on that device.
To solve this, you should either limit the texture size to the minimum supported size of all of the target devices you which to support, or dynamically query the GL_MAX_TEXTURE_SIZE
limit and downscale the data before you try it to the GL, or provide different resolutions to choose from.
If you absolutely need that many pixels, you could also use some texture tiling approach and split it in multiple tiles - but that will probably require some major changes on your rendering code, and it might also lead to performance issues.
来源:https://stackoverflow.com/questions/25226653/glerror-0x0501-when-loading-a-large-texture-with-opengl-es-on-the-iphone4