Combining-OpenGL-ES-Cocos2d functionality -and-OpenGL-ES-(Unity 3d) navigation--within-iOS-app

I am developing an app that is able to run a Unity 3d navigation within it using a UnityAppController and pause it when not using the navigation. The main app also have another engine i.e cocos2d where i have other functionality.

Now issue is that 3d navigation is working only if cocos2d(uses OpenGL-es) functionality is not used, once i used cocos2d functionality & again came back to the 3d navigaton it appears to be frozen. Here is my App delegate(inherits from unity AppController class) where i am handling unity pause & play

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

[super application:application didFinishLaunchingWithOptions:launchOptions];


self.unityVC = [self getRootController];

UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:[UIColor colorWithRed:108.0/255 green:106.0/255 blue:55.0/255 alpha:1]];
[button setTitle:@"DONE" forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setFrame:frame];
[button addTarget:self action:@selector(Fn_RemoveUnity) forControlEvents:UIControlEventTouchUpInside];
[_rootView addSubview:button];
[_rootView bringSubviewToFront:button];


//Default ViewController Code
//--------------------------------------------------------
//    self.window =  [UIApplication sharedApplication].keyWindow;

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

    [self Fn_AddMainScreen];

[self.window makeKeyAndVisible];
//--------------------------------------------------------

    return YES;
 }

 - (void)playUnity
 {

    [self unityPause:NO];
 }

 - (void)pauseUnity
 {
    [self unityPause:YES];

 }

 -(void) Fn_AddUnity{
    [window setHidden:YES];
    [self playUnity];
 }

 -(void) Fn_RemoveUnity{
    [self pauseUnity];
    [window setHidden:NO];
    [self Fn_AddMainScreen];
 }

Here is cocos2d code

EAGLView *glView = [EAGLView viewWithFrame:CGRectMake(md.glview_X,md.glview_Y,md.glview_Width,md.glview_Height)
                               pixelFormat:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                               depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                               preserveBackbuffer:YES sharegroup:nil multiSampling:NO numberOfSamples:nil
                    ];

glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[[CCDirector sharedDirector] setProjection:CCDirectorProjection2D];
[glView setContentScaleFactor:1.0];
[[CCDirector sharedDirector]  enableRetinaDisplay:YES];
[[CCDirector sharedDirector] setOpenGLView:glView];
[self.view insertSubview:glView atIndex:0];
[[CCDirector sharedDirector] runWithScene: [smoothningEffect scene]];

Answers


There can only be one OpenGL context active at any time, so you have to fully shut down either engine when you switch between them. Even then, both engines weren't designed to be cooperating with other render engines, so it may as well prove impossible.

For example caching mechanisms may be a problem, in particular because cocos2d uses Singletons all over the place to keep things cached in memory. I would attempt to make sure that all the essential cocos2d Singleton classes are released from memory before switching back to Unity.

The question here is rather why you would even want to mix two separate render engines in the first place? For one, Unity has a 2D toolset in itself. So your time is better invested by researching how to do whatever you need to do in 2D with Unity's own 2D toolset, or by emulating 2D in Unity's 3D renderer as many other games have done successfully in the past.


Need Your Help

Issues with async receiving UDP Unicast packets in Windows Phone 7

c# sockets windows-phone-7 asynchronous udp

I'm trying to get my Windows Phone 7 Mango app to listen to incoming UDP packets but having a heck of a time. I have the new Beta 2 refresh of the Windows Phone 7.1 SDK and dev tools installed. Any