iphone - OpenGL ES 是否需要为 "shutdown"?

标签 iphone ios4 opengl-es uiviewcontroller

我有一个 View Controller ,其 View 使用 OpenGL ES。当 View Controller 被释放时,是否需要做任何其他工作来“关闭”OpenGL?或者一旦 View Controller 不存在,手机是否会切换出“OpenGL 模式”——如果存在这种情况?

最佳答案

没有真正的“OpenGL 模式”。在 iOS 上,您可以通过 EAGLContext 类创建一个上下文来进行渲染:

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

在此上下文中,您需要设置至少一个帧缓冲区对象 (FBO) 并将其附加到您进行实际绘图的 CAEAGLLayer:

glGenFramebuffers(1, &viewFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);

glGenRenderbuffers(1, &viewRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);

[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];

在进行任何 OpenGL ES 绘图之前指定当前上下文:

[EAGLContext setCurrentContext:context]

然后该绘图将渲染到附加到 CAEAGLLayer 的 FBO 中,从而使其显示在屏幕上。此内容与界面的其余部分合成,因此进行 OpenGL 绘图时没有真正的模式更改,它只是界面中的另一个 View 。

当您完成托管 OpenGL 内容的 View 后,您无需关闭任何内容,但最好清理一下您使用过的所有资源。使用 glDeleteFramebuffers()glDeleteRenderbuffers() 清理 FBO,glDeleteTextures() 清理您使用过的任何纹理,glDeleteBuffers () 适用于任何 VBO 等

关于iphone - OpenGL ES 是否需要为 "shutdown"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5902420/

相关文章:

ios - 图像和文本字段的 Xcode 约束?

iPhone map 套件 : have pins fall one by one

android - 来自 Web 服务的后台 GPS 轮询

c# - gles2 动态壁纸转换为 c# (xamarin) 符合错误“...mono.android.TypeManager cannot be applied to

Android 混合 OpenGLES 1.0 和 OpenGLES 2.0

java - OpenGL ES : Rotating does not seem to take Z axis into consideration?

iphone - 在 iOS 7 中将 UIAlertView 中的消息对齐到左侧

iphone - 我如何为我的 iPhone 应用程序集成谷歌地图 API?

iphone - NSDateFormatter 无法与 UTC 正常工作

ios - 如何在文本字段上双击键盘