OpenGL and multithread

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!

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 ?

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.

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!

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?

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.

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!

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

Dude ur addressing urself.

Can you be more specific about ur problem ?

Where can I get thread programming tutorials using opengl and c++

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.