Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: PBuffer & MultiThread

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jan 2003
    Location
    Shanghai,China
    Posts
    202

    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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,633

    Re: PBuffer & MultiThread

    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.

  3. #3
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    2,833

    Re: PBuffer & MultiThread

    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.
    Knackered

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jan 2003
    Location
    Shanghai,China
    Posts
    202

    Re: PBuffer & MultiThread

    Originally posted by zeckensack:
    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.
    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?

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,633

    Re: PBuffer & MultiThread

    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 .

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jan 2003
    Location
    Shanghai,China
    Posts
    202

    Re: PBuffer & MultiThread

    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?

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2005
    Posts
    4

    Re: PBuffer & MultiThread

    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 - -''

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •