DXGL r154 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r153‎ | r154 | r155 >
Date:00:55, 3 June 2012
Author:admin
Status:new
Tags:
Comment:
Make render window be owned by thread initializing DirectDraw. Removes CPU spikes when calling glRenderer functions.
Currently buggy, but less buggy than the last attempt and doesn't break Direct3D.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -206,16 +206,17 @@
207207 */
208208 glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, HWND hwnd, glDirectDraw7 *glDD7)
209209 {
210 - MSG Msg;
211 - wndbusy = false;
212210 hDC = NULL;
213211 hRC = NULL;
214212 PBO = 0;
 213+ dead = false;
215214 hasHWnd = false;
216215 dib.enabled = false;
217216 hWnd = hwnd;
218217 hRenderWnd = NULL;
219218 InitializeCriticalSection(&cs);
 219+ busy = CreateEvent(NULL,FALSE,FALSE,NULL);
 220+ start = CreateEvent(NULL,FALSE,FALSE,NULL);
220221 if(fullscreen)
221222 {
222223 SetWindowLongPtrA(hWnd,GWL_EXSTYLE,WS_EX_APPWINDOW);
@@ -227,6 +228,43 @@
228229 // TODO: Adjust window rect
229230 }
230231 SetWindowPos(hWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
 232+ if(!wndclasscreated)
 233+ {
 234+ wndclass.cbSize = sizeof(WNDCLASSEXA);
 235+ wndclass.style = 0;
 236+ wndclass.lpfnWndProc = RenderWndProc;
 237+ wndclass.cbClsExtra = 0;
 238+ wndclass.cbWndExtra = 0;
 239+ wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
 240+ wndclass.hIcon = NULL;
 241+ wndclass.hCursor = NULL;
 242+ wndclass.hbrBackground = NULL;
 243+ wndclass.lpszMenuName = NULL;
 244+ wndclass.lpszClassName = "DXGLRenderWindow";
 245+ wndclass.hIconSm = NULL;
 246+ RegisterClassExA(&wndclass);
 247+ wndclasscreated = true;
 248+ }
 249+ if(hDC) ReleaseDC(hRenderWnd,hDC);
 250+ if(hRenderWnd) DestroyWindow(hRenderWnd);
 251+ RECT rectRender;
 252+ GetClientRect(hWnd,&rectRender);
 253+ if(hWnd)
 254+ {
 255+ hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
 256+ rectRender.bottom - rectRender.top,hWnd,NULL,wndclass.hInstance,this);
 257+ hasHWnd = true;
 258+ SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
 259+ }
 260+ else
 261+ {
 262+ width = GetSystemMetrics(SM_CXSCREEN);
 263+ height = GetSystemMetrics(SM_CYSCREEN);
 264+ hRenderWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,
 265+ "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
 266+ hasHWnd = false;
 267+ SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW|SWP_NOACTIVATE);
 268+ }
231269 inputs[0] = (void*)width;
232270 inputs[1] = (void*)height;
233271 inputs[2] = (void*)bpp;
@@ -234,17 +272,8 @@
235273 inputs[4] = (void*)hWnd;
236274 inputs[5] = glDD7;
237275 inputs[6] = this;
238 - wndbusy = true;
239276 hThread = CreateThread(NULL,0,ThreadEntry,inputs,0,NULL);
240 - while(wndbusy)
241 - {
242 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
243 - {
244 - TranslateMessage(&Msg);
245 - DispatchMessage(&Msg);
246 - }
247 - Sleep(0);
248 - }
 277+ WaitForSingleObject(busy,INFINITE);
249278 }
250279
251280 /**
@@ -252,19 +281,12 @@
253282 */
254283 glRenderer::~glRenderer()
255284 {
256 - MSG Msg;
257285 EnterCriticalSection(&cs);
258 - wndbusy = true;
259 - SendMessage(hRenderWnd,GLEVENT_DELETE,0,0);
260 - while(wndbusy)
261 - {
262 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
263 - {
264 - TranslateMessage(&Msg);
265 - DispatchMessage(&Msg);
266 - }
267 - Sleep(0);
268 - }
 286+ opcode = OP_DELETE;
 287+ SetEvent(start);
 288+ WaitForSingleObject(busy,INFINITE);
 289+ CloseHandle(start);
 290+ CloseHandle(busy);
269291 LeaveCriticalSection(&cs);
270292 DeleteCriticalSection(&cs);
271293 }
@@ -310,7 +332,9 @@
311333 inputs[6] = (void*)texformat1;
312334 inputs[7] = (void*)texformat2;
313335 inputs[8] = (void*)texformat3;
314 - SendMessage(hRenderWnd,GLEVENT_CREATE,0,0);
 336+ opcode = OP_CREATE;
 337+ SetEvent(start);
 338+ WaitForSingleObject(busy,INFINITE);
315339 LeaveCriticalSection(&cs);
316340 return (GLuint)outputs[0];
317341 }
@@ -345,7 +369,6 @@
346370 int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3)
347371 {
348372 EnterCriticalSection(&cs);
349 - MSG Msg;
350373 inputs[0] = buffer;
351374 inputs[1] = bigbuffer;
352375 inputs[2] = (void*)texture;
@@ -359,17 +382,9 @@
360383 inputs[10] = (void*)texformat;
361384 inputs[11] = (void*)texformat2;
362385 inputs[12] = (void*)texformat3;
363 - wndbusy = true;
364 - SendMessage(hRenderWnd,GLEVENT_UPLOAD,0,0);
365 - while(wndbusy)
366 - {
367 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
368 - {
369 - TranslateMessage(&Msg);
370 - DispatchMessage(&Msg);
371 - }
372 - Sleep(0);
373 - }
 386+ opcode = OP_UPLOAD;
 387+ SetEvent(start);
 388+ WaitForSingleObject(busy,INFINITE);
374389 LeaveCriticalSection(&cs);
375390 }
376391
@@ -401,7 +416,6 @@
402417 int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2)
403418 {
404419 EnterCriticalSection(&cs);
405 - MSG Msg;
406420 inputs[0] = buffer;
407421 inputs[1] = bigbuffer;
408422 inputs[2] = (void*)texture;
@@ -414,17 +428,9 @@
415429 inputs[9] = (void*)bpp;
416430 inputs[10] = (void*)texformat;
417431 inputs[11] = (void*)texformat2;
418 - wndbusy = true;
419 - SendMessage(hRenderWnd,GLEVENT_DOWNLOAD,0,0);
420 - while(wndbusy)
421 - {
422 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
423 - {
424 - TranslateMessage(&Msg);
425 - DispatchMessage(&Msg);
426 - }
427 - Sleep(0);
428 - }
 432+ opcode = OP_DOWNLOAD;
 433+ SetEvent(start);
 434+ WaitForSingleObject(busy,INFINITE);
429435 LeaveCriticalSection(&cs);
430436 }
431437
@@ -437,7 +443,9 @@
438444 {
439445 EnterCriticalSection(&cs);
440446 inputs[0] = (void*)texture;
441 - SendMessage(hRenderWnd,GLEVENT_DELETETEX,0,0);
 447+ opcode = OP_DELETETEX;
 448+ SetEvent(start);
 449+ WaitForSingleObject(busy,INFINITE);
442450 LeaveCriticalSection(&cs);
443451 }
444452
@@ -467,8 +475,18 @@
468476 HRESULT glRenderer::Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
469477 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
470478 {
471 - MSG Msg;
472479 EnterCriticalSection(&cs);
 480+ RECT r,r2;
 481+ if(((dest->ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
 482+ (dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
 483+ ((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
 484+ !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
 485+ {
 486+ GetClientRect(hWnd,&r);
 487+ GetClientRect(hRenderWnd,&r2);
 488+ if(memcmp(&r2,&r,sizeof(RECT)))
 489+ SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
 490+ }
473491 inputs[0] = lpDestRect;
474492 inputs[1] = src;
475493 inputs[2] = dest;
@@ -475,17 +493,9 @@
476494 inputs[3] = lpSrcRect;
477495 inputs[4] = (void*)dwFlags;
478496 inputs[5] = lpDDBltFx;
479 - wndbusy = true;
480 - SendMessage(hRenderWnd,GLEVENT_BLT,0,0);
481 - while(wndbusy)
482 - {
483 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
484 - {
485 - TranslateMessage(&Msg);
486 - DispatchMessage(&Msg);
487 - }
488 - Sleep(0);
489 - }
 497+ opcode = OP_BLT;
 498+ SetEvent(start);
 499+ WaitForSingleObject(busy,INFINITE);
490500 LeaveCriticalSection(&cs);
491501 return (HRESULT)outputs[0];
492502 }
@@ -503,23 +513,14 @@
504514 */
505515 void glRenderer::DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
506516 {
507 - MSG Msg;
508517 EnterCriticalSection(&cs);
509518 inputs[0] = (void*)texture;
510519 inputs[1] = (void*)paltex;
511520 inputs[2] = dest;
512521 inputs[3] = src;
513 - wndbusy = true;
514 - SendMessage(hRenderWnd,GLEVENT_DRAWSCREEN,0,0);
515 - while(wndbusy)
516 - {
517 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
518 - {
519 - TranslateMessage(&Msg);
520 - DispatchMessage(&Msg);
521 - }
522 - Sleep(0);
523 - }
 522+ opcode = OP_DRAWSCREEN;
 523+ SetEvent(start);
 524+ WaitForSingleObject(busy,INFINITE);
524525 LeaveCriticalSection(&cs);
525526 }
526527
@@ -530,20 +531,10 @@
531532 */
532533 void glRenderer::InitD3D(int zbuffer)
533534 {
534 - MSG Msg;
535535 EnterCriticalSection(&cs);
536 - wndbusy = true;
537 - inputs[0] = (void*)zbuffer;
538 - SendMessage(hRenderWnd,GLEVENT_INITD3D,0,0);
539 - while(wndbusy)
540 - {
541 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
542 - {
543 - TranslateMessage(&Msg);
544 - DispatchMessage(&Msg);
545 - }
546 - Sleep(0);
547 - }
 536+ opcode = OP_INITD3D;
 537+ SetEvent(start);
 538+ WaitForSingleObject(busy,INFINITE);
548539 LeaveCriticalSection(&cs);
549540 }
550541
@@ -568,9 +559,7 @@
569560 */
570561 HRESULT glRenderer::Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
571562 {
572 - MSG Msg;
573563 EnterCriticalSection(&cs);
574 - wndbusy = true;
575564 inputs[0] = target;
576565 inputs[1] = (void*)dwCount;
577566 inputs[2] = lpRects;
@@ -578,38 +567,22 @@
579568 inputs[4] = (void*)dwColor;
580569 memcpy(&inputs[5],&dvZ,4);
581570 inputs[6] = (void*)dwStencil;
582 - SendMessage(hRenderWnd,GLEVENT_CLEAR,0,0);
583 - while(wndbusy)
584 - {
585 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
586 - {
587 - TranslateMessage(&Msg);
588 - DispatchMessage(&Msg);
589 - }
590 - Sleep(0);
591 - }
 571+ opcode = OP_CLEAR;
 572+ SetEvent(start);
 573+ WaitForSingleObject(busy,INFINITE);
592574 LeaveCriticalSection(&cs);
593575 return (HRESULT)outputs[0];
594576 }
595577
596578 /**
597 - * Flushes queued OpenGL commands to the GPU.
 579+ * Instructs the OpenGL driver to send all queued commands to the GPU.
598580 */
599581 void glRenderer::Flush()
600582 {
601 - MSG Msg;
602583 EnterCriticalSection(&cs);
603 - wndbusy = true;
604 - SendMessage(hRenderWnd,GLEVENT_FLUSH,0,0);
605 - while(wndbusy)
606 - {
607 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
608 - {
609 - TranslateMessage(&Msg);
610 - DispatchMessage(&Msg);
611 - }
612 - Sleep(0);
613 - }
 584+ opcode = OP_FLUSH;
 585+ SetEvent(start);
 586+ WaitForSingleObject(busy,INFINITE);
614587 LeaveCriticalSection(&cs);
615588 }
616589
@@ -642,9 +615,7 @@
643616 HRESULT glRenderer::DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
644617 DWORD indexcount, DWORD flags)
645618 {
646 - MSG Msg;
647619 EnterCriticalSection(&cs);
648 - wndbusy = true;
649620 inputs[0] = device;
650621 inputs[1] = (void*)mode;
651622 inputs[2] = vertices;
@@ -653,16 +624,9 @@
654625 inputs[5] = indices;
655626 inputs[6] = (void*)indexcount;
656627 inputs[7] = (void*)flags;
657 - SendMessage(hRenderWnd,GLEVENT_DRAWPRIMITIVES,0,0);
658 - while(wndbusy)
659 - {
660 - while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
661 - {
662 - TranslateMessage(&Msg);
663 - DispatchMessage(&Msg);
664 - }
665 - Sleep(0);
666 - }
 628+ opcode = OP_DRAWPRIMITIVES;
 629+ SetEvent(start);
 630+ WaitForSingleObject(busy,INFINITE);
667631 return (HRESULT)outputs[0];
668632 }
669633
@@ -673,14 +637,92 @@
674638 */
675639 DWORD glRenderer::_Entry()
676640 {
677 - MSG Msg;
 641+ float tmpfloats[16];
678642 EnterCriticalSection(&cs);
679643 _InitGL((int)inputs[0],(int)inputs[1],(int)inputs[2],(int)inputs[3],(HWND)inputs[4],(glDirectDraw7*)inputs[5]);
680644 LeaveCriticalSection(&cs);
681 - while(GetMessage(&Msg, NULL, 0, 0) > 0)
 645+ SetEvent(busy);
 646+ while(!dead)
682647 {
683 - TranslateMessage(&Msg);
684 - DispatchMessage(&Msg);
 648+ WaitForSingleObject(start,INFINITE);
 649+ switch(opcode)
 650+ {
 651+ case OP_DELETE:
 652+ if(hRC)
 653+ {
 654+ if(dib.enabled)
 655+ {
 656+ if(dib.hbitmap) DeleteObject(dib.hbitmap);
 657+ if(dib.hdc) DeleteDC(dib.hdc);
 658+ ZeroMemory(&dib,sizeof(DIB));
 659+ }
 660+ DeleteShaders();
 661+ DeleteFBO();
 662+ if(PBO)
 663+ {
 664+ glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
 665+ glDeleteBuffers(1,&PBO);
 666+ PBO = 0;
 667+ }
 668+ if(backbuffer)
 669+ {
 670+ glDeleteTextures(1,&backbuffer);
 671+ backbuffer = 0;
 672+ backx = 0;
 673+ backy = 0;
 674+ }
 675+ wglMakeCurrent(NULL,NULL);
 676+ wglDeleteContext(hRC);
 677+ };
 678+ if(hDC) ReleaseDC(hRenderWnd,hDC);
 679+ hDC = NULL;
 680+ DestroyWindow(hRenderWnd);
 681+ hRenderWnd = NULL;
 682+ SetEvent(busy);
 683+ dead = true;
 684+ break;
 685+ case OP_CREATE:
 686+ outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
 687+ (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8]);
 688+ break;
 689+ case OP_UPLOAD:
 690+ _UploadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
 691+ (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
 692+ (int)inputs[10],(int)inputs[11],(int)inputs[12]);
 693+ SetEvent(busy);
 694+ break;
 695+ case OP_DOWNLOAD:
 696+ _DownloadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
 697+ (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
 698+ (int)inputs[10],(int)inputs[11]);
 699+ SetEvent(busy);
 700+ break;
 701+ case OP_DELETETEX:
 702+ _DeleteTexture((GLuint)inputs[0]);
 703+ break;
 704+ case OP_BLT:
 705+ outputs[0] = (void*)_Blt((LPRECT)inputs[0],(glDirectDrawSurface7*)inputs[1],(glDirectDrawSurface7*)inputs[2],
 706+ (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
 707+ break;
 708+ case OP_DRAWSCREEN:
 709+ _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3],true);
 710+ break;
 711+ case OP_INITD3D:
 712+ _InitD3D((int)inputs[0]);
 713+ break;
 714+ case OP_CLEAR:
 715+ memcpy(&tmpfloats[0],&inputs[5],4);
 716+ _Clear((glDirectDrawSurface7*)inputs[0],(DWORD)inputs[1],(LPD3DRECT)inputs[2],(DWORD)inputs[3],(DWORD)inputs[4],
 717+ tmpfloats[0],(DWORD)inputs[6]);
 718+ break;
 719+ case OP_FLUSH:
 720+ _Flush();
 721+ break;
 722+ case OP_DRAWPRIMITIVES:
 723+ _DrawPrimitives((glDirect3DDevice7*)inputs[0],(GLenum)inputs[1],(GLVERTEX*)inputs[2],(int*)inputs[3],(DWORD)inputs[4],
 724+ (LPWORD)inputs[5],(DWORD)inputs[6],(DWORD)inputs[7]);
 725+ break;
 726+ }
685727 }
686728 return 0;
687729 }
@@ -704,43 +746,6 @@
705747 BOOL glRenderer::_InitGL(int width, int height, int bpp, int fullscreen, HWND hWnd, glDirectDraw7 *glDD7)
706748 {
707749 ddInterface = glDD7;
708 - if(!wndclasscreated)
709 - {
710 - wndclass.cbSize = sizeof(WNDCLASSEXA);
711 - wndclass.style = 0;
712 - wndclass.lpfnWndProc = RenderWndProc;
713 - wndclass.cbClsExtra = 0;
714 - wndclass.cbWndExtra = 0;
715 - wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
716 - wndclass.hIcon = NULL;
717 - wndclass.hCursor = NULL;
718 - wndclass.hbrBackground = NULL;
719 - wndclass.lpszMenuName = NULL;
720 - wndclass.lpszClassName = "DXGLRenderWindow";
721 - wndclass.hIconSm = NULL;
722 - RegisterClassExA(&wndclass);
723 - wndclasscreated = true;
724 - }
725 - if(hDC) ReleaseDC(hRenderWnd,hDC);
726 - if(hRenderWnd) DestroyWindow(hRenderWnd);
727 - RECT rectRender;
728 - GetClientRect(hWnd,&rectRender);
729 - if(hWnd)
730 - {
731 - hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
732 - rectRender.bottom - rectRender.top,hWnd,NULL,wndclass.hInstance,this);
733 - hasHWnd = true;
734 - SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
735 - }
736 - else
737 - {
738 - width = GetSystemMetrics(SM_CXSCREEN);
739 - height = GetSystemMetrics(SM_CYSCREEN);
740 - hRenderWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,
741 - "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
742 - hasHWnd = false;
743 - SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW|SWP_NOACTIVATE);
744 - }
745750 if(hRC)
746751 {
747752 wglMakeCurrent(NULL,NULL);
@@ -793,7 +798,6 @@
794799 gllock = false;
795800 return FALSE;
796801 }
797 - wndbusy = false;
798802 gllock = false;
799803 InitGLExt();
800804 SetSwap(1);
@@ -844,18 +848,6 @@
845849 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
846850 {
847851 LONG sizes[6];
848 - RECT r,r2;
849 - if(((dest->ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
850 - (dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
851 - ((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
852 - !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
853 - {
854 - GetClientRect(hWnd,&r);
855 - GetClientRect(hRenderWnd,&r2);
856 - if(memcmp(&r2,&r,sizeof(RECT)))
857 - SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
858 - }
859 - wndbusy = false;
860852 ddInterface->GetSizes(sizes);
861853 int error;
862854 error = SetFBO(dest->texture,0,false);
@@ -995,7 +987,8 @@
996988 if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
997989 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
998990 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
999 - !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest);
 991+ !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest,false);
 992+ SetEvent(busy);
1000993 return DD_OK;
1001994 }
1002995
@@ -1009,6 +1002,7 @@
10101003 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,(GLfloat)wraps);
10111004 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,(GLfloat)wrapt);
10121005 glTexImage2D(GL_TEXTURE_2D,0,texformat3,width,height,0,texformat1,texformat2,NULL);
 1006+ SetEvent(busy);
10131007 return texture;
10141008 }
10151009
@@ -1056,7 +1050,7 @@
10571051 SetFBO(0,0,false);
10581052 }
10591053
1060 -void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
 1054+void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, bool setsync)
10611055 {
10621056 RECT r,r2;
10631057 if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
@@ -1066,7 +1060,6 @@
10671061 if(memcmp(&r2,&r,sizeof(RECT)))
10681062 SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
10691063 }
1070 - wndbusy = false;
10711064 RECT *viewrect = &r2;
10721065 SetSwap(swapinterval);
10731066 LONG sizes[6];
@@ -1210,6 +1203,7 @@
12111204 SelectObject(dib.hdc,hPrevObj);
12121205 ::ReleaseDC(hRenderWnd,hRenderDC);
12131206 }
 1207+ if(setsync) SetEvent(busy);
12141208
12151209 }
12161210
@@ -1216,11 +1210,12 @@
12171211 void glRenderer::_DeleteTexture(GLuint texture)
12181212 {
12191213 glDeleteTextures(1,&texture);
 1214+ SetEvent(busy);
12201215 }
12211216
12221217 void glRenderer::_InitD3D(int zbuffer)
12231218 {
1224 - wndbusy = false;
 1219+ SetEvent(busy);
12251220 glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
12261221 GLfloat ambient[] = {0.0,0.0,0.0,0.0};
12271222 if(zbuffer) glEnable(GL_DEPTH_TEST);
@@ -1234,11 +1229,11 @@
12351230 {
12361231 outputs[0] = (void*)DDERR_INVALIDPARAMS;
12371232 FIXME("glDirect3DDevice7::Clear: Cannot clear rects yet.");
1238 - wndbusy = false;
 1233+ SetEvent(busy);
12391234 return;
12401235 }
12411236 outputs[0] = (void*)D3D_OK;
1242 - wndbusy = false;
 1237+ SetEvent(busy);
12431238 GLfloat color[4];
12441239 dwordto4float(dwColor,color);
12451240 if(target->zbuffer) SetFBO(target->texture,target->GetZBuffer()->texture,target->GetZBuffer()->hasstencil);
@@ -1266,7 +1261,7 @@
12671262
12681263 void glRenderer::_Flush()
12691264 {
1270 - wndbusy = false;
 1265+ SetEvent(busy);
12711266 glFlush();
12721267 }
12731268
@@ -1284,7 +1279,7 @@
12851280 if(!vertices[0].data)
12861281 {
12871282 outputs[0] = (void*)DDERR_INVALIDPARAMS;
1288 - wndbusy = false;
 1283+ SetEvent(busy);
12891284 return;
12901285 }
12911286 __int64 shader = device->SelectShader(vertices);
@@ -1455,7 +1450,7 @@
14561451 device->glDDS7->dirty |= 2;
14571452 if(flags & D3DDP_WAIT) glFlush();
14581453 outputs[0] = (void*)D3D_OK;
1459 - wndbusy = false;
 1454+ SetEvent(busy);
14601455 return;
14611456 }
14621457
@@ -1463,7 +1458,6 @@
14641459 {
14651460 int oldx,oldy;
14661461 float mulx, muly;
1467 - float tmpfloats[16];
14681462 int translatex, translatey;
14691463 LPARAM newpos;
14701464 HWND hParent;
@@ -1475,35 +1469,6 @@
14761470 SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this);
14771471 return 0;
14781472 case WM_DESTROY:
1479 - if(hRC)
1480 - {
1481 - if(dib.enabled)
1482 - {
1483 - if(dib.hbitmap) DeleteObject(dib.hbitmap);
1484 - if(dib.hdc) DeleteDC(dib.hdc);
1485 - ZeroMemory(&dib,sizeof(DIB));
1486 - }
1487 - DeleteShaders();
1488 - DeleteFBO();
1489 - if(PBO)
1490 - {
1491 - glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
1492 - glDeleteBuffers(1,&PBO);
1493 - PBO = 0;
1494 - }
1495 - if(backbuffer)
1496 - {
1497 - glDeleteTextures(1,&backbuffer);
1498 - backbuffer = 0;
1499 - backx = 0;
1500 - backy = 0;
1501 - }
1502 - wglMakeCurrent(NULL,NULL);
1503 - wglDeleteContext(hRC);
1504 - };
1505 - if(hDC) ReleaseDC(hRenderWnd,hDC);
1506 - hDC = NULL;
1507 - wndbusy = false;
15081473 PostQuitMessage(0);
15091474 return 0;
15101475 case WM_SETCURSOR:
@@ -1548,50 +1513,6 @@
15491514 return SendMessage(hParent,msg,wParam,newpos);
15501515 }
15511516 else return SendMessage(hParent,msg,wParam,lParam);
1552 - case GLEVENT_DELETE:
1553 - DestroyWindow(hRenderWnd);
1554 - return 0;
1555 - case GLEVENT_CREATE:
1556 - outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
1557 - (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8]);
1558 - return 0;
1559 - case GLEVENT_UPLOAD:
1560 - _UploadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
1561 - (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
1562 - (int)inputs[10],(int)inputs[11],(int)inputs[12]);
1563 - wndbusy = false;
1564 - return 0;
1565 - case GLEVENT_DOWNLOAD:
1566 - _DownloadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
1567 - (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
1568 - (int)inputs[10],(int)inputs[11]);
1569 - wndbusy = false;
1570 - return 0;
1571 - case GLEVENT_DELETETEX:
1572 - _DeleteTexture((GLuint)inputs[0]);
1573 - return 0;
1574 - case GLEVENT_BLT:
1575 - outputs[0] = (void*)_Blt((LPRECT)inputs[0],(glDirectDrawSurface7*)inputs[1],(glDirectDrawSurface7*)inputs[2],
1576 - (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
1577 - return 0;
1578 - case GLEVENT_DRAWSCREEN:
1579 - _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
1580 - return 0;
1581 - case GLEVENT_INITD3D:
1582 - _InitD3D((int)inputs[0]);
1583 - return 0;
1584 - case GLEVENT_CLEAR:
1585 - memcpy(&tmpfloats[0],&inputs[5],4);
1586 - _Clear((glDirectDrawSurface7*)inputs[0],(DWORD)inputs[1],(LPD3DRECT)inputs[2],(DWORD)inputs[3],(DWORD)inputs[4],
1587 - tmpfloats[0],(DWORD)inputs[6]);
1588 - return 0;
1589 - case GLEVENT_FLUSH:
1590 - _Flush();
1591 - return 0;
1592 - case GLEVENT_DRAWPRIMITIVES:
1593 - _DrawPrimitives((glDirect3DDevice7*)inputs[0],(GLenum)inputs[1],(GLVERTEX*)inputs[2],(int*)inputs[3],(DWORD)inputs[4],
1594 - (LPWORD)inputs[5],(DWORD)inputs[6],(DWORD)inputs[7]);
1595 - return 0;
15961517 default:
15971518 return DefWindowProc(hwnd,msg,wParam,lParam);
15981519 }
Index: ddraw/glRenderer.h
@@ -52,18 +52,18 @@
5353
5454 extern BltVertex bltvertices[4];
5555
56 -#define GLEVENT_NULL WM_USER
57 -#define GLEVENT_DELETE WM_USER+1
58 -#define GLEVENT_CREATE WM_USER+2
59 -#define GLEVENT_UPLOAD WM_USER+3
60 -#define GLEVENT_DOWNLOAD WM_USER+4
61 -#define GLEVENT_DELETETEX WM_USER+5
62 -#define GLEVENT_BLT WM_USER+6
63 -#define GLEVENT_DRAWSCREEN WM_USER+7
64 -#define GLEVENT_INITD3D WM_USER+8
65 -#define GLEVENT_CLEAR WM_USER+9
66 -#define GLEVENT_FLUSH WM_USER+10
67 -#define GLEVENT_DRAWPRIMITIVES WM_USER+11
 56+#define OP_NULL 0
 57+#define OP_DELETE 1
 58+#define OP_CREATE 2
 59+#define OP_UPLOAD 3
 60+#define OP_DOWNLOAD 4
 61+#define OP_DELETETEX 5
 62+#define OP_BLT 6
 63+#define OP_DRAWSCREEN 7
 64+#define OP_INITD3D 8
 65+#define OP_CLEAR 9
 66+#define OP_FLUSH 10
 67+#define OP_DRAWPRIMITIVES 11
6868
6969
7070 extern int swapinterval;
@@ -103,7 +103,7 @@
104104 HRESULT _Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
105105 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
106106 GLuint _MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
107 - void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
 107+ void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, bool setsync);
108108 void _DeleteTexture(GLuint texture);
109109 void _DrawBackbuffer(GLuint *texture, int x, int y);
110110 void _InitD3D(int zbuffer);
@@ -112,10 +112,10 @@
113113 DWORD indexcount, DWORD flags);
114114 glDirectDraw7 *ddInterface;
115115 void _Flush();
 116+ int opcode;
116117 void* inputs[32];
117118 void* outputs[32];
118119 HANDLE hThread;
119 - bool wndbusy;
120120 HDC hDC;
121121 HWND hWnd;
122122 HWND hRenderWnd;
@@ -123,6 +123,9 @@
124124 DIB dib;
125125 GLuint PBO;
126126 CRITICAL_SECTION cs;
 127+ HANDLE busy;
 128+ HANDLE start;
 129+ bool dead;
127130 };
128131
129132 #endif //_GLRENDERER_H
\ No newline at end of file