diff options
author | Alex Deucher <alexdeucher@gmail.com> | 2009-07-15 14:17:07 -0400 |
---|---|---|
committer | Alex Deucher <alexdeucher@gmail.com> | 2009-07-15 14:17:07 -0400 |
commit | c5c19919ce627b98d8aab4284da1694573bcccd4 (patch) | |
tree | 2e29b313b79b6a392e020fd5723e3cc00c800fd2 /progs/wgl | |
parent | a0d4a12614fce072fa1eb5516e626909171c95e1 (diff) | |
parent | 3a3b83e5112b725e22f05b32a273a2351b820944 (diff) |
Merge branch 'master' of git+ssh://agd5f@git.freedesktop.org/git/mesa/mesa into r6xx-rewrite
This builds, but I get an assertion in radeonGetLock() due to
the drawable being null.
Diffstat (limited to 'progs/wgl')
-rw-r--r-- | progs/wgl/sharedtex_mt/sharedtex_mt.c | 30 | ||||
-rw-r--r-- | progs/wgl/wglthreads/wglthreads.c | 64 |
2 files changed, 66 insertions, 28 deletions
diff --git a/progs/wgl/sharedtex_mt/sharedtex_mt.c b/progs/wgl/sharedtex_mt/sharedtex_mt.c index 010eb873b8..779e15001d 100644 --- a/progs/wgl/sharedtex_mt/sharedtex_mt.c +++ b/progs/wgl/sharedtex_mt/sharedtex_mt.c @@ -50,6 +50,7 @@ struct window { float Angle; int Id; HGLRC sharedContext; + HANDLE hEventInitialised; }; @@ -414,6 +415,10 @@ threadRunner (void *arg) Error("Couldn't obtain HDC"); } + /* Wait for the previous thread */ + if(tia->id > 0) + WaitForSingleObject(Windows[tia->id - 1].hEventInitialised, INFINITE); + pfd.cColorBits = 24; pfd.cDepthBits = 24; pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; @@ -434,9 +439,16 @@ threadRunner (void *arg) } if (win->sharedContext) { - wglShareLists(win->sharedContext, win->Context); + if(!wglShareLists(win->sharedContext, win->Context)) + Error("Couldn't share WGL context lists"); } + SetEvent(win->hEventInitialised); + + /* Wait for all threads to initialize otherwise wglShareLists will fail */ + if(tia->id < NumWindows - 1) + WaitForSingleObject(Windows[NumWindows - 1].hEventInitialised, INFINITE); + SendMessage(win->Win, WM_SIZE, 0, 0); while (1) { @@ -511,20 +523,26 @@ main(int argc, char *argv[]) h[2] = AddWindow( 10, 350, gCtx); h[3] = AddWindow(330, 350, gCtx); - if (!wglMakeCurrent(gHDC, gCtx)) { - Error("wglMakeCurrent failed for init thread."); - return -1; + for (i = 0; i < NumWindows; i++) { + Windows[i].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL); } - InitGLstuff(); - for (i = 0; i < NumWindows; i++) { DWORD id; tia[i].id = i; threads[i] = CreateThread(NULL, 0, threadRunner, &tia[i], 0, &id); + + WaitForSingleObject(Windows[i].hEventInitialised, INFINITE); + } + + if (!wglMakeCurrent(gHDC, gCtx)) { + Error("wglMakeCurrent failed for init thread."); + return -1; } + InitGLstuff(); + while (1) { MSG msg; diff --git a/progs/wgl/wglthreads/wglthreads.c b/progs/wgl/wglthreads/wglthreads.c index 9ca7f025dc..27dca10f2a 100644 --- a/progs/wgl/wglthreads/wglthreads.c +++ b/progs/wgl/wglthreads/wglthreads.c @@ -72,6 +72,7 @@ struct winthread { int WinWidth, WinHeight; GLboolean NewSize; HANDLE hEventInitialised; + GLboolean Initialized; GLboolean MakeNewTexture; HANDLE hEventRedraw; }; @@ -114,20 +115,20 @@ static void MakeNewTexture(struct winthread *wt) { #define TEX_SIZE 128 - static float step = 0.0; + static float step = 0.0f; GLfloat image[TEX_SIZE][TEX_SIZE][4]; GLint width; int i, j; for (j = 0; j < TEX_SIZE; j++) { for (i = 0; i < TEX_SIZE; i++) { - float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; - float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; + float dt = 5.0f * (j - 0.5f * TEX_SIZE) / TEX_SIZE; + float ds = 5.0f * (i - 0.5f * TEX_SIZE) / TEX_SIZE; float r = dt * dt + ds * ds + step; image[j][i][0] = image[j][i][1] = - image[j][i][2] = 0.75 + 0.25 * cos(r); - image[j][i][3] = 1.0; + image[j][i][2] = 0.75f + 0.25f * (float) cos(r); + image[j][i][3] = 1.0f; } } @@ -159,7 +160,7 @@ static void draw_object(void) { glPushMatrix(); - glScalef(0.75, 0.75, 0.75); + glScalef(0.75f, 0.75f, 0.75f); glColor3f(1, 0, 0); @@ -288,6 +289,15 @@ draw_loop(struct winthread *wt) wglMakeCurrent(wt->hDC, wt->Context); + if (!wt->Initialized) { + printf("wglthreads: %d: GL_RENDERER = %s\n", wt->Index, + (char *) glGetString(GL_RENDERER)); + if (Texture /*&& wt->Index == 0*/) { + MakeNewTexture(wt); + } + wt->Initialized = GL_TRUE; + } + if (Locking) LeaveCriticalSection(&Mutex); @@ -315,13 +325,15 @@ draw_loop(struct winthread *wt) glPushMatrix(); glRotatef(wt->Angle, 0, 1, 0); glRotatef(wt->Angle, 1, 0, 0); - glScalef(0.7, 0.7, 0.7); + glScalef(0.7f, 0.7f, 0.7f); draw_object(); glPopMatrix(); if (Locking) EnterCriticalSection(&Mutex); + SwapBuffers(wt->hDC); + if (Locking) LeaveCriticalSection(&Mutex); @@ -433,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, @@ -471,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 */ @@ -482,14 +495,6 @@ create_window(struct winthread *wt, HGLRC shareCtx) wt->WinWidth = width; wt->WinHeight = height; wt->NewSize = GL_TRUE; - - wglMakeCurrent(hdc, ctx); - printf("wglthreads: %d: GL_RENDERER = %s\n", wt->Index, (char *) glGetString(GL_RENDERER)); - wglMakeCurrent(NULL, NULL); - - if (Texture/* && wt->Index == 0*/) { - MakeNewTexture(wt); - } } @@ -502,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; } @@ -539,6 +556,7 @@ main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0) { usage(); + exit(0); } else if (strcmp(argv[i], "-l") == 0) { Locking = 1; @@ -588,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, @@ -603,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; } |