| Index: ddraw/glDirectDraw.cpp |
| — | — | @@ -1342,54 +1342,6 @@ |
| 1343 | 1343 | sizes[4] = screenx;
|
| 1344 | 1344 | sizes[5] = screeny;
|
| 1345 | 1345 | }
|
| 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 | | -}
|
| 1394 | 1346 |
|
| 1395 | 1347 | void glDirectDraw7::DeleteSurface(glDirectDrawSurface7 *surface)
|
| 1396 | 1348 | {
|
| — | — | @@ -1784,17 +1736,4 @@ |
| 1785 | 1737 | devid.guidDeviceIdentifier = device_template;
|
| 1786 | 1738 | memcpy(lpdddi,&devid,sizeof(DDDEVICEIDENTIFIER));
|
| 1787 | 1739 | 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 @@ |
| 74 | 74 | void RemoveSurface(glDirectDrawSurface7 *surface);
|
| 75 | 75 | void GetSizes(LONG *sizes);
|
| 76 | 76 | GLuint PalProg(){return shaders[PROG_PAL256].prog;}
|
| 77 | | - LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
| 78 | 77 | DWORD GetBPP(){return primarybpp;}
|
| 79 | 78 | DWORD GetBPPMultipleOf8(){if(primarybpp == 15) return 16; else return primarybpp;}
|
| 80 | 79 | DWORD screenx,screeny,screenrefresh,screenbpp;
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -34,6 +34,7 @@ |
| 35 | 35 | #define NextMultipleOfWord NextMultipleOf4
|
| 36 | 36 | #endif
|
| 37 | 37 |
|
| | 38 | +WNDCLASSEXA wndclass;
|
| 38 | 39 | bool wndclasscreated = false;
|
| 39 | 40 |
|
| 40 | 41 | BltVertex bltvertices[4];
|
| — | — | @@ -124,6 +125,8 @@ |
| 125 | 126 |
|
| 126 | 127 | glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, HWND hwnd, glDirectDraw7 *glDD7)
|
| 127 | 128 | {
|
| | 129 | + MSG Msg;
|
| | 130 | + wndbusy = false;
|
| 128 | 131 | hDC = NULL;
|
| 129 | 132 | hRC = NULL;
|
| 130 | 133 | PBO = 0;
|
| — | — | @@ -142,46 +145,7 @@ |
| 143 | 146 | // TODO: Adjust window rect
|
| 144 | 147 | }
|
| 145 | 148 | 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);
|
| 186 | 150 | inputs[0] = (void*)width;
|
| 187 | 151 | inputs[1] = (void*)height;
|
| 188 | 152 | inputs[2] = (void*)bpp;
|
| — | — | @@ -189,19 +153,36 @@ |
| 190 | 154 | inputs[4] = (void*)hWnd;
|
| 191 | 155 | inputs[5] = glDD7;
|
| 192 | 156 | inputs[6] = this;
|
| | 157 | + wndbusy = true;
|
| 193 | 158 | 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 | + }
|
| 195 | 168 | }
|
| 196 | 169 |
|
| 197 | 170 | glRenderer::~glRenderer()
|
| 198 | 171 | {
|
| 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);
|
| 206 | 187 | }
|
| 207 | 188 |
|
| 208 | 189 |
|
| — | — | @@ -214,6 +195,7 @@ |
| 215 | 196 |
|
| 216 | 197 | GLuint glRenderer::MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3)
|
| 217 | 198 | {
|
| | 199 | + EnterCriticalSection(&cs);
|
| 218 | 200 | inputs[0] = (void*)min;
|
| 219 | 201 | inputs[1] = (void*)mag;
|
| 220 | 202 | inputs[2] = (void*)wraps;
|
| — | — | @@ -223,9 +205,8 @@ |
| 224 | 206 | inputs[6] = (void*)texformat1;
|
| 225 | 207 | inputs[7] = (void*)texformat2;
|
| 226 | 208 | 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);
|
| 230 | 211 | return (GLuint)outputs[0];
|
| 231 | 212 | }
|
| 232 | 213 |
|
| — | — | @@ -232,6 +213,8 @@ |
| 233 | 214 | int glRenderer::UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
|
| 234 | 215 | int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3)
|
| 235 | 216 | {
|
| | 217 | + EnterCriticalSection(&cs);
|
| | 218 | + MSG Msg;
|
| 236 | 219 | inputs[0] = buffer;
|
| 237 | 220 | inputs[1] = bigbuffer;
|
| 238 | 221 | inputs[2] = (void*)texture;
|
| — | — | @@ -245,9 +228,18 @@ |
| 246 | 229 | inputs[10] = (void*)texformat;
|
| 247 | 230 | inputs[11] = (void*)texformat2;
|
| 248 | 231 | 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);
|
| 252 | 244 | return (int)outputs[0];
|
| 253 | 245 | }
|
| 254 | 246 |
|
| — | — | @@ -254,6 +246,8 @@ |
| 255 | 247 | int glRenderer::DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
|
| 256 | 248 | int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2)
|
| 257 | 249 | {
|
| | 250 | + EnterCriticalSection(&cs);
|
| | 251 | + MSG Msg;
|
| 258 | 252 | inputs[0] = buffer;
|
| 259 | 253 | inputs[1] = bigbuffer;
|
| 260 | 254 | inputs[2] = (void*)texture;
|
| — | — | @@ -266,34 +260,34 @@ |
| 267 | 261 | inputs[9] = (void*)bpp;
|
| 268 | 262 | inputs[10] = (void*)texformat;
|
| 269 | 263 | 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);
|
| 273 | 276 | return (int)outputs[0];
|
| 274 | 277 | }
|
| 275 | 278 |
|
| 276 | 279 | void glRenderer::DeleteTexture(GLuint texture)
|
| 277 | 280 | {
|
| | 281 | + EnterCriticalSection(&cs);
|
| 278 | 282 | 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);
|
| 282 | 285 | }
|
| 283 | 286 |
|
| 284 | 287 | HRESULT glRenderer::Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 285 | 288 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
| 286 | 289 | {
|
| 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);
|
| 298 | 292 | inputs[0] = lpDestRect;
|
| 299 | 293 | inputs[1] = src;
|
| 300 | 294 | inputs[2] = dest;
|
| — | — | @@ -300,39 +294,56 @@ |
| 301 | 295 | inputs[3] = lpSrcRect;
|
| 302 | 296 | inputs[4] = (void*)dwFlags;
|
| 303 | 297 | 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);
|
| 308 | 310 | return (HRESULT)outputs[0];
|
| 309 | 311 | }
|
| 310 | 312 |
|
| 311 | 313 | void glRenderer::DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
|
| 312 | 314 | {
|
| 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);
|
| 321 | 317 | inputs[0] = (void*)texture;
|
| 322 | 318 | inputs[1] = (void*)paltex;
|
| 323 | 319 | inputs[2] = dest;
|
| 324 | 320 | 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);
|
| 329 | 333 | }
|
| 330 | 334 |
|
| 331 | 335 | DWORD glRenderer::_Entry()
|
| 332 | 336 | {
|
| | 337 | + MSG Msg;
|
| | 338 | + EnterCriticalSection(&cs);
|
| 333 | 339 | _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)
|
| 336 | 342 | {
|
| | 343 | + TranslateMessage(&Msg);
|
| | 344 | + DispatchMessage(&Msg);
|
| | 345 | + }
|
| | 346 | +/* do
|
| | 347 | + {
|
| 337 | 348 | WaitForSingleObject(EventSend,INFINITE);
|
| 338 | 349 | switch(eventnum)
|
| 339 | 350 | {
|
| — | — | @@ -361,38 +372,21 @@ |
| 362 | 373 | break;
|
| 363 | 374 | case GLEVENT_BLT:
|
| 364 | 375 | 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]);
|
| 366 | 377 | SetEvent(EventWait);
|
| 367 | 378 | break;
|
| 368 | 379 | 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]);
|
| 370 | 381 | SetEvent(EventWait);
|
| 371 | 382 | break;
|
| 372 | 383 | default:
|
| 373 | 384 | break;
|
| 374 | 385 | }
|
| 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;
|
| 395 | 390 | hRC = NULL;
|
| 396 | | - SetEvent(EventWait);
|
| 397 | 391 | return 0;
|
| 398 | 392 | }
|
| 399 | 393 |
|
| — | — | @@ -399,6 +393,43 @@ |
| 400 | 394 | BOOL glRenderer::_InitGL(int width, int height, int bpp, int fullscreen, HWND hWnd, glDirectDraw7 *glDD7)
|
| 401 | 395 | {
|
| 402 | 396 | 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;
|
| 403 | 434 | if(hRC)
|
| 404 | 435 | {
|
| 405 | 436 | wglMakeCurrent(NULL,NULL);
|
| — | — | @@ -496,9 +527,21 @@ |
| 497 | 528 | }
|
| 498 | 529 |
|
| 499 | 530 | 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)
|
| 501 | 532 | {
|
| 502 | 533 | 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;
|
| 503 | 546 | ddInterface->GetSizes(sizes);
|
| 504 | 547 | int error;
|
| 505 | 548 | error = SetFBO(dest->texture,0,false);
|
| — | — | @@ -644,7 +687,7 @@ |
| 645 | 688 | if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
|
| 646 | 689 | (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
|
| 647 | 690 | ((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);
|
| 649 | 692 | return DD_OK;
|
| 650 | 693 | }
|
| 651 | 694 |
|
| — | — | @@ -662,8 +705,18 @@ |
| 663 | 706 | return texture;
|
| 664 | 707 | }
|
| 665 | 708 |
|
| 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)
|
| 667 | 710 | {
|
| | 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;
|
| 668 | 721 | SetSwap(swapinterval);
|
| 669 | 722 | LONG sizes[6];
|
| 670 | 723 | GLfloat view[4];
|
| — | — | @@ -792,3 +845,131 @@ |
| 793 | 846 | {
|
| 794 | 847 | glDeleteTextures(1,&texture);
|
| 795 | 848 | }
|
| | 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 @@ |
| 52 | 52 |
|
| 53 | 53 | extern BltVertex bltvertices[4];
|
| 54 | 54 |
|
| 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
|
| 63 | 63 |
|
| 64 | 64 | extern int swapinterval;
|
| 65 | 65 | extern inline void SetSwap(int swap);
|
| — | — | @@ -77,6 +77,7 @@ |
| 78 | 78 | void DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
|
| 79 | 79 | void DeleteTexture(GLuint texture);
|
| 80 | 80 | HGLRC hRC;
|
| | 81 | + LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
| 81 | 82 | private:
|
| 82 | 83 | // In-thread APIs
|
| 83 | 84 | DWORD _Entry();
|
| — | — | @@ -84,17 +85,15 @@ |
| 85 | 86 | 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);
|
| 86 | 87 | 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);
|
| 87 | 88 | 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);
|
| 89 | 90 | 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);
|
| 91 | 92 | void _DeleteTexture(GLuint texture);
|
| 92 | 93 | glDirectDraw7 *ddInterface;
|
| 93 | | - int eventnum;
|
| 94 | 94 | void* inputs[32];
|
| 95 | 95 | void* outputs[32];
|
| 96 | 96 | HANDLE hThread;
|
| 97 | | - HANDLE EventSend;
|
| 98 | | - HANDLE EventWait;
|
| | 97 | + bool wndbusy;
|
| 99 | 98 | HDC hDC;
|
| 100 | 99 | HWND hWnd;
|
| 101 | 100 | HWND hRenderWnd;
|
| — | — | @@ -102,6 +101,7 @@ |
| 103 | 102 | GLCAPS gl_caps;
|
| 104 | 103 | DIB dib;
|
| 105 | 104 | GLuint PBO;
|
| | 105 | + CRITICAL_SECTION cs;
|
| 106 | 106 | };
|
| 107 | 107 |
|
| 108 | 108 | #endif //_GLRENDERER_H |
| \ No newline at end of file |