Index: ddraw/ddraw.cpp |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | #include "glClassFactory.h"
|
22 | 22 | #include "glDirectDraw.h"
|
23 | 23 | #include "glDirectDrawClipper.h"
|
| 24 | +#include "glRenderer.h"
|
24 | 25 | #include <intrin.h>
|
25 | 26 | #include <tlhelp32.h>
|
26 | 27 |
|
— | — | @@ -33,6 +34,7 @@ |
34 | 35 |
|
35 | 36 | DWORD timer;
|
36 | 37 | int vsyncstatus;
|
| 38 | +glRenderer *renderer = NULL;
|
37 | 39 | bool ddenabled = false;
|
38 | 40 |
|
39 | 41 | /**
|
— | — | @@ -59,6 +61,12 @@ |
60 | 62 | }
|
61 | 63 | }
|
62 | 64 |
|
| 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 | +
|
63 | 71 | /// Stub for function found in system ddraw.dll
|
64 | 72 | DDRAW_API void WINAPI AcquireDDThreadLock()
|
65 | 73 | {
|
Index: ddraw/ddraw.h |
— | — | @@ -16,8 +16,8 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #pragma once
|
20 | | -#ifndef _DDRAW_H
|
21 | | -#define _DDRAW_H
|
| 20 | +#ifndef _DDRAW_PRIVATE_H
|
| 21 | +#define _DDRAW_PRIVATE_H
|
22 | 22 |
|
23 | 23 | #ifdef DDRAW_EXPORTS
|
24 | 24 | #define DDRAW_API __declspec(dllexport)
|
— | — | @@ -61,5 +61,9 @@ |
62 | 62 | extern DWORD timer;
|
63 | 63 | extern int vsyncstatus;
|
64 | 64 | 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);
|
65 | 69 |
|
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 @@ |
177 | 177 | <ClInclude Include="glDirectDrawSurface.h" />
|
178 | 178 | <ClInclude Include="glExtensions.h" />
|
179 | 179 | <ClInclude Include="glRenderer.h" />
|
| 180 | + <ClInclude Include="glRenderWindow.h" />
|
180 | 181 | <ClInclude Include="glutil.h" />
|
181 | 182 | <ClInclude Include="include\d3d.h" />
|
182 | 183 | <ClInclude Include="include\d3dcaps.h" />
|
— | — | @@ -221,6 +222,7 @@ |
222 | 223 | <ClCompile Include="glDirectDrawSurface.cpp" />
|
223 | 224 | <ClCompile Include="glExtensions.cpp" />
|
224 | 225 | <ClCompile Include="glRenderer.cpp" />
|
| 226 | + <ClCompile Include="glRenderWindow.cpp" />
|
225 | 227 | <ClCompile Include="glutil.cpp" />
|
226 | 228 | <ClCompile Include="matrix.cpp" />
|
227 | 229 | <ClCompile Include="precomp.cpp">
|
Index: ddraw/ddraw.vcxproj.filters |
— | — | @@ -101,6 +101,9 @@ |
102 | 102 | <ClInclude Include="resource.h">
|
103 | 103 | <Filter>Header Files</Filter>
|
104 | 104 | </ClInclude>
|
| 105 | + <ClInclude Include="glRenderWindow.h">
|
| 106 | + <Filter>Header Files</Filter>
|
| 107 | + </ClInclude>
|
105 | 108 | </ItemGroup>
|
106 | 109 | <ItemGroup>
|
107 | 110 | <ClCompile Include="ddraw.cpp">
|
— | — | @@ -160,6 +163,9 @@ |
161 | 164 | <ClCompile Include="matrix.cpp">
|
162 | 165 | <Filter>Source Files</Filter>
|
163 | 166 | </ClCompile>
|
| 167 | + <ClCompile Include="glRenderWindow.cpp">
|
| 168 | + <Filter>Source Files</Filter>
|
| 169 | + </ClCompile>
|
164 | 170 | </ItemGroup>
|
165 | 171 | <ItemGroup>
|
166 | 172 | <ResourceCompile Include="ddraw.rc">
|
Index: ddraw/dllmain.cpp |
— | — | @@ -16,6 +16,8 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #include "common.h"
|
| 20 | +#include "ddraw.h"
|
| 21 | +#include "glRenderer.h"
|
20 | 22 | ATOM WindowClass = NULL;
|
21 | 23 | BOOL APIENTRY DllMain( HMODULE hModule,
|
22 | 24 | DWORD ul_reason_for_call,
|
Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #include "common.h"
|
| 20 | +#include "ddraw.h"
|
20 | 21 | #include "glDirect3D.h"
|
21 | 22 | #include "glRenderer.h"
|
22 | 23 | #include "glDirectDraw.h"
|
— | — | @@ -233,8 +234,8 @@ |
234 | 235 | memset(gllights,0xff,8*sizeof(int));
|
235 | 236 | memset(gltextures,0,8*sizeof(GLuint));
|
236 | 237 | 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);
|
239 | 240 | }
|
240 | 241 | glDirect3DDevice7::~glDirect3DDevice7()
|
241 | 242 | {
|
— | — | @@ -323,7 +324,7 @@ |
324 | 325 | {
|
325 | 326 | if(!this) return DDERR_INVALIDPARAMS;
|
326 | 327 | 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);
|
328 | 329 | }
|
329 | 330 | HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
|
330 | 331 | DWORD dwFlags, LPDWORD lpdwReturnValues)
|
— | — | @@ -519,7 +520,7 @@ |
520 | 521 | if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
521 | 522 | HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
|
522 | 523 | 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,
|
524 | 525 | dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
|
525 | 526 | }
|
526 | 527 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
— | — | @@ -561,7 +562,7 @@ |
562 | 563 | if(!this) return DDERR_INVALIDPARAMS;
|
563 | 564 | if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
564 | 565 | inscene = false;
|
565 | | - glD3D7->glDD7->renderer->Flush();
|
| 566 | + renderer->Flush();
|
566 | 567 | return D3D_OK;
|
567 | 568 | }
|
568 | 569 | HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
|
Index: ddraw/glDirectDraw.cpp |
— | — | @@ -552,7 +552,6 @@ |
553 | 553 | glD3D7 = NULL;
|
554 | 554 | clippers = NULL;
|
555 | 555 | surfaces = NULL;
|
556 | | - renderer = NULL;
|
557 | 556 | initialized = false;
|
558 | 557 | devid.liDriverVersion.QuadPart = DXGLVERQWORD;
|
559 | 558 | refcount = 1;
|
— | — | @@ -593,7 +592,8 @@ |
594 | 593 | }
|
595 | 594 | free(surfaces);
|
596 | 595 | }
|
597 | | - DeleteGL();
|
| 596 | + if(renderer) delete renderer;
|
| 597 | + renderer = NULL;
|
598 | 598 | ddenabled = false;
|
599 | 599 | directdraw_created = false;
|
600 | 600 | }
|
— | — | @@ -1004,7 +1004,6 @@ |
1005 | 1005 | {
|
1006 | 1006 | if(!this) return DDERR_INVALIDPARAMS;
|
1007 | 1007 | this->hWnd = hWnd;
|
1008 | | - if(renderer) DeleteGL();
|
1009 | 1008 | winstyle = GetWindowLongPtrA(hWnd,GWL_STYLE);
|
1010 | 1009 | winstyleex = GetWindowLongPtrA(hWnd,GWL_EXSTYLE);
|
1011 | 1010 | bool exclusive = false;
|
— | — | @@ -1068,8 +1067,8 @@ |
1069 | 1068 | }
|
1070 | 1069 | bpp = devmode.dmBitsPerPel;
|
1071 | 1070 | 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;
|
1074 | 1073 | }
|
1075 | 1074 |
|
1076 | 1075 | void DiscardUndersizedModes(DEVMODE **array, DWORD *count, DEVMODE comp)
|
— | — | @@ -1174,8 +1173,7 @@ |
1175 | 1174 | primarybpp = dwBPP;
|
1176 | 1175 | if(dwRefreshRate) internalrefresh = primaryrefresh = screenrefresh = dwRefreshRate;
|
1177 | 1176 | else internalrefresh = primaryrefresh = screenrefresh = currmode.dmDisplayFrequency;
|
1178 | | - DeleteGL();
|
1179 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1177 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1180 | 1178 | primarylost = true;
|
1181 | 1179 | return DD_OK;
|
1182 | 1180 | case DISP_CHANGE_BADMODE:
|
— | — | @@ -1205,8 +1203,7 @@ |
1206 | 1204 | if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
|
1207 | 1205 | else internalbpp = screenbpp = currmode.dmBitsPerPel;
|
1208 | 1206 | primarybpp = dwBPP;
|
1209 | | - DeleteGL();
|
1210 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1207 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1211 | 1208 | primarylost = true;
|
1212 | 1209 | return DD_OK;
|
1213 | 1210 | break;
|
— | — | @@ -1231,8 +1228,7 @@ |
1232 | 1229 | if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
|
1233 | 1230 | else internalbpp = screenbpp = currmode.dmBitsPerPel;
|
1234 | 1231 | primarybpp = dwBPP;
|
1235 | | - DeleteGL();
|
1236 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1232 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1237 | 1233 | primarylost = true;
|
1238 | 1234 | return DD_OK;
|
1239 | 1235 | break;
|
— | — | @@ -1244,8 +1240,7 @@ |
1245 | 1241 | primarybpp = dwBPP;
|
1246 | 1242 | if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
|
1247 | 1243 | else internalbpp = screenbpp = currmode.dmBitsPerPel;
|
1248 | | - DeleteGL();
|
1249 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1244 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1250 | 1245 | break;
|
1251 | 1246 | case 4: // Switch then stretch
|
1252 | 1247 | case 5: // Switch then scale
|
— | — | @@ -1279,8 +1274,7 @@ |
1280 | 1275 | if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
|
1281 | 1276 | else internalbpp = screenbpp = newmode2.dmBitsPerPel;
|
1282 | 1277 | primarybpp = dwBPP;
|
1283 | | - DeleteGL();
|
1284 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1278 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1285 | 1279 | primarylost = true;
|
1286 | 1280 | return DD_OK;
|
1287 | 1281 | break;
|
— | — | @@ -1305,8 +1299,7 @@ |
1306 | 1300 | if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
|
1307 | 1301 | else internalbpp = screenbpp = newmode2.dmBitsPerPel;
|
1308 | 1302 | primarybpp = dwBPP;
|
1309 | | - DeleteGL();
|
1310 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1303 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1311 | 1304 | primarylost = true;
|
1312 | 1305 | return DD_OK;
|
1313 | 1306 | break;
|
— | — | @@ -1319,8 +1312,7 @@ |
1320 | 1313 | primarybpp = dwBPP;
|
1321 | 1314 | if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
|
1322 | 1315 | else internalbpp = screenbpp = newmode2.dmBitsPerPel;
|
1323 | | - DeleteGL();
|
1324 | | - InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1316 | + InitGL(screenx,screeny,screenbpp,true,hWnd,this);
|
1325 | 1317 | primarylost = true;
|
1326 | 1318 | return DD_OK;
|
1327 | 1319 | break;
|
— | — | @@ -1384,17 +1376,6 @@ |
1385 | 1377 | ERR(DDERR_GENERIC);
|
1386 | 1378 | }
|
1387 | 1379 |
|
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 | | -}
|
1399 | 1380 | void glDirectDraw7::GetSizes(LONG *sizes) // allocate 6 dwords
|
1400 | 1381 | {
|
1401 | 1382 | sizes[0] = internalx;
|
Index: ddraw/glDirectDraw.h |
— | — | @@ -24,8 +24,6 @@ |
25 | 25 | class glDirect3D7;
|
26 | 26 | class glRenderer;
|
27 | 27 |
|
28 | | -LRESULT CALLBACK RenderWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
29 | | -
|
30 | 28 | class glDirectDraw7 : public IDirectDraw7
|
31 | 29 | {
|
32 | 30 | public:
|
— | — | @@ -83,10 +81,7 @@ |
84 | 82 | void DeleteClipper(glDirectDrawClipper *clipper);
|
85 | 83 | glDirectDrawSurface7 *primary;
|
86 | 84 | bool primarylost;
|
87 | | - glRenderer *renderer;
|
88 | 85 | private:
|
89 | | - void DeleteGL();
|
90 | | - BOOL InitGL(int width, int height, int bpp, bool fullscreen, HWND hWnd);
|
91 | 86 | HRESULT error;
|
92 | 87 | ULONG refcount;
|
93 | 88 | HWND hWnd;
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -66,8 +66,7 @@ |
67 | 67 | else
|
68 | 68 | {
|
69 | 69 | ddInterface = (glDirectDraw7 *)lpDD7;
|
70 | | - renderer = ddInterface->renderer;
|
71 | | - hRC = ddInterface->renderer->hRC;
|
| 70 | + hRC = renderer->hRC;
|
72 | 71 | ddsd = *lpDDSurfaceDesc2;
|
73 | 72 | }
|
74 | 73 | LONG sizes[6];
|
— | — | @@ -895,7 +894,7 @@ |
896 | 895 | HRESULT WINAPI glDirectDrawSurface7::IsLost()
|
897 | 896 | {
|
898 | 897 | if(!this) return DDERR_INVALIDPARAMS;
|
899 | | - if(hRC == ddInterface->renderer->hRC) return DD_OK;
|
| 898 | + if(hRC == renderer->hRC) return DD_OK;
|
900 | 899 | else return DDERR_SURFACELOST;
|
901 | 900 | }
|
902 | 901 |
|
— | — | @@ -951,7 +950,7 @@ |
952 | 951 | void glDirectDrawSurface7::Restore2()
|
953 | 952 | {
|
954 | 953 | LONG sizes[6];
|
955 | | - if(hRC != ddInterface->renderer->hRC)
|
| 954 | + if(hRC != renderer->hRC)
|
956 | 955 | {
|
957 | 956 | ddInterface->GetSizes(sizes);
|
958 | 957 | if(ddInterface->GetFullscreen())
|
— | — | @@ -986,8 +985,8 @@ |
987 | 986 | {
|
988 | 987 | if(!this) return DDERR_INVALIDPARAMS;
|
989 | 988 | 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)
|
992 | 991 | {
|
993 | 992 | if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
994 | 993 | {
|
Index: ddraw/glDirectDrawSurface.h |
— | — | @@ -26,7 +26,6 @@ |
27 | 27 | DDCOLORKEY key;
|
28 | 28 | } CKEY;
|
29 | 29 |
|
30 | | -class glRenderer;
|
31 | 30 | class glDirectDrawClipper;
|
32 | 31 | class glDirectDrawPalette;
|
33 | 32 | class glDirectDrawSurface1;
|
— | — | @@ -115,7 +114,6 @@ |
116 | 115 | GLint texformat3;
|
117 | 116 | DWORD fakex,fakey;
|
118 | 117 | DWORD dirty;
|
119 | | - glRenderer *renderer;
|
120 | 118 | // dirty bits:
|
121 | 119 | // 1 - Surface was locked
|
122 | 120 | // 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 @@ |
20 | 20 | #include "glDirectDraw.h"
|
21 | 21 | #include "glDirectDrawSurface.h"
|
22 | 22 | #include "glDirectDrawPalette.h"
|
| 23 | +#include "glRenderWindow.h"
|
23 | 24 | #include "glRenderer.h"
|
24 | 25 | #include "glDirect3DDevice.h"
|
25 | 26 | #include "glDirect3DLight.h"
|
— | — | @@ -30,8 +31,6 @@ |
31 | 32 | #include "shadergen.h"
|
32 | 33 | #include "matrix.h"
|
33 | 34 |
|
34 | | -WNDCLASSEXA wndclass;
|
35 | | -bool wndclasscreated = false;
|
36 | 35 | GLuint backbuffer = 0;
|
37 | 36 | int backx = 0;
|
38 | 37 | int backy = 0;
|
— | — | @@ -209,10 +208,8 @@ |
210 | 209 | hDC = NULL;
|
211 | 210 | hRC = NULL;
|
212 | 211 | PBO = 0;
|
213 | | - hasHWnd = false;
|
214 | 212 | dib.enabled = false;
|
215 | 213 | hWnd = hwnd;
|
216 | | - hRenderWnd = NULL;
|
217 | 214 | InitializeCriticalSection(&cs);
|
218 | 215 | busy = CreateEvent(NULL,FALSE,FALSE,NULL);
|
219 | 216 | start = CreateEvent(NULL,FALSE,FALSE,NULL);
|
— | — | @@ -227,47 +224,7 @@ |
228 | 225 | // TODO: Adjust window rect
|
229 | 226 | }
|
230 | 227 | 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);
|
272 | 229 | inputs[0] = (void*)width;
|
273 | 230 | inputs[1] = (void*)height;
|
274 | 231 | inputs[2] = (void*)bpp;
|
— | — | @@ -287,7 +244,7 @@ |
288 | 245 | EnterCriticalSection(&cs);
|
289 | 246 | opcode = OP_DELETE;
|
290 | 247 | SetEvent(start);
|
291 | | - WaitForSingleObject(busy,INFINITE);
|
| 248 | + WaitForObjectAndMessages(busy);
|
292 | 249 | CloseHandle(start);
|
293 | 250 | CloseHandle(busy);
|
294 | 251 | LeaveCriticalSection(&cs);
|
— | — | @@ -487,9 +444,9 @@ |
488 | 445 | !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
|
489 | 446 | {
|
490 | 447 | GetClientRect(hWnd,&r);
|
491 | | - GetClientRect(hRenderWnd,&r2);
|
| 448 | + GetClientRect(RenderWnd->GetHWnd(),&r2);
|
492 | 449 | 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);
|
494 | 451 | }
|
495 | 452 | inputs[0] = lpDestRect;
|
496 | 453 | inputs[1] = src;
|
— | — | @@ -591,6 +548,33 @@ |
592 | 549 | }
|
593 | 550 |
|
594 | 551 | /**
|
| 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 | +/**
|
595 | 579 | * Draws one or more primitives to the currently selected render target.
|
596 | 580 | * @param device
|
597 | 581 | * glDirect3DDevice7 interface to use for drawing
|
— | — | @@ -651,7 +635,7 @@ |
652 | 636 | WaitForSingleObject(start,INFINITE);
|
653 | 637 | switch(opcode)
|
654 | 638 | {
|
655 | | - case OP_DELETE:
|
| 639 | + case OP_DELETE:
|
656 | 640 | if(hRC)
|
657 | 641 | {
|
658 | 642 | if(dib.enabled)
|
— | — | @@ -679,14 +663,16 @@ |
680 | 664 | wglDeleteContext(hRC);
|
681 | 665 | hRC = NULL;
|
682 | 666 | };
|
683 | | - if(hDC) ReleaseDC(hRenderWnd,hDC);
|
| 667 | + if(hDC) ReleaseDC(RenderWnd->GetHWnd(),hDC);
|
684 | 668 | hDC = NULL;
|
685 | | - SetWindowLongPtr(hRenderWnd,GWLP_USERDATA,0);
|
686 | | - PostMessage(hRenderWnd,WM_CLOSE,0,0);
|
687 | | - hRenderWnd = NULL;
|
| 669 | + delete RenderWnd;
|
| 670 | + RenderWnd = NULL;
|
688 | 671 | SetEvent(busy);
|
689 | 672 | return 0;
|
690 | 673 | break;
|
| 674 | + case OP_SETWND:
|
| 675 | + _SetWnd((int)inputs[0],(int)inputs[1],(int)inputs[2],(int)inputs[3],(HWND)inputs[4]);
|
| 676 | + break;
|
691 | 677 | case OP_CREATE:
|
692 | 678 | outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
|
693 | 679 | (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8],true);
|
— | — | @@ -762,44 +748,38 @@ |
763 | 749 | ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
|
764 | 750 | pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
765 | 751 | 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;
|
768 | 753 | 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;
|
775 | 755 | pfd.iLayerType = PFD_MAIN_PLANE;
|
776 | | - hDC = GetDC(hRenderWnd);
|
| 756 | + gllock = true;
|
| 757 | + hDC = GetDC(RenderWnd->GetHWnd());
|
777 | 758 | if(!hDC)
|
778 | 759 | {
|
779 | | - DEBUG("glDirectDraw7::InitGL: Can not create hDC\n");
|
| 760 | + DEBUG("glRenderer::InitGL: Can not create hDC\n");
|
780 | 761 | return FALSE;
|
781 | 762 | }
|
782 | 763 | pf = ChoosePixelFormat(hDC,&pfd);
|
783 | 764 | if(!pf)
|
784 | 765 | {
|
785 | | - DEBUG("glDirectDraw7::InitGL: Can not get pixelformat\n");
|
| 766 | + DEBUG("glRenderer::InitGL: Can not get pixelformat\n");
|
786 | 767 | return FALSE;
|
787 | 768 | }
|
788 | 769 | 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");
|
791 | 771 | hRC = wglCreateContext(hDC);
|
792 | 772 | if(!hRC)
|
793 | 773 | {
|
794 | | - DEBUG("glDirectDraw7::InitGL: Can not create GL context\n");
|
| 774 | + DEBUG("glRenderer::InitGL: Can not create GL context\n");
|
795 | 775 | gllock = false;
|
796 | 776 | return FALSE;
|
797 | 777 | }
|
798 | 778 | if(!wglMakeCurrent(hDC,hRC))
|
799 | 779 | {
|
800 | | - DEBUG("glDirectDraw7::InitGL: Can not activate GL context\n");
|
| 780 | + DEBUG("glRenderer::InitGL: Can not activate GL context\n");
|
801 | 781 | wglDeleteContext(hRC);
|
802 | 782 | hRC = NULL;
|
803 | | - ReleaseDC(hRenderWnd,hDC);
|
| 783 | + ReleaseDC(RenderWnd->GetHWnd(),hDC);
|
804 | 784 | hDC = NULL;
|
805 | 785 | gllock = false;
|
806 | 786 | return FALSE;
|
— | — | @@ -826,7 +806,7 @@ |
827 | 807 | glFlush();
|
828 | 808 | SwapBuffers(hDC);
|
829 | 809 | SetActiveTexture(0);
|
830 | | - if(!hasHWnd)
|
| 810 | + if(hWnd)
|
831 | 811 | {
|
832 | 812 | dib.enabled = true;
|
833 | 813 | dib.width = width;
|
— | — | @@ -842,11 +822,11 @@ |
843 | 823 | dib.info.bmiHeader.biCompression = BI_RGB;
|
844 | 824 | dib.info.bmiHeader.biPlanes = 1;
|
845 | 825 | 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);
|
850 | 826 | }
|
| 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);
|
851 | 831 | return TRUE;
|
852 | 832 | }
|
853 | 833 |
|
— | — | @@ -1062,9 +1042,9 @@ |
1063 | 1043 | if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
|
1064 | 1044 | {
|
1065 | 1045 | GetClientRect(hWnd,&r);
|
1066 | | - GetClientRect(hRenderWnd,&r2);
|
| 1046 | + GetClientRect(RenderWnd->GetHWnd(),&r2);
|
1067 | 1047 | 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);
|
1069 | 1049 | }
|
1070 | 1050 | RECT *viewrect = &r2;
|
1071 | 1051 | SetSwap(swapinterval);
|
— | — | @@ -1097,8 +1077,8 @@ |
1098 | 1078 | viewport[0] = viewport[1] = 0;
|
1099 | 1079 | viewport[2] = viewrect->right;
|
1100 | 1080 | 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);
|
1103 | 1083 | view[0] = (GLfloat)viewrect->left;
|
1104 | 1084 | view[1] = (GLfloat)viewrect->right;
|
1105 | 1085 | view[2] = (GLfloat)dest->fakey-(GLfloat)viewrect->top;
|
— | — | @@ -1178,7 +1158,7 @@ |
1179 | 1159 | }
|
1180 | 1160 | glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
|
1181 | 1161 | glFlush();
|
1182 | | - if(hasHWnd) SwapBuffers(hDC);
|
| 1162 | + if(hWnd) SwapBuffers(hDC);
|
1183 | 1163 | else
|
1184 | 1164 | {
|
1185 | 1165 | glReadBuffer(GL_FRONT);
|
— | — | @@ -1196,7 +1176,7 @@ |
1197 | 1177 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
1198 | 1178 | glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
1199 | 1179 | glPixelStorei(GL_PACK_ALIGNMENT,packalign);
|
1200 | | - HDC hRenderDC = (HDC)::GetDC(hRenderWnd);
|
| 1180 | + HDC hRenderDC = (HDC)::GetDC(RenderWnd->GetHWnd());
|
1201 | 1181 | HGDIOBJ hPrevObj = 0;
|
1202 | 1182 | POINT dest = {0,0};
|
1203 | 1183 | POINT src = {0,0};
|
— | — | @@ -1203,11 +1183,11 @@ |
1204 | 1184 | SIZE wnd = {dib.width,dib.height};
|
1205 | 1185 | BLENDFUNCTION func = {AC_SRC_OVER,0,255,AC_SRC_ALPHA};
|
1206 | 1186 | 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,
|
1209 | 1189 | dib.hdc,&src,0,&func,ULW_ALPHA);
|
1210 | 1190 | SelectObject(dib.hdc,hPrevObj);
|
1211 | | - ::ReleaseDC(hRenderWnd,hRenderDC);
|
| 1191 | + ReleaseDC(RenderWnd->GetHWnd(),hRenderDC);
|
1212 | 1192 | }
|
1213 | 1193 | if(setsync) SetEvent(busy);
|
1214 | 1194 |
|
— | — | @@ -1271,6 +1251,43 @@ |
1272 | 1252 | SetEvent(busy);
|
1273 | 1253 | }
|
1274 | 1254 |
|
| 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 | +
|
1275 | 1292 | void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
1276 | 1293 | DWORD indexcount, DWORD flags)
|
1277 | 1294 | {
|
— | — | @@ -1458,84 +1475,4 @@ |
1459 | 1476 | outputs[0] = (void*)D3D_OK;
|
1460 | 1477 | SetEvent(busy);
|
1461 | 1478 | 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 @@ |
54 | 54 | extern BltVertex bltvertices[4];
|
55 | 55 |
|
56 | 56 | #define OP_NULL 0
|
57 | | -#define OP_DELETE 1
|
58 | | -#define OP_CREATE 2
|
59 | | -#define OP_UPLOAD 3
|
60 | | -#define OP_DOWNLOAD 4
|
61 | | -#define OP_DELETETEX 5
|
62 | | -#define OP_BLT 6
|
63 | | -#define OP_DRAWSCREEN 7
|
64 | | -#define OP_INITD3D 8
|
65 | | -#define OP_CLEAR 9
|
66 | | -#define OP_FLUSH 10
|
67 | | -#define OP_DRAWPRIMITIVES 11
|
| 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
|
68 | 69 |
|
69 | 70 |
|
70 | 71 | extern int swapinterval;
|
— | — | @@ -72,6 +73,7 @@ |
73 | 74 | class glDirectDraw7;
|
74 | 75 | class glDirect3DDevice7;
|
75 | 76 | class glDirectDrawSurface7;
|
| 77 | +class glRenderWindow;
|
76 | 78 |
|
77 | 79 | /** @brief glRenderer class
|
78 | 80 | * OpenGL renderer class for DXGL.
|
— | — | @@ -91,11 +93,11 @@ |
92 | 94 | void DeleteTexture(GLuint texture);
|
93 | 95 | void InitD3D(int zbuffer);
|
94 | 96 | void Flush();
|
| 97 | + void SetWnd(int width, int height, int fullscreen, int bpp, HWND newwnd);
|
95 | 98 | HRESULT Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
|
96 | 99 | HRESULT DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
97 | 100 | DWORD indexcount, DWORD flags);
|
98 | 101 | HGLRC hRC;
|
99 | | - LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
100 | 102 | GLCAPS gl_caps;
|
101 | 103 | private:
|
102 | 104 | // In-thread APIs
|
— | — | @@ -115,6 +117,7 @@ |
116 | 118 | DWORD indexcount, DWORD flags);
|
117 | 119 | glDirectDraw7 *ddInterface;
|
118 | 120 | void _Flush();
|
| 121 | + void _SetWnd(int width, int height, int fullscreen, int bpp, HWND newwnd);
|
119 | 122 | int opcode;
|
120 | 123 | void* inputs[32];
|
121 | 124 | void* outputs[32];
|
— | — | @@ -121,8 +124,7 @@ |
122 | 125 | HANDLE hThread;
|
123 | 126 | HDC hDC;
|
124 | 127 | HWND hWnd;
|
125 | | - HWND hRenderWnd;
|
126 | | - bool hasHWnd;
|
| 128 | + glRenderWindow *RenderWnd;
|
127 | 129 | DIB dib;
|
128 | 130 | GLuint PBO;
|
129 | 131 | CRITICAL_SECTION cs;
|