Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1118 lines
38 KiB

  1. /****************************************************************************
  2. *
  3. * File: testd3d8.cpp
  4. * Project: DxDiag (DirectX Diagnostic Tool)
  5. * Author: Jason Sandlin (jasonsa@microsoft.com)
  6. * Purpose: Test D3D8/AGP Texturing functionality on this machine
  7. *
  8. * (C) Copyright 2000 Microsoft Corp. All rights reserved.
  9. *
  10. ****************************************************************************/
  11. #include <Windows.h>
  12. #define DIRECT3D_VERSION 0x0800 // file uses DX8
  13. #include <d3d8.h>
  14. #include <d3dx8.h>
  15. #include "reginfo.h"
  16. #include "sysinfo.h"
  17. #include "dispinfo.h"
  18. #include "testagp.h"
  19. #include "resource.h"
  20. #ifndef ReleasePpo
  21. #define ReleasePpo(ppo) \
  22. if (*(ppo) != NULL) \
  23. { \
  24. (*(ppo))->Release(); \
  25. *(ppo) = NULL; \
  26. } \
  27. else (VOID)0
  28. #endif
  29. typedef IDirect3D8* (WINAPI* LPDIRECT3DCREATE8)(UINT SDKVersion);
  30. #define D3DFVF_VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
  31. #define MAX_FORMATS 64
  32. #define MAX_MODES 256
  33. #define MAX_CONFIRMED_MODES 256
  34. struct D3DVERTEX
  35. {
  36. D3DXVECTOR3 p;
  37. D3DXVECTOR3 n;
  38. FLOAT tu, tv;
  39. D3DVERTEX() {};
  40. D3DVERTEX( D3DXVECTOR3 vp, D3DXVECTOR3 vn, FLOAT fTu, FLOAT fTv ) : p(vp), n(vn), tu(fTu), tv(fTv) {}
  41. };
  42. struct D3DModeInfo
  43. {
  44. DWORD Width; // Screen width in this mode
  45. DWORD Height; // Screen height in this mode
  46. D3DFORMAT Format; // Pixel format in this mode
  47. DWORD dwBehavior; // Hardware / Software / Mixed vertex processing
  48. };
  49. enum TESTID
  50. {
  51. TESTID_LOAD_D3D8_DLL=1,
  52. TESTID_GET_D3DCREATE8,
  53. TESTID_D3DCREATE8,
  54. TESTID_ENUMADAPTERMODES,
  55. TESTID_GETDEVICECAPS,
  56. TESTID_NOMODEFOUND,
  57. TESTID_CREATE_TEST_WINDOW,
  58. TESTID_CREATE_DEVICE,
  59. TESTID_GETBACKBUFFER,
  60. TESTID_GETDESC,
  61. TESTID_CREATE_VERTEX_BUFFER,
  62. TESTID_CREATE_INDEX_BUFFER,
  63. TESTID_LOCK,
  64. TESTID_UNLOCK,
  65. TESTID_SETLIGHT,
  66. TESTID_LIGHTENABLE,
  67. TESTID_SETTRANSFORM,
  68. TESTID_SETRENDERSTATE,
  69. TESTID_CREATETEXTURE,
  70. TESTID_SETTEXTURESTAGESTATE,
  71. TESTID_SETTEXTURE,
  72. TESTID_SETVERTEXSHADER,
  73. TESTID_USER_CANCELLED,
  74. TESTID_VIEWPORT_CLEAR,
  75. TESTID_BEGINSCENE,
  76. TESTID_SETMATERIAL,
  77. TESTID_SETSTREAMSOURCE,
  78. TESTID_SETINDICES,
  79. TESTID_DRAW_INDEXED_PRIMITIVE,
  80. TESTID_ENDSCENE,
  81. TESTID_PRESENT,
  82. TESTID_USER_VERIFY_D3D7_RENDERING,
  83. TESTID_USER_VERIFY_D3D8_RENDERING,
  84. TESTID_LOAD_DDRAW_DLL,
  85. TESTID_GET_DIRECTDRAWCREATE,
  86. TESTID_DIRECTDRAWCREATE,
  87. TESTID_SETCOOPERATIVELEVEL_FULLSCREEN,
  88. TESTID_SETCOOPERATIVELEVEL_NORMAL,
  89. TESTID_SETDISPLAYMODE,
  90. TESTID_CREATEPRIMARYSURFACE_FLIP_ONEBACK,
  91. TESTID_GETATTACHEDSURFACE,
  92. TESTID_QUERY_D3D,
  93. TESTID_SETVIEWPORT,
  94. TESTID_ENUMTEXTUREFORMATS,
  95. TESTID_CREATESURFACE,
  96. TESTID_GETDC,
  97. TESTID_RELEASEDC,
  98. };
  99. BOOL BTranslateError(HRESULT hr, TCHAR* psz, BOOL bEnglish = FALSE); // from main.cpp
  100. static HRESULT SelectModeAndFormat( DisplayInfo* pDisplayInfo, IDirect3D8* pD3D8, D3DModeInfo* pSelectedMode, D3DDEVTYPE* pSelectedDeviceType );
  101. static HRESULT Test3D( BOOL bUseTexture, IDirect3D8* pD3D8, HWND hwndMain, DWORD iAdapter, D3DModeInfo selectedMode, D3DDEVTYPE selectedDeviceType, LONG* piStepThatFailed );
  102. static HRESULT CreateTestWindow(HWND hwndMain, HWND* phwnd);
  103. static HRESULT InitVertexBuffer( IDirect3DDevice8* pd3dDevice, const D3DVERTEX* vertexArray, DWORD dwNumVertices, LPDIRECT3DVERTEXBUFFER8* ppVB, LONG* piStepThatFailed );
  104. static HRESULT InitIndexBuffer( IDirect3DDevice8* pd3dDevice, const WORD* wIndexArray, DWORD dwNumIndices, LPDIRECT3DINDEXBUFFER8* ppIB, LONG* piStepThatFailed );
  105. static HRESULT DrawTwoSides( BOOL bUseTexture, IDirect3DDevice8* pd3dDevice, D3DMATERIAL8* pMtrl, LPDIRECT3DVERTEXBUFFER8 pVB1, LPDIRECT3DINDEXBUFFER8 pIB1, LPDIRECT3DVERTEXBUFFER8 pVB2, LPDIRECT3DINDEXBUFFER8 pIB2, LONG* piStepThatFailed );
  106. //-----------------------------------------------------------------------------
  107. // Name: TestD3Dv8()
  108. // Desc:
  109. //-----------------------------------------------------------------------------
  110. VOID TestD3Dv8( BOOL bUseTexture, HWND hwndMain, DisplayInfo* pDisplayInfo)
  111. {
  112. HRESULT hr = S_OK;
  113. TCHAR sz[MAX_PATH];
  114. TCHAR szTitle[MAX_PATH];
  115. HINSTANCE hInstD3D8 = NULL;
  116. IDirect3D8* pD3D8 = NULL;
  117. HWND hwnd = NULL;
  118. D3DModeInfo selectedMode;
  119. D3DDEVTYPE selectedDeviceType;
  120. if( pDisplayInfo == NULL )
  121. return;
  122. LoadString(NULL, IDS_APPFULLNAME, szTitle, MAX_PATH);
  123. LPDIRECT3DCREATE8 pD3DCreate8 = NULL;
  124. TCHAR szPath[MAX_PATH];
  125. GetSystemDirectory(szPath, MAX_PATH);
  126. lstrcat(szPath, TEXT("\\d3d8.dll"));
  127. // This may fail if DX8 isn't on the system
  128. hInstD3D8 = LoadLibrary(szPath);
  129. if (hInstD3D8 == NULL)
  130. {
  131. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_LOAD_D3D8_DLL;
  132. pDisplayInfo->m_testResultD3D8.m_hr = E_FAIL;
  133. goto LEnd;
  134. }
  135. pD3DCreate8 = (LPDIRECT3DCREATE8)GetProcAddress(hInstD3D8, "Direct3DCreate8");
  136. if (pD3DCreate8 == NULL)
  137. {
  138. FreeLibrary(hInstD3D8);
  139. hInstD3D8 = NULL;
  140. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_GET_D3DCREATE8;
  141. pDisplayInfo->m_testResultD3D8.m_hr = E_POINTER;
  142. goto LEnd;
  143. }
  144. pD3D8 = pD3DCreate8(D3D_SDK_VERSION);
  145. if( pD3D8 == NULL )
  146. {
  147. // We have the wrong headers since d3d8.dll loaded but D3DCreate8() failed.
  148. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_D3DCREATE8;
  149. pDisplayInfo->m_testResultD3D8.m_hr = E_FAIL;
  150. goto LEnd;
  151. }
  152. // Enum and select a support mode and format and device type
  153. if( FAILED( SelectModeAndFormat( pDisplayInfo, pD3D8,
  154. &selectedMode, &selectedDeviceType ) ) )
  155. goto LEnd;
  156. // Save the cursor
  157. POINT ptMouse;
  158. GetCursorPos(&ptMouse);
  159. // Run the test
  160. if (FAILED(hr = Test3D( bUseTexture, pD3D8, hwndMain, pDisplayInfo->m_iAdapter, selectedMode,
  161. selectedDeviceType, &pDisplayInfo->m_testResultD3D8.m_iStepThatFailed)))
  162. {
  163. pDisplayInfo->m_testResultD3D8.m_hr = hr;
  164. goto LEnd;
  165. }
  166. // Restore the cursor position
  167. SetCursorPos( ptMouse.x, ptMouse.y );
  168. // Tell the user if they canceled
  169. if (pDisplayInfo->m_testResultD3D8.m_iStepThatFailed == TESTID_USER_CANCELLED)
  170. {
  171. LoadString(NULL, IDS_YOUCANCELLED, sz, MAX_PATH);
  172. MessageBox(hwndMain, sz, szTitle, MB_OK);
  173. pDisplayInfo->m_testResultD3D8.m_bCancelled = TRUE;
  174. goto LEnd;
  175. }
  176. // Confirm the test succeeded
  177. LoadString(NULL, IDS_CONFIRMD3DTEST, sz, MAX_PATH);
  178. if (IDNO == MessageBox(hwndMain, sz, szTitle, MB_YESNO))
  179. {
  180. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_USER_VERIFY_D3D8_RENDERING;
  181. pDisplayInfo->m_testResultD3D8.m_hr = S_OK;
  182. goto LEnd;
  183. }
  184. LEnd:
  185. ReleasePpo( &pD3D8 );
  186. if( hInstD3D8 )
  187. {
  188. FreeLibrary(hInstD3D8);
  189. hInstD3D8 = NULL;
  190. }
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Name: Test3D()
  194. // Desc: Generate a spinning 3D cube
  195. //-----------------------------------------------------------------------------
  196. HRESULT Test3D( BOOL bUseTexture, IDirect3D8* pD3D8, HWND hwndMain, DWORD iAdapter,
  197. D3DModeInfo selectedMode, D3DDEVTYPE selectedDeviceType,
  198. LONG* piStepThatFailed )
  199. {
  200. LPDIRECT3DDEVICE8 pd3dDevice = NULL;
  201. LPDIRECT3DTEXTURE8 pTexture = NULL;
  202. LPDIRECT3DVERTEXBUFFER8 pVBFront = NULL;
  203. LPDIRECT3DINDEXBUFFER8 pIBFront = NULL;
  204. LPDIRECT3DVERTEXBUFFER8 pVBBack = NULL;
  205. LPDIRECT3DINDEXBUFFER8 pIBBack = NULL;
  206. LPDIRECT3DVERTEXBUFFER8 pVBLeft = NULL;
  207. LPDIRECT3DINDEXBUFFER8 pIBLeft = NULL;
  208. LPDIRECT3DVERTEXBUFFER8 pVBRight = NULL;
  209. LPDIRECT3DINDEXBUFFER8 pIBRight = NULL;
  210. LPDIRECT3DVERTEXBUFFER8 pVBTop = NULL;
  211. LPDIRECT3DINDEXBUFFER8 pIBTop = NULL;
  212. LPDIRECT3DVERTEXBUFFER8 pVBBottom = NULL;
  213. LPDIRECT3DINDEXBUFFER8 pIBBottom = NULL;
  214. LPDIRECT3DSURFACE8 pBackBuffer = NULL;
  215. D3DMATERIAL8 mtrlWhite;
  216. D3DMATERIAL8 mtrlRed;
  217. D3DMATERIAL8 mtrlBlue;
  218. D3DMATERIAL8 mtrlGreen;
  219. D3DXMATRIX matRotY;
  220. D3DXMATRIX matRotX;
  221. D3DXMATRIX mat;
  222. D3DSURFACE_DESC d3dsdBackBuffer;
  223. FLOAT fRotY;
  224. FLOAT fRotX;
  225. HRESULT hr;
  226. HWND hwnd;
  227. MSG msg;
  228. DWORD i;
  229. static const D3DVERTEX vertexArrayFront[] =
  230. {
  231. D3DVERTEX(D3DXVECTOR3(-1.0, -1.0, -1.0), D3DXVECTOR3(0.0, 0.0, -1.0), 1.0f, 0.0f),
  232. D3DVERTEX(D3DXVECTOR3( 1.0, -1.0, -1.0), D3DXVECTOR3(0.0, 0.0, -1.0), 0.0f, 0.0f),
  233. D3DVERTEX(D3DXVECTOR3(-1.0, 1.0, -1.0), D3DXVECTOR3(0.0, 0.0, -1.0), 1.0f, 1.0f),
  234. D3DVERTEX(D3DXVECTOR3( 1.0, 1.0, -1.0), D3DXVECTOR3(0.0, 0.0, -1.0), 0.0f, 1.0f),
  235. };
  236. static const WORD indexArrayFront[] =
  237. {
  238. 0, 2, 1,
  239. 2, 3, 1,
  240. };
  241. static const D3DVERTEX vertexArrayBack[] =
  242. {
  243. D3DVERTEX(D3DXVECTOR3(-1.0, -1.0, 1.0), D3DXVECTOR3(0.0, 0.0, 1.0), 0.0f, 0.0f),
  244. D3DVERTEX(D3DXVECTOR3( 1.0, -1.0, 1.0), D3DXVECTOR3(0.0, 0.0, 1.0), 1.0f, 0.0f),
  245. D3DVERTEX(D3DXVECTOR3(-1.0, 1.0, 1.0), D3DXVECTOR3(0.0, 0.0, 1.0), 0.0f, 1.0f),
  246. D3DVERTEX(D3DXVECTOR3( 1.0, 1.0, 1.0), D3DXVECTOR3(0.0, 0.0, 1.0), 1.0f, 1.0f),
  247. };
  248. static const WORD indexArrayBack[] =
  249. {
  250. 0, 1, 2,
  251. 2, 1, 3,
  252. };
  253. static const D3DVERTEX vertexArrayLeft[] =
  254. {
  255. D3DVERTEX(D3DXVECTOR3(-1.0, -1.0, -1.0), D3DXVECTOR3(-1.0, 0.0, 0.0), 0.0f, 0.0f),
  256. D3DVERTEX(D3DXVECTOR3(-1.0, -1.0, 1.0), D3DXVECTOR3(-1.0, 0.0, 0.0), 1.0f, 0.0f),
  257. D3DVERTEX(D3DXVECTOR3(-1.0, 1.0, -1.0), D3DXVECTOR3(-1.0, 0.0, 0.0), 0.0f, 1.0f),
  258. D3DVERTEX(D3DXVECTOR3(-1.0, 1.0, 1.0), D3DXVECTOR3(-1.0, 0.0, 0.0), 1.0f, 1.0f),
  259. };
  260. static const WORD indexArrayLeft[] =
  261. {
  262. 0, 1, 2,
  263. 2, 1, 3,
  264. };
  265. static const D3DVERTEX vertexArrayRight[] =
  266. {
  267. D3DVERTEX(D3DXVECTOR3(1.0, -1.0, -1.0), D3DXVECTOR3(1.0, 0.0, 0.0), 1.0f, 0.0f),
  268. D3DVERTEX(D3DXVECTOR3(1.0, -1.0, 1.0), D3DXVECTOR3(1.0, 0.0, 0.0), 0.0f, 0.0f),
  269. D3DVERTEX(D3DXVECTOR3(1.0, 1.0, -1.0), D3DXVECTOR3(1.0, 0.0, 0.0), 1.0f, 1.0f),
  270. D3DVERTEX(D3DXVECTOR3(1.0, 1.0, 1.0), D3DXVECTOR3(1.0, 0.0, 0.0), 0.0f, 1.0f),
  271. };
  272. static const WORD indexArrayRight[] =
  273. {
  274. 0, 2, 1,
  275. 2, 3, 1,
  276. };
  277. static const D3DVERTEX vertexArrayTop[] =
  278. {
  279. D3DVERTEX(D3DXVECTOR3(-1.0, 1.0, -1.0), D3DXVECTOR3(0.0, 1.0, 0.0), 0.0f, 1.0f),
  280. D3DVERTEX(D3DXVECTOR3( 1.0, 1.0, -1.0), D3DXVECTOR3(0.0, 1.0, 0.0), 1.0f, 1.0f),
  281. D3DVERTEX(D3DXVECTOR3(-1.0, 1.0, 1.0), D3DXVECTOR3(0.0, 1.0, 0.0), 0.0f, 0.0f),
  282. D3DVERTEX(D3DXVECTOR3( 1.0, 1.0, 1.0), D3DXVECTOR3(0.0, 1.0, 0.0), 1.0f, 0.0f),
  283. };
  284. static const WORD indexArrayTop[] =
  285. {
  286. 0, 2, 1,
  287. 2, 3, 1,
  288. };
  289. static const D3DVERTEX vertexArrayBottom[] =
  290. {
  291. D3DVERTEX(D3DXVECTOR3(-1.0, -1.0, -1.0), D3DXVECTOR3(0.0, -1.0, 0.0), 1.0f, 1.0f),
  292. D3DVERTEX(D3DXVECTOR3( 1.0, -1.0, -1.0), D3DXVECTOR3(0.0, -1.0, 0.0), 0.0f, 1.0f),
  293. D3DVERTEX(D3DXVECTOR3(-1.0, -1.0, 1.0), D3DXVECTOR3(0.0, -1.0, 0.0), 1.0f, 0.0f),
  294. D3DVERTEX(D3DXVECTOR3( 1.0, -1.0, 1.0), D3DXVECTOR3(0.0, -1.0, 0.0), 0.0f, 0.0f),
  295. };
  296. static const WORD indexArrayBottom[] =
  297. {
  298. 0, 1, 2,
  299. 2, 1, 3,
  300. };
  301. ShowCursor(FALSE);
  302. // Create test window
  303. if (FAILED(hr = CreateTestWindow(hwndMain, &hwnd)))
  304. {
  305. *piStepThatFailed = TESTID_CREATE_TEST_WINDOW;
  306. goto LEnd;
  307. }
  308. // Set up the presentation parameters
  309. D3DPRESENT_PARAMETERS d3dpp;
  310. ZeroMemory( &d3dpp, sizeof(d3dpp) );
  311. d3dpp.Windowed = FALSE;
  312. d3dpp.BackBufferCount = 1;
  313. d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
  314. d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  315. d3dpp.EnableAutoDepthStencil = FALSE;
  316. d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
  317. d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;
  318. d3dpp.hDeviceWindow = hwnd;
  319. d3dpp.BackBufferWidth = selectedMode.Width;
  320. d3dpp.BackBufferHeight = selectedMode.Height;
  321. d3dpp.BackBufferFormat = selectedMode.Format;
  322. // Create the device
  323. if( FAILED( hr = pD3D8->CreateDevice( iAdapter, selectedDeviceType,
  324. hwnd, selectedMode.dwBehavior, &d3dpp,
  325. &pd3dDevice ) ) )
  326. {
  327. *piStepThatFailed = TESTID_CREATE_DEVICE;
  328. goto LEnd;
  329. }
  330. if( pd3dDevice == NULL )
  331. {
  332. *piStepThatFailed = TESTID_CREATE_DEVICE;
  333. hr = E_POINTER;
  334. goto LEnd;
  335. }
  336. // Get the desc of the backbuffer
  337. if( FAILED( hr = pd3dDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ) ) )
  338. {
  339. *piStepThatFailed = TESTID_GETBACKBUFFER;
  340. goto LEnd;
  341. }
  342. if( pBackBuffer == NULL )
  343. {
  344. *piStepThatFailed = TESTID_GETBACKBUFFER;
  345. hr = E_POINTER;
  346. goto LEnd;
  347. }
  348. if( FAILED( hr = pBackBuffer->GetDesc( &d3dsdBackBuffer ) ) )
  349. {
  350. *piStepThatFailed = TESTID_GETDESC;
  351. goto LEnd;
  352. }
  353. ReleasePpo(&pBackBuffer);
  354. // Init the vertex/index buffer for the Front
  355. if( FAILED( hr = InitVertexBuffer( pd3dDevice, vertexArrayFront, sizeof(vertexArrayFront)/sizeof(D3DVERTEX), &pVBFront, piStepThatFailed ) ) )
  356. goto LEnd;
  357. if( FAILED( hr = InitIndexBuffer( pd3dDevice, indexArrayFront, sizeof(indexArrayFront)/sizeof(WORD), &pIBFront, piStepThatFailed ) ) )
  358. goto LEnd;
  359. // Init the vertex/index buffer for the Back
  360. if( FAILED( hr = InitVertexBuffer( pd3dDevice, vertexArrayBack, sizeof(vertexArrayBack)/sizeof(D3DVERTEX), &pVBBack, piStepThatFailed ) ) )
  361. goto LEnd;
  362. if( FAILED( hr = InitIndexBuffer( pd3dDevice, indexArrayBack, sizeof(indexArrayBack)/sizeof(WORD), &pIBBack, piStepThatFailed ) ) )
  363. goto LEnd;
  364. // Init the vertex/index buffer for the Left
  365. if( FAILED( hr = InitVertexBuffer( pd3dDevice, vertexArrayLeft, sizeof(vertexArrayLeft)/sizeof(D3DVERTEX), &pVBLeft, piStepThatFailed ) ) )
  366. goto LEnd;
  367. if( FAILED( hr = InitIndexBuffer( pd3dDevice, indexArrayLeft, sizeof(indexArrayLeft)/sizeof(WORD), &pIBLeft, piStepThatFailed ) ) )
  368. goto LEnd;
  369. // Init the vertex/index buffer for the Right
  370. if( FAILED( hr = InitVertexBuffer( pd3dDevice, vertexArrayRight, sizeof(vertexArrayRight)/sizeof(D3DVERTEX), &pVBRight, piStepThatFailed ) ) )
  371. goto LEnd;
  372. if( FAILED( hr = InitIndexBuffer( pd3dDevice, indexArrayRight, sizeof(indexArrayRight)/sizeof(WORD), &pIBRight, piStepThatFailed ) ) )
  373. goto LEnd;
  374. // Init the vertex/index buffer for the Top
  375. if( FAILED( hr = InitVertexBuffer( pd3dDevice, vertexArrayTop, sizeof(vertexArrayTop)/sizeof(D3DVERTEX), &pVBTop, piStepThatFailed ) ) )
  376. goto LEnd;
  377. if( FAILED( hr = InitIndexBuffer( pd3dDevice, indexArrayTop, sizeof(indexArrayTop)/sizeof(WORD), &pIBTop, piStepThatFailed ) ) )
  378. goto LEnd;
  379. // Init the vertex/index buffer for the Bottom
  380. if( FAILED( hr = InitVertexBuffer( pd3dDevice, vertexArrayBottom, sizeof(vertexArrayBottom)/sizeof(D3DVERTEX), &pVBBottom, piStepThatFailed ) ) )
  381. goto LEnd;
  382. if( FAILED( hr = InitIndexBuffer( pd3dDevice, indexArrayBottom, sizeof(indexArrayBottom)/sizeof(WORD), &pIBBottom, piStepThatFailed ) ) )
  383. goto LEnd;
  384. // Add a light
  385. D3DLIGHT8 light;
  386. ZeroMemory( &light, sizeof(D3DLIGHT8) );
  387. light.Type = D3DLIGHT_DIRECTIONAL;
  388. light.Diffuse.r = 1.0f;
  389. light.Diffuse.g = 1.0f;
  390. light.Diffuse.b = 1.0f;
  391. light.Direction.x = 0.0f;
  392. light.Direction.y = 0.0f;
  393. light.Direction.z = 1.0f;
  394. if( FAILED( hr = pd3dDevice->SetLight( 0, &light ) ) )
  395. {
  396. *piStepThatFailed = TESTID_SETLIGHT;
  397. goto LEnd;
  398. }
  399. if( FAILED( hr = pd3dDevice->LightEnable( 0, TRUE ) ) )
  400. {
  401. *piStepThatFailed = TESTID_LIGHTENABLE;
  402. goto LEnd;
  403. }
  404. // Set up matrices
  405. mat = D3DXMATRIX(1.0f, 0.0f, 0.0f, 0.0f,
  406. 0.0f, 1.0f, 0.0f, 0.0f,
  407. 0.0f, 0.0f, 1.0f, 0.0f,
  408. 0.0f, 0.0f, 0.0f, 1.0f);
  409. if( FAILED( hr = pd3dDevice->SetTransform( D3DTS_WORLD, &mat ) ) )
  410. {
  411. *piStepThatFailed = TESTID_SETTRANSFORM;
  412. goto LEnd;
  413. }
  414. mat = D3DXMATRIX(1.0f, 0.0f, 0.0f, 0.0f,
  415. 0.0f, 1.0f, 0.0f, 0.0f,
  416. 0.0f, 0.0f, 1.0f, 0.0f,
  417. 0.0f, 0.0f, 5.0f, 1.0f);
  418. if( FAILED( hr = pd3dDevice->SetTransform( D3DTS_VIEW, &mat ) ) )
  419. {
  420. *piStepThatFailed = TESTID_SETTRANSFORM;
  421. goto LEnd;
  422. }
  423. D3DXMatrixPerspectiveFovLH( &mat, D3DXToRadian(60.0f),
  424. (float) d3dsdBackBuffer.Width / (float) d3dsdBackBuffer.Height,
  425. 1.0f, 1000.0f );
  426. if( FAILED( hr = pd3dDevice->SetTransform( D3DTS_PROJECTION, &mat ) ) )
  427. {
  428. *piStepThatFailed = TESTID_SETTRANSFORM;
  429. goto LEnd;
  430. }
  431. fRotY = 3.14f;
  432. fRotX = 0.0f;
  433. if( FAILED( hr = pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE ) ) )
  434. {
  435. *piStepThatFailed = TESTID_SETRENDERSTATE;
  436. goto LEnd;
  437. }
  438. if( FAILED( hr = pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x40404040 ) ) )
  439. {
  440. *piStepThatFailed = TESTID_SETRENDERSTATE;
  441. goto LEnd;
  442. }
  443. ZeroMemory( &mtrlWhite, sizeof(D3DMATERIAL8) );
  444. mtrlWhite.Diffuse.r = mtrlWhite.Ambient.r = 1.0f;
  445. mtrlWhite.Diffuse.g = mtrlWhite.Ambient.g = 1.0f;
  446. mtrlWhite.Diffuse.b = mtrlWhite.Ambient.b = 1.0f;
  447. mtrlWhite.Diffuse.a = mtrlWhite.Ambient.a = 0.0f;
  448. ZeroMemory( &mtrlRed, sizeof(D3DMATERIAL8) );
  449. mtrlRed.Diffuse.r = mtrlRed.Ambient.r = 1.0f;
  450. mtrlRed.Diffuse.g = mtrlRed.Ambient.g = 0.0f;
  451. mtrlRed.Diffuse.b = mtrlRed.Ambient.b = 0.0f;
  452. mtrlRed.Diffuse.a = mtrlRed.Ambient.a = 0.0f;
  453. ZeroMemory( &mtrlGreen, sizeof(D3DMATERIAL8) );
  454. mtrlGreen.Diffuse.r = mtrlGreen.Ambient.r = 0.0f;
  455. mtrlGreen.Diffuse.g = mtrlGreen.Ambient.g = 1.0f;
  456. mtrlGreen.Diffuse.b = mtrlGreen.Ambient.b = 0.0f;
  457. mtrlGreen.Diffuse.a = mtrlGreen.Ambient.a = 0.0f;
  458. ZeroMemory( &mtrlBlue, sizeof(D3DMATERIAL8) );
  459. mtrlBlue.Diffuse.r = mtrlBlue.Ambient.r = 0.0f;
  460. mtrlBlue.Diffuse.g = mtrlBlue.Ambient.g = 0.0f;
  461. mtrlBlue.Diffuse.b = mtrlBlue.Ambient.b = 1.0f;
  462. mtrlBlue.Diffuse.a = mtrlBlue.Ambient.a = 0.0f;
  463. if( bUseTexture )
  464. {
  465. D3DCAPS8 d3dCaps;
  466. // Load default texture in resource anDefaultTextureResource[i]
  467. if( FAILED( hr = D3DXCreateTextureFromResourceEx( pd3dDevice, NULL, TEXT("DIRECTX"),
  468. D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, d3dsdBackBuffer.Format,
  469. D3DPOOL_DEFAULT, D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR,
  470. D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 0, NULL, NULL, &pTexture ) ) )
  471. {
  472. *piStepThatFailed = TESTID_CREATETEXTURE;
  473. goto LEnd;
  474. }
  475. if( FAILED( hr = pd3dDevice->GetDeviceCaps( &d3dCaps ) ) )
  476. {
  477. *piStepThatFailed = TESTID_GETDEVICECAPS;
  478. goto LEnd;
  479. }
  480. if( d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR )
  481. {
  482. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR )))
  483. {
  484. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  485. goto LEnd;
  486. }
  487. }
  488. if( d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR )
  489. {
  490. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR )))
  491. {
  492. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  493. goto LEnd;
  494. }
  495. }
  496. if (FAILED( hr = pd3dDevice->SetTexture( 0, pTexture ) ) )
  497. {
  498. *piStepThatFailed = TESTID_SETTEXTURE;
  499. goto LEnd;
  500. }
  501. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP ) ) )
  502. {
  503. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  504. goto LEnd;
  505. }
  506. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP ) ) )
  507. {
  508. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  509. goto LEnd;
  510. }
  511. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ) ) )
  512. {
  513. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  514. goto LEnd;
  515. }
  516. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ) ) )
  517. {
  518. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  519. goto LEnd;
  520. }
  521. if (FAILED(hr = pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ) ) )
  522. {
  523. *piStepThatFailed = TESTID_SETTEXTURESTAGESTATE;
  524. goto LEnd;
  525. }
  526. // Set color
  527. if( FAILED( hr = pd3dDevice->SetMaterial( &mtrlWhite ) ) )
  528. {
  529. *piStepThatFailed = TESTID_SETMATERIAL;
  530. goto LEnd;
  531. }
  532. }
  533. if( FAILED( hr = pd3dDevice->SetVertexShader( D3DFVF_VERTEX ) ) )
  534. {
  535. *piStepThatFailed = TESTID_SETVERTEXSHADER;
  536. goto LEnd;
  537. }
  538. // Here's the draw loop:
  539. for (i = 0; i < 600; i++)
  540. {
  541. if (PeekMessage(&msg, hwnd, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE))
  542. {
  543. *piStepThatFailed = TESTID_USER_CANCELLED;
  544. goto LEnd;
  545. }
  546. if( FAILED( hr = pd3dDevice->TestCooperativeLevel() ) )
  547. {
  548. *piStepThatFailed = TESTID_USER_CANCELLED;
  549. goto LEnd;
  550. }
  551. // Build world matrix
  552. D3DXMatrixRotationY( &matRotY, fRotY );
  553. D3DXMatrixRotationX( &matRotX, fRotX );
  554. D3DXMatrixMultiply( &mat, &matRotY, &matRotX );
  555. if( FAILED( hr = pd3dDevice->SetTransform( D3DTS_WORLD, &mat ) ) )
  556. {
  557. *piStepThatFailed = TESTID_SETTRANSFORM;
  558. goto LEnd;
  559. }
  560. // Clear the backbuffer
  561. if (FAILED(hr = pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
  562. 0x00000000, 1.0f, 0L )))
  563. {
  564. *piStepThatFailed = TESTID_VIEWPORT_CLEAR;
  565. goto LEnd;
  566. }
  567. // Begin the scene
  568. if( FAILED(hr = pd3dDevice->BeginScene() ) )
  569. {
  570. *piStepThatFailed = TESTID_BEGINSCENE;
  571. goto LEnd;
  572. }
  573. // Green, Front/Back
  574. if( FAILED( hr = DrawTwoSides( bUseTexture, pd3dDevice, &mtrlGreen,
  575. pVBFront, pIBFront, pVBBack, pIBBack,
  576. piStepThatFailed ) ) )
  577. goto LEnd;
  578. // Red, Left/Right
  579. if( FAILED( hr = DrawTwoSides( bUseTexture, pd3dDevice, &mtrlRed,
  580. pVBLeft, pIBLeft, pVBRight, pIBRight,
  581. piStepThatFailed ) ) )
  582. goto LEnd;
  583. // Blue, Top/Bottom
  584. if( FAILED( hr = DrawTwoSides( bUseTexture, pd3dDevice, &mtrlBlue,
  585. pVBTop, pIBTop, pVBBottom, pIBBottom,
  586. piStepThatFailed ) ) )
  587. goto LEnd;
  588. // End the scene.
  589. if (FAILED(hr = pd3dDevice->EndScene()))
  590. {
  591. *piStepThatFailed = TESTID_ENDSCENE;
  592. goto LEnd;
  593. }
  594. if (FAILED(hr = pd3dDevice->Present( NULL, NULL, NULL, NULL ) ) )
  595. {
  596. *piStepThatFailed = TESTID_PRESENT;
  597. goto LEnd;
  598. }
  599. fRotY += 0.05f;
  600. fRotX += 0.02f;
  601. Sleep(10);
  602. }
  603. LEnd:
  604. ShowCursor(TRUE);
  605. ReleasePpo(&pTexture);
  606. ReleasePpo(&pVBFront);
  607. ReleasePpo(&pIBFront);
  608. ReleasePpo(&pVBBack);
  609. ReleasePpo(&pIBBack);
  610. ReleasePpo(&pVBLeft);
  611. ReleasePpo(&pIBLeft);
  612. ReleasePpo(&pVBRight);
  613. ReleasePpo(&pIBRight);
  614. ReleasePpo(&pVBTop);
  615. ReleasePpo(&pIBTop);
  616. ReleasePpo(&pVBBottom);
  617. ReleasePpo(&pIBBottom);
  618. ReleasePpo(&pBackBuffer);
  619. ReleasePpo(&pd3dDevice);
  620. if (hwnd != NULL)
  621. SendMessage(hwnd, WM_CLOSE, 0, 0);
  622. return hr;
  623. }
  624. //-----------------------------------------------------------------------------
  625. // Name: CreateTestWindow()
  626. // Desc:
  627. //-----------------------------------------------------------------------------
  628. HRESULT CreateTestWindow(HWND hwndMain, HWND* phwnd)
  629. {
  630. static BOOL bClassRegistered = FALSE;
  631. WNDCLASS wndClass;
  632. TCHAR* pszClass = TEXT("DxDiag D3D8 Test Window"); // Don't need to localize
  633. HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(hwndMain, GWLP_HINSTANCE);
  634. TCHAR szTitle[MAX_PATH];
  635. if (!bClassRegistered)
  636. {
  637. ZeroMemory(&wndClass, sizeof(wndClass));
  638. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  639. wndClass.lpfnWndProc = DefWindowProc;
  640. wndClass.cbClsExtra = 0;
  641. wndClass.cbWndExtra = 0;
  642. wndClass.hInstance = hInst;
  643. wndClass.hIcon = NULL;
  644. wndClass.hCursor = NULL;
  645. wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  646. wndClass.lpszMenuName = NULL;
  647. wndClass.lpszClassName = pszClass;
  648. if (NULL == RegisterClass(&wndClass))
  649. return E_FAIL;
  650. bClassRegistered = TRUE;
  651. }
  652. LoadString(NULL, IDS_APPFULLNAME, szTitle, MAX_PATH);
  653. *phwnd = CreateWindow( pszClass, szTitle, WS_OVERLAPPED,
  654. 0, 0, 0, 0, hwndMain, NULL, hInst, NULL);
  655. if (*phwnd == NULL)
  656. return E_FAIL;
  657. ShowWindow(*phwnd, SW_SHOW);
  658. return S_OK;
  659. }
  660. //-----------------------------------------------------------------------------
  661. // Name: SortModesCallback()
  662. // Desc: Callback function for sorting display modes (used by BuildDeviceList).
  663. //-----------------------------------------------------------------------------
  664. static int SortModesCallback( const VOID* arg1, const VOID* arg2 )
  665. {
  666. D3DDISPLAYMODE* p1 = (D3DDISPLAYMODE*)arg1;
  667. D3DDISPLAYMODE* p2 = (D3DDISPLAYMODE*)arg2;
  668. if( p1->Format > p2->Format ) return -1;
  669. if( p1->Format < p2->Format ) return +1;
  670. if( p1->Width < p2->Width ) return -1;
  671. if( p1->Width > p2->Width ) return +1;
  672. if( p1->Height < p2->Height ) return -1;
  673. if( p1->Height > p2->Height ) return +1;
  674. return 0;
  675. }
  676. //-----------------------------------------------------------------------------
  677. // Name: SelectModeAndFormat()
  678. // Desc:
  679. //-----------------------------------------------------------------------------
  680. HRESULT SelectModeAndFormat( DisplayInfo* pDisplayInfo, IDirect3D8* pD3D8,
  681. D3DModeInfo* pSelectedMode, D3DDEVTYPE* pSelectedDeviceType )
  682. {
  683. // Enumerate all display modes on this adapter
  684. HRESULT hr;
  685. D3DDISPLAYMODE modes[MAX_MODES];
  686. D3DFORMAT formats[MAX_FORMATS];
  687. DWORD dwBehavior[MAX_FORMATS];
  688. D3DModeInfo confirmedModes[MAX_CONFIRMED_MODES];
  689. ZeroMemory( pSelectedMode, sizeof(D3DModeInfo) );
  690. DWORD dwNumConfirmedModes = 0;
  691. DWORD dwNumFormats = 0;
  692. DWORD dwNumModes = 0;
  693. DWORD dwNumAdapterModes = pD3D8->GetAdapterModeCount( pDisplayInfo->m_iAdapter );
  694. DWORD dwBestMatchMode = 0;
  695. for( UINT iMode = 0; iMode < dwNumAdapterModes; iMode++ )
  696. {
  697. // Get the display mode attributes
  698. D3DDISPLAYMODE DisplayMode;
  699. if( FAILED( hr = pD3D8->EnumAdapterModes( pDisplayInfo->m_iAdapter, iMode, &DisplayMode ) ) )
  700. {
  701. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_ENUMADAPTERMODES;
  702. pDisplayInfo->m_testResultD3D8.m_hr = hr;
  703. return hr;
  704. }
  705. // Check if the mode already exists (to filter out refresh rates)
  706. for( DWORD m=0L; m<dwNumModes; m++ )
  707. {
  708. if( ( modes[m].Width == DisplayMode.Width ) &&
  709. ( modes[m].Height == DisplayMode.Height ) &&
  710. ( modes[m].Format == DisplayMode.Format ) )
  711. break;
  712. }
  713. // If we found a new mode, add it to the list of modes
  714. if( m == dwNumModes )
  715. {
  716. modes[dwNumModes].Width = DisplayMode.Width;
  717. modes[dwNumModes].Height = DisplayMode.Height;
  718. modes[dwNumModes].Format = DisplayMode.Format;
  719. modes[dwNumModes].RefreshRate = 0;
  720. dwNumModes++;
  721. // Check if the mode's format already exists
  722. for( DWORD f=0; f<dwNumFormats; f++ )
  723. {
  724. if( DisplayMode.Format == formats[f] )
  725. break;
  726. }
  727. // If the format is new, add it to the list
  728. if( f== dwNumFormats )
  729. formats[dwNumFormats++] = DisplayMode.Format;
  730. }
  731. if( dwNumFormats == MAX_FORMATS || dwNumModes == MAX_MODES )
  732. break;
  733. }
  734. // Sort the list of display modes (by format, then width, then height)
  735. qsort( modes, dwNumModes, sizeof(D3DDISPLAYMODE), SortModesCallback );
  736. const DWORD dwNumDeviceTypes = 2;
  737. const D3DDEVTYPE DeviceTypes[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_SW };
  738. // Add devices to adapter
  739. for( UINT iDevice = 0; iDevice < dwNumDeviceTypes; iDevice++ )
  740. {
  741. // Fill in device info
  742. D3DCAPS8 d3dCaps;
  743. if( FAILED( hr = pD3D8->GetDeviceCaps( pDisplayInfo->m_iAdapter, DeviceTypes[iDevice], &d3dCaps ) ) )
  744. {
  745. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_GETDEVICECAPS;
  746. pDisplayInfo->m_testResultD3D8.m_hr = hr;
  747. return hr;
  748. }
  749. // Examine each format supported by the adapter
  750. for( DWORD f=0; f<dwNumFormats; f++ )
  751. {
  752. // Skip formats that cannot be used as render targets on this device
  753. if( FAILED( pD3D8->CheckDeviceType( pDisplayInfo->m_iAdapter, DeviceTypes[iDevice],
  754. formats[f], formats[f], FALSE ) ) )
  755. continue;
  756. // Figure out the behavior
  757. if( d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
  758. {
  759. if( d3dCaps.DevCaps & D3DDEVCAPS_PUREDEVICE )
  760. {
  761. dwBehavior[f] = D3DCREATE_HARDWARE_VERTEXPROCESSING |
  762. D3DCREATE_PUREDEVICE;
  763. }
  764. else
  765. {
  766. dwBehavior[f] = D3DCREATE_HARDWARE_VERTEXPROCESSING;
  767. }
  768. }
  769. else
  770. {
  771. dwBehavior[f] = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
  772. }
  773. }
  774. // Add all enumerated display modes with confirmed formats to the
  775. // device's list of valid modes
  776. for( DWORD m=0L; m<dwNumModes; m++ )
  777. {
  778. for( DWORD f=0; f<dwNumFormats; f++ )
  779. {
  780. if( modes[m].Format == formats[f] )
  781. {
  782. // Add this mode to the device's list of valid modes
  783. confirmedModes[dwNumConfirmedModes].Width = modes[m].Width;
  784. confirmedModes[dwNumConfirmedModes].Height = modes[m].Height;
  785. confirmedModes[dwNumConfirmedModes].Format = modes[m].Format;
  786. confirmedModes[dwNumConfirmedModes].dwBehavior = dwBehavior[f];
  787. dwNumConfirmedModes++;
  788. }
  789. }
  790. }
  791. // Select any 640x480 mode for default (but prefer a 16-bit mode)
  792. for( m=0; m<dwNumConfirmedModes; m++ )
  793. {
  794. if( confirmedModes[m].Width==640 && confirmedModes[m].Height==480 )
  795. {
  796. dwBestMatchMode = m;
  797. if( confirmedModes[m].Format == D3DFMT_R5G6B5 ||
  798. confirmedModes[m].Format == D3DFMT_X1R5G5B5 ||
  799. confirmedModes[m].Format == D3DFMT_A1R5G5B5 )
  800. {
  801. break;
  802. }
  803. }
  804. }
  805. // If valid modes were found then stop and use this device
  806. if( dwNumConfirmedModes > 0 )
  807. break;
  808. }
  809. if( dwNumConfirmedModes > 0 )
  810. {
  811. *pSelectedDeviceType = DeviceTypes[iDevice];
  812. *pSelectedMode = confirmedModes[dwBestMatchMode];
  813. return S_OK;
  814. }
  815. else
  816. {
  817. pDisplayInfo->m_testResultD3D8.m_iStepThatFailed = TESTID_NOMODEFOUND;
  818. pDisplayInfo->m_testResultD3D8.m_hr = E_FAIL;
  819. return E_FAIL;
  820. }
  821. }
  822. //-----------------------------------------------------------------------------
  823. // Name: InitVertexBuffer()
  824. // Desc:
  825. //-----------------------------------------------------------------------------
  826. HRESULT InitVertexBuffer( IDirect3DDevice8* pd3dDevice, const D3DVERTEX* vertexArray,
  827. DWORD dwNumVertices, LPDIRECT3DVERTEXBUFFER8* ppVB,
  828. LONG* piStepThatFailed )
  829. {
  830. HRESULT hr = S_OK;
  831. DWORD i;
  832. D3DVERTEX* vVertex = NULL;
  833. if( FAILED( hr = pd3dDevice->CreateVertexBuffer( dwNumVertices*sizeof(D3DVERTEX),
  834. D3DUSAGE_WRITEONLY, D3DFVF_VERTEX,
  835. D3DPOOL_MANAGED, ppVB ) ) )
  836. {
  837. *piStepThatFailed = TESTID_CREATE_VERTEX_BUFFER;
  838. goto LEnd;
  839. }
  840. if( *ppVB == NULL )
  841. {
  842. *piStepThatFailed = TESTID_CREATE_VERTEX_BUFFER;
  843. hr = E_POINTER;
  844. goto LEnd;
  845. }
  846. if( FAILED( hr = (*ppVB)->Lock( 0, 0, (BYTE**)&vVertex, 0 ) ) )
  847. {
  848. *piStepThatFailed = TESTID_LOCK;
  849. goto LEnd;
  850. }
  851. if( vVertex == NULL )
  852. {
  853. *piStepThatFailed = TESTID_LOCK;
  854. goto LEnd;
  855. }
  856. for( i=0; i<dwNumVertices; i++ )
  857. vVertex[i] = vertexArray[i];
  858. if( FAILED( hr = (*ppVB)->Unlock() ) )
  859. {
  860. *piStepThatFailed = TESTID_UNLOCK;
  861. goto LEnd;
  862. }
  863. LEnd:
  864. return hr;
  865. }
  866. //-----------------------------------------------------------------------------
  867. // Name: InitIndexBuffer()
  868. // Desc:
  869. //-----------------------------------------------------------------------------
  870. HRESULT InitIndexBuffer( IDirect3DDevice8* pd3dDevice, const WORD* wIndexArray,
  871. DWORD dwNumIndices, LPDIRECT3DINDEXBUFFER8* ppIB,
  872. LONG* piStepThatFailed )
  873. {
  874. HRESULT hr = S_OK;
  875. DWORD i;
  876. WORD* pwIndices = NULL;
  877. if( FAILED( hr = pd3dDevice->CreateIndexBuffer( dwNumIndices*sizeof(WORD),
  878. D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
  879. D3DPOOL_MANAGED, ppIB ) ) )
  880. {
  881. *piStepThatFailed = TESTID_CREATE_INDEX_BUFFER;
  882. goto LEnd;
  883. }
  884. if( *ppIB == NULL )
  885. {
  886. *piStepThatFailed = TESTID_CREATE_INDEX_BUFFER;
  887. hr = E_POINTER;
  888. goto LEnd;
  889. }
  890. if( FAILED( hr = (*ppIB)->Lock( 0, dwNumIndices*sizeof(WORD), (BYTE**) &pwIndices, 0 ) ) )
  891. {
  892. *piStepThatFailed = TESTID_LOCK;
  893. goto LEnd;
  894. }
  895. if( pwIndices == NULL )
  896. {
  897. *piStepThatFailed = TESTID_LOCK;
  898. goto LEnd;
  899. }
  900. for( i=0; i<dwNumIndices; i++ )
  901. *pwIndices++ = wIndexArray[i];
  902. if( FAILED( hr = (*ppIB)->Unlock() ) )
  903. {
  904. *piStepThatFailed = TESTID_UNLOCK;
  905. goto LEnd;
  906. }
  907. LEnd:
  908. return hr;
  909. }
  910. //-----------------------------------------------------------------------------
  911. // Name: DrawTwoSides()
  912. // Desc:
  913. //-----------------------------------------------------------------------------
  914. HRESULT DrawTwoSides( BOOL bUseTexture, IDirect3DDevice8* pd3dDevice, D3DMATERIAL8* pMtrl,
  915. LPDIRECT3DVERTEXBUFFER8 pVB1, LPDIRECT3DINDEXBUFFER8 pIB1,
  916. LPDIRECT3DVERTEXBUFFER8 pVB2, LPDIRECT3DINDEXBUFFER8 pIB2,
  917. LONG* piStepThatFailed )
  918. {
  919. HRESULT hr;
  920. if( !bUseTexture )
  921. {
  922. // Set color
  923. if( FAILED( hr = pd3dDevice->SetMaterial( pMtrl ) ) )
  924. {
  925. *piStepThatFailed = TESTID_SETMATERIAL;
  926. goto LEnd;
  927. }
  928. }
  929. // #1
  930. if( FAILED( hr = pd3dDevice->SetStreamSource( 0, pVB1, sizeof(D3DVERTEX) ) ) )
  931. {
  932. *piStepThatFailed = TESTID_SETSTREAMSOURCE;
  933. goto LEnd;
  934. }
  935. if( FAILED( hr = pd3dDevice->SetIndices( pIB1, 0 ) ) )
  936. {
  937. *piStepThatFailed = TESTID_SETINDICES;
  938. goto LEnd;
  939. }
  940. if( FAILED( hr = pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 4, 0, 2 ) ) )
  941. {
  942. *piStepThatFailed = TESTID_DRAW_INDEXED_PRIMITIVE;
  943. goto LEnd;
  944. }
  945. // #2
  946. if( FAILED( hr = pd3dDevice->SetStreamSource( 0, pVB2, sizeof(D3DVERTEX) ) ) )
  947. {
  948. *piStepThatFailed = TESTID_SETSTREAMSOURCE;
  949. goto LEnd;
  950. }
  951. if( FAILED( hr = pd3dDevice->SetIndices( pIB2, 0 ) ) )
  952. {
  953. *piStepThatFailed = TESTID_SETINDICES;
  954. goto LEnd;
  955. }
  956. if( FAILED( hr = pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 4, 0, 2 ) ) )
  957. {
  958. *piStepThatFailed = TESTID_DRAW_INDEXED_PRIMITIVE;
  959. goto LEnd;
  960. }
  961. LEnd:
  962. return hr;
  963. }