7

My main view controller contains many sub-views. One such subview is a GLKView linked up to a GLKViewController. The GLKViewController seems to be the one in charge of updating the GLKView's display, and something automagical is calling that update function on the main thread.

One of my other views in this main view controller is a UITableView. When the user is interacting with the table view, the GLKView stops updating.

I'll admit, I am pretty new to OGL ES programming, so I'm not sure how to approach this. I need to get the GLKViewController's

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect;

method to be called on a separate thread from the main thread, so I can keep the GLKView animating while the user is interacting with other elements.

Dan F
  • 17,654
  • 5
  • 72
  • 110
  • The problem with this is the way that apple has it set up I'm pretty sure all GLES calls have to come from the main thread... so... IDK man... I never tried to use a table over GLES before :-/ I'll look into it if I have time later! – Matthew Clark Jan 08 '13 at 02:55
  • What sort of interactions are they doing with the UITableView? Does that take a long time to process their inputs? – Liron Jan 10 '13 at 12:40
  • @Liron as soon as the user starts scrolling the tableview, the `GLKView` does not update until the table has stopped scrolling – Dan F Jan 10 '13 at 14:12
  • @DanF Hmmm. I'll try and think about it more later. Nothing is immediately coming to mind. – Liron Jan 10 '13 at 14:24
  • Did you ever make progress on this? – user3344977 Oct 17 '16 at 14:43
  • @user3344977, unfortunately, no. I have since moved on from that company – Dan F Oct 17 '16 at 22:42

2 Answers2

2

GLKViewController is using a CADisplayLink to call update/draw at a frequency which matches your display refresh rate. When your tableview/scrollview starts tracking a touch, the run loop starts giving it all the priority. You may have to split out your own GLKView and CADisplayLink (instead of using GLKViewController), in order to modify the run loop mode of the CADisplayLink so that it will keep going even if the tableview/scrollview is tracking touches. See this discussion for more info:

Community
  • 1
  • 1
mattorb
  • 3,075
  • 3
  • 22
  • 16
0

This is tricky, I didn't find a good way of doing it and I am sure there are better ways, but for me performance weren't a huge problem so I settled for it. I don't have a complete solution and it's not solving the problem in the way you asked for (i.e. by threading the rendering) but perhaps something that might be worth looking at at least. If I can come up with a better solution I will update it, but for now this is all I've got.

The way I did it is that I actually have a transparent ViewController "on top" of the glkViewController, and anything that I want to interact with on top of the GLKViewController (such as tablesViews, buttons, and pretty much UI stuff) is added to that.

The way I do this is that I have a singleton object for my view controller called OverlayViewController which I found helpful since I want to access it easily from anywhere, don't know if that would fit into your design but it made sense for me. And this is added in the GLKViewController::viewWillAppear selector.

And that really is all the magic. So I have a overlay view which is playing host to any IOKit-type objects. I add it like this (easier to just paste my viewWillAppear: from my GLKViewController subclass)

- (void) viewWillAppear: (BOOL) animated {
    [[[OverlayViewController shared] view] setUserInteractionEnabled:NO];
    [self.parentViewController.view addSubview: [[OverlayViewController shared] view]];
    ...
}

this basically mean that there will be two views controllers which you see but they are "independent" of each other.

There are obvious problems with this approach however, such as the tedious work of keeping track of which view will currently accept user interaction, since they are on top of each other this isn't handled.

So with that said I am looking into if it's possible to dispatch a thread dedicated to rendering in GLKit.

qrikko
  • 2,483
  • 2
  • 22
  • 35
  • Not sure how this solves the updating problem. All it seems to do is manage interactivity, and that portion I am not at all having a problem with. My `GLKView` and `UITableView` are completely separated on the screen, and I have no problems getting them to interact independently from each other. The problem is as soon as I start interacting with the table view, `drawInRect` stops being called on my `GLKViewController`, and therefore, my spinning model stops spinning – Dan F Jan 04 '13 at 15:07