DXGL r89 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r88‎ | r89 | r90 >
Date:20:37, 27 January 2012
Author:admin
Status:new
Tags:
Comment:
Add IDirectDrawSurface::Restore
Fix vsync
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -700,8 +700,17 @@
701701 }
702702 HRESULT WINAPI glDirectDraw7::CreateSurface(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
703703 {
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+ }
706715 surfacecount++;
707716 if(surfacecount > surfacecountmax)
708717 {
@@ -716,7 +725,10 @@
717726 HRESULT error;
718727 surfaces[surfacecount-1] = new glDirectDrawSurface7(this,lpDDSurfaceDesc2,lplpDDSurface,&error,false,NULL);
719728 if(lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
 729+ {
720730 primary = surfaces[surfacecount-1];
 731+ primarylost = false;
 732+ }
721733 *lplpDDSurface = surfaces[surfacecount-1];
722734 return error;
723735 }
@@ -892,6 +904,7 @@
893905 HRESULT WINAPI glDirectDraw7::Initialize(GUID FAR *lpGUID)
894906 {
895907 if(initialized) return DDERR_ALREADYINITIALIZED;
 908+ primarylost = true;
896909 glD3D7 = NULL;
897910 renderer = NULL;
898911 primary = NULL;
@@ -1111,6 +1124,7 @@
11121125 else internalrefresh = primaryrefresh = screenrefresh = currmode.dmDisplayFrequency;
11131126 DeleteGL();
11141127 InitGL(screenx,screeny,screenbpp,true,hWnd);
 1128+ primarylost = true;
11151129 return DD_OK;
11161130 case DISP_CHANGE_BADMODE:
11171131 ERR(DDERR_INVALIDMODE);
@@ -1141,6 +1155,7 @@
11421156 primarybpp = dwBPP;
11431157 DeleteGL();
11441158 InitGL(screenx,screeny,screenbpp,true,hWnd);
 1159+ primarylost = true;
11451160 return DD_OK;
11461161 break;
11471162 case 2: // Scale to screen
@@ -1166,6 +1181,7 @@
11671182 primarybpp = dwBPP;
11681183 DeleteGL();
11691184 InitGL(screenx,screeny,screenbpp,true,hWnd);
 1185+ primarylost = true;
11701186 return DD_OK;
11711187 break;
11721188 case 3: // Center image
@@ -1213,6 +1229,7 @@
12141230 primarybpp = dwBPP;
12151231 DeleteGL();
12161232 InitGL(screenx,screeny,screenbpp,true,hWnd);
 1233+ primarylost = true;
12171234 return DD_OK;
12181235 break;
12191236 case 5:
@@ -1238,6 +1255,7 @@
12391256 primarybpp = dwBPP;
12401257 DeleteGL();
12411258 InitGL(screenx,screeny,screenbpp,true,hWnd);
 1259+ primarylost = true;
12421260 return DD_OK;
12431261 break;
12441262 case 6:
@@ -1251,6 +1269,8 @@
12521270 else internalbpp = screenbpp = newmode2.dmBitsPerPel;
12531271 DeleteGL();
12541272 InitGL(screenx,screeny,screenbpp,true,hWnd);
 1273+ primarylost = true;
 1274+ return DD_OK;
12551275 break;
12561276 }
12571277 break;
@@ -1260,9 +1280,9 @@
12611281 HRESULT WINAPI glDirectDraw7::WaitForVerticalBlank(DWORD dwFlags, HANDLE hEvent)
12621282 {
12631283 if(dwFlags & DDWAITVB_BLOCKBEGINEVENT) return DDERR_UNSUPPORTED;
1264 - SetSwap(1);
 1284+ swapinterval=1;
12651285 primary->RenderScreen(primary->texture,primary);
1266 - SetSwap(0);
 1286+ swapinterval=0;
12671287 return DD_OK;
12681288 }
12691289 HRESULT WINAPI glDirectDraw7::GetAvailableVidMem(LPDDSCAPS2 lpDDSCaps2, LPDWORD lpdwTotal, LPDWORD lpdwFree)
Index: ddraw/glDirectDraw.h
@@ -82,6 +82,7 @@
8383 bool GetFullscreen(){return fullscreen;};
8484 void DeleteSurface(glDirectDrawSurface7 *surface);
8585 glDirectDrawSurface7 *primary;
 86+ bool primarylost;
8687 glRenderer *renderer;
8788 private:
8889 void DeleteGL();
Index: ddraw/glDirectDrawSurface.cpp
@@ -63,7 +63,7 @@
6464 bigbuffer = NULL;
6565 zbuffer = NULL;
6666 DWORD colormasks[3];
67 - GLint filter = GL_NEAREST;
 67+ filter = GL_NEAREST;
6868 if(copysurface)
6969 {
7070 FIXME("glDirectDrawSurface7::glDirectDrawSurface7: copy surface stub\n");
@@ -74,6 +74,7 @@
7575 {
7676 ddInterface = (glDirectDraw7 *)lpDD7;
7777 renderer = ddInterface->renderer;
 78+ hRC = ddInterface->renderer->hRC;
7879 ddsd = *lpDDSurfaceDesc2;
7980 }
8081 LONG sizes[6];
@@ -384,6 +385,7 @@
385386 }
386387 glDirectDrawSurface7::~glDirectDrawSurface7()
387388 {
 389+ AddRef();
388390 if(dds1) dds1->Release();
389391 if(dds2) dds2->Release();
390392 if(dds3) dds3->Release();
@@ -577,13 +579,13 @@
578580 }
579581 HRESULT WINAPI glDirectDrawSurface7::Flip(LPDIRECTDRAWSURFACE7 lpDDSurfaceTargetOverride, DWORD dwFlags)
580582 {
581 - if(dwFlags & DDFLIP_NOVSYNC) SetSwap(0);
 583+ if(dwFlags & DDFLIP_NOVSYNC) swapinterval=0;
582584 else
583585 {
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;
588590 }
589591 int flips = 1;
590592 if(lpDDSurfaceTargetOverride) ERR(DDERR_GENERIC);
@@ -741,6 +743,7 @@
742744 }
743745 HRESULT WINAPI glDirectDrawSurface7::GetFlipStatus(DWORD dwFlags)
744746 {
 747+ return DD_OK;
745748 FIXME("glDirectDrawSurface7::GetFlipStatus: stub\n");
746749 ERR(DDERR_GENERIC);
747750 }
@@ -782,7 +785,7 @@
783786 }
784787 HRESULT WINAPI glDirectDrawSurface7::IsLost()
785788 {
786 - if(renderer == ddInterface->renderer) return DD_OK;
 789+ if(hRC == ddInterface->renderer->hRC) return DD_OK;
787790 else return DDERR_SURFACELOST;
788791 }
789792
@@ -833,12 +836,81 @@
834837 hdc = NULL;
835838 return DD_OK;
836839 }
 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+}
837874 HRESULT WINAPI glDirectDrawSurface7::Restore()
838875 {
839 - if(renderer != ddInterface->renderer)
 876+ LONG sizes[6];
 877+ if(hRC != ddInterface->renderer->hRC)
840878 {
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;
843915 }
844916 else return DD_OK;
845917 }
Index: ddraw/glDirectDrawSurface.h
@@ -96,6 +96,7 @@
9797 GLuint GetTexture(){
9898 return texture;
9999 }
 100+ void Restore2();
100101 void SetTexture(GLuint newtexture){texture = newtexture;};
101102 glDirectDrawSurface7 *GetBackbuffer(){return backbuffer;};
102103 glDirectDrawSurface7 *GetZBuffer(){return zbuffer;};
@@ -125,6 +126,7 @@
126127 char *gdibuffer;
127128 DDSURFACEDESC2 ddsd;
128129 glDirectDrawPalette *palette;
 130+ HGLRC hRC;
129131 private:
130132 ULONG refcount;
131133 int locked;
@@ -137,6 +139,7 @@
138140 glDirectDrawSurface7 *zbuffer;
139141 glDirectDrawClipper *clipper;
140142 int pagelocked;
 143+ GLint filter;
141144 };
142145
143146 // Legacy DDRAW Interfaces
Index: ddraw/glRenderer.cpp
@@ -39,6 +39,7 @@
4040 BltVertex bltvertices[4];
4141 const GLushort bltindices[4] = {0,1,2,3};
4242
 43+
4344 inline int _5to8bit(int number)
4445 {
4546 return (number << 3)+(number>>2);
@@ -48,14 +49,15 @@
4950 return (number<<2)+(number>>4);
5051 }
5152
 53+int oldswap = 0;
5254 int swapinterval = 0;
5355 inline void SetSwap(int swap)
5456 {
55 - if(swap != swapinterval)
 57+ if(swap != oldswap)
5658 {
5759 wglSwapIntervalEXT(swap);
58 - swapinterval = wglGetSwapIntervalEXT();
59 - swapinterval = swap;
 60+ oldswap = wglGetSwapIntervalEXT();
 61+ oldswap = swap;
6062 }
6163 }
6264
@@ -662,6 +664,7 @@
663665
664666 void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, RECT *viewrect)
665667 {
 668+ SetSwap(swapinterval);
666669 LONG sizes[6];
667670 GLfloat view[4];
668671 if(src->dirty & 1)
Index: ddraw/glRenderer.h
@@ -60,6 +60,7 @@
6161 #define GLEVENT_BLT 6
6262 #define GLEVENT_DRAWSCREEN 7
6363
 64+extern int swapinterval;
6465 extern inline void SetSwap(int swap);
6566
6667 class glRenderer
@@ -75,6 +76,7 @@
7677 GLuint MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
7778 void DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
7879 void DeleteTexture(GLuint texture);
 80+ HGLRC hRC;
7981 private:
8082 // In-thread APIs
8183 DWORD _Entry();
@@ -93,7 +95,6 @@
9496 HANDLE hThread;
9597 HANDLE EventSend;
9698 HANDLE EventWait;
97 - HGLRC hRC;
9899 HDC hDC;
99100 HWND hWnd;
100101 HWND hRenderWnd;