如何用GLKit中的OpenGL视图替换OpenGL ES 1.1 EAGLLayer视图?

时间:2022-09-07 09:33:56

I have a simple game which uses EAGLLayer directly. I had to set up the runloop and all OpenGL ES boilerplate. Game sometimes crashes because of OpenGL backgrounding problems. I heard the GLKit has a robust boilerplate OpenGL view which takes care of OpenGL initialize and suspension.

我有一个简单的游戏直接使用EAGLLayer。我必须设置runloop和所有OpenGL ES样板。由于OpenGL背景问题,游戏有时会崩溃。我听说GLKit有一个强大的样板OpenGL视图,它负责OpenGL的初始化和暂停。

Is it possible to set up this GLKit view for OpenGL 1.1 and where would I start?

是否可以为OpenGL 1.1设置此GLKit视图,我将从哪里开始?

1 个解决方案

#1


1  

This is a rather open-ended question, so it's probably best to start by getting yourself some background with GLKit and then ask more questions if you have specific issues.

这是一个相当开放的问题,所以最好先让自己了解一下GLKit的背景,然后在遇到具体问题时再提出更多问题。

Take a look at the code you get when creating a new Xcode project using the "OpenGL Game" template -- this sets up a GLKView and GLKViewController for you. There's also some description of how these classes work and how to use them in Apple's OpenGL ES Programming Guide.

看看使用“OpenGL游戏”模板创建新Xcode项目时获得的代码 - 这将为您设置GLKView和GLKViewController。在Apple的OpenGL ES编程指南中还有一些关于这些类如何工作以及如何使用它们的描述。

The overall gist of it: GLKView does all of the framebuffer, renderbuffer, and viewport setup and presentation for basic OpenGL ES drawing (including all the extra framebuffer juggling for multisampling if you want that) so that all you have to do is issue drawing commands. GLKViewController owns a GLKView and runs an animation timer that calls your drawing code -- by default, it makes sure not to call your drawing code when the app is in the background.

它的总体要点:GLKView为基本的OpenGL ES绘图执行所有帧缓冲,渲染缓冲和视口设置和演示(包括所有额外的帧缓冲,以便在需要时进行多重采样),这样您所要做的就是发出绘图命令。 GLKViewController拥有一个GLKView并运行一个动画计时器来调用你的绘图代码 - 默认情况下,它确保当应用程序在后台时不调用你的绘图代码。

If you're using GLKViewController and only making OpenGL ES calls from the GLKView (subclass or delegate) drawing method, you shouldn't have to worry about crashing due to GPU use in the background. If you are seeing such crashes (with gpus_ReturnNotPermittedKillClient in the stack trace), it can help to try forcing the GL to complete processing before going to the background -- call glFinish() in applicationWillResignActive:.

如果您正在使用GLKViewController并且仅从GLKView(子类或委托)绘制方法进行OpenGL ES调用,则您不必担心由于在后台使用GPU而导致崩溃。如果你看到这样的崩溃(在堆栈跟踪中使用gpus_ReturnNotPermittedKillClient),它可以帮助尝试强制GL在进入后台之前完成处理 - 在applicationWillResignActive:中调用glFinish()。

#1


1  

This is a rather open-ended question, so it's probably best to start by getting yourself some background with GLKit and then ask more questions if you have specific issues.

这是一个相当开放的问题,所以最好先让自己了解一下GLKit的背景,然后在遇到具体问题时再提出更多问题。

Take a look at the code you get when creating a new Xcode project using the "OpenGL Game" template -- this sets up a GLKView and GLKViewController for you. There's also some description of how these classes work and how to use them in Apple's OpenGL ES Programming Guide.

看看使用“OpenGL游戏”模板创建新Xcode项目时获得的代码 - 这将为您设置GLKView和GLKViewController。在Apple的OpenGL ES编程指南中还有一些关于这些类如何工作以及如何使用它们的描述。

The overall gist of it: GLKView does all of the framebuffer, renderbuffer, and viewport setup and presentation for basic OpenGL ES drawing (including all the extra framebuffer juggling for multisampling if you want that) so that all you have to do is issue drawing commands. GLKViewController owns a GLKView and runs an animation timer that calls your drawing code -- by default, it makes sure not to call your drawing code when the app is in the background.

它的总体要点:GLKView为基本的OpenGL ES绘图执行所有帧缓冲,渲染缓冲和视口设置和演示(包括所有额外的帧缓冲,以便在需要时进行多重采样),这样您所要做的就是发出绘图命令。 GLKViewController拥有一个GLKView并运行一个动画计时器来调用你的绘图代码 - 默认情况下,它确保当应用程序在后台时不调用你的绘图代码。

If you're using GLKViewController and only making OpenGL ES calls from the GLKView (subclass or delegate) drawing method, you shouldn't have to worry about crashing due to GPU use in the background. If you are seeing such crashes (with gpus_ReturnNotPermittedKillClient in the stack trace), it can help to try forcing the GL to complete processing before going to the background -- call glFinish() in applicationWillResignActive:.

如果您正在使用GLKViewController并且仅从GLKView(子类或委托)绘制方法进行OpenGL ES调用,则您不必担心由于在后台使用GPU而导致崩溃。如果你看到这样的崩溃(在堆栈跟踪中使用gpus_ReturnNotPermittedKillClient),它可以帮助尝试强制GL在进入后台之前完成处理 - 在applicationWillResignActive:中调用glFinish()。