wglShareLists multi-threaded

  • Follow


I've seen this question posted but with no satisfying answer.  Your
help would be greatly appreciated!

Basically, I want to share a texture between two threads (in the same
process) each with their own render context.  My platform is Win2K,
OpenGL 2, NVidia FX 4000.  The details are as follows.

I have a thread which has a render context and is constantly rendering.
 In my main application (which is the second thread) I would like to
load textures to be used by my rendering thread.  The main application
has it's own render context and uses glBindTexture and
gluBuild2DMipmaps to load the texture.  In order to share the texture
between the two render contexts I use wglShareLists.

I can get wglShareList to work properly if I put both the rendering
hglrc and the texture-loading hglrc in the same thread, call
wglShareLists, and activate the rendering hglrc when I am rendering and
the texture-loading hglrc when I am loading.  However, I need the
rendering and loading in separate threads.

When I use separate threads I get the Windows error: "The requested
resource is in use."  This a typical Windows threading error message.

0
Reply jgeduldig (4) 10/7/2005 1:52:55 PM

jgeduldig@gmail.com wrote:
> 
> When I use separate threads I get the Windows error: "The requested
> resource is in use."  This a typical Windows threading error message.
> 

It should work. Maybe you have a bug in your code.



-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

In science it often happens that scientists say, 'You know
that's a really good argument; my position is mistaken,'
and then they actually change their minds and you never
hear that old view from them again.  They really do it.
It doesn't happen as often as it should, because scientists
are human and change is sometimes painful.  But it happens
every day.  I cannot recall the last time something like
that happened in politics or religion.

- Carl Sagan, 1987 CSICOP keynote address

0
Reply fungus 10/7/2005 2:55:05 PM


I made a new example.  This one has two windows.  Each window is
rendered by a separate thread.  Each thread has its own render context.
 Both threads are created by the main application.  Each window has a
texture loaded.

Now, instead, lets say I want to load a texture into thread1 and share
it with thread2.

1. Who should call wglShareLists?  The main app, thread1, thread2, or
any of the above?

2. When I inspect the value of the render context handle, it is NULL
everywhere except inside the thread that owns the handle.  How do I
pass this handle to the caller of wglShareLists?

0
Reply jgeduldig 10/7/2005 6:13:49 PM

jgeduldig@gmail.com wrote:
> I made a new example.  This one has two windows.  Each window is
> rendered by a separate thread.  Each thread has its own render context.
>  Both threads are created by the main application.  Each window has a
> texture loaded.
> 
> Now, instead, lets say I want to load a texture into thread1 and share
> it with thread2.
> 
> 1. Who should call wglShareLists?  The main app, thread1, thread2, or
> any of the above?
> 

Doesn't matter. The only thing is you have
to do it before you create any textures, etc.
in a context you want to share.

> 2. When I inspect the value of the render context handle, it is NULL
> everywhere except inside the thread that owns the handle.  How do I
> pass this handle to the caller of wglShareLists?
> 

That's not good....this may be your problem.


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

In science it often happens that scientists say, 'You know
that's a really good argument; my position is mistaken,'
and then they actually change their minds and you never
hear that old view from them again.  They really do it.
It doesn't happen as often as it should, because scientists
are human and change is sometimes painful.  But it happens
every day.  I cannot recall the last time something like
that happened in politics or religion.

- Carl Sagan, 1987 CSICOP keynote address

0
Reply fungus 10/7/2005 6:25:54 PM

Finally figured this out!  Calling wglShareLists at the right time was
critical.  This worked for me...

1. app creates thread and the app's rc
2. thread creates its rc and deactivates the rc
3. app calls wglShareLists
4. thread activates rc
5. thread starts render loop
6. app loads textures

0
Reply jgeduldig 10/9/2005 3:47:49 AM

4 Replies
253 Views

(page loaded in 0.354 seconds)


Reply: