Jump to content
  • Advertisement
Sign in to follow this  
skow

Loading textures in a win32 thread?

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I’m trying to create a threaded texture manager. When I want to load a texture on the fly, I spawn a thread, load the texture in that thread, and then kill the thread. Is there any way to give the thread the same context as the parent program? That way I don’t have to create a new context, and when the thread dies the contetx/textures are killed too.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by skow
Is there any way to give the thread the same context as the parent program? That way I don’t have to create a new context, and when the thread dies the contetx/textures are killed too.

There's ::wglShareLists() but it only works for 'merging' contexts of single process... perhaps you could modify your manager so the separate thread just loads/prepares the data as needed, and then the main program builds the texture out of it when it finds it convenient..?

Share this post


Link to post
Share on other sites
I have tried doing just the loading on the process, and there was too long of a pause when creating a texture from that data, so I really need to find a way to both load and create on the thread.

Share this post


Link to post
Share on other sites
I had the same problem a while ago but everybody said its impossible, so i split the loading into memory and the linking to opengl part and it works for me.
A second thread creates a second rendering context which does not share anything.

Aidamina,

Share this post


Link to post
Share on other sites
Quote:
Original post by Aidamina
so i split the loading into memory and the linking to opengl part and it works for me.
Aidamina,


I'm sorry, i dont understand, could you explain it a little please?

Share this post


Link to post
Share on other sites
Well create a thread that loads the image file.

And let the w32 main thread check if its done while it loops
after that do the opengl calls. Like these:



glGenTextures(1, &TextureList[id].texID);
glBindTexture(GL_TEXTURE_2D, TextureList[id].texID);
glTexImage2D(GL_TEXTURE_2D, 0, TextureList[id].bpp / 8, TextureList[id].width, TextureList[id].height, 0, TextureList[id].type, GL_UNSIGNED_BYTE, TextureList[id].imageData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);



Note this code wont work on your program since i copy pasted it from my own texture manager.

fixed your code tags as it was breaking the forums width, please be more carefull in future

[Edited by - _the_phantom_ on June 26, 2005 6:37:49 AM]

Share this post


Link to post
Share on other sites
Opengl is not thread safe by default. So texture creation is likely to fail.
Cant rember how to make ogl thread safe though cause I gave up.

Texture creation is usually done in a preeprocess phase anyway though and stored as compressed DXT* dd surfaces.

Share this post


Link to post
Share on other sites
Ahh that is what im currently doing aidamina, im still not happy with it :(

Share this post


Link to post
Share on other sites
Quote:
Original post by skow
Ahh that is what im currently doing aidamina, im still not happy with it :(


Why? You do realize that seperate threads are for CPU, not GPU, right? You can't except from the card to render a sphere in one thread and carry out a glTexImage2D() command in the other.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!