iPhone 如何知道在 1.1 和 2.0 之间使用哪个 OpenGL ES 上下文?
我最近一直在网上挖掘,注意到一些视频教程显示了一个带有一个 OpenGL ES 上下文的旧模板(SDK 3.2 之前的版本)。现在有两个,我收集到的是较新的 iMobile 设备上可用的 OpenGL ES 的两个版本。
我可以只使用旧的,还是需要将所有操作都做两次?我如何告诉 iPhone 使用旧的上下文,或者它会自动这样做吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了扩展 Frogblast 所说的内容,模板代码定义了两个类:
ES1Renderer
和ES2Renderer
。EAGLView
类首先尝试创建一个ES2Renderer
实例,但如果失败,它会创建一个ES1Renderer
。如果ES2Renderer
无法使用以下代码设置 OpenGL ES 2.0 上下文,则会出现失败:如果设备支持 OpenGL ES 2.0,则此操作应该会成功。如果没有,应用程序将回退到
ES1Renderer
OpenGL ES 1.1 渲染器。应用程序具有两个不同渲染类的原因是 OpenGL ES 1.1 和 2.0 具有不同且不兼容的渲染管道。 OpenGL ES 2.0 允许您创建可编程着色器以实现一些令人惊叹的效果,但与 OpenGL ES 1.1 相比,它可能更难以用于简单的任务。
许多人在使用 OpenGL ES 2.0 时会向他们的应用程序添加后备,因为只有 iPhone 3G S 及更高版本的设备才支持这种从不 API。但是,如果您正在开发仅适用于 iPad 的应用程序,则可以假设它将支持 2.0。您还可以通过将
opengles-2
键添加到 Info.plist 中的UIRequiredDeviceCapability
来限制您的应用程序在具有此功能的设备上运行。您可以在较新的设备上很好地使用 OpenGL ES 1.1,因此如果您想禁用 2.0 渲染路径,您可以让模板中的 EAGLView 忽略
ES2Renderer
类,只使用ES1渲染器
。您还可以从ES1Renderer
获取 OpenGL ES 代码并将其放置在 EAGLView 中。To expand upon what Frogblast said, the template code defines two classes:
ES1Renderer
andES2Renderer
. TheEAGLView
class first tries to create anES2Renderer
instance, but if that fails it creates anES1Renderer
. The failure comes about if theES2Renderer
is unable to set up an OpenGL ES 2.0 context using the following code: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 theUIRequiredDeviceCapabilities
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 theES1Renderer
. You could also take the OpenGL ES code from theES1Renderer
and just place it within the EAGLView.默认情况下,模板尝试创建 ES2 上下文,如果失败,则尝试创建 ES1 上下文。如果您想单独使用 ES 1.1(所有设备都支持),您只需从模板项目中删除对 ES2 的所有引用即可。
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.