Quote:
Originally Posted by axlsd
Hello everybody,
my application has a NSTimer for rendering, I want to load my textures and other data in a parallel thread while timer renders a loading screen.
My problem is:
if I try to create a texture2d (using a code very similiar to crash landing example) starting an NSThread, glGenTextures call freezes my application and I can understand why..
Any help is appreciated, thanks.
|
I actually got this working, but it's a big pain. What you're dealing with is the fact that your texture thread doesn't have an OpenGL context. You can create a new one for it, but then any texture you create in that context won't be shared between that context and your main thread's context. You have to use something called an EAGLSharegroup to link the contexts together so they can share resources. You can do this by changing your EAGLView code to initialize its context like this:
Code:
EAGLSharegroup *sharegroup = [[EAGLSharegroup alloc] init];
context = [[EAGLContext alloc] initWithAPI:EAGLRenderingAPIOpenGLES1 sharegroup:sharegroup];
Once this is done, go into your thread and create a context using the above call with the same sharegroup. You'll have to initialize the context with whatever OpenGL initializations you want, but you should be able to get it to work.
Note:
This code does not work in the Simulator. The EAGLContext initialization with a sharegroup crashes the Simulator. The code does, however, work on the device itself, so keep that in mind. I'd opened a bug report regarding this bug, 6367125, and currently it is in the Open state.