开发者

Detect iPhone hardware older than 3GS

I have a rendering intensive game and using png it's too slow to run on 3G phones. But it runs fast using pvrtc so I need to know what model I'm running on.

Question: how can I detect the hardware I'm running on?

Many tha开发者_如何学编程nks for your help!


What you're probably actually interested is whether you're on PowerVR MBX hardware (as in the 3G, the original iPhone, the first and second generation iPod Touches and the low-end third generation iPod) or PowerVR SGX hardware (as in the 3GS and iPhone 4, both iPads and the iPod Touches not in the above list).

With that in mind, how about just:

EAGLContext *testContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

BOOL isSGX = testContext ? YES : NO;
[testContext release];

return isSGX;

The SGX is a programmable part that can support ES 2, the MBX isn't. The MBX is also limited to 16mb of VRAM whereas the SGX isn't, which is probably why your app runs poorly with full fat textures but fine with pvrtc.


You could use this class by Erica Sadun.


See my example gist, the core is the following method:

- (NSString*) platformID
{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    return platform;
}


Compile for ARM v7 only, all iPhone after the 3G are ARM v7.

This is what the layar app also does.

If you want to detect the older hardware is even easier, since you are creating a fat binary (support for ARMv6 and ARMv7). There is a define for the ARMv&, just can't find it write now. This way you do not have to loop up the type at runt time, just create a fat binary for ARMv6 and ARMv7 then with a macro add the optimization for the ARMv& with the #if armv7 macro.


You could also disable Thumb for the armv6 build. This will speed up the game on older models. You should leave Thumb enabled for the armv7 architecture, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜