DXGL r875 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r874‎ | r875 | r876 >
Date:00:05, 16 October 2018
Author:admin
Status:new
Tags:
Comment:
Add UI for source and destination formats to surface format test.
Add source format selection and partial error handling to surface format test.
Modified paths:
  • /dxglcfg/surfacegen.cpp (modified) (history)
  • /dxglcfg/surfacegen.h (modified) (history)
  • /dxglcfg/tests.cpp (modified) (history)

Diff [purge]

Index: dxglcfg/surfacegen.cpp
@@ -1682,8 +1682,33 @@
16831683 _T("32-bit Z/st.rev")
16841684 };
16851685 static const int END_SURFACEFORMATS = __LINE__ - 4;
1686 -static const int numsurfaceformats = END_SURFACEFORMATS - START_SURFACEFORMATS;
 1686+const int numsurfaceformats = END_SURFACEFORMATS - START_SURFACEFORMATS;
16871687
 1688+const DDPIXELFORMAT surfaceformats[] =
 1689+{
 1690+ {0, 0, 0, 0, 0, 0, 0, 0}, // reserved
 1691+ {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0}, // 8-bit paletted
 1692+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0}, // 8 bit 332
 1693+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0}, // 15 bit 555
 1694+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x7E0, 0x1F, 0}, // 16 bit 565
 1695+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0xFF0000, 0xFF00, 0xFF, 0}, // 24 bit 888
 1696+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0}, // 32 bit 888
 1697+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0}, // 32 bit 888 RGB
 1698+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xE0, 0x1C, 0x3, 0xFF00}, // 16-bit 8332
 1699+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xF00, 0xF0, 0xF, 0xF000}, // 16-bit 4444
 1700+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0x7c00, 0x3E0, 0x1F, 0x8000}, // 16-bit 1555
 1701+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000}, // 32-bit 8888
 1702+ {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF, 0, 0, 0}, // 8-bit luminance
 1703+ {sizeof(DDPIXELFORMAT), DDPF_ALPHA, 0, 8, 0, 0, 0, 0}, // 8-bit alpha
 1704+ {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE|DDPF_ALPHAPIXELS,0, 16, 0xFF, 0, 0, 0xFF00}, // 8-bit luminance alpha
 1705+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 16, 0, 0xFFFF, 0, 0}, // 16 bit Z buffer
 1706+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 24, 0, 0xFFFFFF00, 0, 0}, // 24 bit Z buffer
 1707+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0}, // 24 bit Z buffer, 32-bit space
 1708+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0}, // 32 bit Z buffer
 1709+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0}, // 32 bit Z buffer with stencil
 1710+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0} // 32 bit Z buffer with stencil, reversed
 1711+};
 1712+
16881713 static const LPTSTR strErrorMessages[] =
16891714 {
16901715 _T("Unknown error"),
@@ -1707,6 +1732,7 @@
17081733 HFONT newfont;
17091734 RECT r;
17101735 TCHAR buffer[256];
 1736+ TCHAR number[34];
17111737 int oldbk;
17121738 SIZE charsize;
17131739 int rows, cols;
@@ -1714,6 +1740,7 @@
17151741 int posx, posy;
17161742 int formatposy;
17171743 int formatfirst, formatlast;
 1744+ int i;
17181745 err = surface->GetDC(&hdc);
17191746 if (FAILED(err)) return;
17201747 if (y < 350)
@@ -1773,20 +1800,98 @@
17741801 TextOutShadow(hdc, posx, posy, buffer, _tcslen(buffer), RGB(0, 0, 192));
17751802 // List source formats
17761803 formatposy = posy + charsize.cy;
 1804+ posy = formatposy;
17771805 SetBkMode(hdc, TRANSPARENT);
17781806 formatrows = rows - (formatposy / charsize.cy) - 1;
17791807 if (formatrows > numsurfaceformats)
17801808 {
 1809+ formatfirst = 0;
 1810+ formatlast = numsurfaceformats - 1;
 1811+ }
 1812+ else
 1813+ {
 1814+ if (srcformat < formatrows / 2)
 1815+ {
 1816+ formatfirst = 0;
 1817+ formatlast = formatrows;
 1818+ }
 1819+ else if (srcformat+2 > (numsurfaceformats - (formatrows / 2)))
 1820+ {
 1821+ formatlast = numsurfaceformats - 1;
 1822+ formatfirst = formatlast - (formatrows);
 1823+ }
 1824+ else
 1825+ {
 1826+ formatfirst = srcformat - (formatrows / 2);
 1827+ formatlast = srcformat + (formatrows / 2) + (formatrows % 2);
 1828+ }
 1829+ }
 1830+ for (i = formatfirst; i < formatlast; i++)
 1831+ {
 1832+ if (i == srcformat)
 1833+ {
 1834+ posx = 0;
 1835+ SetTextColor(hdc, RGB(255, 255, 255));
 1836+ TextOutShadow(hdc, posx, posy, _T("-->"), 3, RGB(0, 0, 192));
 1837+ posx = 3 * charsize.cx;
 1838+ TextOutShadow(hdc, posx, posy, strSurfaceFormats[i + 1], _tcslen(strSurfaceFormats[i + 1]), RGB(0, 0, 192));
 1839+ }
 1840+ else
 1841+ {
 1842+ SetTextColor(hdc, RGB(192, 192, 192));
 1843+ posx = 3 * charsize.cx;
 1844+ TextOut(hdc, posx, posy, strSurfaceFormats[i + 1], _tcslen(strSurfaceFormats[i + 1]));
 1845+ }
 1846+ posy += charsize.cy;
 1847+ }
 1848+ // List destination formats
 1849+ posy = formatposy;
 1850+ SetBkMode(hdc, TRANSPARENT);
 1851+ formatrows = rows - (formatposy / charsize.cy) - 1;
 1852+ if (formatrows >= numsurfaceformats)
 1853+ {
17811854 formatfirst = -1;
1782 - formatlast = numsurfaceformats - 2;
 1855+ formatlast = numsurfaceformats - 1;
17831856 }
17841857 else
17851858 {
1786 -
 1859+ if (destformat < formatrows / 2)
 1860+ {
 1861+ formatfirst = 0;
 1862+ formatlast = formatrows;
 1863+ }
 1864+ else if (destformat + 2 > (numsurfaceformats - (formatrows / 2)))
 1865+ {
 1866+ formatlast = numsurfaceformats - 1;
 1867+ formatfirst = formatlast - (formatrows);
 1868+ }
 1869+ else
 1870+ {
 1871+ formatfirst = destformat - (formatrows / 2);
 1872+ formatlast = destformat + (formatrows / 2) + (formatrows % 2);
 1873+ }
17871874 }
 1875+ for (i = formatfirst; i < formatlast; i++)
 1876+ {
 1877+ if (i == destformat)
 1878+ {
 1879+ posx = (cols / 2) * charsize.cx;
 1880+ SetTextColor(hdc, RGB(255, 255, 255));
 1881+ TextOutShadow(hdc, posx, posy, _T("-->"), 3, RGB(0, 0, 192));
 1882+ posx = ((cols / 2) + 3) * charsize.cx;
 1883+ TextOutShadow(hdc, posx, posy, strSurfaceFormats[i + 1], _tcslen(strSurfaceFormats[i + 1]), RGB(0, 0, 192));
 1884+ }
 1885+ else
 1886+ {
 1887+ SetTextColor(hdc, RGB(192, 192, 192));
 1888+ posx = ((cols / 2) + 3) * charsize.cx;
 1889+ TextOut(hdc, posx, posy, strSurfaceFormats[i + 1], _tcslen(strSurfaceFormats[i + 1]));
 1890+ }
 1891+ posy += charsize.cy;
 1892+ }
17881893 }
17891894 // Display error if present
1790 - if (error)
 1895+ if (error != 0)
17911896 {
17921897 SetBkMode(hdc, OPAQUE);
17931898 SetBkColor(hdc, RGB(255, 0, 0));
@@ -1793,6 +1898,13 @@
17941899 SetTextColor(hdc, RGB(255, 255, 255));
17951900 if (errorlocation < 0) errorlocation = 0;
17961901 if (errorlocation > 7) errorlocation = 0;
 1902+ posx = 0;
 1903+ posy = charsize.cy * (rows - 1);
 1904+ _tcscpy(buffer, strErrorMessages[errorlocation]);
 1905+ _tcscat(buffer, _T("0x"));
 1906+ _itot(error, number, 16);
 1907+ _tcscat(buffer, number);
 1908+ TextOutShadow(hdc, posx, posy, buffer, _tcslen(buffer), RGB(192, 0, 0));
17971909 }
17981910 SelectObject(hdc, DefaultFont);
17991911 DeleteObject(newfont);
Index: dxglcfg/surfacegen.h
@@ -30,5 +30,7 @@
3131 void DrawColorKeyCompPatterns(DDSURFACEDESC2 ddsd, unsigned char *buffer, int bpp, int index);
3232 void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud,
3333 int testpattern, int testmethod, int x, int y, int errorlocation, HRESULT error);
 34+extern const DDPIXELFORMAT surfaceformats[];
 35+extern const int numsurfaceformats;
3436
3537 #endif //_SURFACEGEN_H
\ No newline at end of file
Index: dxglcfg/tests.cpp
@@ -55,8 +55,10 @@
5656 static int testpattern = 0;
5757 static int testmethod = 0;
5858 static BOOL d3dfail = FALSE;
 59+static int errorlocation;
 60+static int errornumber;
 61+void RunSurfaceFormatTest();
5962
60 -
6163 #define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
6264 struct COLORVERTEX
6365 {
@@ -213,7 +215,11 @@
214216 case WM_DESTROY:
215217 StopTimer();
216218 for(int i = 0; i < 16; i++)
217 - if(sprites[i].surface) sprites[i].surface->Release();
 219+ if (sprites[i].surface)
 220+ {
 221+ sprites[i].surface->Release();
 222+ sprites[i].surface = NULL;
 223+ }
218224 for (int i = 0; i < 8; i++)
219225 {
220226 if (textures[i])
@@ -297,10 +303,27 @@
298304 switch (wParam)
299305 {
300306 case VK_SPACE: // Show/hide HUD
 307+ showhud++;
 308+ if (showhud > 2) showhud = 0;
 309+ RunSurfaceFormatTest();
301310 break;
302311 case VK_UP: // Source format -
 312+ srcformat--;
 313+ if (srcformat < 0)
 314+ {
 315+ srcformat = 0;
 316+ break;
 317+ }
 318+ RunSurfaceFormatTest();
303319 break;
304320 case VK_DOWN: // Source format +
 321+ srcformat++;
 322+ if (srcformat > numsurfaceformats - 2)
 323+ {
 324+ srcformat = numsurfaceformats - 2;
 325+ break;
 326+ }
 327+ RunSurfaceFormatTest();
305328 break;
306329 case VK_LEFT: // Test pattern -
307330 break;
@@ -307,8 +330,22 @@
308331 case VK_RIGHT: // Test pattern +
309332 break;
310333 case VK_PRIOR: // Dest format - (PgUp)
 334+ destformat--;
 335+ if (destformat < -1)
 336+ {
 337+ destformat = -1;
 338+ break;
 339+ }
 340+ RunSurfaceFormatTest();
311341 break;
312342 case VK_NEXT: // Dest format + (PgDn)
 343+ destformat++;
 344+ if (destformat > numsurfaceformats - 2)
 345+ {
 346+ destformat = numsurfaceformats - 2;
 347+ break;
 348+ }
 349+ RunSurfaceFormatTest();
313350 break;
314351 case VK_TAB: // Render method
315352 break;
@@ -2257,6 +2294,78 @@
22582295 }
22592296 }
22602297
 2298+void RunSurfaceFormatTest()
 2299+{
 2300+ HRESULT error;
 2301+ DDSURFACEDESC2 ddsd;
 2302+ DDBLTFX bltfx;
 2303+ errorlocation = 0;
 2304+ errornumber = 0;
 2305+ if (ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2306+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 2307+ if (sprites[0].surface)
 2308+ {
 2309+ sprites[0].surface->Release();
 2310+ sprites[0].surface = NULL;
 2311+ }
 2312+ if (sprites[1].surface)
 2313+ {
 2314+ sprites[1].surface->Release();
 2315+ sprites[1].surface = NULL;
 2316+ }
 2317+ ddsrender->GetSurfaceDesc(&ddsd);
 2318+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 2319+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 2320+ if (srcformat > 0)
 2321+ {
 2322+ ddsd.dwFlags |= DDSD_PIXELFORMAT;
 2323+ ddsd.ddpfPixelFormat = surfaceformats[srcformat];
 2324+ }
 2325+ error = ddinterface->CreateSurface(&ddsd, &sprites[0].surface, NULL);
 2326+ if(error)
 2327+ {
 2328+ errorlocation = 1;
 2329+ errornumber = error;
 2330+ bltfx.dwSize = sizeof(DDBLTFX);
 2331+ bltfx.dwFillColor = 0;
 2332+ ddsrender->Blt(NULL,NULL,NULL,DDBLT_WAIT|DDBLT_COLORFILL,&bltfx);
 2333+ }
 2334+ else
 2335+ {
 2336+ // FIXME: Select pattern
 2337+ error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 2338+ if(error)
 2339+ {
 2340+ errorlocation = 2;
 2341+ errornumber = error;
 2342+ bltfx.dwSize = sizeof(DDBLTFX);
 2343+ bltfx.dwFillColor = 0;
 2344+ ddsrender->Blt(NULL,NULL,NULL,DDBLT_WAIT|DDBLT_COLORFILL,&bltfx);
 2345+ sprites[0].surface->Release();
 2346+ sprites[0].surface = NULL;
 2347+ }
 2348+ else
 2349+ {
 2350+ DrawPalette(ddsd, (unsigned char*)ddsd.lpSurface);
 2351+ error = sprites[0].surface->Unlock(NULL);
 2352+ // FIXME: Get dest surface type
 2353+ error = ddsrender->Blt(NULL, sprites[0].surface, NULL, DDBLT_WAIT, NULL);
 2354+ if(error)
 2355+ {
 2356+ errorlocation = 5;
 2357+ errornumber = error;
 2358+ bltfx.dwSize = sizeof(DDBLTFX);
 2359+ bltfx.dwFillColor = 0;
 2360+ ddsrender->Blt(NULL,NULL,NULL,DDBLT_WAIT|DDBLT_COLORFILL,&bltfx);
 2361+ sprites[0].surface->Release();
 2362+ sprites[0].surface = NULL;
 2363+ }
 2364+ }
 2365+ }
 2366+ DrawFormatTestHUD(ddsrender, srcformat, destformat, showhud, testpattern,
 2367+ testmethod, ddsd.dwWidth, ddsd.dwHeight, errorlocation, errornumber);
 2368+}
 2369+
22612370 void RunTestLooped(int test)
22622371 {
22632372 randnum += rand(); // Improves randomness of "snow" patterns at certain resolutions