DXGL r83 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r82‎ | r83 | r84 >
Date:00:39, 24 January 2012
Author:admin
Status:new
Tags:
Comment:
Fix GetDisplayMode
Fix GDI bitmaps
Implement DDERR_DIRECTDRAWALREADYCREATED
Modified paths:
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/ddraw.h (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)

Diff [purge]

Index: ddraw/ddraw.cpp
@@ -33,6 +33,7 @@
3434
3535 DWORD timer;
3636 int vsyncstatus;
 37+bool ddenabled = false;
3738
3839 DDRAW_API void WINAPI AcquireDDThreadLock()
3940 {
@@ -103,6 +104,7 @@
104105 }
105106 return sysddrawcreate(lpGUID,lplpDD,pUnkOuter);
106107 }
 108+ if(ddenabled) return DDERR_DIRECTDRAWALREADYCREATED;
107109 GetCurrentConfig(&dxglcfg);
108110 glDirectDraw7 *myddraw7;
109111 glDirectDraw1 *myddraw;
@@ -114,6 +116,7 @@
115117 delete myddraw7;
116118 return error;
117119 }
 120+ ddenabled = true;
118121 myddraw7->QueryInterface(IID_IDirectDraw,(VOID**)&myddraw);
119122 myddraw7->Release();
120123 *lplpDD = (LPDIRECTDRAW)myddraw;
@@ -126,6 +129,7 @@
127130 }
128131 HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter)
129132 {
 133+ if(ddenabled) return DDERR_DIRECTDRAWALREADYCREATED;
130134 GetCurrentConfig(&dxglcfg);
131135 glDirectDraw7 *myddraw;
132136 HRESULT error;
@@ -137,6 +141,7 @@
138142 delete myddraw;
139143 return error;
140144 }
 145+ ddenabled = true;
141146 *lplpDD = (LPDIRECTDRAW7)myddraw;
142147 return error;
143148 }
Index: ddraw/ddraw.h
@@ -60,6 +60,6 @@
6161 extern bool gllock;
6262 extern DWORD timer;
6363 extern int vsyncstatus;
 64+extern bool ddenabled;
6465
65 -
6666 #endif //_DDRAW_H
\ No newline at end of file
Index: ddraw/glDirectDraw.cpp
@@ -582,6 +582,7 @@
583583 free(surfaces);
584584 }
585585 DeleteGL();
 586+ ddenabled = false;
586587 }
587588
588589 HRESULT WINAPI glDirectDraw7::QueryInterface(REFIID riid, void** ppvObj)
@@ -777,6 +778,44 @@
778779 ZeroMemory(&ddsdMode, sizeof(DDSURFACEDESC2));
779780 ddsdMode.dwSize = sizeof(DDSURFACEDESC2);
780781 DEVMODE currmode;
 782+ if(fullscreen)
 783+ {
 784+ if(primarybpp == 8)
 785+ {
 786+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0;
 787+ ddsdMode.ddpfPixelFormat.dwGBitMask = 0;
 788+ ddsdMode.ddpfPixelFormat.dwBBitMask = 0;
 789+ }
 790+ else if(primarybpp == 15)
 791+ {
 792+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0x7C00;
 793+ ddsdMode.ddpfPixelFormat.dwGBitMask = 0x3E0;
 794+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0x1F;
 795+ }
 796+ else if(primarybpp == 16)
 797+ {
 798+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0xF800;
 799+ ddsdMode.ddpfPixelFormat.dwGBitMask = 0x7E0;
 800+ ddsdMode.ddpfPixelFormat.dwBBitMask = 0x1F;
 801+ }
 802+ else
 803+ {
 804+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0xFF0000;
 805+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0xFF00;
 806+ ddsdMode.ddpfPixelFormat.dwRBitMask = 0xFF;
 807+ }
 808+ ddsdMode.ddpfPixelFormat.dwRGBBitCount = GetBPPMultipleOf8();
 809+ ddsdMode.dwWidth = primaryx;
 810+ ddsdMode.dwHeight = primaryy;
 811+ if(primarybpp == 15) ddsdMode.lPitch = primaryx * 2;
 812+ else if(primarybpp == 4) ddsdMode.lPitch = primaryx / 2;
 813+ else ddsdMode.lPitch = primaryx * (primarybpp / 8);
 814+ if(lpDDSurfaceDesc2->dwSize < sizeof(DDSURFACEDESC)) ERR(DDERR_INVALIDPARAMS);
 815+ if(lpDDSurfaceDesc2->dwSize > sizeof(DDSURFACEDESC2))
 816+ lpDDSurfaceDesc2->dwSize = sizeof(DDSURFACEDESC2);
 817+ memcpy(lpDDSurfaceDesc2,&ddsdMode,lpDDSurfaceDesc2->dwSize);
 818+ return DD_OK;
 819+ }
781820 EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&currmode);
782821 if(currmode.dmBitsPerPel == 8) ddsdMode.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
783822 else if(currmode.dmBitsPerPel == 4) ddsdMode.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED4;
@@ -829,7 +868,7 @@
830869 }
831870 HRESULT WINAPI glDirectDraw7::GetMonitorFrequency(LPDWORD lpdwFrequency)
832871 {
833 - FIXME("IDirectDraw::GetMonitorFrequency: support multi-monitor\n");
 872+ DEBUG("IDirectDraw::GetMonitorFrequency: support multi-monitor\n");
834873 DEVMODE devmode;
835874 devmode.dmSize = sizeof(DEVMODE);
836875 EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&devmode);
@@ -904,6 +943,7 @@
905944 HRESULT WINAPI glDirectDraw7::SetCooperativeLevel(HWND hWnd, DWORD dwFlags)
906945 {
907946 this->hWnd = hWnd;
 947+ if(hRC) DeleteGL();
908948 winstyle = GetWindowLongPtrA(hWnd,GWL_STYLE);
909949 winstyleex = GetWindowLongPtrA(hWnd,GWL_EXSTYLE);
910950 bool exclusive = false;
@@ -1267,10 +1307,17 @@
12681308 {
12691309 if(hRC)
12701310 {
 1311+ if(dib.enabled)
 1312+ {
 1313+ if(dib.hbitmap) DeleteObject(dib.hbitmap);
 1314+ if(dib.hdc) DeleteDC(dib.hdc);
 1315+ ZeroMemory(&dib,sizeof(DIB));
 1316+ }
12711317 DeleteShaders();
12721318 DeleteFBO();
12731319 if(PBO)
12741320 {
 1321+ glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
12751322 glDeleteBuffers(1,&PBO);
12761323 PBO = 0;
12771324 }
Index: ddraw/glDirectDrawSurface.cpp
@@ -130,6 +130,7 @@
131131 flipcount = 0;
132132 ZeroMemory(colorkey,4*sizeof(CKEY));
133133 bitmapinfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+(255*sizeof(RGBQUAD)));
 134+ ZeroMemory(bitmapinfo,sizeof(BITMAPINFO)+(255*sizeof(RGBQUAD)));
134135 palette = NULL;
135136 paltex = NULL;
136137 texture = NULL;
@@ -226,12 +227,11 @@
227228 if(ddsd.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
228229 {
229230 BITMAPINFO info;
 231+ ZeroMemory(&info,sizeof(BITMAPINFO));
230232 if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
231233 {
232 - info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
233234 info.bmiHeader.biWidth = fakex;
234235 info.bmiHeader.biHeight = -(signed)fakey;
235 - info.bmiHeader.biPlanes = 1;
236236 info.bmiHeader.biCompression = BI_RGB;
237237 info.bmiHeader.biSizeImage = 0;
238238 info.bmiHeader.biXPelsPerMeter = 0;
@@ -246,10 +246,8 @@
247247 if(ddsd.dwFlags & DDSD_PIXELFORMAT) surfacetype=2;
248248 else
249249 {
250 - info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
251250 info.bmiHeader.biWidth = fakex;
252251 info.bmiHeader.biHeight = -(signed)fakey;
253 - info.bmiHeader.biPlanes = 1;
254252 info.bmiHeader.biCompression = BI_RGB;
255253 info.bmiHeader.biSizeImage = 0;
256254 info.bmiHeader.biXPelsPerMeter = 0;
@@ -263,8 +261,6 @@
264262 }
265263 else
266264 {
267 - bitmapinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
268 - bitmapinfo->bmiHeader.biPlanes = 1;
269265 bitmapinfo->bmiHeader.biSizeImage = 0;
270266 bitmapinfo->bmiHeader.biXPelsPerMeter = 0;
271267 bitmapinfo->bmiHeader.biYPelsPerMeter = 0;
@@ -274,8 +270,10 @@
275271 bitmapinfo->bmiHeader.biBitCount = (WORD)ddInterface->GetBPPMultipleOf8();
276272 }
277273 surfacetype=2;
 274+ bitmapinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
278275 bitmapinfo->bmiHeader.biWidth = ddsd.dwWidth;
279276 bitmapinfo->bmiHeader.biHeight = -(signed)ddsd.dwHeight;
 277+ bitmapinfo->bmiHeader.biPlanes = 1;
280278 switch(surfacetype)
281279 {
282280 case 0:
@@ -308,8 +306,43 @@
309307 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
310308 if(ddsd.dwFlags & DDSD_PIXELFORMAT)
311309 {
312 - if(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)
 310+ if(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)
313311 {
 312+ switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
 313+ {
 314+ case 8:
 315+ if(ddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
 316+ {
 317+ texformat = GL_LUMINANCE;
 318+ texformat2 = GL_UNSIGNED_BYTE;
 319+ if(dxglcfg.texformat) texformat3 = GL_LUMINANCE8;
 320+ else texformat3 = GL_RGBA8;
 321+ if(!palettein) palette = new glDirectDrawPalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE,NULL,NULL);
 322+ bitmapinfo->bmiHeader.biBitCount = 8;
 323+ }
 324+ else
 325+ {
 326+ texformat = GL_RGB;
 327+ texformat2 = GL_UNSIGNED_BYTE_3_3_2;
 328+ if(dxglcfg.texformat) texformat3 = GL_R3_G3_B2;
 329+ else texformat3 = GL_RGBA8;
 330+ }
 331+ ddsd.ddpfPixelFormat.dwRBitMask = 0;
 332+ ddsd.ddpfPixelFormat.dwGBitMask = 0;
 333+ ddsd.ddpfPixelFormat.dwBBitMask = 0;
 334+ ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth);
 335+ break;
 336+ case 16:
 337+ FIXME("Support 16 bit pixelformat");
 338+ case 24:
 339+ FIXME("Support 24 bit pixelformat");
 340+ case 32:
 341+ default:
 342+ FIXME("Support 32 bit pixelformat");
 343+ }
 344+ }
 345+ else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)
 346+ {
314347 switch(ddsd.ddpfPixelFormat.dwZBufferBitDepth)
315348 {
316349 case 16:
@@ -447,7 +480,7 @@
448481 else *error = DDERR_INVALIDPARAMS;
449482 }
450483 }
451 - ddInterface->AddRef();
 484+ //ddInterface->AddRef();
452485 }
453486 glDirectDrawSurface7::~glDirectDrawSurface7()
454487 {
@@ -935,14 +968,14 @@
936969 if(error != DD_OK) return error;
937970 hdc = CreateCompatibleDC(NULL);
938971 bitmapinfo->bmiHeader.biWidth = ddsd.lPitch / (bitmapinfo->bmiHeader.biBitCount / 8);
939 - if(ddInterface->GetBPP() == 8)
 972+ if(ddsd.ddpfPixelFormat.dwRGBBitCount == 8)
940973 {
941 - memcpy(colors,ddInterface->primary->palette->GetPalette(NULL),1024);
 974+ memcpy(colors,palette->GetPalette(NULL),1024);
942975 for(int i = 0; i < 256; i++)
943976 colors[i] = ((colors[i]&0x0000FF)<<16) | (colors[i]&0x00FF00) | ((colors[i]&0xFF0000)>>16);
944977 memcpy(bitmapinfo->bmiColors,colors,1024);
945978 }
946 - else if(ddInterface->GetBPPMultipleOf8() == 16)bitmapinfo->bmiHeader.biCompression = BI_BITFIELDS;
 979+ else if(ddsd.ddpfPixelFormat.dwRGBBitCount == 16)bitmapinfo->bmiHeader.biCompression = BI_BITFIELDS;
947980 hbitmap = CreateDIBSection(hdc,bitmapinfo,DIB_RGB_COLORS,&surface,NULL,0);
948981 memcpy(surface,ddsd.lpSurface,ddsd.lPitch*ddsd.dwHeight);
949982 HGDIOBJ temp = SelectObject(hdc,hbitmap);