From 557421b6de9d8cba7e71828ec3a60a344fff9e88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 17 Jun 2009 14:48:25 +0100 Subject: [PATCH] progs/wgl: Get wglShareLists working in wglthreads. wglShareLists is a little picky -- it seems to check if it has exclusive access to a lock, and fails if it doesn't. This allows the texture to be shared with all windows. --- progs/wgl/wglthreads/wglthreads.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/progs/wgl/wglthreads/wglthreads.c b/progs/wgl/wglthreads/wglthreads.c index 2f67dd670f2..405b5db8842 100644 --- a/progs/wgl/wglthreads/wglthreads.c +++ b/progs/wgl/wglthreads/wglthreads.c @@ -331,7 +331,9 @@ draw_loop(struct winthread *wt) if (Locking) EnterCriticalSection(&Mutex); + SwapBuffers(wt->hDC); + if (Locking) LeaveCriticalSection(&Mutex); @@ -481,7 +483,8 @@ create_window(struct winthread *wt, HGLRC shareCtx) } if (shareCtx) { - wglShareLists(shareCtx, ctx); + if(!wglShareLists(shareCtx, ctx)) + Error("Couldn't share WGL context lists"); } /* save the info for this window/context */ @@ -504,10 +507,22 @@ ThreadProc(void *p) struct winthread *wt = (struct winthread *) p; HGLRC share; + /* Wait for first thread context */ + if(Texture && wt->Index > 0) { + WaitForSingleObject(WinThreads[0].hEventInitialised, INFINITE); + share = WinThreads[0].Context; + } + else + share = 0; + share = (Texture && wt->Index > 0) ? WinThreads[0].Context : 0; create_window(wt, share); SetEvent(wt->hEventInitialised); + /* Wait for all threads to initialize otherwise wglShareLists will fail */ + if(wt->Index < NumWinThreads - 1) + WaitForSingleObject(WinThreads[NumWinThreads - 1].hEventInitialised, INFINITE); + draw_loop(wt); return 0; } @@ -591,13 +606,17 @@ main(int argc, char *argv[]) printf("wglthreads: creating threads\n"); - /* Create the threads */ + /* Create the events */ for (i = 0; i < NumWinThreads; i++) { - DWORD id; - WinThreads[i].Index = i; WinThreads[i].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL); WinThreads[i].hEventRedraw = CreateEvent(NULL, FALSE, FALSE, NULL); + } + + /* Create the threads */ + for (i = 0; i < NumWinThreads; i++) { + DWORD id; + WinThreads[i].Thread = CreateThread(NULL, 0, ThreadProc, @@ -606,8 +625,6 @@ main(int argc, char *argv[]) &id); printf("wglthreads: Created thread %p\n", (void *) WinThreads[i].Thread); - WaitForSingleObject(WinThreads[i].hEventInitialised, INFINITE); - threads[i] = WinThreads[i].Thread; } -- 2.30.2