问题
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.
回答1:
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:
回答2:
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.
来源:https://stackoverflow.com/questions/13653113/multithreading-glkview-drawing