多个 EAGLView,但每个纹理只有一个副本 - 怎么办?
我有一个在 iPad 上运行的应用程序,它使用大量纹理,渲染到一个 EAGLView 中。现在我需要第二个 EAGLView,与第一个共享纹理。
通过修复 Apple 代码中的一些设计错误(例如,默认 ViewController 需要进行一些调整以支持多个子 EAGLView 对象),我可以在屏幕上并行地很好地渲染两个视图。但我无法共享纹理。
我无法复制纹理(这会使内存使用量加倍 - 而且我们已经使用了大部分内存)。
我找不到 Apple 关于如何在多个 EAGLView 之间共享纹理的任何文档 - 有“暗示”这就是 EAGLShareGroup 的用途,允许每个 GLView 拥有自己的上下文,但两个上下文共享一个 ShareGroup - 但是我找不到任何明确的内容。
我尝试遵循这个问题的答案:纹理如果多个则不绘制使用 EAGLViews
...但这并不是真正的答案。它指向 EAGLSharegroup,但没有实际解释如何使用它 - 它似乎没有任何区别。它还间接指向有关从多个线程渲染的页面 - 这是一个完全不同的问题,并且我没有在那里列出任何问题(应用程序崩溃等)。
I have an app running on iPad which is using lots of textures, rendering into one EAGLView. Now I need a second EAGLView, sharing textures with the first.
I can get both views rendering fine, in parallel, on screen, by fixing some design mistakes in Apple's code (e.g. the default ViewController needs some tweaks to support multiple child EAGLView objects). But I can't get the textures to be shared.
I cannot duplicate the textures (that would double memory usage - and we're using most of the mem already).
I can't find any documentation from Apple on how to share textures between multiple EAGLView's - there are "hints" that this is what EAGLShareGroup is for, allowing each GLView to have its own context, but the two contexts to share a ShareGroup - but nothing explicit that I could find.
I've tried following the answer to this question: Textures not drawing if multiple EAGLViews are used
...but it wasn't really an answer. It pointed to EAGLSharegroup without actually explaining how to use it - it seems to make no difference at all. It also pointed indirectly to a page about rendering from multiple threads - which is a completely different problem, and I don't have any of the problems listed there (app crashes etc).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两个选项,使用与第一个相同的共享组创建第二个上下文,使用 Adam 的第二个代码示例。
或者,您可以对两个视图使用相同的上下文。为此,您可能应该让 ViewController 拥有上下文。然后,当您想要使用上下文渲染到特定视图时,您可以在该视图的帧缓冲区对象上调用 glBindFramebuffer() ,并在特定于视图的颜色缓冲区上调用 -presentRenderbuffer 。这种情况可能比使用两个共享上下文更有效。
There are two options, create the second context using the same sharegroup as the first Use Adam's second code example for that.
Alternatively, you can use the same context for both views. To do this, you should probably have the context be owned by the ViewController. Then, when you want to use the context to render to a particular view, you call glBindFramebuffer() on that view's framebuffer object, and call -presentRenderbuffer on the view-specific colorbuffer. This case is probably slightly more efficient than using two shared contexts.
事实证明,Apple 未记录的 EAGLShareGroup ( http://developer.apple.com/library/ios/#documentation/OpenGLES/Reference/EAGLSharegroup_ClassRef/Reference/EAGLSharegroup.html ) ...在不知道其秘密 init 的情况下无法实例化方法)。
我不知道那是什么 - 它没有记录 - 但您可以获取 EAGLContext 来为您实例化第一个共享组,然后将其设为您共享的全局共享组。
因此,以下内容永远不会工作:
但是,以下内容完美工作:(
编辑以使 context2 也使用 context1 的 API - 根据 Apple 的 ES 编程指南,根据 Pivot 的评论)
It turns out that Apple's undocumented EAGLShareGroup ( http://developer.apple.com/library/ios/#documentation/OpenGLES/Reference/EAGLSharegroup_ClassRef/Reference/EAGLSharegroup.html ) ... cannot be instantiated without knowing its secret init method(s).
I have no idea what that is - it's undocumented - but you can get an EAGLContext to instantiate the first sharegroup for you, and then make that your shared, global sharegroup.
So, the following will never work:
HOWEVER, the following works perfectly:
(edited to make context2 use context1's API too - as per Apple's ES programming guide, as per Pivot's comment)