Jump to content
  • Advertisement
Sign in to follow this  
littleeboy

OpenGL How to use glGetTexImage() in assistant thread to retrieve data of main thread

This topic is 3122 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 have a terrain rendering project. The terrain heightmap texture was modified in main thread. I want to use the glGetTexImage in another assistant thread to save the modified texture data. Unfortunally I am failed. The Project only has one window. Do I need two different opengl rendering contexts to solve my problem? I know the heightmap texture belong to the main thread, but how to get the data in another thread? I use Microsoft OS and OpenGL 3.0 programming language and Geforce 9 Card.

Share this post


Link to post
Share on other sites
Advertisement
OpenGL commands on a single context must be made from a single thread only. You can move contexts between threads, but they will only be active in exactly one thread at any time. The simplest way is to not multithread anything related to OpenGL, or just process it in some thread and pass it to the render thread before loading it in OpenGL.

Share this post


Link to post
Share on other sites
P-Buffers are the way to go if you want upload data asynchronously. Most of the other OpenGL operations are async. anyway such that there is really no need to call gl function from more than one thread.

Share this post


Link to post
Share on other sites
If you want to go async with OpenGL for retrieving/uploading pixel data, you could use Pixel Buffer Objects (PBOs). There are a couple of good PBO tutorials on the web, simply use Google to find them.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kambiz
P-Buffers are the way to go if you want upload data asynchronously. Most of the other OpenGL operations are async. anyway such that there is really no need to call gl function from more than one thread.


No, PBuffers don't do that, you probably confused them with Pixel Buffer Objects (PBOs), which do help in this case.

Share this post


Link to post
Share on other sites
Thanks,



I think I only need one render context. When I use wglMakeCurrent to sync between the two thread,I got the texture data.

My purpose is to alleviate the burden for saving the texture data to disk for my project.

I found even use assistant thread to save data, the project still "pause" one second to save data to disk.

Do I need use pbos to solve my problem?

Share this post


Link to post
Share on other sites
Quote:
Original post by littleeboy
I found even use assistant thread to save data, the project still "pause" one second to save data to disk.
There are two issues here: the time to read-back the texture into main memory, and the time to write it to disk.

The first is relatively straightforward to make asynchronous: read the texture into a pixel buffer object, and then a frame or two later, read it back to main memory.

However, I would wager that the second is the real show stopper performance-wise. Luckily file I/O can also be done asynchronously, either by writing on a secondary thread, or by using the API for asynchronous file access provided by your target platform(s).

Share this post


Link to post
Share on other sites
Quote:
Original post by littleeboy
If I use Pbos, then do you mean I donot need multithread any more,right?


If you use PBO, you do not need to multithread.
Even if you want to write to disk, you do not need to multithread since it should not consume CPU resources.

##I forgot to add that compressing to a format like jpeg would consume cpu obviously.

[Edited by - V-man on March 7, 2010 5:20:20 PM]

Share this post


Link to post
Share on other sites
Thanks v-man


In my original project, I use glGetTexImage2d to get data, then save to disk in PNG format.I found my rendering pause for a few second.

If I use pbos to get data, does this would solve the pause phenomen.

I do need to save data as PNG format, then I still mutithread,right?

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!