AkademiksQc AkademiksQc - 1 year ago 132
iOS Question

Unable to display 2 GLKViewController at the same time

I am building an app that is required to show to opengl views, one fullscreen and the other one smaller as an overlay. The two views represent 2 completely different apps.

Right now it seems I can't have two EAGLContext/Framebuffers displaying at the same time; I always end up with the "Failed to make complete framebuffer object 8cd6" error message.

I need to implement the 2 gl views using two different implementations :

1- Use 2 GLKViewControllers at the same time on the same screen

Hi, i have read some solution for this problem, mostly people says that you just need to use view controller containment but i tried without luck. With my setup, I have one EAGLContext per glview...I also tried to use a single context for both.
Here is my setup for the first GLKViewController's viewDidLoad() method:

- (void)viewDidLoad
[super viewDidLoad];

self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

if (!self.context) {
NSLog(@"Failed to create ES context");

GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;

[self setupGL];

// Add the sub glkviewcontroller
subViewController = [[SubGLControllerViewController alloc] init];

[self addChildViewController:subViewController];
[self.view addSubview:subViewController.view];
[subViewController didMoveToParentViewController:self];

I have basically the same code for the SubGLControllerViewController but without the add sub view controller...

2- In my second implementation I need to create my framebuffers manually without using a glkviewcontroller like this :

// Create the MAIN FBO.
glGenFramebuffers(1, &mainFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, mainFramebuffer);

glGenRenderbuffers(1, &mainColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, mainColorRenderbuffer);

[mainContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];


// Create the secondary FBO
glGenFramebuffers(1, &secondaryFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, secondaryFramebuffer);

glGenRenderbuffers(1, &secondaryColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, secondaryColorRenderbuffer);

[secondaryContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];


// This status will fail at this point...if i remove either the main or secondary //framebuffer, the status is valid
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

Answer Source

As for the first try I wouldn't even count on it to be able to work.

The second one though has only 1 problem: you use the same layer twice. As you said you want 2 views with openGL, so create 2 views and use the layer of each.

As for the contexts I would suggest you do only use 1 and that you do all the GL work strictly on a single thread, for instance creating a NSTimer in a view controller that will "on fire" call draw methods of both views and remember you need to bind the frame buffer each time you switch the view you wish to draw onto.

Just to note, in general it would seem to be best to avoid multiple views with openGL. There is nothing you can't handle with 1 view and in most cases to achieve 2 windows all you need to do is call another glViewport to draw to another part of a view.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download