iosopengl-escocos2d-iphoneglkview

Combining Cocos2d and GLKView to render the same data


I use cocos2d engine to render some animation to CCGLView which is placed on app main window next to regular UIViews. My application uses external screen and I would like to render on that screen exactly the same content as in CCGLView but without any other views. And I need to perform this operation in an efficient manner so taking screenshots of CCGLView is not an option.

As I understand there is no such option using cocos2d as It supports presenting only one scene at time (CCDirector updates only one CCGLView at time).

So my question is:

Is it possible to achieve this goal using GLKView? I have access to frame buffer object from CCGLView and I can read pixels from the buffer. I think that the best option would be to use cocos2d runloop and perform this operation next to regular cocos2d rendering. Unfortunately I don't know too much about openGLES and I don't know how I can achieve this. cocos2d uses openGLES 2.0.

Edit:

For now the only suggestion came from @s1ddok (thanks) and the idea is to use CCRenderTexture to draw into CCGLView placed on main window and use CCRenderTexture's data to render to the external window. But I still don't understand how I can render the texture for the second time - this time to another view. Using another CCGLView would require configuring this view as a target for CCDirector, how can I do that? Moreover second CCGLView will share EAGLContext with the first one... So how to force cocos2d to render to the second CCGLView? Any help is appreciated!


Solution

  • I guess the best way you can go is CCRenderTexture. Render the whole scene onto it and then display the data on external screen.

    It is a common practice for multiple purposes, for example, if you need to apply shader to a whole scene or something.

    This actually will allow you to render scene only once every frame, and then use the same data for UIKit and external screen.