Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAOpenGLLayer displaying remote Context

I have a sub-classed CAOpenGLLayer class which overrides drawInCGLContext there I draw a rectangle with OpenGL. The CAOpenGLLayer is added to a CALayer and shown.

So when I would like to draw something I would need to do it in drawInCGLContext with this architecture.

What I would like to have is a sort of context used by an other class to draw, animate or render to but will be displayed every time drawInCGLContext occurs.

So basically the only thing my subclass should do is display a remote (OpenGL)context, what's the best way to achieve this? Or should I consider a different approach?

*Not using a CALayer is not an option.

like image 901
Johan_ Avatar asked Nov 08 '11 14:11

Johan_


1 Answers

Have you considered using a frame buffer object (FBO)? You can create one which is backed by a texture. Your "remote" drawing class could draw into the FBO, which will cause the drawing to go to the texture that backs it. You can then use that texture elsewhere, like blitting it to the screen in your CAOpenGLLayer subclass. See this link for details of how to use an FBO.

like image 93
user1118321 Avatar answered Oct 15 '22 06:10

user1118321