Multiple EAGLViews but only one copy of each texture - how?

走远了吗. 提交于 2019-12-05 19:42:55

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.

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:

EAGLShareGroup *group = [[EAGLShareGropu alloc] init];
EAGLContext *context1 = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:group];
EAGLContext *context2 = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:group];

HOWEVER, the following works perfectly:

EAGLContext *context1 = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
EAGLContext *context2 = [[EAGLContext alloc] initWithAPI:[context1 API] sharegroup:context1.sharegroup];

(edited to make context2 use context1's API too - as per Apple's ES programming guide, as per Pivot's comment)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!