DXGL r172 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r171‎ | r172 | r173 >
Date:23:28, 22 June 2012
Author:admin
Status:new
Tags:
Comment:
Move render window to dedicated thread
Modified paths:
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/ddraw.h (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/dllmain.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderWindow.cpp (added) (history)
  • /ddraw/glRenderWindow.h (added) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/ddraw.cpp
@@ -20,6 +20,7 @@
2121 #include "glClassFactory.h"
2222 #include "glDirectDraw.h"
2323 #include "glDirectDrawClipper.h"
 24+#include "glRenderer.h"
2425 #include <intrin.h>
2526 #include <tlhelp32.h>
2627
@@ -33,6 +34,7 @@
3435
3536 DWORD timer;
3637 int vsyncstatus;
 38+glRenderer *renderer = NULL;
3739 bool ddenabled = false;
3840
3941 /**
@@ -59,6 +61,12 @@
6062 }
6163 }
6264
 65+void InitGL(int width, int height, int bpp, bool fullscreen, HWND hWnd, glDirectDraw7 *glDD7)
 66+{
 67+ if(!renderer) renderer = new glRenderer(width,height,bpp,fullscreen,hWnd,glDD7);
 68+ else renderer->SetWnd(width,height,bpp,fullscreen,hWnd);
 69+}
 70+
6371 /// Stub for function found in system ddraw.dll
6472 DDRAW_API void WINAPI AcquireDDThreadLock()
6573 {
Index: ddraw/ddraw.h
@@ -16,8 +16,8 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #pragma once
20 -#ifndef _DDRAW_H
21 -#define _DDRAW_H
 20+#ifndef _DDRAW_PRIVATE_H
 21+#define _DDRAW_PRIVATE_H
2222
2323 #ifdef DDRAW_EXPORTS
2424 #define DDRAW_API __declspec(dllexport)
@@ -61,5 +61,9 @@
6262 extern DWORD timer;
6363 extern int vsyncstatus;
6464 extern bool ddenabled;
 65+class glRenderer;
 66+extern glRenderer *renderer;
 67+class glDirectDraw7;
 68+void InitGL(int width, int height, int bpp, bool fullscreen, HWND hWnd, glDirectDraw7 *glDD7);
6569
66 -#endif //_DDRAW_H
\ No newline at end of file
 70+#endif //_DDRAW_PRIVATE_H
\ No newline at end of file
Index: ddraw/ddraw.vcxproj
@@ -176,6 +176,7 @@
177177 <ClInclude Include="glDirectDrawSurface.h" />
178178 <ClInclude Include="glExtensions.h" />
179179 <ClInclude Include="glRenderer.h" />
 180+ <ClInclude Include="glRenderWindow.h" />
180181 <ClInclude Include="glutil.h" />
181182 <ClInclude Include="include\d3d.h" />
182183 <ClInclude Include="include\d3dcaps.h" />
@@ -221,6 +222,7 @@
222223 <ClCompile Include="glDirectDrawSurface.cpp" />
223224 <ClCompile Include="glExtensions.cpp" />
224225 <ClCompile Include="glRenderer.cpp" />
 226+ <ClCompile Include="glRenderWindow.cpp" />
225227 <ClCompile Include="glutil.cpp" />
226228 <ClCompile Include="matrix.cpp" />
227229 <ClCompile Include="precomp.cpp">
Index: ddraw/ddraw.vcxproj.filters
@@ -101,6 +101,9 @@
102102 <ClInclude Include="resource.h">
103103 <Filter>Header Files</Filter>
104104 </ClInclude>
 105+ <ClInclude Include="glRenderWindow.h">
 106+ <Filter>Header Files</Filter>
 107+ </ClInclude>
105108 </ItemGroup>
106109 <ItemGroup>
107110 <ClCompile Include="ddraw.cpp">
@@ -160,6 +163,9 @@
161164 <ClCompile Include="matrix.cpp">
162165 <Filter>Source Files</Filter>
163166 </ClCompile>
 167+ <ClCompile Include="glRenderWindow.cpp">
 168+ <Filter>Source Files</Filter>
 169+ </ClCompile>
164170 </ItemGroup>
165171 <ItemGroup>
166172 <ResourceCompile Include="ddraw.rc">
Index: ddraw/dllmain.cpp
@@ -16,6 +16,8 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "ddraw.h"
 21+#include "glRenderer.h"
2022 ATOM WindowClass = NULL;
2123 BOOL APIENTRY DllMain( HMODULE hModule,
2224 DWORD ul_reason_for_call,
Index: ddraw/glDirect3DDevice.cpp
@@ -16,6 +16,7 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "ddraw.h"
2021 #include "glDirect3D.h"
2122 #include "glRenderer.h"
2223 #include "glDirectDraw.h"
@@ -233,8 +234,8 @@
234235 memset(gllights,0xff,8*sizeof(int));
235236 memset(gltextures,0,8*sizeof(GLuint));
236237 d3ddesc.dwMaxTextureWidth = d3ddesc.dwMaxTextureHeight =
237 - d3ddesc.dwMaxTextureRepeat = d3ddesc.dwMaxTextureAspectRatio = glD3D7->glDD7->renderer->gl_caps.TextureMax;
238 - glD3D7->glDD7->renderer->InitD3D(zbuffer);
 238+ d3ddesc.dwMaxTextureRepeat = d3ddesc.dwMaxTextureAspectRatio = renderer->gl_caps.TextureMax;
 239+ renderer->InitD3D(zbuffer);
239240 }
240241 glDirect3DDevice7::~glDirect3DDevice7()
241242 {
@@ -323,7 +324,7 @@
324325 {
325326 if(!this) return DDERR_INVALIDPARAMS;
326327 if(dwCount && !lpRects) return DDERR_INVALIDPARAMS;
327 - return glD3D7->glDD7->renderer->Clear(glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil);
 328+ return renderer->Clear(glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil);
328329 }
329330 HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
330331 DWORD dwFlags, LPDWORD lpdwReturnValues)
@@ -519,7 +520,7 @@
520521 if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
521522 HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
522523 if(err != D3D_OK) return err;
523 - return glD3D7->glDD7->renderer->DrawPrimitives(this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
 524+ return renderer->DrawPrimitives(this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
524525 dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
525526 }
526527 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
@@ -561,7 +562,7 @@
562563 if(!this) return DDERR_INVALIDPARAMS;
563564 if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
564565 inscene = false;
565 - glD3D7->glDD7->renderer->Flush();
 566+ renderer->Flush();
566567 return D3D_OK;
567568 }
568569 HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
Index: ddraw/glDirectDraw.cpp
@@ -552,7 +552,6 @@
553553 glD3D7 = NULL;
554554 clippers = NULL;
555555 surfaces = NULL;
556 - renderer = NULL;
557556 initialized = false;
558557 devid.liDriverVersion.QuadPart = DXGLVERQWORD;
559558 refcount = 1;
@@ -593,7 +592,8 @@
594593 }
595594 free(surfaces);
596595 }
597 - DeleteGL();
 596+ if(renderer) delete renderer;
 597+ renderer = NULL;
598598 ddenabled = false;
599599 directdraw_created = false;
600600 }
@@ -1004,7 +1004,6 @@
10051005 {
10061006 if(!this) return DDERR_INVALIDPARAMS;
10071007 this->hWnd = hWnd;
1008 - if(renderer) DeleteGL();
10091008 winstyle = GetWindowLongPtrA(hWnd,GWL_STYLE);
10101009 winstyleex = GetWindowLongPtrA(hWnd,GWL_EXSTYLE);
10111010 bool exclusive = false;
@@ -1068,8 +1067,8 @@
10691068 }
10701069 bpp = devmode.dmBitsPerPel;
10711070 primarybpp = bpp;
1072 - if(InitGL(x,y,bpp,fullscreen,hWnd)) return DD_OK;
1073 - ERR(DDERR_GENERIC);
 1071+ InitGL(x,y,bpp,fullscreen,hWnd,this);
 1072+ return DD_OK;
10741073 }
10751074
10761075 void DiscardUndersizedModes(DEVMODE **array, DWORD *count, DEVMODE comp)
@@ -1174,8 +1173,7 @@
11751174 primarybpp = dwBPP;
11761175 if(dwRefreshRate) internalrefresh = primaryrefresh = screenrefresh = dwRefreshRate;
11771176 else internalrefresh = primaryrefresh = screenrefresh = currmode.dmDisplayFrequency;
1178 - DeleteGL();
1179 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1177+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
11801178 primarylost = true;
11811179 return DD_OK;
11821180 case DISP_CHANGE_BADMODE:
@@ -1205,8 +1203,7 @@
12061204 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
12071205 else internalbpp = screenbpp = currmode.dmBitsPerPel;
12081206 primarybpp = dwBPP;
1209 - DeleteGL();
1210 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1207+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
12111208 primarylost = true;
12121209 return DD_OK;
12131210 break;
@@ -1231,8 +1228,7 @@
12321229 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
12331230 else internalbpp = screenbpp = currmode.dmBitsPerPel;
12341231 primarybpp = dwBPP;
1235 - DeleteGL();
1236 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1232+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
12371233 primarylost = true;
12381234 return DD_OK;
12391235 break;
@@ -1244,8 +1240,7 @@
12451241 primarybpp = dwBPP;
12461242 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
12471243 else internalbpp = screenbpp = currmode.dmBitsPerPel;
1248 - DeleteGL();
1249 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1244+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
12501245 break;
12511246 case 4: // Switch then stretch
12521247 case 5: // Switch then scale
@@ -1279,8 +1274,7 @@
12801275 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
12811276 else internalbpp = screenbpp = newmode2.dmBitsPerPel;
12821277 primarybpp = dwBPP;
1283 - DeleteGL();
1284 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1278+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
12851279 primarylost = true;
12861280 return DD_OK;
12871281 break;
@@ -1305,8 +1299,7 @@
13061300 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
13071301 else internalbpp = screenbpp = newmode2.dmBitsPerPel;
13081302 primarybpp = dwBPP;
1309 - DeleteGL();
1310 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1303+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
13111304 primarylost = true;
13121305 return DD_OK;
13131306 break;
@@ -1319,8 +1312,7 @@
13201313 primarybpp = dwBPP;
13211314 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
13221315 else internalbpp = screenbpp = newmode2.dmBitsPerPel;
1323 - DeleteGL();
1324 - InitGL(screenx,screeny,screenbpp,true,hWnd);
 1316+ InitGL(screenx,screeny,screenbpp,true,hWnd,this);
13251317 primarylost = true;
13261318 return DD_OK;
13271319 break;
@@ -1384,17 +1376,6 @@
13851377 ERR(DDERR_GENERIC);
13861378 }
13871379
1388 -void glDirectDraw7::DeleteGL()
1389 -{
1390 - delete renderer;
1391 - renderer = NULL;
1392 -}
1393 -
1394 -BOOL glDirectDraw7::InitGL(int width, int height, int bpp, bool fullscreen, HWND hWnd)
1395 -{
1396 - renderer = new glRenderer(width,height,bpp,fullscreen,hWnd,this);
1397 - return TRUE;
1398 -}
13991380 void glDirectDraw7::GetSizes(LONG *sizes) // allocate 6 dwords
14001381 {
14011382 sizes[0] = internalx;
Index: ddraw/glDirectDraw.h
@@ -24,8 +24,6 @@
2525 class glDirect3D7;
2626 class glRenderer;
2727
28 -LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
29 -
3028 class glDirectDraw7 : public IDirectDraw7
3129 {
3230 public:
@@ -83,10 +81,7 @@
8482 void DeleteClipper(glDirectDrawClipper *clipper);
8583 glDirectDrawSurface7 *primary;
8684 bool primarylost;
87 - glRenderer *renderer;
8885 private:
89 - void DeleteGL();
90 - BOOL InitGL(int width, int height, int bpp, bool fullscreen, HWND hWnd);
9186 HRESULT error;
9287 ULONG refcount;
9388 HWND hWnd;
Index: ddraw/glDirectDrawSurface.cpp
@@ -66,8 +66,7 @@
6767 else
6868 {
6969 ddInterface = (glDirectDraw7 *)lpDD7;
70 - renderer = ddInterface->renderer;
71 - hRC = ddInterface->renderer->hRC;
 70+ hRC = renderer->hRC;
7271 ddsd = *lpDDSurfaceDesc2;
7372 }
7473 LONG sizes[6];
@@ -895,7 +894,7 @@
896895 HRESULT WINAPI glDirectDrawSurface7::IsLost()
897896 {
898897 if(!this) return DDERR_INVALIDPARAMS;
899 - if(hRC == ddInterface->renderer->hRC) return DD_OK;
 898+ if(hRC == renderer->hRC) return DD_OK;
900899 else return DDERR_SURFACELOST;
901900 }
902901
@@ -951,7 +950,7 @@
952951 void glDirectDrawSurface7::Restore2()
953952 {
954953 LONG sizes[6];
955 - if(hRC != ddInterface->renderer->hRC)
 954+ if(hRC != renderer->hRC)
956955 {
957956 ddInterface->GetSizes(sizes);
958957 if(ddInterface->GetFullscreen())
@@ -986,8 +985,8 @@
987986 {
988987 if(!this) return DDERR_INVALIDPARAMS;
989988 LONG sizes[6];
990 - if(!ddInterface->renderer) return DDERR_INVALIDOBJECT;
991 - if(hRC != ddInterface->renderer->hRC)
 989+ if(!renderer) return DDERR_INVALIDOBJECT;
 990+ if(hRC != renderer->hRC)
992991 {
993992 if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
994993 {
Index: ddraw/glDirectDrawSurface.h
@@ -26,7 +26,6 @@
2727 DDCOLORKEY key;
2828 } CKEY;
2929
30 -class glRenderer;
3130 class glDirectDrawClipper;
3231 class glDirectDrawPalette;
3332 class glDirectDrawSurface1;
@@ -115,7 +114,6 @@
116115 GLint texformat3;
117116 DWORD fakex,fakey;
118117 DWORD dirty;
119 - glRenderer *renderer;
120118 // dirty bits:
121119 // 1 - Surface was locked
122120 // 2 - Texture was written to by ddraw
Index: ddraw/glRenderWindow.cpp
@@ -0,0 +1,203 @@
 2+// DXGL
 3+// Copyright (C) 2012 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+#include "glDirectDraw.h"
 21+#include "glRenderWindow.h"
 22+#include "ddraw.h"
 23+
 24+
 25+WNDCLASSEXA wndclass;
 26+bool wndclasscreated = false;
 27+
 28+void WaitForObjectAndMessages(HANDLE object)
 29+{
 30+ MSG Msg;
 31+ while(1)
 32+ {
 33+ switch(MsgWaitForMultipleObjects(1,&object,FALSE,INFINITE,QS_ALLINPUT))
 34+ {
 35+ case WAIT_OBJECT_0:
 36+ return;
 37+ case WAIT_OBJECT_0+1:
 38+ while(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
 39+ {
 40+ TranslateMessage(&Msg);
 41+ DispatchMessage(&Msg);
 42+ }
 43+ }
 44+ }
 45+
 46+}
 47+
 48+glRenderWindow::glRenderWindow(int width, int height, bool fullscreen, HWND parent, glDirectDraw7 *glDD7)
 49+{
 50+ ddInterface = glDD7;
 51+ this->width = width;
 52+ this->height = height;
 53+ this->fullscreen = fullscreen;
 54+ hParentWnd = parent;
 55+ ReadyEvent = CreateEvent(NULL,false,false,NULL);
 56+ hThread = CreateThread(NULL,0,ThreadEntry,this,0,NULL);
 57+ WaitForObjectAndMessages(ReadyEvent);
 58+ CloseHandle(ReadyEvent);
 59+ ReadyEvent = NULL;
 60+}
 61+
 62+DWORD WINAPI glRenderWindow::ThreadEntry(void *entry)
 63+{
 64+ return ((glRenderWindow*)entry)->_Entry();
 65+}
 66+
 67+DWORD glRenderWindow::_Entry()
 68+{
 69+ MSG Msg;
 70+ if(!wndclasscreated)
 71+ {
 72+ wndclass.cbSize = sizeof(WNDCLASSEXA);
 73+ wndclass.style = 0;
 74+ wndclass.lpfnWndProc = RenderWndProc;
 75+ wndclass.cbClsExtra = 0;
 76+ wndclass.cbWndExtra = 0;
 77+ wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
 78+ wndclass.hIcon = NULL;
 79+ wndclass.hCursor = NULL;
 80+ wndclass.hbrBackground = NULL;
 81+ wndclass.lpszMenuName = NULL;
 82+ wndclass.lpszClassName = "DXGLRenderWindow";
 83+ wndclass.hIconSm = NULL;
 84+ RegisterClassExA(&wndclass);
 85+ wndclasscreated = true;
 86+ }
 87+ RECT rectRender;
 88+ GetClientRect(hParentWnd,&rectRender);
 89+ dead = false;
 90+ if(hParentWnd)
 91+ {
 92+ hWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
 93+ rectRender.bottom - rectRender.top,hParentWnd,NULL,wndclass.hInstance,this);
 94+ SetWindowPos(hWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
 95+ }
 96+ else
 97+ {
 98+ width = GetSystemMetrics(SM_CXSCREEN);
 99+ height = GetSystemMetrics(SM_CYSCREEN);
 100+ hWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,
 101+ "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
 102+ SetWindowPos(hWnd,HWND_TOP,0,0,width,height,SWP_SHOWWINDOW|SWP_NOACTIVATE);
 103+ }
 104+ SetEvent(ReadyEvent);
 105+ while((GetMessage(&Msg, NULL, 0, 0) > 0) && !dead)
 106+ {
 107+ TranslateMessage(&Msg);
 108+ DispatchMessage(&Msg);
 109+ }
 110+ return 0;
 111+}
 112+
 113+glRenderWindow::~glRenderWindow()
 114+{
 115+ SendMessage(hWnd,WM_CLOSE,0,0);
 116+ WaitForSingleObject(hThread,INFINITE);
 117+ CloseHandle(hThread);
 118+}
 119+
 120+LRESULT glRenderWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 121+{
 122+ int oldx,oldy;
 123+ float mulx, muly;
 124+ int translatex, translatey;
 125+ LPARAM newpos;
 126+ HWND hParent;
 127+ LONG sizes[6];
 128+ HCURSOR cursor;
 129+ switch(msg)
 130+ {
 131+ case WM_CREATE:
 132+ SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this);
 133+ return 0;
 134+ case WM_SETCURSOR:
 135+ hParent = GetParent(hwnd);
 136+ cursor = (HCURSOR)GetClassLong(hParent,GCL_HCURSOR);
 137+ SetCursor(cursor);
 138+ return SendMessage(hParent,msg,wParam,lParam);
 139+ case WM_MOUSEMOVE:
 140+ case WM_LBUTTONDOWN:
 141+ case WM_LBUTTONUP:
 142+ case WM_LBUTTONDBLCLK:
 143+ case WM_RBUTTONDOWN:
 144+ case WM_RBUTTONUP:
 145+ case WM_RBUTTONDBLCLK:
 146+ case WM_MBUTTONDOWN:
 147+ case WM_MBUTTONUP:
 148+ case WM_MBUTTONDBLCLK:
 149+ case WM_MOUSEWHEEL:
 150+ case WM_XBUTTONDOWN:
 151+ case WM_XBUTTONUP:
 152+ case WM_XBUTTONDBLCLK:
 153+ case WM_MOUSEHWHEEL:
 154+ hParent = GetParent(hwnd);
 155+ if((dxglcfg.scaler != 0) && ddInterface->GetFullscreen())
 156+ {
 157+ oldx = LOWORD(lParam);
 158+ oldy = HIWORD(lParam);
 159+ ddInterface->GetSizes(sizes);
 160+ mulx = (float)sizes[2] / (float)sizes[0];
 161+ muly = (float)sizes[3] / (float)sizes[1];
 162+ translatex = (sizes[4]-sizes[0])/2;
 163+ translatey = (sizes[5]-sizes[1])/2;
 164+ oldx -= translatex;
 165+ oldy -= translatey;
 166+ oldx = (int)((float)oldx * mulx);
 167+ oldy = (int)((float)oldy * muly);
 168+ if(oldx < 0) oldx = 0;
 169+ if(oldy < 0) oldy = 0;
 170+ if(oldx >= sizes[2]) oldx = sizes[2]-1;
 171+ if(oldy >= sizes[3]) oldy = sizes[3]-1;
 172+ newpos = oldx + (oldy << 16);
 173+ return SendMessage(hParent,msg,wParam,newpos);
 174+ }
 175+ else return SendMessage(hParent,msg,wParam,lParam);
 176+ case WM_CLOSE:
 177+ DestroyWindow(hWnd);
 178+ return 0;
 179+ case WM_DESTROY:
 180+ PostQuitMessage(0);
 181+ dead = true;
 182+ return 0;
 183+ default:
 184+ return DefWindowProc(hwnd,msg,wParam,lParam);
 185+ }
 186+ return 0;
 187+}
 188+
 189+
 190+
 191+
 192+
 193+// Render Window event handler
 194+LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 195+{
 196+ glRenderWindow* instance = reinterpret_cast<glRenderWindow*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
 197+ if(!instance)
 198+ {
 199+ if(msg == WM_CREATE)
 200+ instance = reinterpret_cast<glRenderWindow*>(*(LONG_PTR*)lParam);
 201+ else return DefWindowProc(hwnd,msg,wParam,lParam);
 202+ }
 203+ return instance->WndProc(hwnd,msg,wParam,lParam);
 204+}
Index: ddraw/glRenderWindow.h
@@ -0,0 +1,49 @@
 2+// DXGL
 3+// Copyright (C) 2012 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#pragma once
 20+#ifndef _GLRENDERWINDOW_H
 21+#define _GLRENDERWINDOW_H
 22+
 23+LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
 24+
 25+class glDirectDraw7;
 26+void WaitForObjectAndMessages(HANDLE object);
 27+class glRenderWindow
 28+{
 29+public:
 30+ glRenderWindow(int width, int height, bool fullscreen, HWND parent, glDirectDraw7 *glDD7);
 31+ ~glRenderWindow();
 32+ void resize(int width, int height);
 33+ HWND GetHWnd(){return hWnd;};
 34+ LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
 35+ static DWORD WINAPI ThreadEntry(void *entry);
 36+private:
 37+ DWORD _Entry();
 38+ HWND hWnd;
 39+ HWND hParentWnd;
 40+ HANDLE hThread;
 41+ HANDLE ReadyEvent;
 42+ int width;
 43+ int height;
 44+ bool fullscreen;
 45+ bool dead;
 46+ glDirectDraw7 *ddInterface;
 47+};
 48+
 49+
 50+#endif //_GLRENDERWINDOW_H
\ No newline at end of file
Index: ddraw/glRenderer.cpp
@@ -19,6 +19,7 @@
2020 #include "glDirectDraw.h"
2121 #include "glDirectDrawSurface.h"
2222 #include "glDirectDrawPalette.h"
 23+#include "glRenderWindow.h"
2324 #include "glRenderer.h"
2425 #include "glDirect3DDevice.h"
2526 #include "glDirect3DLight.h"
@@ -30,8 +31,6 @@
3132 #include "shadergen.h"
3233 #include "matrix.h"
3334
34 -WNDCLASSEXA wndclass;
35 -bool wndclasscreated = false;
3635 GLuint backbuffer = 0;
3736 int backx = 0;
3837 int backy = 0;
@@ -209,10 +208,8 @@
210209 hDC = NULL;
211210 hRC = NULL;
212211 PBO = 0;
213 - hasHWnd = false;
214212 dib.enabled = false;
215213 hWnd = hwnd;
216 - hRenderWnd = NULL;
217214 InitializeCriticalSection(&cs);
218215 busy = CreateEvent(NULL,FALSE,FALSE,NULL);
219216 start = CreateEvent(NULL,FALSE,FALSE,NULL);
@@ -227,47 +224,7 @@
228225 // TODO: Adjust window rect
229226 }
230227 SetWindowPos(hWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
231 - if(!wndclasscreated)
232 - {
233 - wndclass.cbSize = sizeof(WNDCLASSEXA);
234 - wndclass.style = 0;
235 - wndclass.lpfnWndProc = RenderWndProc;
236 - wndclass.cbClsExtra = 0;
237 - wndclass.cbWndExtra = 0;
238 - wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
239 - wndclass.hIcon = NULL;
240 - wndclass.hCursor = NULL;
241 - wndclass.hbrBackground = NULL;
242 - wndclass.lpszMenuName = NULL;
243 - wndclass.lpszClassName = "DXGLRenderWindow";
244 - wndclass.hIconSm = NULL;
245 - RegisterClassExA(&wndclass);
246 - wndclasscreated = true;
247 - }
248 - if(hDC) ReleaseDC(hRenderWnd,hDC);
249 - if(hRenderWnd)
250 - {
251 - SetWindowLongPtr(hRenderWnd,GWLP_USERDATA,0);
252 - PostMessage(hRenderWnd,WM_CLOSE,0,0);
253 - }
254 - RECT rectRender;
255 - GetClientRect(hWnd,&rectRender);
256 - if(hWnd)
257 - {
258 - hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
259 - rectRender.bottom - rectRender.top,hWnd,NULL,wndclass.hInstance,this);
260 - hasHWnd = true;
261 - SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
262 - }
263 - else
264 - {
265 - width = GetSystemMetrics(SM_CXSCREEN);
266 - height = GetSystemMetrics(SM_CYSCREEN);
267 - hRenderWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,
268 - "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
269 - hasHWnd = false;
270 - SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW|SWP_NOACTIVATE);
271 - }
 228+ RenderWnd = new glRenderWindow(width,height,fullscreen,hWnd,glDD7);
272229 inputs[0] = (void*)width;
273230 inputs[1] = (void*)height;
274231 inputs[2] = (void*)bpp;
@@ -287,7 +244,7 @@
288245 EnterCriticalSection(&cs);
289246 opcode = OP_DELETE;
290247 SetEvent(start);
291 - WaitForSingleObject(busy,INFINITE);
 248+ WaitForObjectAndMessages(busy);
292249 CloseHandle(start);
293250 CloseHandle(busy);
294251 LeaveCriticalSection(&cs);
@@ -487,9 +444,9 @@
488445 !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
489446 {
490447 GetClientRect(hWnd,&r);
491 - GetClientRect(hRenderWnd,&r2);
 448+ GetClientRect(RenderWnd->GetHWnd(),&r2);
492449 if(memcmp(&r2,&r,sizeof(RECT)))
493 - SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
 450+ SetWindowPos(RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
494451 }
495452 inputs[0] = lpDestRect;
496453 inputs[1] = src;
@@ -591,6 +548,33 @@
592549 }
593550
594551 /**
 552+ * Changes the window used for rendering.
 553+ * @param width,height
 554+ * Width and height of the new window.
 555+ * @param fullscreen
 556+ * True if fullscreen
 557+ * @param newwnd
 558+ * HWND of the new window
 559+ */
 560+void glRenderer::SetWnd(int width, int height, int bpp, int fullscreen, HWND newwnd)
 561+{
 562+ if(fullscreen && newwnd)
 563+ {
 564+ SetWindowLongPtrA(newwnd,GWL_EXSTYLE,WS_EX_APPWINDOW);
 565+ SetWindowLongPtrA(newwnd,GWL_STYLE,WS_OVERLAPPED);
 566+ ShowWindow(newwnd,SW_MAXIMIZE);
 567+ }
 568+ inputs[0] = (void*)width;
 569+ inputs[1] = (void*)height;
 570+ inputs[2] = (void*)bpp;
 571+ inputs[3] = (void*)fullscreen;
 572+ inputs[4] = (void*)newwnd;
 573+ opcode = OP_SETWND;
 574+ SetEvent(start);
 575+ WaitForSingleObject(busy,INFINITE);
 576+ LeaveCriticalSection(&cs);
 577+}
 578+/**
595579 * Draws one or more primitives to the currently selected render target.
596580 * @param device
597581 * glDirect3DDevice7 interface to use for drawing
@@ -651,7 +635,7 @@
652636 WaitForSingleObject(start,INFINITE);
653637 switch(opcode)
654638 {
655 - case OP_DELETE:
 639+ case OP_DELETE:
656640 if(hRC)
657641 {
658642 if(dib.enabled)
@@ -679,14 +663,16 @@
680664 wglDeleteContext(hRC);
681665 hRC = NULL;
682666 };
683 - if(hDC) ReleaseDC(hRenderWnd,hDC);
 667+ if(hDC) ReleaseDC(RenderWnd->GetHWnd(),hDC);
684668 hDC = NULL;
685 - SetWindowLongPtr(hRenderWnd,GWLP_USERDATA,0);
686 - PostMessage(hRenderWnd,WM_CLOSE,0,0);
687 - hRenderWnd = NULL;
 669+ delete RenderWnd;
 670+ RenderWnd = NULL;
688671 SetEvent(busy);
689672 return 0;
690673 break;
 674+ case OP_SETWND:
 675+ _SetWnd((int)inputs[0],(int)inputs[1],(int)inputs[2],(int)inputs[3],(HWND)inputs[4]);
 676+ break;
691677 case OP_CREATE:
692678 outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
693679 (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8],true);
@@ -762,44 +748,38 @@
763749 ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
764750 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
765751 pfd.nVersion = 1;
766 - if(hasHWnd) pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
767 - else pfd.dwFlags = pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
 752+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
768753 pfd.iPixelType = PFD_TYPE_RGBA;
769 - if(hasHWnd) pfd.cColorBits = bpp;
770 - else
771 - {
772 - pfd.cColorBits = 24;
773 - pfd.cAlphaBits = 8;
774 - }
 754+ pfd.cColorBits = bpp;
775755 pfd.iLayerType = PFD_MAIN_PLANE;
776 - hDC = GetDC(hRenderWnd);
 756+ gllock = true;
 757+ hDC = GetDC(RenderWnd->GetHWnd());
777758 if(!hDC)
778759 {
779 - DEBUG("glDirectDraw7::InitGL: Can not create hDC\n");
 760+ DEBUG("glRenderer::InitGL: Can not create hDC\n");
780761 return FALSE;
781762 }
782763 pf = ChoosePixelFormat(hDC,&pfd);
783764 if(!pf)
784765 {
785 - DEBUG("glDirectDraw7::InitGL: Can not get pixelformat\n");
 766+ DEBUG("glRenderer::InitGL: Can not get pixelformat\n");
786767 return FALSE;
787768 }
788769 if(!SetPixelFormat(hDC,pf,&pfd))
789 - DEBUG("glDirectDraw7::InitGL: Can not set pixelformat\n");
790 - gllock = true;
 770+ DEBUG("glRenderer::InitGL: Can not set pixelformat\n");
791771 hRC = wglCreateContext(hDC);
792772 if(!hRC)
793773 {
794 - DEBUG("glDirectDraw7::InitGL: Can not create GL context\n");
 774+ DEBUG("glRenderer::InitGL: Can not create GL context\n");
795775 gllock = false;
796776 return FALSE;
797777 }
798778 if(!wglMakeCurrent(hDC,hRC))
799779 {
800 - DEBUG("glDirectDraw7::InitGL: Can not activate GL context\n");
 780+ DEBUG("glRenderer::InitGL: Can not activate GL context\n");
801781 wglDeleteContext(hRC);
802782 hRC = NULL;
803 - ReleaseDC(hRenderWnd,hDC);
 783+ ReleaseDC(RenderWnd->GetHWnd(),hDC);
804784 hDC = NULL;
805785 gllock = false;
806786 return FALSE;
@@ -826,7 +806,7 @@
827807 glFlush();
828808 SwapBuffers(hDC);
829809 SetActiveTexture(0);
830 - if(!hasHWnd)
 810+ if(hWnd)
831811 {
832812 dib.enabled = true;
833813 dib.width = width;
@@ -842,11 +822,11 @@
843823 dib.info.bmiHeader.biCompression = BI_RGB;
844824 dib.info.bmiHeader.biPlanes = 1;
845825 dib.hbitmap = CreateDIBSection(dib.hdc,&dib.info,DIB_RGB_COLORS,(void**)&dib.pixels,NULL,0);
846 - glGenBuffers(1,&PBO);
847 - glBindBuffer(GL_PIXEL_PACK_BUFFER,PBO);
848 - glBufferData(GL_PIXEL_PACK_BUFFER,width*height*4,NULL,GL_STREAM_READ);
849 - glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
850826 }
 827+ glGenBuffers(1,&PBO);
 828+ glBindBuffer(GL_PIXEL_PACK_BUFFER,PBO);
 829+ glBufferData(GL_PIXEL_PACK_BUFFER,width*height*4,NULL,GL_STREAM_READ);
 830+ glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
851831 return TRUE;
852832 }
853833
@@ -1062,9 +1042,9 @@
10631043 if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
10641044 {
10651045 GetClientRect(hWnd,&r);
1066 - GetClientRect(hRenderWnd,&r2);
 1046+ GetClientRect(RenderWnd->GetHWnd(),&r2);
10671047 if(memcmp(&r2,&r,sizeof(RECT)))
1068 - SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
 1048+ SetWindowPos(RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
10691049 }
10701050 RECT *viewrect = &r2;
10711051 SetSwap(swapinterval);
@@ -1097,8 +1077,8 @@
10981078 viewport[0] = viewport[1] = 0;
10991079 viewport[2] = viewrect->right;
11001080 viewport[3] = viewrect->bottom;
1101 - ClientToScreen(hRenderWnd,(LPPOINT)&viewrect->left);
1102 - ClientToScreen(hRenderWnd,(LPPOINT)&viewrect->right);
 1081+ ClientToScreen(RenderWnd->GetHWnd(),(LPPOINT)&viewrect->left);
 1082+ ClientToScreen(RenderWnd->GetHWnd(),(LPPOINT)&viewrect->right);
11031083 view[0] = (GLfloat)viewrect->left;
11041084 view[1] = (GLfloat)viewrect->right;
11051085 view[2] = (GLfloat)dest->fakey-(GLfloat)viewrect->top;
@@ -1178,7 +1158,7 @@
11791159 }
11801160 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
11811161 glFlush();
1182 - if(hasHWnd) SwapBuffers(hDC);
 1162+ if(hWnd) SwapBuffers(hDC);
11831163 else
11841164 {
11851165 glReadBuffer(GL_FRONT);
@@ -1196,7 +1176,7 @@
11971177 glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
11981178 glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
11991179 glPixelStorei(GL_PACK_ALIGNMENT,packalign);
1200 - HDC hRenderDC = (HDC)::GetDC(hRenderWnd);
 1180+ HDC hRenderDC = (HDC)::GetDC(RenderWnd->GetHWnd());
12011181 HGDIOBJ hPrevObj = 0;
12021182 POINT dest = {0,0};
12031183 POINT src = {0,0};
@@ -1203,11 +1183,11 @@
12041184 SIZE wnd = {dib.width,dib.height};
12051185 BLENDFUNCTION func = {AC_SRC_OVER,0,255,AC_SRC_ALPHA};
12061186 hPrevObj = SelectObject(dib.hdc,dib.hbitmap);
1207 - ClientToScreen(hRenderWnd,&dest);
1208 - UpdateLayeredWindow(hRenderWnd,hRenderDC,&dest,&wnd,
 1187+ ClientToScreen(RenderWnd->GetHWnd(),&dest);
 1188+ UpdateLayeredWindow(RenderWnd->GetHWnd(),hRenderDC,&dest,&wnd,
12091189 dib.hdc,&src,0,&func,ULW_ALPHA);
12101190 SelectObject(dib.hdc,hPrevObj);
1211 - ::ReleaseDC(hRenderWnd,hRenderDC);
 1191+ ReleaseDC(RenderWnd->GetHWnd(),hRenderDC);
12121192 }
12131193 if(setsync) SetEvent(busy);
12141194
@@ -1271,6 +1251,43 @@
12721252 SetEvent(busy);
12731253 }
12741254
 1255+void glRenderer::_SetWnd(int width, int height, int bpp, int fullscreen, HWND newwnd)
 1256+{
 1257+ if(newwnd != hWnd)
 1258+ {
 1259+ wglMakeCurrent(NULL,NULL);
 1260+ ReleaseDC(hWnd,hDC);
 1261+ delete RenderWnd;
 1262+ RenderWnd = new glRenderWindow(width,height,fullscreen,newwnd,ddInterface);
 1263+ PIXELFORMATDESCRIPTOR pfd;
 1264+ GLuint pf;
 1265+ gllock = true;
 1266+ ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
 1267+ pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
 1268+ pfd.nVersion = 1;
 1269+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
 1270+ pfd.iPixelType = PFD_TYPE_RGBA;
 1271+ pfd.cColorBits = bpp;
 1272+ pfd.iLayerType = PFD_MAIN_PLANE;
 1273+ hDC = GetDC(RenderWnd->GetHWnd());
 1274+ if(!hDC)
 1275+ DEBUG("glRenderer::SetWnd: Can not create hDC\n");
 1276+ pf = ChoosePixelFormat(hDC,&pfd);
 1277+ if(!pf)
 1278+ DEBUG("glRenderer::SetWnd: Can not get pixelformat\n");
 1279+ if(!SetPixelFormat(hDC,pf,&pfd))
 1280+ DEBUG("glRenderer::SetWnd: Can not set pixelformat\n");
 1281+ if(!wglMakeCurrent(hDC,hRC))
 1282+ DEBUG("glRenderer::SetWnd: Can not activate GL context\n");
 1283+ gllock = false;
 1284+ SetSwap(1);
 1285+ SetSwap(0);
 1286+ glViewport(0,0,width,height);
 1287+ }
 1288+
 1289+ SetEvent(busy);
 1290+}
 1291+
12751292 void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
12761293 DWORD indexcount, DWORD flags)
12771294 {
@@ -1458,84 +1475,4 @@
14591476 outputs[0] = (void*)D3D_OK;
14601477 SetEvent(busy);
14611478 return;
1462 -}
1463 -
1464 -LRESULT glRenderer::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1465 -{
1466 - int oldx,oldy;
1467 - float mulx, muly;
1468 - int translatex, translatey;
1469 - LPARAM newpos;
1470 - HWND hParent;
1471 - LONG sizes[6];
1472 - HCURSOR cursor;
1473 - switch(msg)
1474 - {
1475 - case WM_CREATE:
1476 - SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this);
1477 - return 0;
1478 - case WM_SETCURSOR:
1479 - hParent = GetParent(hwnd);
1480 - cursor = (HCURSOR)GetClassLong(hParent,GCL_HCURSOR);
1481 - SetCursor(cursor);
1482 - return SendMessage(hParent,msg,wParam,lParam);
1483 - case WM_MOUSEMOVE:
1484 - case WM_LBUTTONDOWN:
1485 - case WM_LBUTTONUP:
1486 - case WM_LBUTTONDBLCLK:
1487 - case WM_RBUTTONDOWN:
1488 - case WM_RBUTTONUP:
1489 - case WM_RBUTTONDBLCLK:
1490 - case WM_MBUTTONDOWN:
1491 - case WM_MBUTTONUP:
1492 - case WM_MBUTTONDBLCLK:
1493 - case WM_MOUSEWHEEL:
1494 - case WM_XBUTTONDOWN:
1495 - case WM_XBUTTONUP:
1496 - case WM_XBUTTONDBLCLK:
1497 - case WM_MOUSEHWHEEL:
1498 - hParent = GetParent(hwnd);
1499 - if((dxglcfg.scaler != 0) && ddInterface->GetFullscreen())
1500 - {
1501 - oldx = LOWORD(lParam);
1502 - oldy = HIWORD(lParam);
1503 - ddInterface->GetSizes(sizes);
1504 - mulx = (float)sizes[2] / (float)sizes[0];
1505 - muly = (float)sizes[3] / (float)sizes[1];
1506 - translatex = (sizes[4]-sizes[0])/2;
1507 - translatey = (sizes[5]-sizes[1])/2;
1508 - oldx -= translatex;
1509 - oldy -= translatey;
1510 - oldx = (int)((float)oldx * mulx);
1511 - oldy = (int)((float)oldy * muly);
1512 - if(oldx < 0) oldx = 0;
1513 - if(oldy < 0) oldy = 0;
1514 - if(oldx >= sizes[2]) oldx = sizes[2]-1;
1515 - if(oldy >= sizes[3]) oldy = sizes[3]-1;
1516 - newpos = oldx + (oldy << 16);
1517 - return SendMessage(hParent,msg,wParam,newpos);
1518 - }
1519 - else return SendMessage(hParent,msg,wParam,lParam);
1520 - default:
1521 - return DefWindowProc(hwnd,msg,wParam,lParam);
1522 - }
1523 - return 0;
1524 -}
1525 -
1526 -
1527 -// Render Window event handler
1528 -LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1529 -{
1530 - glRenderer* instance = reinterpret_cast<glRenderer*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
1531 - if(msg == WM_DESTROY)
1532 - {
1533 - return 0;
1534 - }
1535 - if(!instance)
1536 - {
1537 - if(msg == WM_CREATE)
1538 - instance = reinterpret_cast<glRenderer*>(*(LONG_PTR*)lParam);
1539 - else return DefWindowProc(hwnd,msg,wParam,lParam);
1540 - }
1541 - return instance->WndProc(hwnd,msg,wParam,lParam);
1542 -}
 1479+}
\ No newline at end of file
Index: ddraw/glRenderer.h
@@ -53,17 +53,18 @@
5454 extern BltVertex bltvertices[4];
5555
5656 #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
 57+#define OP_SETWND 1
 58+#define OP_DELETE 2
 59+#define OP_CREATE 3
 60+#define OP_UPLOAD 4
 61+#define OP_DOWNLOAD 5
 62+#define OP_DELETETEX 6
 63+#define OP_BLT 7
 64+#define OP_DRAWSCREEN 8
 65+#define OP_INITD3D 9
 66+#define OP_CLEAR 10
 67+#define OP_FLUSH 11
 68+#define OP_DRAWPRIMITIVES 12
6869
6970
7071 extern int swapinterval;
@@ -72,6 +73,7 @@
7374 class glDirectDraw7;
7475 class glDirect3DDevice7;
7576 class glDirectDrawSurface7;
 77+class glRenderWindow;
7678
7779 /** @brief glRenderer class
7880 * OpenGL renderer class for DXGL.
@@ -91,11 +93,11 @@
9294 void DeleteTexture(GLuint texture);
9395 void InitD3D(int zbuffer);
9496 void Flush();
 97+ void SetWnd(int width, int height, int fullscreen, int bpp, HWND newwnd);
9598 HRESULT Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
9699 HRESULT DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
97100 DWORD indexcount, DWORD flags);
98101 HGLRC hRC;
99 - LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
100102 GLCAPS gl_caps;
101103 private:
102104 // In-thread APIs
@@ -115,6 +117,7 @@
116118 DWORD indexcount, DWORD flags);
117119 glDirectDraw7 *ddInterface;
118120 void _Flush();
 121+ void _SetWnd(int width, int height, int fullscreen, int bpp, HWND newwnd);
119122 int opcode;
120123 void* inputs[32];
121124 void* outputs[32];
@@ -121,8 +124,7 @@
122125 HANDLE hThread;
123126 HDC hDC;
124127 HWND hWnd;
125 - HWND hRenderWnd;
126 - bool hasHWnd;
 128+ glRenderWindow *RenderWnd;
127129 DIB dib;
128130 GLuint PBO;
129131 CRITICAL_SECTION cs;