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.
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.