在iPhone4上使用OpenGL ES加载大纹理时出现glError 0x0501 [英] glError 0x0501 when loading a large texture with OpenGL ES on the iPhone4

查看:706
本文介绍了在iPhone4上使用OpenGL ES加载大纹理时出现glError 0x0501的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在设备上加载PVR图像时出现此错误.它可以在iPhone 5s,5、4s和iPad上很好地工作,但在4s中则不起作用.我的PVR图像大小为:width = 4096height = 2048.

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

我从链接:

支持的尺寸为:iPhone 3gs/iPhone 4/iPad 1/iPod 3/4:2048x2048 iPad 2/3/4/迷你/iPhone 4S/5/iPod 5:4096x4096

Supported sizes are: iPhone 3gs / iPhone 4 / iPad 1 / iPod 3 / 4 : 2048x2048 iPad 2 / 3 / 4 / Mini / iPhone 4S / 5 / iPod 5 : 4096x4096

顺便说一句,您可以在4096x4096的分辨率下导入纹理并打开mip贴图,这将在较旧的设备上自动使用较小分辨率的纹理.

Btw, you can import texture at 4096x4096 and turn mip maps on, this would automatically use smaller resolution texture on older devices.

但是如何打开mip-maps ..,这是怎么做的呢?

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);

推荐答案

好吧,您尝试创建一个大于GL_MAX_TEXTURE_SIZE的纹理,因此它将失败.没有办法解决.

Well, you try to create a texture bigger than GL_MAX_TEXTURE_SIZE, so it will fail. There is no way around that.

顺便说一句,您可以导入4096x4096的纹理并启用Mip贴图, 会在较旧的设备上自动使用分辨率较低的纹理.

Btw, you can import texture at 4096x4096 and turn mip maps on, this would automatically use smaller resolution texture on older devices.

不,您不能.那不是mipmap的目的.在采样纹理时使用它们,以避免在显示较小的纹理时由于稀疏采样而导致的伪影.您仍在尝试创建4096x4096的纹理,但该纹理在该设备上根本无法使用.

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.

要解决此问题,您应该将纹理大小限制为要支持的所有目标设备的最小支持大小,或者在尝试将其尝试到GL之前,动态查询GL_MAX_TEXTURE_SIZE限制并缩小数据规模,或提供不同的分辨率以供选择.

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.

这篇关于在iPhone4上使用OpenGL ES加载大纹理时出现glError 0x0501的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆