Index: ddraw/glRenderer.cpp |
— | — | @@ -206,16 +206,17 @@ |
207 | 207 | */
|
208 | 208 | glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, HWND hwnd, glDirectDraw7 *glDD7)
|
209 | 209 | {
|
210 | | - MSG Msg;
|
211 | | - wndbusy = false;
|
212 | 210 | hDC = NULL;
|
213 | 211 | hRC = NULL;
|
214 | 212 | PBO = 0;
|
| 213 | + dead = false;
|
215 | 214 | hasHWnd = false;
|
216 | 215 | dib.enabled = false;
|
217 | 216 | hWnd = hwnd;
|
218 | 217 | hRenderWnd = NULL;
|
219 | 218 | InitializeCriticalSection(&cs);
|
| 219 | + busy = CreateEvent(NULL,FALSE,FALSE,NULL);
|
| 220 | + start = CreateEvent(NULL,FALSE,FALSE,NULL);
|
220 | 221 | if(fullscreen)
|
221 | 222 | {
|
222 | 223 | SetWindowLongPtrA(hWnd,GWL_EXSTYLE,WS_EX_APPWINDOW);
|
— | — | @@ -227,6 +228,43 @@ |
228 | 229 | // TODO: Adjust window rect
|
229 | 230 | }
|
230 | 231 | 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 | + }
|
231 | 269 | inputs[0] = (void*)width;
|
232 | 270 | inputs[1] = (void*)height;
|
233 | 271 | inputs[2] = (void*)bpp;
|
— | — | @@ -234,17 +272,8 @@ |
235 | 273 | inputs[4] = (void*)hWnd;
|
236 | 274 | inputs[5] = glDD7;
|
237 | 275 | inputs[6] = this;
|
238 | | - wndbusy = true;
|
239 | 276 | 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);
|
249 | 278 | }
|
250 | 279 |
|
251 | 280 | /**
|
— | — | @@ -252,19 +281,12 @@ |
253 | 282 | */
|
254 | 283 | glRenderer::~glRenderer()
|
255 | 284 | {
|
256 | | - MSG Msg;
|
257 | 285 | 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);
|
269 | 291 | LeaveCriticalSection(&cs);
|
270 | 292 | DeleteCriticalSection(&cs);
|
271 | 293 | }
|
— | — | @@ -310,7 +332,9 @@ |
311 | 333 | inputs[6] = (void*)texformat1;
|
312 | 334 | inputs[7] = (void*)texformat2;
|
313 | 335 | inputs[8] = (void*)texformat3;
|
314 | | - SendMessage(hRenderWnd,GLEVENT_CREATE,0,0);
|
| 336 | + opcode = OP_CREATE;
|
| 337 | + SetEvent(start);
|
| 338 | + WaitForSingleObject(busy,INFINITE);
|
315 | 339 | LeaveCriticalSection(&cs);
|
316 | 340 | return (GLuint)outputs[0];
|
317 | 341 | }
|
— | — | @@ -345,7 +369,6 @@ |
346 | 370 | int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3)
|
347 | 371 | {
|
348 | 372 | EnterCriticalSection(&cs);
|
349 | | - MSG Msg;
|
350 | 373 | inputs[0] = buffer;
|
351 | 374 | inputs[1] = bigbuffer;
|
352 | 375 | inputs[2] = (void*)texture;
|
— | — | @@ -359,17 +382,9 @@ |
360 | 383 | inputs[10] = (void*)texformat;
|
361 | 384 | inputs[11] = (void*)texformat2;
|
362 | 385 | 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);
|
374 | 389 | LeaveCriticalSection(&cs);
|
375 | 390 | }
|
376 | 391 |
|
— | — | @@ -401,7 +416,6 @@ |
402 | 417 | int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2)
|
403 | 418 | {
|
404 | 419 | EnterCriticalSection(&cs);
|
405 | | - MSG Msg;
|
406 | 420 | inputs[0] = buffer;
|
407 | 421 | inputs[1] = bigbuffer;
|
408 | 422 | inputs[2] = (void*)texture;
|
— | — | @@ -414,17 +428,9 @@ |
415 | 429 | inputs[9] = (void*)bpp;
|
416 | 430 | inputs[10] = (void*)texformat;
|
417 | 431 | 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);
|
429 | 435 | LeaveCriticalSection(&cs);
|
430 | 436 | }
|
431 | 437 |
|
— | — | @@ -437,7 +443,9 @@ |
438 | 444 | {
|
439 | 445 | EnterCriticalSection(&cs);
|
440 | 446 | inputs[0] = (void*)texture;
|
441 | | - SendMessage(hRenderWnd,GLEVENT_DELETETEX,0,0);
|
| 447 | + opcode = OP_DELETETEX;
|
| 448 | + SetEvent(start);
|
| 449 | + WaitForSingleObject(busy,INFINITE);
|
442 | 450 | LeaveCriticalSection(&cs);
|
443 | 451 | }
|
444 | 452 |
|
— | — | @@ -467,8 +475,18 @@ |
468 | 476 | HRESULT glRenderer::Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
469 | 477 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
470 | 478 | {
|
471 | | - MSG Msg;
|
472 | 479 | 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 | + }
|
473 | 491 | inputs[0] = lpDestRect;
|
474 | 492 | inputs[1] = src;
|
475 | 493 | inputs[2] = dest;
|
— | — | @@ -475,17 +493,9 @@ |
476 | 494 | inputs[3] = lpSrcRect;
|
477 | 495 | inputs[4] = (void*)dwFlags;
|
478 | 496 | 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);
|
490 | 500 | LeaveCriticalSection(&cs);
|
491 | 501 | return (HRESULT)outputs[0];
|
492 | 502 | }
|
— | — | @@ -503,23 +513,14 @@ |
504 | 514 | */
|
505 | 515 | void glRenderer::DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
|
506 | 516 | {
|
507 | | - MSG Msg;
|
508 | 517 | EnterCriticalSection(&cs);
|
509 | 518 | inputs[0] = (void*)texture;
|
510 | 519 | inputs[1] = (void*)paltex;
|
511 | 520 | inputs[2] = dest;
|
512 | 521 | 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);
|
524 | 525 | LeaveCriticalSection(&cs);
|
525 | 526 | }
|
526 | 527 |
|
— | — | @@ -530,20 +531,10 @@ |
531 | 532 | */
|
532 | 533 | void glRenderer::InitD3D(int zbuffer)
|
533 | 534 | {
|
534 | | - MSG Msg;
|
535 | 535 | 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);
|
548 | 539 | LeaveCriticalSection(&cs);
|
549 | 540 | }
|
550 | 541 |
|
— | — | @@ -568,9 +559,7 @@ |
569 | 560 | */
|
570 | 561 | HRESULT glRenderer::Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
|
571 | 562 | {
|
572 | | - MSG Msg;
|
573 | 563 | EnterCriticalSection(&cs);
|
574 | | - wndbusy = true;
|
575 | 564 | inputs[0] = target;
|
576 | 565 | inputs[1] = (void*)dwCount;
|
577 | 566 | inputs[2] = lpRects;
|
— | — | @@ -578,38 +567,22 @@ |
579 | 568 | inputs[4] = (void*)dwColor;
|
580 | 569 | memcpy(&inputs[5],&dvZ,4);
|
581 | 570 | 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);
|
592 | 574 | LeaveCriticalSection(&cs);
|
593 | 575 | return (HRESULT)outputs[0];
|
594 | 576 | }
|
595 | 577 |
|
596 | 578 | /**
|
597 | | - * Flushes queued OpenGL commands to the GPU.
|
| 579 | + * Instructs the OpenGL driver to send all queued commands to the GPU.
|
598 | 580 | */
|
599 | 581 | void glRenderer::Flush()
|
600 | 582 | {
|
601 | | - MSG Msg;
|
602 | 583 | 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);
|
614 | 587 | LeaveCriticalSection(&cs);
|
615 | 588 | }
|
616 | 589 |
|
— | — | @@ -642,9 +615,7 @@ |
643 | 616 | HRESULT glRenderer::DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
644 | 617 | DWORD indexcount, DWORD flags)
|
645 | 618 | {
|
646 | | - MSG Msg;
|
647 | 619 | EnterCriticalSection(&cs);
|
648 | | - wndbusy = true;
|
649 | 620 | inputs[0] = device;
|
650 | 621 | inputs[1] = (void*)mode;
|
651 | 622 | inputs[2] = vertices;
|
— | — | @@ -653,16 +624,9 @@ |
654 | 625 | inputs[5] = indices;
|
655 | 626 | inputs[6] = (void*)indexcount;
|
656 | 627 | 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);
|
667 | 631 | return (HRESULT)outputs[0];
|
668 | 632 | }
|
669 | 633 |
|
— | — | @@ -673,14 +637,92 @@ |
674 | 638 | */
|
675 | 639 | DWORD glRenderer::_Entry()
|
676 | 640 | {
|
677 | | - MSG Msg;
|
| 641 | + float tmpfloats[16];
|
678 | 642 | EnterCriticalSection(&cs);
|
679 | 643 | _InitGL((int)inputs[0],(int)inputs[1],(int)inputs[2],(int)inputs[3],(HWND)inputs[4],(glDirectDraw7*)inputs[5]);
|
680 | 644 | LeaveCriticalSection(&cs);
|
681 | | - while(GetMessage(&Msg, NULL, 0, 0) > 0)
|
| 645 | + SetEvent(busy);
|
| 646 | + while(!dead)
|
682 | 647 | {
|
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 | + }
|
685 | 727 | }
|
686 | 728 | return 0;
|
687 | 729 | }
|
— | — | @@ -704,43 +746,6 @@ |
705 | 747 | BOOL glRenderer::_InitGL(int width, int height, int bpp, int fullscreen, HWND hWnd, glDirectDraw7 *glDD7)
|
706 | 748 | {
|
707 | 749 | 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 | | - }
|
745 | 750 | if(hRC)
|
746 | 751 | {
|
747 | 752 | wglMakeCurrent(NULL,NULL);
|
— | — | @@ -793,7 +798,6 @@ |
794 | 799 | gllock = false;
|
795 | 800 | return FALSE;
|
796 | 801 | }
|
797 | | - wndbusy = false;
|
798 | 802 | gllock = false;
|
799 | 803 | InitGLExt();
|
800 | 804 | SetSwap(1);
|
— | — | @@ -844,18 +848,6 @@ |
845 | 849 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
846 | 850 | {
|
847 | 851 | 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;
|
860 | 852 | ddInterface->GetSizes(sizes);
|
861 | 853 | int error;
|
862 | 854 | error = SetFBO(dest->texture,0,false);
|
— | — | @@ -995,7 +987,8 @@ |
996 | 988 | if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
|
997 | 989 | (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
|
998 | 990 | ((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);
|
1000 | 993 | return DD_OK;
|
1001 | 994 | }
|
1002 | 995 |
|
— | — | @@ -1009,6 +1002,7 @@ |
1010 | 1003 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,(GLfloat)wraps);
|
1011 | 1004 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,(GLfloat)wrapt);
|
1012 | 1005 | glTexImage2D(GL_TEXTURE_2D,0,texformat3,width,height,0,texformat1,texformat2,NULL);
|
| 1006 | + SetEvent(busy);
|
1013 | 1007 | return texture;
|
1014 | 1008 | }
|
1015 | 1009 |
|
— | — | @@ -1056,7 +1050,7 @@ |
1057 | 1051 | SetFBO(0,0,false);
|
1058 | 1052 | }
|
1059 | 1053 |
|
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)
|
1061 | 1055 | {
|
1062 | 1056 | RECT r,r2;
|
1063 | 1057 | if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
|
— | — | @@ -1066,7 +1060,6 @@ |
1067 | 1061 | if(memcmp(&r2,&r,sizeof(RECT)))
|
1068 | 1062 | SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
|
1069 | 1063 | }
|
1070 | | - wndbusy = false;
|
1071 | 1064 | RECT *viewrect = &r2;
|
1072 | 1065 | SetSwap(swapinterval);
|
1073 | 1066 | LONG sizes[6];
|
— | — | @@ -1210,6 +1203,7 @@ |
1211 | 1204 | SelectObject(dib.hdc,hPrevObj);
|
1212 | 1205 | ::ReleaseDC(hRenderWnd,hRenderDC);
|
1213 | 1206 | }
|
| 1207 | + if(setsync) SetEvent(busy);
|
1214 | 1208 |
|
1215 | 1209 | }
|
1216 | 1210 |
|
— | — | @@ -1216,11 +1210,12 @@ |
1217 | 1211 | void glRenderer::_DeleteTexture(GLuint texture)
|
1218 | 1212 | {
|
1219 | 1213 | glDeleteTextures(1,&texture);
|
| 1214 | + SetEvent(busy);
|
1220 | 1215 | }
|
1221 | 1216 |
|
1222 | 1217 | void glRenderer::_InitD3D(int zbuffer)
|
1223 | 1218 | {
|
1224 | | - wndbusy = false;
|
| 1219 | + SetEvent(busy);
|
1225 | 1220 | glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
|
1226 | 1221 | GLfloat ambient[] = {0.0,0.0,0.0,0.0};
|
1227 | 1222 | if(zbuffer) glEnable(GL_DEPTH_TEST);
|
— | — | @@ -1234,11 +1229,11 @@ |
1235 | 1230 | {
|
1236 | 1231 | outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
1237 | 1232 | FIXME("glDirect3DDevice7::Clear: Cannot clear rects yet.");
|
1238 | | - wndbusy = false;
|
| 1233 | + SetEvent(busy);
|
1239 | 1234 | return;
|
1240 | 1235 | }
|
1241 | 1236 | outputs[0] = (void*)D3D_OK;
|
1242 | | - wndbusy = false;
|
| 1237 | + SetEvent(busy);
|
1243 | 1238 | GLfloat color[4];
|
1244 | 1239 | dwordto4float(dwColor,color);
|
1245 | 1240 | if(target->zbuffer) SetFBO(target->texture,target->GetZBuffer()->texture,target->GetZBuffer()->hasstencil);
|
— | — | @@ -1266,7 +1261,7 @@ |
1267 | 1262 |
|
1268 | 1263 | void glRenderer::_Flush()
|
1269 | 1264 | {
|
1270 | | - wndbusy = false;
|
| 1265 | + SetEvent(busy);
|
1271 | 1266 | glFlush();
|
1272 | 1267 | }
|
1273 | 1268 |
|
— | — | @@ -1284,7 +1279,7 @@ |
1285 | 1280 | if(!vertices[0].data)
|
1286 | 1281 | {
|
1287 | 1282 | outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
1288 | | - wndbusy = false;
|
| 1283 | + SetEvent(busy);
|
1289 | 1284 | return;
|
1290 | 1285 | }
|
1291 | 1286 | __int64 shader = device->SelectShader(vertices);
|
— | — | @@ -1455,7 +1450,7 @@ |
1456 | 1451 | device->glDDS7->dirty |= 2;
|
1457 | 1452 | if(flags & D3DDP_WAIT) glFlush();
|
1458 | 1453 | outputs[0] = (void*)D3D_OK;
|
1459 | | - wndbusy = false;
|
| 1454 | + SetEvent(busy);
|
1460 | 1455 | return;
|
1461 | 1456 | }
|
1462 | 1457 |
|
— | — | @@ -1463,7 +1458,6 @@ |
1464 | 1459 | {
|
1465 | 1460 | int oldx,oldy;
|
1466 | 1461 | float mulx, muly;
|
1467 | | - float tmpfloats[16];
|
1468 | 1462 | int translatex, translatey;
|
1469 | 1463 | LPARAM newpos;
|
1470 | 1464 | HWND hParent;
|
— | — | @@ -1475,35 +1469,6 @@ |
1476 | 1470 | SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this);
|
1477 | 1471 | return 0;
|
1478 | 1472 | 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;
|
1508 | 1473 | PostQuitMessage(0);
|
1509 | 1474 | return 0;
|
1510 | 1475 | case WM_SETCURSOR:
|
— | — | @@ -1548,50 +1513,6 @@ |
1549 | 1514 | return SendMessage(hParent,msg,wParam,newpos);
|
1550 | 1515 | }
|
1551 | 1516 | 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;
|
1596 | 1517 | default:
|
1597 | 1518 | return DefWindowProc(hwnd,msg,wParam,lParam);
|
1598 | 1519 | }
|
Index: ddraw/glRenderer.h |
— | — | @@ -52,18 +52,18 @@ |
53 | 53 |
|
54 | 54 | extern BltVertex bltvertices[4];
|
55 | 55 |
|
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
|
68 | 68 |
|
69 | 69 |
|
70 | 70 | extern int swapinterval;
|
— | — | @@ -103,7 +103,7 @@ |
104 | 104 | HRESULT _Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
105 | 105 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
|
106 | 106 | 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);
|
108 | 108 | void _DeleteTexture(GLuint texture);
|
109 | 109 | void _DrawBackbuffer(GLuint *texture, int x, int y);
|
110 | 110 | void _InitD3D(int zbuffer);
|
— | — | @@ -112,10 +112,10 @@ |
113 | 113 | DWORD indexcount, DWORD flags);
|
114 | 114 | glDirectDraw7 *ddInterface;
|
115 | 115 | void _Flush();
|
| 116 | + int opcode;
|
116 | 117 | void* inputs[32];
|
117 | 118 | void* outputs[32];
|
118 | 119 | HANDLE hThread;
|
119 | | - bool wndbusy;
|
120 | 120 | HDC hDC;
|
121 | 121 | HWND hWnd;
|
122 | 122 | HWND hRenderWnd;
|
— | — | @@ -123,6 +123,9 @@ |
124 | 124 | DIB dib;
|
125 | 125 | GLuint PBO;
|
126 | 126 | CRITICAL_SECTION cs;
|
| 127 | + HANDLE busy;
|
| 128 | + HANDLE start;
|
| 129 | + bool dead;
|
127 | 130 | };
|
128 | 131 |
|
129 | 132 | #endif //_GLRENDERER_H |
\ No newline at end of file |