summaryrefslogtreecommitdiff
path: root/progs/wgl/wglthreads/wglthreads.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/wgl/wglthreads/wglthreads.c')
-rw-r--r--progs/wgl/wglthreads/wglthreads.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/progs/wgl/wglthreads/wglthreads.c b/progs/wgl/wglthreads/wglthreads.c
index 1a8219ccc9..27dca10f2a 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);
@@ -443,7 +445,7 @@ create_window(struct winthread *wt, HGLRC shareCtx)
win = CreateWindowEx(0,
wc.lpszClassName,
"wglthreads",
- WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TILEDWINDOW,
xpos,
ypos,
width,
@@ -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 the previous thread */
+ if(Texture && wt->Index > 0) {
+ WaitForSingleObject(WinThreads[wt->Index - 1].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;
}