iPhone 如何知道在 1.1 和 2.0 之间使用哪个 OpenGL ES 上下文?

发布于 2024-08-31 12:16:45 字数 181 浏览 2 评论 0原文

我最近一直在网上挖掘,注意到一些视频教程显示了一个带有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

土豪我们做朋友吧 2024-09-07 12:16:45

为了扩展 Frogblast 所说的内容,模板代码定义了两个类:ES1RendererES2RendererEAGLView 类首先尝试创建一个 ES2Renderer 实例,但如果失败,它会创建一个 ES1Renderer。如果 ES2Renderer 无法使用以下代码设置 OpenGL ES 2.0 上下文,则会出现失败:

context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

if (!context || ![EAGLContext setCurrentContext:context] || ![self loadShaders])
{
    [self release];
    return nil;
}

如果设备支持 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 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.

提笔书几行 2024-09-07 12:16:45

默认情况下,模板尝试创建 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文