DXGL r874 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r873‎ | r874 | r875 >
Date:00:23, 9 October 2018
Author:admin
Status:new
Tags:
Comment:
Add initial help text for the surface format test.
Add code to gracefully fail Direct3D when initializing a test.
Modified paths:
  • /ddraw/glTexture.cpp (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)
  • /dxglcfg/surfacegen.h (modified) (history)
  • /dxglcfg/tests.cpp (modified) (history)

Diff [purge]

Index: ddraw/glTexture.cpp
@@ -74,7 +74,7 @@
7575 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x7E0, 0x1F, 0}, // 16 bit 565
7676 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0xFF0000, 0xFF00, 0xFF, 0}, // 24 bit 888
7777 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0}, // 32 bit 888
78 - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0}, // 32 bit 888 BGR
 78+ {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0}, // 32 bit 888 RGB
7979 {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xE0, 0x1C, 0x3, 0xFF00}, // 16-bit 8332
8080 {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xF00, 0xF0, 0xF, 0xF000}, // 16-bit 4444
8181 {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0x7c00, 0x3E0, 0x1F, 0x8000}, // 16-bit 1555
Index: dxglcfg/surfacegen.cpp
@@ -1636,51 +1636,105 @@
16371637 return ret;
16381638 }
16391639
1640 -static const TCHAR strFormatTestTitle[] = _T("Surface format test");
1641 -static const TCHAR strFormatTestKeys1[] = _T("UP/DOWN: src type PGUP/DN: dest type ");
1642 -static const TCHAR strFormatTestKeys2[] = _T("LEFT/RIGHT: pattern TAB: render method");
1643 -static const TCHAR strFormatTestKeys3[] = _T("SPACE: show/hide help/info");
 1640+static const LPTSTR strFormatTestTitle = _T("Surface format test");
 1641+static const LPTSTR strFormatTestKeys1 = _T("UP/DOWN: src type PGUP/DN: dest type ");
 1642+static const LPTSTR strFormatTestKeys2 = _T("LEFT/RIGHT: pattern TAB: render method");
 1643+static const LPTSTR strFormatTestKeys3 = _T("SPACE: show/hide help/info");
 1644+static const LPTSTR strFormatTestStatus1 = _T("PATTERN: ");
 1645+static const LPTSTR strFormatTestStatus2 = _T("METHOD: ");
 1646+static const LPTSTR strFormatTestPatterns[] =
 1647+{
 1648+ _T("Unknown "),
 1649+ _T("Palettes "),
 1650+ _T("Gradients "),
 1651+};
 1652+static const LPTSTR StrFormatTestMethods[] =
 1653+{
 1654+ _T("Unknown"),
 1655+ _T("DDraw Blt"),
 1656+ _T("D3D Quad"),
 1657+ _T("Overlay")
 1658+};
 1659+static const int START_SURFACEFORMATS = __LINE__;
 1660+static const LPTSTR strSurfaceFormats[] =
 1661+{
 1662+ _T("Primary surface"), // -1
 1663+ _T("Same as primary"), // 0
 1664+ _T("8-bit Palette"),
 1665+ _T("8-bit 332"),
 1666+ _T("15-bit 555"),
 1667+ _T("16-bit 565"),
 1668+ _T("24-bit 888"),
 1669+ _T("32-bit 888"),
 1670+ _T("32-bit 888 RGB"),
 1671+ _T("16-bit 8332"),
 1672+ _T("16-bit 4444"),
 1673+ _T("16-bit 1555"),
 1674+ _T("32-bit 8888"),
 1675+ _T("8-bit luminance"),
 1676+ _T("8-bit alpha"),
 1677+ _T("8-bit lum/alpha"),
 1678+ _T("16-bit Zbuffer"),
 1679+ _T("24-bit Zbuffer"),
 1680+ _T("24-bit Z, 32bit"),
 1681+ _T("32-bit Zbuffer"),
 1682+ _T("32-bit Z/stencil"),
 1683+ _T("32-bit Z/st.rev")
 1684+};
 1685+static const int END_SURFACEFORMATS = __LINE__ - 4;
 1686+static const int numsurfaceformats = END_SURFACEFORMATS - START_SURFACEFORMATS;
16441687
1645 -void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud, int testpattern, int testmethod, int x, int y)
 1688+static const LPTSTR strErrorMessages[] =
16461689 {
 1690+ _T("Unknown error"),
 1691+ _T("Error creating src surf: "),
 1692+ _T("Error locking src surf: "),
 1693+ _T("Error getting hdc: "),
 1694+ _T("Error creating dest surf: "),
 1695+ _T("Error blitting src to pri: "),
 1696+ _T("Error blitting src to dest: "),
 1697+ _T("Error blitting dest to pri: ")
 1698+};
 1699+
 1700+void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud,
 1701+ int testpattern, int testmethod, int x, int y, int errorlocation, HRESULT error)
 1702+{
16471703 HDC hdc;
1648 - HRESULT error;
 1704+ HRESULT err;
16491705 COLORREF oldcolor;
16501706 COLORREF oldbkcolor;
16511707 HFONT DefaultFont;
16521708 HFONT newfont;
16531709 RECT r;
 1710+ TCHAR buffer[256];
16541711 int oldbk;
16551712 SIZE charsize;
16561713 int rows, cols;
 1714+ int formatrows;
16571715 int posx, posy;
1658 - if (!showhud) return;
1659 - error = surface->GetDC(&hdc);
1660 - if (FAILED(error)) return;
 1716+ int formatposy;
 1717+ int formatfirst, formatlast;
 1718+ err = surface->GetDC(&hdc);
 1719+ if (FAILED(err)) return;
16611720 if (y < 350)
16621721 {
16631722 newfont = CreateFont(-8, -8, 0, 0, 0, 0, 0, 0, OEM_CHARSET, OUT_DEVICE_PRECIS,
16641723 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Terminal"));
1665 - charsize.cx = 8;
1666 - charsize.cy = 8;
16671724 }
16681725 else if ((x > 1024) && (y > 600))
16691726 {
16701727 newfont = CreateFont(-16, -12, 0, 0, 0, 0, 0, 0, OEM_CHARSET, OUT_DEVICE_PRECIS,
16711728 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Terminal"));
1672 - charsize.cx = 12;
1673 - charsize.cy = 16;
16741729 }
16751730 else
16761731 {
16771732 newfont = CreateFont(-12, -8, 0, 0, 0, 0, 0, 0, OEM_CHARSET, OUT_DEVICE_PRECIS,
16781733 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Terminal"));
1679 - charsize.cx = 8;
1680 - charsize.cy = 12;
16811734 }
 1735+ DefaultFont = (HFONT)SelectObject(hdc, newfont);
 1736+ GetTextExtentPoint(hdc, _T("A"), 1, &charsize);
16821737 rows = y / charsize.cy;
16831738 cols = x / charsize.cx;
1684 - DefaultFont = (HFONT)SelectObject(hdc, newfont);
16851739 r.left = 0;
16861740 r.right = 128;
16871741 r.top = 0;
@@ -1687,24 +1741,59 @@
16881742 r.bottom = 16;
16891743 oldcolor = SetTextColor(hdc, RGB(255, 255, 255));
16901744 oldbkcolor = SetBkColor(hdc, RGB(0, 0, 255));
1691 - if(showhud == 2) oldbk = SetBkMode(hdc, TRANSPARENT);
 1745+ if (showhud == 2) oldbk = SetBkMode(hdc, TRANSPARENT);
16921746 else oldbk = SetBkMode(hdc, OPAQUE);
1693 - TextOutShadow(hdc, 0, 0, strFormatTestTitle, _tcslen(strFormatTestTitle), RGB(0, 0, 192));
1694 - TextOutShadow(hdc, 0, charsize.cy, strFormatTestKeys1, _tcslen(strFormatTestKeys1), RGB(0, 0, 192));
1695 - if (cols < (_tcslen(strFormatTestKeys1) + _tcslen(strFormatTestKeys2)))
 1747+ if (showhud)
16961748 {
 1749+ TextOutShadow(hdc, 0, 0, strFormatTestTitle, _tcslen(strFormatTestTitle), RGB(0, 0, 192));
 1750+ TextOutShadow(hdc, 0, charsize.cy, strFormatTestKeys1, _tcslen(strFormatTestKeys1), RGB(0, 0, 192));
 1751+ if (cols < (_tcslen(strFormatTestKeys1) + _tcslen(strFormatTestKeys2)))
 1752+ {
 1753+ posx = 0;
 1754+ posy = 2 * charsize.cy;
 1755+ }
 1756+ else
 1757+ {
 1758+ posx = _tcslen(strFormatTestKeys1) * charsize.cx;
 1759+ posy = charsize.cy;
 1760+ }
 1761+ TextOutShadow(hdc, posx, posy, strFormatTestKeys2, _tcslen(strFormatTestKeys2), RGB(0, 0, 192));
16971762 posx = 0;
1698 - posy = 2 * charsize.cy;
 1763+ posy += charsize.cy;
 1764+ TextOutShadow(hdc, posx, posy, strFormatTestKeys3, _tcslen(strFormatTestKeys3), RGB(0, 0, 192));
 1765+ posy += charsize.cy;
 1766+ _tcscpy(buffer, strFormatTestStatus1);
 1767+ if (testpattern < 0) testpattern = 0;
 1768+ if (testpattern > 2) testpattern = 0;
 1769+ _tcscat(buffer, strFormatTestPatterns[testpattern]);
 1770+ _tcscat(buffer, strFormatTestStatus2);
 1771+ if (testmethod < 0) testmethod = 0;
 1772+ if (testmethod > 3) testmethod = 0;
 1773+ _tcscat(buffer, StrFormatTestMethods[testmethod]);
 1774+ TextOutShadow(hdc, posx, posy, buffer, _tcslen(buffer), RGB(0, 0, 192));
 1775+ // List source formats
 1776+ formatposy = posy + charsize.cy;
 1777+ SetBkMode(hdc, TRANSPARENT);
 1778+ formatrows = rows - (formatposy / charsize.cy) - 1;
 1779+ if (formatrows > numsurfaceformats)
 1780+ {
 1781+ formatfirst = -1;
 1782+ formatlast = numsurfaceformats - 2;
 1783+ }
 1784+ else
 1785+ {
 1786+
 1787+ }
16991788 }
1700 - else
 1789+ // Display error if present
 1790+ if (error)
17011791 {
1702 - posx = _tcslen(strFormatTestKeys1) * charsize.cx;
1703 - posy = charsize.cy;
 1792+ SetBkMode(hdc, OPAQUE);
 1793+ SetBkColor(hdc, RGB(255, 0, 0));
 1794+ SetTextColor(hdc, RGB(255, 255, 255));
 1795+ if (errorlocation < 0) errorlocation = 0;
 1796+ if (errorlocation > 7) errorlocation = 0;
17041797 }
1705 - TextOutShadow(hdc, posx, posy, strFormatTestKeys2, _tcslen(strFormatTestKeys2), RGB(0, 0, 192));
1706 - posx = 0;
1707 - posy += charsize.cy;
1708 - TextOutShadow(hdc, posx, posy, strFormatTestKeys3, _tcslen(strFormatTestKeys3), RGB(0, 0, 192));
17091798 SelectObject(hdc, DefaultFont);
17101799 DeleteObject(newfont);
17111800 SetTextColor(hdc, oldcolor);
Index: dxglcfg/surfacegen.h
@@ -28,6 +28,7 @@
2929 HWND hwnd, LPDIRECTDRAWPALETTE palette); // ROP pattern test
3030 void DrawRotatedBlt(MultiDirectDrawSurface *primary, DDSPRITE *sprites);
3131 void DrawColorKeyCompPatterns(DDSURFACEDESC2 ddsd, unsigned char *buffer, int bpp, int index);
32 -void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud, int testpattern, int testmethod, int x, int y);
 32+void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud,
 33+ int testpattern, int testmethod, int x, int y, int errorlocation, HRESULT error);
3334
3435 #endif //_SURFACEGEN_H
\ No newline at end of file
Index: dxglcfg/tests.cpp
@@ -54,6 +54,7 @@
5555 static int showhud = 1;
5656 static int testpattern = 0;
5757 static int testmethod = 0;
 58+static BOOL d3dfail = FALSE;
5859
5960
6061 #define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
@@ -423,6 +424,7 @@
424425 HINSTANCE hinstance = (HINSTANCE)GetModuleHandle(NULL);
425426 WNDCLASSEX wc;
426427 MSG Msg;
 428+ d3dfail = FALSE;
427429 ZeroMemory(&wc,sizeof(WNDCLASS));
428430 wc.cbSize = sizeof(WNDCLASSEX);
429431 wc.style = CS_HREDRAW | CS_VREDRAW;
@@ -475,6 +477,12 @@
476478 if(is3d) ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
477479 }
478480 error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
 481+ if(FAILED(error))
 482+ {
 483+ d3dfail = TRUE;
 484+ ddsd.ddsCaps.dwCaps &= ~DDSCAPS_3DDEVICE;
 485+ error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
 486+ }
479487 if(!fullscreen)
480488 {
481489 error = ddinterface->CreateClipper(0,&ddclipper,NULL);
@@ -503,23 +511,45 @@
504512 ddsrender->SetPalette(pal);
505513 }
506514 else pal = NULL;
507 - if (is3d)
 515+ if (is3d )
508516 {
509517 error = ddinterface->QueryInterface(IID_IDirect3D7, (VOID**)&d3d7);
510 - error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice, zcallback, &ddpfz);
511 - error = ddsrender->GetSurfaceDesc(&ddsd);
512 - ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
513 - ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
514 - memcpy(&ddsd.ddpfPixelFormat, &ddpfz, sizeof(DDPIXELFORMAT));
515 - error = ddinterface->CreateSurface(&ddsd, &zbuffer, NULL);
516 - error = ddsrender->AddAttachedSurface(zbuffer);
517 - error = d3d7->CreateDevice(IID_IDirect3DHALDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
518 - if (error != D3D_OK)
519 - error = d3d7->CreateDevice(IID_IDirect3DRGBDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
520 - ddsrender->GetSurfaceDesc(&ddsd);
521 - D3DVIEWPORT7 vp = { 0,0,ddsd.dwWidth,ddsd.dwHeight,0.0f,1.0f };
522 - error = d3d7dev->SetViewport(&vp);
523 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
 518+ if (FAILED(error)) d3dfail = TRUE;
 519+ else
 520+ {
 521+ error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice, zcallback, &ddpfz);
 522+ error = ddsrender->GetSurfaceDesc(&ddsd);
 523+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
 524+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
 525+ memcpy(&ddsd.ddpfPixelFormat, &ddpfz, sizeof(DDPIXELFORMAT));
 526+ error = ddinterface->CreateSurface(&ddsd, &zbuffer, NULL);
 527+ if (FAILED(error))
 528+ {
 529+ d3dfail = TRUE;
 530+ d3d7->Release();
 531+ }
 532+ else
 533+ {
 534+ error = ddsrender->AddAttachedSurface(zbuffer);
 535+ error = d3d7->CreateDevice(IID_IDirect3DHALDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 536+ if (error != D3D_OK)
 537+ error = d3d7->CreateDevice(IID_IDirect3DRGBDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 538+ if (error != D3D_OK)
 539+ {
 540+ d3dfail = TRUE;
 541+ zbuffer->Release();
 542+ d3d7->Release();
 543+ }
 544+ else
 545+ {
 546+ ddsrender->GetSurfaceDesc(&ddsd);
 547+ D3DVIEWPORT7 vp = { 0,0,ddsd.dwWidth,ddsd.dwHeight,0.0f,1.0f };
 548+ error = d3d7dev->SetViewport(&vp);
 549+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
 550+ d3dfail = FALSE;
 551+ }
 552+ }
 553+ }
524554 }
525555 InitTest(testnum);
526556 if(!fullscreen) SendMessage(hWnd,WM_PAINT,0,0);
@@ -1454,7 +1484,7 @@
14551485 DrawPalette(ddsd, (unsigned char*)ddsd.lpSurface);
14561486 error = sprites[0].surface->Unlock(NULL);
14571487 ddsrender->Blt(NULL, sprites[0].surface, NULL, DDBLT_WAIT, NULL);
1458 - DrawFormatTestHUD(ddsrender, 0, -1, 1, 0, 0, ddsd.dwWidth, ddsd.dwHeight);
 1488+ DrawFormatTestHUD(ddsrender, 0, -1, 1, 0, 0, ddsd.dwWidth, ddsd.dwHeight, 0, DD_OK);
14591489 default:
14601490 break;
14611491 }