How does the iPhone know which OpenGL ES context to use between 1.1 and 2.0?
I've been digging around the net recently and noticed some video tutorials show an开发者_如何学运维 older template (pre SDK 3.2) with one OpenGL ES context. Now there are two of them, which, I've gleaned are the two versions of OpenGL ES available on the newer iMobile devices.
Can I just use the older one or do I need to do everything twice? How do I tell the iPhone to use the older context, or will it do so automatically?
To expand upon what Frogblast said, the template code defines two classes: ES1Renderer
and ES2Renderer
. The EAGLView
class first tries to create an ES2Renderer
instance, but if that fails it creates an ES1Renderer
. The failure comes about if the ES2Renderer
is unable to set up an OpenGL ES 2.0 context using the following code:
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!context || ![EAGLContext setCurrentContext:context] || ![self loadShaders])
{
[self release];
return nil;
}
If a device supports OpenGL ES 2.0, this should succeed. If not, the application falls back to the ES1Renderer
OpenGL ES 1.1 renderer.
The reason the application has two different rendering classes is that OpenGL ES 1.1 and 2.0 have different and incompatible rendering pipelines. OpenGL ES 2.0 lets you create programmable shaders for some stunning effects, but it can be more difficult to use for simple tasks than OpenGL ES 1.1.
Many people add fallbacks to their application if they use OpenGL ES 2.0, because only the iPhone 3G S and later devices have support for this never API. However, if you are developing an iPad-only application, you can assume it will have 2.0 support. You could also restrict your application to running on devices with this capability by adding the opengles-2
key to the UIRequiredDeviceCapabilities
in your Info.plist.
You can use OpenGL ES 1.1 just fine on the newer devices, so if you want to disable the 2.0 rendering path you can have the EAGLView in the template ignore the ES2Renderer
class and just work with the ES1Renderer
. You could also take the OpenGL ES code from the ES1Renderer
and just place it within the EAGLView.
By default, the template tries to create an ES2 context, and if that fails, then tries to create an ES1 context. If you want to work with ES 1.1 alone (which is supported on all devices), you can just delete all references to ES2 from the template project.
精彩评论