DXGL r91 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r90‎ | r91 | r92 >
Date:17:20, 28 January 2012
Author:admin
Status:new
Tags:
Comment:
Move render window to OpenGL thread.
Hide overlay window from taskbar.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -1342,54 +1342,6 @@
13431343 sizes[4] = screenx;
13441344 sizes[5] = screeny;
13451345 }
1346 -LRESULT glDirectDraw7::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1347 -{
1348 - int oldx,oldy;
1349 - float mulx, muly;
1350 - int translatex, translatey;
1351 - LPARAM newpos;
1352 - HWND hParent;
1353 - LONG sizes[6];
1354 - HCURSOR cursor;
1355 - if(msg == WM_CREATE)
1356 - {
1357 - SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this);
1358 - return 0;
1359 - }
1360 - if(msg == WM_SETCURSOR)
1361 - {
1362 - hParent = GetParent(hwnd);
1363 - cursor = (HCURSOR)GetClassLong(hParent,GCL_HCURSOR);
1364 - SetCursor(cursor);
1365 - return SendMessage(hParent,msg,wParam,lParam);
1366 - }
1367 - if((msg >= WM_MOUSEFIRST) && (msg <= WM_MOUSELAST))
1368 - {
1369 - hParent = GetParent(hwnd);
1370 - if((dxglcfg.scaler != 0) && fullscreen)
1371 - {
1372 - oldx = LOWORD(lParam);
1373 - oldy = HIWORD(lParam);
1374 - GetSizes(sizes);
1375 - mulx = (float)sizes[2] / (float)sizes[0];
1376 - muly = (float)sizes[3] / (float)sizes[1];
1377 - translatex = (sizes[4]-sizes[0])/2;
1378 - translatey = (sizes[5]-sizes[1])/2;
1379 - oldx -= translatex;
1380 - oldy -= translatey;
1381 - oldx = (int)((float)oldx * mulx);
1382 - oldy = (int)((float)oldy * muly);
1383 - if(oldx < 0) oldx = 0;
1384 - if(oldy < 0) oldy = 0;
1385 - if(oldx >= sizes[2]) oldx = sizes[2]-1;
1386 - if(oldy >= sizes[3]) oldy = sizes[3]-1;
1387 - newpos = oldx + (oldy << 16);
1388 - return SendMessage(hParent,msg,wParam,newpos);
1389 - }
1390 - else return SendMessage(hParent,msg,wParam,lParam);
1391 - }
1392 - return DefWindowProc(hwnd,msg,wParam,lParam);
1393 -}
13941346
13951347 void glDirectDraw7::DeleteSurface(glDirectDrawSurface7 *surface)
13961348 {
@@ -1784,17 +1736,4 @@
17851737 devid.guidDeviceIdentifier = device_template;
17861738 memcpy(lpdddi,&devid,sizeof(DDDEVICEIDENTIFIER));
17871739 return DD_OK;
1788 -}
1789 -
1790 -// Render Window event handler
1791 -LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1792 -{
1793 - glDirectDraw7* instance = reinterpret_cast<glDirectDraw7*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
1794 - if(!instance)
1795 - {
1796 - if(msg == WM_CREATE)
1797 - instance = reinterpret_cast<glDirectDraw7*>(*(LONG_PTR*)lParam);
1798 - else return DefWindowProc(hwnd,msg,wParam,lParam);
1799 - }
1800 - return instance->WndProc(hwnd,msg,wParam,lParam);
1801 -}
 1740+}
\ No newline at end of file
Index: ddraw/glDirectDraw.h
@@ -73,7 +73,6 @@
7474 void RemoveSurface(glDirectDrawSurface7 *surface);
7575 void GetSizes(LONG *sizes);
7676 GLuint PalProg(){return shaders[PROG_PAL256].prog;}
77 - LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
7877 DWORD GetBPP(){return primarybpp;}
7978 DWORD GetBPPMultipleOf8(){if(primarybpp == 15) return 16; else return primarybpp;}
8079 DWORD screenx,screeny,screenrefresh,screenbpp;
Index: ddraw/glRenderer.cpp
@@ -34,6 +34,7 @@
3535 #define NextMultipleOfWord NextMultipleOf4
3636 #endif
3737
 38+WNDCLASSEXA wndclass;
3839 bool wndclasscreated = false;
3940
4041 BltVertex bltvertices[4];
@@ -124,6 +125,8 @@
125126
126127 glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, HWND hwnd, glDirectDraw7 *glDD7)
127128 {
 129+ MSG Msg;
 130+ wndbusy = false;
128131 hDC = NULL;
129132 hRC = NULL;
130133 PBO = 0;
@@ -142,46 +145,7 @@
143146 // TODO: Adjust window rect
144147 }
145148 SetWindowPos(hWnd,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
146 - if(hDC) ReleaseDC(hRenderWnd,hDC);
147 - if(hRenderWnd) DestroyWindow(hRenderWnd);
148 - WNDCLASSEXA wndclass;
149 - if(!wndclasscreated)
150 - {
151 - wndclass.cbSize = sizeof(WNDCLASSEXA);
152 - wndclass.style = 0;
153 - wndclass.lpfnWndProc = RenderWndProc;
154 - wndclass.cbClsExtra = 0;
155 - wndclass.cbWndExtra = 0;
156 - wndclass.hInstance = (HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
157 - wndclass.hIcon = NULL;
158 - wndclass.hCursor = NULL;
159 - wndclass.hbrBackground = NULL;
160 - wndclass.lpszMenuName = NULL;
161 - wndclass.lpszClassName = "DXGLRenderWindow";
162 - wndclass.hIconSm = NULL;
163 - RegisterClassExA(&wndclass);
164 - wndclasscreated = true;
165 - }
166 - RECT rectRender;
167 - GetClientRect(hWnd,&rectRender);
168 - if(hWnd)
169 - {
170 - hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
171 - rectRender.bottom - rectRender.top,hWnd,NULL,NULL,this);
172 - hasHWnd = true;
173 - }
174 - else
175 - {
176 - width = GetSystemMetrics(SM_CXSCREEN);
177 - height = GetSystemMetrics(SM_CYSCREEN);
178 - hRenderWnd = CreateWindowExA(WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,"DXGLRenderWindow","Renderer",
179 - WS_POPUP,0,0,width,height,0,0,NULL,this);
180 - hasHWnd = false;
181 - }
182 - SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
183 - eventnum = GLEVENT_NULL;
184 - EventSend = CreateEventA(NULL,FALSE,FALSE,NULL);
185 - EventWait = CreateEventA(NULL,FALSE,FALSE,NULL);
 149+ InitializeCriticalSection(&cs);
186150 inputs[0] = (void*)width;
187151 inputs[1] = (void*)height;
188152 inputs[2] = (void*)bpp;
@@ -189,19 +153,36 @@
190154 inputs[4] = (void*)hWnd;
191155 inputs[5] = glDD7;
192156 inputs[6] = this;
 157+ wndbusy = true;
193158 hThread = CreateThread(NULL,0,ThreadEntry,inputs,0,NULL);
194 - WaitForSingleObject(EventWait,INFINITE);
 159+ while(wndbusy)
 160+ {
 161+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 162+ {
 163+ TranslateMessage(&Msg);
 164+ DispatchMessage(&Msg);
 165+ }
 166+ Sleep(0);
 167+ }
195168 }
196169
197170 glRenderer::~glRenderer()
198171 {
199 - eventnum = GLEVENT_DELETE;
200 - SetEvent(EventSend);
201 - WaitForSingleObject(EventWait,INFINITE);
202 - if(hDC) ReleaseDC(hRenderWnd,hDC);
203 - if(hRenderWnd) DestroyWindow(hRenderWnd);
204 - hDC = NULL;
205 - hRenderWnd = NULL;
 172+ MSG Msg;
 173+ EnterCriticalSection(&cs);
 174+ wndbusy = true;
 175+ SendMessage(hRenderWnd,GLEVENT_DELETE,0,0);
 176+ while(wndbusy)
 177+ {
 178+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 179+ {
 180+ TranslateMessage(&Msg);
 181+ DispatchMessage(&Msg);
 182+ }
 183+ Sleep(0);
 184+ }
 185+ LeaveCriticalSection(&cs);
 186+ DeleteCriticalSection(&cs);
206187 }
207188
208189
@@ -214,6 +195,7 @@
215196
216197 GLuint glRenderer::MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3)
217198 {
 199+ EnterCriticalSection(&cs);
218200 inputs[0] = (void*)min;
219201 inputs[1] = (void*)mag;
220202 inputs[2] = (void*)wraps;
@@ -223,9 +205,8 @@
224206 inputs[6] = (void*)texformat1;
225207 inputs[7] = (void*)texformat2;
226208 inputs[8] = (void*)texformat3;
227 - eventnum = GLEVENT_CREATE;
228 - SetEvent(EventSend);
229 - WaitForSingleObject(EventWait,INFINITE);
 209+ SendMessage(hRenderWnd,GLEVENT_CREATE,0,0);
 210+ LeaveCriticalSection(&cs);
230211 return (GLuint)outputs[0];
231212 }
232213
@@ -232,6 +213,8 @@
233214 int glRenderer::UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
234215 int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3)
235216 {
 217+ EnterCriticalSection(&cs);
 218+ MSG Msg;
236219 inputs[0] = buffer;
237220 inputs[1] = bigbuffer;
238221 inputs[2] = (void*)texture;
@@ -245,9 +228,18 @@
246229 inputs[10] = (void*)texformat;
247230 inputs[11] = (void*)texformat2;
248231 inputs[12] = (void*)texformat3;
249 - eventnum = GLEVENT_UPLOAD;
250 - SetEvent(EventSend);
251 - WaitForSingleObject(EventWait,INFINITE);
 232+ wndbusy = true;
 233+ SendMessage(hRenderWnd,GLEVENT_UPLOAD,0,0);
 234+ while(wndbusy)
 235+ {
 236+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 237+ {
 238+ TranslateMessage(&Msg);
 239+ DispatchMessage(&Msg);
 240+ }
 241+ Sleep(0);
 242+ }
 243+ LeaveCriticalSection(&cs);
252244 return (int)outputs[0];
253245 }
254246
@@ -254,6 +246,8 @@
255247 int glRenderer::DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
256248 int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2)
257249 {
 250+ EnterCriticalSection(&cs);
 251+ MSG Msg;
258252 inputs[0] = buffer;
259253 inputs[1] = bigbuffer;
260254 inputs[2] = (void*)texture;
@@ -266,34 +260,34 @@
267261 inputs[9] = (void*)bpp;
268262 inputs[10] = (void*)texformat;
269263 inputs[11] = (void*)texformat2;
270 - eventnum = GLEVENT_DOWNLOAD;
271 - SetEvent(EventSend);
272 - WaitForSingleObject(EventWait,INFINITE);
 264+ wndbusy = true;
 265+ SendMessage(hRenderWnd,GLEVENT_DOWNLOAD,0,0);
 266+ while(wndbusy)
 267+ {
 268+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 269+ {
 270+ TranslateMessage(&Msg);
 271+ DispatchMessage(&Msg);
 272+ }
 273+ Sleep(0);
 274+ }
 275+ LeaveCriticalSection(&cs);
273276 return (int)outputs[0];
274277 }
275278
276279 void glRenderer::DeleteTexture(GLuint texture)
277280 {
 281+ EnterCriticalSection(&cs);
278282 inputs[0] = (void*)texture;
279 - eventnum = GLEVENT_DELETETEX;
280 - SetEvent(EventSend);
281 - WaitForSingleObject(EventWait,INFINITE);
 283+ SendMessage(hRenderWnd,GLEVENT_DELETETEX,0,0);
 284+ LeaveCriticalSection(&cs);
282285 }
283286
284287 HRESULT glRenderer::Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
285288 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
286289 {
287 - RECT r,r2;
288 - if(((dest->ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
289 - (dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
290 - ((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
291 - !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
292 - {
293 - GetClientRect(hWnd,&r);
294 - GetClientRect(hRenderWnd,&r2);
295 - if(memcmp(&r2,&r,sizeof(RECT)))
296 - SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
297 - }
 290+ MSG Msg;
 291+ EnterCriticalSection(&cs);
298292 inputs[0] = lpDestRect;
299293 inputs[1] = src;
300294 inputs[2] = dest;
@@ -300,39 +294,56 @@
301295 inputs[3] = lpSrcRect;
302296 inputs[4] = (void*)dwFlags;
303297 inputs[5] = lpDDBltFx;
304 - inputs[6] = &r2;
305 - eventnum = GLEVENT_BLT;
306 - SetEvent(EventSend);
307 - WaitForSingleObject(EventWait,INFINITE);
 298+ wndbusy = true;
 299+ SendMessage(hRenderWnd,GLEVENT_BLT,0,0);
 300+ while(wndbusy)
 301+ {
 302+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 303+ {
 304+ TranslateMessage(&Msg);
 305+ DispatchMessage(&Msg);
 306+ }
 307+ Sleep(0);
 308+ }
 309+ LeaveCriticalSection(&cs);
308310 return (HRESULT)outputs[0];
309311 }
310312
311313 void glRenderer::DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
312314 {
313 - RECT r,r2;
314 - if(!(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
315 - {
316 - GetClientRect(hWnd,&r);
317 - GetClientRect(hRenderWnd,&r2);
318 - if(memcmp(&r2,&r,sizeof(RECT)))
319 - SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
320 - }
 315+ MSG Msg;
 316+ EnterCriticalSection(&cs);
321317 inputs[0] = (void*)texture;
322318 inputs[1] = (void*)paltex;
323319 inputs[2] = dest;
324320 inputs[3] = src;
325 - inputs[4] = &r2;
326 - eventnum = GLEVENT_DRAWSCREEN;
327 - SetEvent(EventSend);
328 - WaitForSingleObject(EventWait,INFINITE);
 321+ wndbusy = true;
 322+ SendMessage(hRenderWnd,GLEVENT_DRAWSCREEN,0,0);
 323+ while(wndbusy)
 324+ {
 325+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 326+ {
 327+ TranslateMessage(&Msg);
 328+ DispatchMessage(&Msg);
 329+ }
 330+ Sleep(0);
 331+ }
 332+ LeaveCriticalSection(&cs);
329333 }
330334
331335 DWORD glRenderer::_Entry()
332336 {
 337+ MSG Msg;
 338+ EnterCriticalSection(&cs);
333339 _InitGL((int)inputs[0],(int)inputs[1],(int)inputs[2],(int)inputs[3],(HWND)inputs[4],(glDirectDraw7*)inputs[5]);
334 - SetEvent(EventWait);
335 - do
 340+ LeaveCriticalSection(&cs);
 341+ while(GetMessage(&Msg, NULL, 0, 0) > 0)
336342 {
 343+ TranslateMessage(&Msg);
 344+ DispatchMessage(&Msg);
 345+ }
 346+/* do
 347+ {
337348 WaitForSingleObject(EventSend,INFINITE);
338349 switch(eventnum)
339350 {
@@ -361,38 +372,21 @@
362373 break;
363374 case GLEVENT_BLT:
364375 outputs[0] = (void*)_Blt((LPRECT)inputs[0],(glDirectDrawSurface7*)inputs[1],(glDirectDrawSurface7*)inputs[2],
365 - (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5],(RECT*)inputs[6]);
 376+ (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
366377 SetEvent(EventWait);
367378 break;
368379 case GLEVENT_DRAWSCREEN:
369 - _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3],(RECT*)inputs[4]);
 380+ _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
370381 SetEvent(EventWait);
371382 break;
372383 default:
373384 break;
374385 }
375 - } while(eventnum != GLEVENT_DELETE);
376 - if(hRC)
377 - {
378 - if(dib.enabled)
379 - {
380 - if(dib.hbitmap) DeleteObject(dib.hbitmap);
381 - if(dib.hdc) DeleteDC(dib.hdc);
382 - ZeroMemory(&dib,sizeof(DIB));
383 - }
384 - DeleteShaders();
385 - DeleteFBO();
386 - if(PBO)
387 - {
388 - glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
389 - glDeleteBuffers(1,&PBO);
390 - PBO = 0;
391 - }
392 - wglMakeCurrent(NULL,NULL);
393 - wglDeleteContext(hRC);
394 - };
 386+ } while(eventnum != GLEVENT_DELETE);*/
 387+ if(hRenderWnd) DestroyWindow(hRenderWnd);
 388+ hRenderWnd = NULL;
 389+ wndbusy = false;
395390 hRC = NULL;
396 - SetEvent(EventWait);
397391 return 0;
398392 }
399393
@@ -399,6 +393,43 @@
400394 BOOL glRenderer::_InitGL(int width, int height, int bpp, int fullscreen, HWND hWnd, glDirectDraw7 *glDD7)
401395 {
402396 ddInterface = glDD7;
 397+ if(!wndclasscreated)
 398+ {
 399+ wndclass.cbSize = sizeof(WNDCLASSEXA);
 400+ wndclass.style = 0;
 401+ wndclass.lpfnWndProc = RenderWndProc;
 402+ wndclass.cbClsExtra = 0;
 403+ wndclass.cbWndExtra = 0;
 404+ wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);//(HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
 405+ wndclass.hIcon = NULL;
 406+ wndclass.hCursor = NULL;
 407+ wndclass.hbrBackground = NULL;
 408+ wndclass.lpszMenuName = NULL;
 409+ wndclass.lpszClassName = "DXGLRenderWindow";
 410+ wndclass.hIconSm = NULL;
 411+ RegisterClassExA(&wndclass);
 412+ wndclasscreated = true;
 413+ }
 414+ if(hDC) ReleaseDC(hRenderWnd,hDC);
 415+ if(hRenderWnd) DestroyWindow(hRenderWnd);
 416+ RECT rectRender;
 417+ GetClientRect(hWnd,&rectRender);
 418+ if(hWnd)
 419+ {
 420+ hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
 421+ rectRender.bottom - rectRender.top,hWnd,NULL,wndclass.hInstance,this);
 422+ hasHWnd = true;
 423+ }
 424+ else
 425+ {
 426+ width = GetSystemMetrics(SM_CXSCREEN);
 427+ height = GetSystemMetrics(SM_CYSCREEN);
 428+ hRenderWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,
 429+ "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
 430+ hasHWnd = false;
 431+ }
 432+ SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
 433+ wndbusy = false;
403434 if(hRC)
404435 {
405436 wglMakeCurrent(NULL,NULL);
@@ -496,9 +527,21 @@
497528 }
498529
499530 HRESULT glRenderer::_Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
500 - glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx, RECT *viewrect)
 531+ glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
501532 {
502533 LONG sizes[6];
 534+ RECT r,r2;
 535+ if(((dest->ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
 536+ (dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
 537+ ((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
 538+ !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
 539+ {
 540+ GetClientRect(hWnd,&r);
 541+ GetClientRect(hRenderWnd,&r2);
 542+ if(memcmp(&r2,&r,sizeof(RECT)))
 543+ SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
 544+ }
 545+ wndbusy = false;
503546 ddInterface->GetSizes(sizes);
504547 int error;
505548 error = SetFBO(dest->texture,0,false);
@@ -644,7 +687,7 @@
645688 if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
646689 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
647690 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
648 - !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest,viewrect);
 691+ !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest);
649692 return DD_OK;
650693 }
651694
@@ -662,8 +705,18 @@
663706 return texture;
664707 }
665708
666 -void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, RECT *viewrect)
 709+void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
667710 {
 711+ RECT r,r2;
 712+ if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
 713+ {
 714+ GetClientRect(hWnd,&r);
 715+ GetClientRect(hRenderWnd,&r2);
 716+ if(memcmp(&r2,&r,sizeof(RECT)))
 717+ SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
 718+ }
 719+ wndbusy = false;
 720+ RECT *viewrect = &r2;
668721 SetSwap(swapinterval);
669722 LONG sizes[6];
670723 GLfloat view[4];
@@ -792,3 +845,131 @@
793846 {
794847 glDeleteTextures(1,&texture);
795848 }
 849+
 850+LRESULT glRenderer::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 851+{
 852+ int oldx,oldy;
 853+ float mulx, muly;
 854+ int translatex, translatey;
 855+ LPARAM newpos;
 856+ HWND hParent;
 857+ LONG sizes[6];
 858+ HCURSOR cursor;
 859+ switch(msg)
 860+ {
 861+ case WM_CREATE:
 862+ SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this);
 863+ return 0;
 864+ case WM_DESTROY:
 865+ if(hRC)
 866+ {
 867+ if(dib.enabled)
 868+ {
 869+ if(dib.hbitmap) DeleteObject(dib.hbitmap);
 870+ if(dib.hdc) DeleteDC(dib.hdc);
 871+ ZeroMemory(&dib,sizeof(DIB));
 872+ }
 873+ DeleteShaders();
 874+ DeleteFBO();
 875+ if(PBO)
 876+ {
 877+ glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
 878+ glDeleteBuffers(1,&PBO);
 879+ PBO = 0;
 880+ }
 881+ wglMakeCurrent(NULL,NULL);
 882+ wglDeleteContext(hRC);
 883+ };
 884+ if(hDC) ReleaseDC(hRenderWnd,hDC);
 885+ hDC = NULL;
 886+ return 0;
 887+ case WM_SETCURSOR:
 888+ hParent = GetParent(hwnd);
 889+ cursor = (HCURSOR)GetClassLong(hParent,GCL_HCURSOR);
 890+ SetCursor(cursor);
 891+ return SendMessage(hParent,msg,wParam,lParam);
 892+ case WM_MOUSEMOVE:
 893+ case WM_LBUTTONDOWN:
 894+ case WM_LBUTTONUP:
 895+ case WM_LBUTTONDBLCLK:
 896+ case WM_RBUTTONDOWN:
 897+ case WM_RBUTTONUP:
 898+ case WM_RBUTTONDBLCLK:
 899+ case WM_MBUTTONDOWN:
 900+ case WM_MBUTTONUP:
 901+ case WM_MBUTTONDBLCLK:
 902+ case WM_MOUSEWHEEL:
 903+ case WM_XBUTTONDOWN:
 904+ case WM_XBUTTONUP:
 905+ case WM_XBUTTONDBLCLK:
 906+ case WM_MOUSEHWHEEL:
 907+ hParent = GetParent(hwnd);
 908+ if((dxglcfg.scaler != 0) && ddInterface->GetFullscreen())
 909+ {
 910+ oldx = LOWORD(lParam);
 911+ oldy = HIWORD(lParam);
 912+ ddInterface->GetSizes(sizes);
 913+ mulx = (float)sizes[2] / (float)sizes[0];
 914+ muly = (float)sizes[3] / (float)sizes[1];
 915+ translatex = (sizes[4]-sizes[0])/2;
 916+ translatey = (sizes[5]-sizes[1])/2;
 917+ oldx -= translatex;
 918+ oldy -= translatey;
 919+ oldx = (int)((float)oldx * mulx);
 920+ oldy = (int)((float)oldy * muly);
 921+ if(oldx < 0) oldx = 0;
 922+ if(oldy < 0) oldy = 0;
 923+ if(oldx >= sizes[2]) oldx = sizes[2]-1;
 924+ if(oldy >= sizes[3]) oldy = sizes[3]-1;
 925+ newpos = oldx + (oldy << 16);
 926+ return SendMessage(hParent,msg,wParam,newpos);
 927+ }
 928+ else return SendMessage(hParent,msg,wParam,lParam);
 929+ case GLEVENT_DELETE:
 930+ DestroyWindow(hRenderWnd);
 931+ wndbusy = false;
 932+ return 0;
 933+ case GLEVENT_CREATE:
 934+ outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
 935+ (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8]);
 936+ return 0;
 937+ case GLEVENT_UPLOAD:
 938+ outputs[0] = (void*)_UploadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
 939+ (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
 940+ (int)inputs[10],(int)inputs[11],(int)inputs[12]);
 941+ wndbusy = false;
 942+ return 0;
 943+ case GLEVENT_DOWNLOAD:
 944+ outputs[0] = (void*)_DownloadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
 945+ (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
 946+ (int)inputs[10],(int)inputs[11]);
 947+ wndbusy = false;
 948+ return 0;
 949+ case GLEVENT_DELETETEX:
 950+ _DeleteTexture((GLuint)inputs[0]);
 951+ return 0;
 952+ case GLEVENT_BLT:
 953+ outputs[0] = (void*)_Blt((LPRECT)inputs[0],(glDirectDrawSurface7*)inputs[1],(glDirectDrawSurface7*)inputs[2],
 954+ (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
 955+ wndbusy = false;
 956+ return 0;
 957+ case GLEVENT_DRAWSCREEN:
 958+ _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
 959+ return 0;
 960+ }
 961+ return DefWindowProc(hwnd,msg,wParam,lParam);
 962+}
 963+
 964+
 965+// Render Window event handler
 966+LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 967+{
 968+ glRenderer* instance = reinterpret_cast<glRenderer*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
 969+ if(!instance)
 970+ {
 971+ if(msg == WM_CREATE)
 972+ instance = reinterpret_cast<glRenderer*>(*(LONG_PTR*)lParam);
 973+ else return DefWindowProc(hwnd,msg,wParam,lParam);
 974+ }
 975+ return instance->WndProc(hwnd,msg,wParam,lParam);
 976+}
Index: ddraw/glRenderer.h
@@ -51,14 +51,14 @@
5252
5353 extern BltVertex bltvertices[4];
5454
55 -#define GLEVENT_NULL 0
56 -#define GLEVENT_DELETE 1
57 -#define GLEVENT_CREATE 2
58 -#define GLEVENT_UPLOAD 3
59 -#define GLEVENT_DOWNLOAD 4
60 -#define GLEVENT_DELETETEX 5
61 -#define GLEVENT_BLT 6
62 -#define GLEVENT_DRAWSCREEN 7
 55+#define GLEVENT_NULL WM_USER
 56+#define GLEVENT_DELETE WM_USER+1
 57+#define GLEVENT_CREATE WM_USER+2
 58+#define GLEVENT_UPLOAD WM_USER+3
 59+#define GLEVENT_DOWNLOAD WM_USER+4
 60+#define GLEVENT_DELETETEX WM_USER+5
 61+#define GLEVENT_BLT WM_USER+6
 62+#define GLEVENT_DRAWSCREEN WM_USER+7
6363
6464 extern int swapinterval;
6565 extern inline void SetSwap(int swap);
@@ -77,6 +77,7 @@
7878 void DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
7979 void DeleteTexture(GLuint texture);
8080 HGLRC hRC;
 81+ LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
8182 private:
8283 // In-thread APIs
8384 DWORD _Entry();
@@ -84,17 +85,15 @@
8586 int _UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3);
8687 int _DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2);
8788 HRESULT _Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
88 - glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx, RECT *viewrect);
 89+ glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
8990 GLuint _MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
90 - void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, RECT *viewrect);
 91+ void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
9192 void _DeleteTexture(GLuint texture);
9293 glDirectDraw7 *ddInterface;
93 - int eventnum;
9494 void* inputs[32];
9595 void* outputs[32];
9696 HANDLE hThread;
97 - HANDLE EventSend;
98 - HANDLE EventWait;
 97+ bool wndbusy;
9998 HDC hDC;
10099 HWND hWnd;
101100 HWND hRenderWnd;
@@ -102,6 +101,7 @@
103102 GLCAPS gl_caps;
104103 DIB dib;
105104 GLuint PBO;
 105+ CRITICAL_SECTION cs;
106106 };
107107
108108 #endif //_GLRENDERER_H
\ No newline at end of file