Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-07-2008, 07:47 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 7
Default Loading Texture2d on parallel thread

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.
axlsd is offline   Reply With Quote
Old 12-09-2008, 08:59 AM   #2 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 10
Default

Quote:
Originally Posted by axlsd View Post
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.
nuudles is offline   Reply With Quote
Old 12-10-2008, 04:23 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 7
Default

Thanks for the answer..
you are right.. it seems a really big pain.

For now I skip the glGenTex error calling the initWithData function in the first draw call and not on parallel thread.. I think this is not the better solution.. but works pretty well.

glGenTex seems fast enough so I can posticipate it at first draw.
axlsd is offline   Reply With Quote
Old 12-10-2008, 11:40 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 50
Default

Why don't you just swap buffers every once you load a new texture?
This will allow you to draw a smooth enough loading bar.
jaguard is offline   Reply With Quote
Old 04-16-2009, 05:35 PM   #5 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 1
Default

Quote:
Originally Posted by jaguard View Post
Why don't you just swap buffers every once you load a new texture?
This will allow you to draw a smooth enough loading bar.
Because having loading on a separate thread allows you to be loading in textures while the game itself is running, rather than a loading screen. Which means bypassing loading screens altogether, where possible.

Thanks everyone for this thread by the way, it's been extremely useful :-)
joephish is offline   Reply With Quote
Old 02-06-2010, 12:27 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 2
Default A simple idea

I got around this issue by doing this before creating the textures:
Code:
[EAGLContext setCurrentContext:[my current context in EAGLView]];
It seems to work fine (in the Simulator as well as the device). Does anybody know if this could potentially cause problems?

Last edited by csmartdalton; 02-06-2010 at 12:29 PM.
csmartdalton is offline   Reply With Quote
Old 02-10-2010, 03:21 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 2
Default

Quote:
Originally Posted by csmartdalton View Post
I got around this issue by doing this before creating the textures:
Code:
[EAGLContext setCurrentContext:[my current context in EAGLView]];
It seems to work fine (in the Simulator as well as the device). Does anybody know if this could potentially cause problems?
Never mind. Don't do this! It turns out to be a very bad idea. Your never know what state the other thread has the context in - is it drawing, updating the state, etc.? I ended up loading and decompressing the image file in the worker thread and just doing final calls to glGenTextures() and glTexImage2D() in the main thread.
csmartdalton is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Online Users: 384
24 members and 360 guests
AdamSubach, anonymous@, benoitr007, bensj, Danneman, Duncan C, gtyt38, gustavo7sexton, HemiMG, Jeremy1026, lifeCoder45, maxus182, mox, Ovidius, Paul10, pofak, raheel, Sega dude, squidboy, timle8n1, ufbobbo, ultrayard077
Most users ever online was 965, 06-30-2010 at 04:26 AM.
» Stats
Members: 41,860
Threads: 49,768
Posts: 213,052
Top Poster: BrianSlick (3,138)
Welcome to our newest member, gustavo7sexton
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0