PBuffer & MultiThread

I create an OpenGL App,the app create a new thread and create a pbuffer in that thread.My Windows OS is chinese version,and it has a chinese input app shipped with Windows.But when my app is running,if I run the chinese input app,my app is hung.I find the key is that I create a pbuffer not in main thread(if the pbuffer created in main thread,the problem is gone),so what’s the difference the pbuffer created in other thread than in main thread?Is it safe create some OpenGL objects in a new thread?

Note:My hardware & software environment is:
HW: P4 3.0G + NV 6800GT
SW: WINXP Simple Chinese Version+SP1+NV 71.89 driver

Are you using a dummy window to import the pbuffer functions? If so, do you create this dummy window in the “pbuffer thread” or in the “main thread”?

You should never do anything window related in a thread that doesn’t have a message queue (GetMessage/DispatchMessage or similar). Windows is designed in this (IMO severely broken) way.

You’re right, it should check to see if the current thread is the owner of the window, else determine which thread the window object is owned by and forward a message to it, and wait for the reply.

Originally posted by zeckensack:
[b]Are you using a dummy window to import the pbuffer functions? If so, do you create this dummy window in the “pbuffer thread” or in the “main thread”?

You should never do anything window related in a thread that doesn’t have a message queue (GetMessage/DispatchMessage or similar). Windows is designed in this (IMO severely broken) way.[/b]
Thanks Zeckensack,do you mean the key is that the window is not created in the pbuffer thread?I should create a window in pbuffer thread firstly,and then create the window render & pbuffer render,is it right?

Originally posted by pango:
Thanks Zeckensack,do you mean the key is that the window is not created in the pbuffer thread?I should create a window in pbuffer thread firstly,and then create the window render & pbuffer render,is it right?
No.
In fact I meant it the other way round: you should avoid creating a window in the pbuffer thread. It will force you to do (Windows) message processing, which you probably don’t want. Your main thread should handle everything that requires calling a Win32 function.

Please answer my questions! I need to know the answers to give you the right kind of advice.

If you’re using a dummy GL context that checks for the pbuffer extension, I’d split the responsibilities this way:
Main thread:
*modeswitch (optional, of course)
*open dummy window, create a GL context and make it current
*check presence of pbuffer extension, import the functions
*destroy GL context, close dummy window
NOTE: function pointers for pbuffer extensions are still valid
*create main render window
*start pbuffer thread
*run main loop:
**PeekMessage/DispatchMessage
**render

Pbuffer thread:
*make pbuffer
*pbuffer thread loop:
**render
**don’t touch any window, don’t process window messages

If you do not use the dummy GL context, the whole thing is much simpler, of course. The point is to not let Windows force you to do things you do not want to do.

Suggested reading .

Thanks zeckensack,I hadn’t create a window in the pbuffer thread,the window is created in main thread,but I create a render context (wglCreateContext()) using the window’s dc in that pbuffer thread,because it must has a context firstly before the thread create the pbuffer.It is said that I create a window in main thread,but I create a gl context in pbuffer thread using the window’s dc,so what’s problem of my idea?

What’s the mean of “dummy GL context” in your reply?

OK I’m also caring about the answer. As What i do is that Create a windows within main thread and pass the window handle via parameter into render thread and create gl context within render thread,it works.but I’ve never tried to use pbuffer - -’’