Index: ddraw/glDirectDraw.cpp |
— | — | @@ -700,8 +700,17 @@ |
701 | 701 | }
|
702 | 702 | HRESULT WINAPI glDirectDraw7::CreateSurface(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
|
703 | 703 | {
|
704 | | - if(primary && (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (renderer == primary->renderer) )
|
705 | | - ERR(DDERR_PRIMARYSURFACEALREADYEXISTS);
|
| 704 | + if(primary && (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (renderer->hRC == primary->hRC) )
|
| 705 | + {
|
| 706 | + if(primarylost)
|
| 707 | + {
|
| 708 | + primary->Restore();
|
| 709 | + *lplpDDSurface = primary;
|
| 710 | + primarylost = false;
|
| 711 | + return DD_OK;
|
| 712 | + }
|
| 713 | + else return DDERR_PRIMARYSURFACEALREADYEXISTS;
|
| 714 | + }
|
706 | 715 | surfacecount++;
|
707 | 716 | if(surfacecount > surfacecountmax)
|
708 | 717 | {
|
— | — | @@ -716,7 +725,10 @@ |
717 | 726 | HRESULT error;
|
718 | 727 | surfaces[surfacecount-1] = new glDirectDrawSurface7(this,lpDDSurfaceDesc2,lplpDDSurface,&error,false,NULL);
|
719 | 728 | if(lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
| 729 | + {
|
720 | 730 | primary = surfaces[surfacecount-1];
|
| 731 | + primarylost = false;
|
| 732 | + }
|
721 | 733 | *lplpDDSurface = surfaces[surfacecount-1];
|
722 | 734 | return error;
|
723 | 735 | }
|
— | — | @@ -892,6 +904,7 @@ |
893 | 905 | HRESULT WINAPI glDirectDraw7::Initialize(GUID FAR *lpGUID)
|
894 | 906 | {
|
895 | 907 | if(initialized) return DDERR_ALREADYINITIALIZED;
|
| 908 | + primarylost = true;
|
896 | 909 | glD3D7 = NULL;
|
897 | 910 | renderer = NULL;
|
898 | 911 | primary = NULL;
|
— | — | @@ -1111,6 +1124,7 @@ |
1112 | 1125 | else internalrefresh = primaryrefresh = screenrefresh = currmode.dmDisplayFrequency;
|
1113 | 1126 | DeleteGL();
|
1114 | 1127 | InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1128 | + primarylost = true;
|
1115 | 1129 | return DD_OK;
|
1116 | 1130 | case DISP_CHANGE_BADMODE:
|
1117 | 1131 | ERR(DDERR_INVALIDMODE);
|
— | — | @@ -1141,6 +1155,7 @@ |
1142 | 1156 | primarybpp = dwBPP;
|
1143 | 1157 | DeleteGL();
|
1144 | 1158 | InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1159 | + primarylost = true;
|
1145 | 1160 | return DD_OK;
|
1146 | 1161 | break;
|
1147 | 1162 | case 2: // Scale to screen
|
— | — | @@ -1166,6 +1181,7 @@ |
1167 | 1182 | primarybpp = dwBPP;
|
1168 | 1183 | DeleteGL();
|
1169 | 1184 | InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1185 | + primarylost = true;
|
1170 | 1186 | return DD_OK;
|
1171 | 1187 | break;
|
1172 | 1188 | case 3: // Center image
|
— | — | @@ -1213,6 +1229,7 @@ |
1214 | 1230 | primarybpp = dwBPP;
|
1215 | 1231 | DeleteGL();
|
1216 | 1232 | InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1233 | + primarylost = true;
|
1217 | 1234 | return DD_OK;
|
1218 | 1235 | break;
|
1219 | 1236 | case 5:
|
— | — | @@ -1238,6 +1255,7 @@ |
1239 | 1256 | primarybpp = dwBPP;
|
1240 | 1257 | DeleteGL();
|
1241 | 1258 | InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1259 | + primarylost = true;
|
1242 | 1260 | return DD_OK;
|
1243 | 1261 | break;
|
1244 | 1262 | case 6:
|
— | — | @@ -1251,6 +1269,8 @@ |
1252 | 1270 | else internalbpp = screenbpp = newmode2.dmBitsPerPel;
|
1253 | 1271 | DeleteGL();
|
1254 | 1272 | InitGL(screenx,screeny,screenbpp,true,hWnd);
|
| 1273 | + primarylost = true;
|
| 1274 | + return DD_OK;
|
1255 | 1275 | break;
|
1256 | 1276 | }
|
1257 | 1277 | break;
|
— | — | @@ -1260,9 +1280,9 @@ |
1261 | 1281 | HRESULT WINAPI glDirectDraw7::WaitForVerticalBlank(DWORD dwFlags, HANDLE hEvent)
|
1262 | 1282 | {
|
1263 | 1283 | if(dwFlags & DDWAITVB_BLOCKBEGINEVENT) return DDERR_UNSUPPORTED;
|
1264 | | - SetSwap(1);
|
| 1284 | + swapinterval=1;
|
1265 | 1285 | primary->RenderScreen(primary->texture,primary);
|
1266 | | - SetSwap(0);
|
| 1286 | + swapinterval=0;
|
1267 | 1287 | return DD_OK;
|
1268 | 1288 | }
|
1269 | 1289 | HRESULT WINAPI glDirectDraw7::GetAvailableVidMem(LPDDSCAPS2 lpDDSCaps2, LPDWORD lpdwTotal, LPDWORD lpdwFree)
|
Index: ddraw/glDirectDraw.h |
— | — | @@ -82,6 +82,7 @@ |
83 | 83 | bool GetFullscreen(){return fullscreen;};
|
84 | 84 | void DeleteSurface(glDirectDrawSurface7 *surface);
|
85 | 85 | glDirectDrawSurface7 *primary;
|
| 86 | + bool primarylost;
|
86 | 87 | glRenderer *renderer;
|
87 | 88 | private:
|
88 | 89 | void DeleteGL();
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | bigbuffer = NULL;
|
65 | 65 | zbuffer = NULL;
|
66 | 66 | DWORD colormasks[3];
|
67 | | - GLint filter = GL_NEAREST;
|
| 67 | + filter = GL_NEAREST;
|
68 | 68 | if(copysurface)
|
69 | 69 | {
|
70 | 70 | FIXME("glDirectDrawSurface7::glDirectDrawSurface7: copy surface stub\n");
|
— | — | @@ -74,6 +74,7 @@ |
75 | 75 | {
|
76 | 76 | ddInterface = (glDirectDraw7 *)lpDD7;
|
77 | 77 | renderer = ddInterface->renderer;
|
| 78 | + hRC = ddInterface->renderer->hRC;
|
78 | 79 | ddsd = *lpDDSurfaceDesc2;
|
79 | 80 | }
|
80 | 81 | LONG sizes[6];
|
— | — | @@ -384,6 +385,7 @@ |
385 | 386 | }
|
386 | 387 | glDirectDrawSurface7::~glDirectDrawSurface7()
|
387 | 388 | {
|
| 389 | + AddRef();
|
388 | 390 | if(dds1) dds1->Release();
|
389 | 391 | if(dds2) dds2->Release();
|
390 | 392 | if(dds3) dds3->Release();
|
— | — | @@ -577,13 +579,13 @@ |
578 | 580 | }
|
579 | 581 | HRESULT WINAPI glDirectDrawSurface7::Flip(LPDIRECTDRAWSURFACE7 lpDDSurfaceTargetOverride, DWORD dwFlags)
|
580 | 582 | {
|
581 | | - if(dwFlags & DDFLIP_NOVSYNC) SetSwap(0);
|
| 583 | + if(dwFlags & DDFLIP_NOVSYNC) swapinterval=0;
|
582 | 584 | else
|
583 | 585 | {
|
584 | | - if(dwFlags & DDFLIP_INTERVAL3) SetSwap(3);
|
585 | | - else if(dwFlags & DDFLIP_INTERVAL2) SetSwap(2);
|
586 | | - else if(dwFlags & DDFLIP_INTERVAL4) SetSwap(4);
|
587 | | - else SetSwap(1);
|
| 586 | + if(dwFlags & DDFLIP_INTERVAL3) swapinterval=3;
|
| 587 | + else if(dwFlags & DDFLIP_INTERVAL2) swapinterval=2;
|
| 588 | + else if(dwFlags & DDFLIP_INTERVAL4) swapinterval=4;
|
| 589 | + else swapinterval=1;
|
588 | 590 | }
|
589 | 591 | int flips = 1;
|
590 | 592 | if(lpDDSurfaceTargetOverride) ERR(DDERR_GENERIC);
|
— | — | @@ -741,6 +743,7 @@ |
742 | 744 | }
|
743 | 745 | HRESULT WINAPI glDirectDrawSurface7::GetFlipStatus(DWORD dwFlags)
|
744 | 746 | {
|
| 747 | + return DD_OK;
|
745 | 748 | FIXME("glDirectDrawSurface7::GetFlipStatus: stub\n");
|
746 | 749 | ERR(DDERR_GENERIC);
|
747 | 750 | }
|
— | — | @@ -782,7 +785,7 @@ |
783 | 786 | }
|
784 | 787 | HRESULT WINAPI glDirectDrawSurface7::IsLost()
|
785 | 788 | {
|
786 | | - if(renderer == ddInterface->renderer) return DD_OK;
|
| 789 | + if(hRC == ddInterface->renderer->hRC) return DD_OK;
|
787 | 790 | else return DDERR_SURFACELOST;
|
788 | 791 | }
|
789 | 792 |
|
— | — | @@ -833,12 +836,81 @@ |
834 | 837 | hdc = NULL;
|
835 | 838 | return DD_OK;
|
836 | 839 | }
|
| 840 | +void glDirectDrawSurface7::Restore2()
|
| 841 | +{
|
| 842 | + LONG sizes[6];
|
| 843 | + if(hRC != ddInterface->renderer->hRC)
|
| 844 | + {
|
| 845 | + ddInterface->GetSizes(sizes);
|
| 846 | + if(ddInterface->GetFullscreen())
|
| 847 | + {
|
| 848 | + ddsd.dwWidth = sizes[2];
|
| 849 | + ddsd.dwHeight = sizes[3];
|
| 850 | + if(dxglcfg.highres)
|
| 851 | + {
|
| 852 | + fakex = sizes[0];
|
| 853 | + fakey = sizes[1];
|
| 854 | + }
|
| 855 | + else
|
| 856 | + {
|
| 857 | + fakex = ddsd.dwWidth;
|
| 858 | + fakey = ddsd.dwHeight;
|
| 859 | + }
|
| 860 | + ddsd.dwFlags |= (DDSD_WIDTH | DDSD_HEIGHT);
|
| 861 | + }
|
| 862 | + else
|
| 863 | + {
|
| 864 | + fakex = ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
|
| 865 | + fakey = ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
|
| 866 | + ddsd.dwFlags |= (DDSD_WIDTH | DDSD_HEIGHT);
|
| 867 | + }
|
| 868 | + if(backbuffer) backbuffer->Restore2();
|
| 869 | + if(zbuffer) zbuffer->Restore2();
|
| 870 | + if(paltex) paltex = renderer->MakeTexture(GL_NEAREST,GL_NEAREST,GL_CLAMP,GL_CLAMP,256,1,GL_RGBA,GL_UNSIGNED_BYTE,GL_RGB);
|
| 871 | + texture = renderer->MakeTexture(filter,filter,GL_CLAMP,GL_CLAMP,fakex,fakey,texformat,texformat2,texformat3);
|
| 872 | + }
|
| 873 | +}
|
837 | 874 | HRESULT WINAPI glDirectDrawSurface7::Restore()
|
838 | 875 | {
|
839 | | - if(renderer != ddInterface->renderer)
|
| 876 | + LONG sizes[6];
|
| 877 | + if(hRC != ddInterface->renderer->hRC)
|
840 | 878 | {
|
841 | | - FIXME("glDirectDrawSurface7::Restore: stub\n");
|
842 | | - ERR(DDERR_GENERIC);
|
| 879 | + if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
| 880 | + {
|
| 881 | + ddInterface->GetSizes(sizes);
|
| 882 | + if(ddInterface->GetFullscreen())
|
| 883 | + {
|
| 884 | + ddsd.dwWidth = sizes[2];
|
| 885 | + ddsd.dwHeight = sizes[3];
|
| 886 | + if(dxglcfg.highres)
|
| 887 | + {
|
| 888 | + fakex = sizes[0];
|
| 889 | + fakey = sizes[1];
|
| 890 | + }
|
| 891 | + else
|
| 892 | + {
|
| 893 | + fakex = ddsd.dwWidth;
|
| 894 | + fakey = ddsd.dwHeight;
|
| 895 | + }
|
| 896 | + ddsd.dwFlags |= (DDSD_WIDTH | DDSD_HEIGHT);
|
| 897 | + }
|
| 898 | + else
|
| 899 | + {
|
| 900 | + fakex = ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
|
| 901 | + fakey = ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
|
| 902 | + ddsd.dwFlags |= (DDSD_WIDTH | DDSD_HEIGHT);
|
| 903 | + }
|
| 904 | + if(backbuffer) backbuffer->Restore2();
|
| 905 | + if(zbuffer) zbuffer->Restore2();
|
| 906 | + }
|
| 907 | + else
|
| 908 | + {
|
| 909 | + if(backbuffer) backbuffer->Restore();
|
| 910 | + if(zbuffer) zbuffer->Restore();
|
| 911 | + }
|
| 912 | + if(paltex) paltex = renderer->MakeTexture(GL_NEAREST,GL_NEAREST,GL_CLAMP,GL_CLAMP,256,1,GL_RGBA,GL_UNSIGNED_BYTE,GL_RGB);
|
| 913 | + texture = renderer->MakeTexture(filter,filter,GL_CLAMP,GL_CLAMP,fakex,fakey,texformat,texformat2,texformat3);
|
| 914 | + return DD_OK;
|
843 | 915 | }
|
844 | 916 | else return DD_OK;
|
845 | 917 | }
|
Index: ddraw/glDirectDrawSurface.h |
— | — | @@ -96,6 +96,7 @@ |
97 | 97 | GLuint GetTexture(){
|
98 | 98 | return texture;
|
99 | 99 | }
|
| 100 | + void Restore2();
|
100 | 101 | void SetTexture(GLuint newtexture){texture = newtexture;};
|
101 | 102 | glDirectDrawSurface7 *GetBackbuffer(){return backbuffer;};
|
102 | 103 | glDirectDrawSurface7 *GetZBuffer(){return zbuffer;};
|
— | — | @@ -125,6 +126,7 @@ |
126 | 127 | char *gdibuffer;
|
127 | 128 | DDSURFACEDESC2 ddsd;
|
128 | 129 | glDirectDrawPalette *palette;
|
| 130 | + HGLRC hRC;
|
129 | 131 | private:
|
130 | 132 | ULONG refcount;
|
131 | 133 | int locked;
|
— | — | @@ -137,6 +139,7 @@ |
138 | 140 | glDirectDrawSurface7 *zbuffer;
|
139 | 141 | glDirectDrawClipper *clipper;
|
140 | 142 | int pagelocked;
|
| 143 | + GLint filter;
|
141 | 144 | };
|
142 | 145 |
|
143 | 146 | // Legacy DDRAW Interfaces
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | BltVertex bltvertices[4];
|
41 | 41 | const GLushort bltindices[4] = {0,1,2,3};
|
42 | 42 |
|
| 43 | +
|
43 | 44 | inline int _5to8bit(int number)
|
44 | 45 | {
|
45 | 46 | return (number << 3)+(number>>2);
|
— | — | @@ -48,14 +49,15 @@ |
49 | 50 | return (number<<2)+(number>>4);
|
50 | 51 | }
|
51 | 52 |
|
| 53 | +int oldswap = 0;
|
52 | 54 | int swapinterval = 0;
|
53 | 55 | inline void SetSwap(int swap)
|
54 | 56 | {
|
55 | | - if(swap != swapinterval)
|
| 57 | + if(swap != oldswap)
|
56 | 58 | {
|
57 | 59 | wglSwapIntervalEXT(swap);
|
58 | | - swapinterval = wglGetSwapIntervalEXT();
|
59 | | - swapinterval = swap;
|
| 60 | + oldswap = wglGetSwapIntervalEXT();
|
| 61 | + oldswap = swap;
|
60 | 62 | }
|
61 | 63 | }
|
62 | 64 |
|
— | — | @@ -662,6 +664,7 @@ |
663 | 665 |
|
664 | 666 | void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, RECT *viewrect)
|
665 | 667 | {
|
| 668 | + SetSwap(swapinterval);
|
666 | 669 | LONG sizes[6];
|
667 | 670 | GLfloat view[4];
|
668 | 671 | if(src->dirty & 1)
|
Index: ddraw/glRenderer.h |
— | — | @@ -60,6 +60,7 @@ |
61 | 61 | #define GLEVENT_BLT 6
|
62 | 62 | #define GLEVENT_DRAWSCREEN 7
|
63 | 63 |
|
| 64 | +extern int swapinterval;
|
64 | 65 | extern inline void SetSwap(int swap);
|
65 | 66 |
|
66 | 67 | class glRenderer
|
— | — | @@ -75,6 +76,7 @@ |
76 | 77 | GLuint MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
|
77 | 78 | void DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
|
78 | 79 | void DeleteTexture(GLuint texture);
|
| 80 | + HGLRC hRC;
|
79 | 81 | private:
|
80 | 82 | // In-thread APIs
|
81 | 83 | DWORD _Entry();
|
— | — | @@ -93,7 +95,6 @@ |
94 | 96 | HANDLE hThread;
|
95 | 97 | HANDLE EventSend;
|
96 | 98 | HANDLE EventWait;
|
97 | | - HGLRC hRC;
|
98 | 99 | HDC hDC;
|
99 | 100 | HWND hWnd;
|
100 | 101 | HWND hRenderWnd;
|