Module: Mesa
Branch: mesa_7_5_branch
Commit: 557421b6de9d8cba7e71828ec3a60a344fff9e88
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=557421b6de9d8cba7e71828ec3a60a344fff9e88

Author: José Fonseca <[email protected]>
Date:   Wed Jun 17 14:48:25 2009 +0100

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 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/progs/wgl/wglthreads/wglthreads.c 
b/progs/wgl/wglthreads/wglthreads.c
index 2f67dd6..405b5db 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;
       }
 

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to