PDA

View Full Version : OpenGL and multithread



Bumbala
10-03-2005, 02:35 AM
Hi!

I continuously generate and delete textures. If I do this on a single thread, the app runs slow. So that, I want the generating to be done on a separate thread and drawing on the main thread. Can anyone give me some hints or examples on that? I use AfxBeginThread to start a thread, then what?

Thanks!

dimensionX
10-03-2005, 07:37 AM
If you generate and delete textures on the fly certainly you will see performance drop. What exactly do you want to do, can you be more specific ?

Bumbala
10-03-2005, 09:40 AM
I view large tiled-tiff images using OpenGL. When you pan the view, the tiles outside the viewport are deleted and the new ones are generated. To increase the performance I want to generate textures in a separate thread. The rendering part will be on the main thread.

dimensionX
10-03-2005, 03:49 PM
Read the specification of "wglMakeCurrent", this will help. It says you cannot make the same context current simultaneously in two different threads.

If you have to create textures in one thread while rendering in the main thread, how would you make the same context current in both threads ? It's just not possible.

A possible solution:-
1) Create two different rendering contexts
2) Draw in one context
3) Create textures in another context
4) Share resources (Textures, etc...) between the two rendering contexts using "wglShareLists"

Hope this helps!

Bumbala
10-03-2005, 09:45 PM
According to what I read on the web, I cannot render and load textures at the same time. Each one has to wait for the other. I guess the best solution will be to read image to raw data on the memory in separate thread and do the OpenGL stuff on the main thread.

What is the fastest way to generate textures? I use glTexImage2D, is there any other that that?

Omaha
10-03-2005, 10:01 PM
glTexImage2D performs the actual upload from client memory to server texture memory, or today usually from system memory to video memory, drivers/circumstances permitting.

Short of procedural texture coordinate lookup (which would probably require a texture to be loaded anyway) or plain vertex coloring, I think the glTexImage* calls are the only ways to get data into texture memory.

dimensionX
10-04-2005, 02:28 PM
Originally posted by Omaha:
glTexImage2D performs the actual upload from client memory to server texture memory, or today usually from system memory to video memory, drivers/circumstances permitting.It depends entirely on the driver when the data is downloaded into texture memory.


Originally posted by Omaha:
Short of procedural texture coordinate lookup (which would probably require a texture to be loaded anyway) or plain vertex coloring, I think the glTexImage* calls are the only ways to get data into texture memory.You would think so!

10-10-2005, 11:08 PM
Dear Rajesh,

I am also facing similar problem relating to multithreading of texture rendering.

I am developing my application with Windows console project Setting. What is the alternative for wglMakeCurrent.

With regards
Rajesh.R
IRIS
Bangalore

dimensionX
10-11-2005, 07:16 AM
Dude ur addressing urself.

Can you be more specific about ur problem ?

10-12-2005, 09:07 PM
Where can I get thread programming tutorials using opengl and c++

dimensionX
10-14-2005, 07:27 AM
Rajesh,

Google but even there it is hard to find tutorials on Multithreading + OpenGL.

Read the specification of wglMakeCurrent + wglSwapBuffers on MSDN. They have some information on how to use the above calls in a multithreaded environment. Added to this you need Win32 Threads which also you can find it on MSDN. That's how I learned.