跨不同 ViewController/EAGLView 使用相同的 EAGLContext
我在 EAGLViews
中使用相同的 EAGLContext
时遇到一些问题。我有两个视图控制器,每个控制器都有一个 EAGLView。
每个视图控制器分配一个新的EAGLContext
,并为每个相应的EAGLView
创建后续的帧缓冲区/颜色缓冲区,但这会浪费内存资源。
我知道可以通过简单地将不同的帧缓冲区/颜色缓冲区绑定到不同的 EAGLViews 来跨 ViewController 使用相同的 EAGLContext :
但到目前为止我还没有做到这一点。
有什么想法吗?
提前致谢。
I'm having some issues using the same EAGLContext
across EAGLViews
. I have two View Controllers, each one has one EAGLView
.
Each View Controller allocates a new EAGLContext
, and a subsequent framebuffer/colorbuffer is created for each respective EAGLView
, but this is a waste of memory resources.
I know that it is possible to use the same EAGLContext
across ViewControllers by simply binding different framebuffers/colorbuffers to different EAGLViews
:
Using Multiple OpenGL Views And UIKit
But i didnt manage to achieve that so far.
Any ideas?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终成功解决了问题。
在我使用的视图控制器之一中:
在多线程环境中使用 EAGLContext 时,必须小心防止其他线程同时使用:
并在将控制权传递给另一个 ViewController 之前耗尽当前的dispatch_queue(通过presentViewController: ),使用:
因此,通过使用这两个技巧,我能够在多个视图中仅使用一个 EAGLContext。还必须特别注意 EAGLContext 的当前状态。我得到了意想不到的结果,因为在第一个视图中我有:
在第二个视图中我有完全不同的绘图代码,当然我忘记使用:
瞧!
谢谢 :)
Finally managed to solve the problem.
In one of the view controllers i was using:
When using EAGLContext in a multithreading environment one must be cautious to prevent other threads from accessing it at the same time using:
and to drain the current dispatch_queue before passing control to another ViewController (through presentViewController:), using:
So, by using these two tricks i was able to just use one EAGLContext across multiple views. One must also pay extra attention to the current state of the EAGLContext. I was having unexpected results because in the first view i had:
In the second view i had completely different drawing code, and i forgot to, of course, use:
And voilá!
Thanks :)
EAGLView
实际上并不是一个单独的类;它是一个类。它是一个同名的类家族,Apple 倾向于将其放入其示例文件中。因此,就具体修改提出建议相对困难。我最初的解决方案是创建一个提供单个共享 EAGLContext 的单例类。 EAGLContext 一次只能在一个线程上使用,因此这不一定是一个完整的解决方案,但您想要执行的操作可能取决于程序的语义,并且感觉像是一个不同的主题你的实际问题。
Xcode 4.1“OpenGL ES 应用程序”模板在视图外部创建上下文,而我认为它之前是在视图内部,这使事情变得更容易一些。
EAGLView
isn't actually a single class; it's a family of classes with the same name that Apple tend to throw into their example files. So it's relatively difficult to advise on specific modifications.My initial solution was to create a singleton class that vends a single, shared
EAGLContext
.EAGLContext
s can be used on only one thread at a time so that's not necessarily a complete solution, but exactly what you want to do will probably depend on the semantics of your program and feels like a different topic from your actual question.The Xcode 4.1 'OpenGL ES Application' template has context creation outside of the view, whereas I think it was previously inside, which makes things a little easier.