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

Started by
9 comments, last by V-man 14 years, 1 month ago
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.
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.
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.
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.
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.
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?
If I use Pbos, then do you mean I donot need multithread any more,right?
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).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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]
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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?

This topic is closed to new replies.

Advertisement