Sharing Rendering Context, Multithreading

Hi,

My question is simple, how i can share a share a display list between the main process and one of his thread. I using the Windows environment with MFC.

There is the call wglShareLists(…) i know, but in the Thread, made with the AfxBeginThread(…) i can’t define any redering context there is no HDC possible to retrive.

My goal is to have a thread how write in the display list of the father process.

Someone can help me, i’ll apreciate.

Sharelists is for sharing resources between contexts - as you only have one context, this doesn’t count. However, I’m not sure exactly what you are trying to do in this case. do you have a main process and a thread, both wanting to render to the same render context?

If you want your thread to do the rendering, create the render context and window within that thread.

What I’m try to do, is Sharing the Rendering context and the Display list beetween the father process and his thread.

So, the thread and the father process write in the same rendering Context, it’s possible to do ?

Ex : if the thread change the display list, the display list of the father process is change.

By the way, the father process do the drawing by calling the display list.

Set up a render context in your thread, then use wglsharelists to share display lists between the “father” process and your thread. Assume you will need 2 render contexts in this case - even if you never execute a swap on the second process.

Personally, I cannot see the benefits of doing this - but its one solution.

The Gurus will probably come up with others!

I what to use the Thread in the set-up of the main application(father process)

The worker thread will feed the display list of the father process.

But i can’t find any way to retrive a HDC from the process.

Perhaps the process can’t have a rendering context?

I use the CWinTread class in MFC

GetDC(HWND) will give you the HDC of the window (presumably you have the window handle for your dialog - or you at least know how to get it).

I am wondering if you mean what you are saying by

The worker thread will feed the display list of the father process.

I think what you mean is you want to update the display buffer from the child threads.

Display lists are essentially pre-compiled sets of instructions for OpenGL whereas it looks like you want a child thread to update the display buffer of a Window that is created by the “father” thread.

I think he meant what he said (generate display lists in the child thread, execute them in the parent thread).

By the way, you should be aware that when each thread has its own rendering context, OpenGL context switches will effectively occur as often as thread context switches occur (which is very frequently, in the order of 20-100 times per second I think). Since OpenGL context switches are costly (requires complete update of gfx hardware state), this technique can potentially degrade the performance of your application.