Index: dxgltest/Tests3D.cpp |
— | — | @@ -44,6 +44,13 @@ |
45 | 45 | static unsigned int randnum;
|
46 | 46 | static int testtypes[] = {0};
|
47 | 47 |
|
| 48 | +static D3DVECTOR points[256];
|
| 49 | +static D3DVECTOR normals[256];
|
| 50 | +static D3DVERTEX vertices[256];
|
| 51 | +static WORD mesh[256];
|
| 52 | +static WORD cube_mesh[] = {0,1,2, 2,1,3, 4,5,6, 6,5,7, 8,9,10, 10,9,11, 12,13,14, 14,13,15, 16,17,18,
|
| 53 | + 18,17,19, 20,21,22, 22,21,23 };
|
| 54 | +
|
48 | 55 | LRESULT CALLBACK D3DWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
49 | 56 | {
|
50 | 57 | bool paintwnd = true;
|
— | — | @@ -58,6 +65,16 @@ |
59 | 66 | break;
|
60 | 67 | case WM_DESTROY:
|
61 | 68 | StopTimer();
|
| 69 | + if(d3d7dev)
|
| 70 | + {
|
| 71 | + d3d7dev->Release();
|
| 72 | + d3d7dev = NULL;
|
| 73 | + }
|
| 74 | + if(d3d7)
|
| 75 | + {
|
| 76 | + d3d7->Release();
|
| 77 | + d3d7dev = NULL;
|
| 78 | + }
|
62 | 79 | if(ddsrender)
|
63 | 80 | {
|
64 | 81 | ddsrender->Release();
|
— | — | @@ -148,6 +165,7 @@ |
149 | 166 | void RunTest3D(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
|
150 | 167 | int filter, int msaa, double fps, bool fullscreen, bool resizable)
|
151 | 168 | {
|
| 169 | + DDSCAPS2 caps;
|
152 | 170 | DDSURFACEDESC2 ddsd;
|
153 | 171 | BOOL done = false;
|
154 | 172 | ::testnum = testnum;
|
— | — | @@ -240,8 +258,17 @@ |
241 | 259 | }
|
242 | 260 | else
|
243 | 261 | {
|
244 | | - ddsrender = ddsurface;
|
245 | | - ddsrender->AddRef();
|
| 262 | + if(backbuffers)
|
| 263 | + {
|
| 264 | + ZeroMemory(&caps,sizeof(DDSCAPS2));
|
| 265 | + caps.dwCaps = DDSCAPS_BACKBUFFER;
|
| 266 | + error = ddsurface->GetAttachedSurface(&caps,&ddsrender);
|
| 267 | + }
|
| 268 | + else
|
| 269 | + {
|
| 270 | + ddsrender = ddsurface;
|
| 271 | + ddsrender->AddRef();
|
| 272 | + }
|
246 | 273 | }
|
247 | 274 | error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
|
248 | 275 | error = d3d7->CreateDevice(IID_IDirect3DHALDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
|
— | — | @@ -294,14 +321,83 @@ |
295 | 322 | StopTimer();
|
296 | 323 | }
|
297 | 324 |
|
| 325 | +void MakeCube3D(D3DVECTOR *points, D3DVECTOR *normals, D3DVERTEX *vertices)
|
| 326 | +{
|
| 327 | + points[0] = D3DVECTOR(0.0f,0.0f,0.0f);
|
| 328 | + points[1] = D3DVECTOR(0.0f,3.0f,0.0f);
|
| 329 | + points[2] = D3DVECTOR(3.0f,0.0f,0.0f);
|
| 330 | + points[3] = D3DVECTOR(3.0f,3.0f,0.0f);
|
| 331 | + points[4] = D3DVECTOR(3.0f,0.0f,3.0f);
|
| 332 | + points[5] = D3DVECTOR(3.0f,3.0f,3.0f);
|
| 333 | + points[6] = D3DVECTOR(0.0f,0.0f,3.0f);
|
| 334 | + points[7] = D3DVECTOR(0.0f,3.0f,3.0f);
|
| 335 | + normals[0] = D3DVECTOR(0.0f,0.0f,-1.0f);
|
| 336 | + normals[1] = D3DVECTOR(1.0f,0.0f,0.0f);
|
| 337 | + normals[2] = D3DVECTOR(0.0f,0.0f,1.0f);
|
| 338 | + normals[3] = D3DVECTOR(-1.0f,0.0f,0.0f);
|
| 339 | + normals[4] = D3DVECTOR(0.0f,1.0f,0.0f);
|
| 340 | + normals[5] = D3DVECTOR(0.0f,-10.0f,0.0f);
|
| 341 | + vertices[0] = D3DVERTEX(points[0],normals[0],0,0);
|
| 342 | + vertices[1] = D3DVERTEX(points[1],normals[0],0,0);
|
| 343 | + vertices[2] = D3DVERTEX(points[2],normals[0],0,0);
|
| 344 | + vertices[3] = D3DVERTEX(points[3],normals[0],0,0);
|
| 345 | + vertices[4] = D3DVERTEX(points[2],normals[1],0,0);
|
| 346 | + vertices[5] = D3DVERTEX(points[3],normals[1],0,0);
|
| 347 | + vertices[6] = D3DVERTEX(points[4],normals[1],0,0);
|
| 348 | + vertices[7] = D3DVERTEX(points[5],normals[1],0,0);
|
| 349 | + vertices[8] = D3DVERTEX(points[4],normals[2],0,0);
|
| 350 | + vertices[9] = D3DVERTEX(points[5],normals[2],0,0);
|
| 351 | + vertices[10] = D3DVERTEX(points[6],normals[2],0,0);
|
| 352 | + vertices[11] = D3DVERTEX(points[7],normals[2],0,0);
|
| 353 | + vertices[12] = D3DVERTEX(points[6],normals[3],0,0);
|
| 354 | + vertices[13] = D3DVERTEX(points[7],normals[3],0,0);
|
| 355 | + vertices[14] = D3DVERTEX(points[0],normals[3],0,0);
|
| 356 | + vertices[15] = D3DVERTEX(points[1],normals[3],0,0);
|
| 357 | + vertices[16] = D3DVERTEX(points[1],normals[4],0,0);
|
| 358 | + vertices[17] = D3DVERTEX(points[7],normals[4],0,0);
|
| 359 | + vertices[18] = D3DVERTEX(points[3],normals[4],0,0);
|
| 360 | + vertices[19] = D3DVERTEX(points[5],normals[4],0,0);
|
| 361 | + vertices[20] = D3DVERTEX(points[6],normals[5],0,0);
|
| 362 | + vertices[21] = D3DVERTEX(points[0],normals[5],0,0);
|
| 363 | + vertices[22] = D3DVERTEX(points[4],normals[5],0,0);
|
| 364 | + vertices[23] = D3DVERTEX(points[2],normals[5],0,0);
|
| 365 | +}
|
| 366 | +
|
298 | 367 | void InitTest3D(int test)
|
299 | 368 | {
|
300 | | - D3DVECTOR p0,p1,p2,p3,p4,p5,p6,p7;
|
301 | | - D3DVERTEX vertices[256];
|
| 369 | + HRESULT error;
|
| 370 | + D3DMATRIX matWorld;
|
| 371 | + D3DMATRIX matView;
|
| 372 | + D3DMATRIX matProj;
|
| 373 | + D3DMATRIX mat;
|
302 | 374 | switch(test)
|
303 | 375 | {
|
304 | 376 | case 0:
|
305 | | - p0 = D3DVECTOR(0.0f,0.0f,0.0f);
|
| 377 | + MakeCube3D(points,normals,vertices);
|
| 378 | + D3DMATERIAL7 material;
|
| 379 | + ZeroMemory(&material,sizeof(D3DMATERIAL7));
|
| 380 | + material.ambient.r = 1.0f;
|
| 381 | + material.ambient.g = 1.0f;
|
| 382 | + material.ambient.b = 0.0f;
|
| 383 | + error = d3d7dev->SetMaterial(&material);
|
| 384 | + error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT,0xffffffff);
|
| 385 | + mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
|
| 386 | + mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
|
| 387 | + mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
|
| 388 | + mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
|
| 389 | + matWorld = mat;
|
| 390 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);
|
| 391 | + matView = mat;
|
| 392 | + matView._43 = 10.0f;
|
| 393 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
|
| 394 | + matProj = mat;
|
| 395 | + matProj._11 = 2.0f;
|
| 396 | + matProj._22 = 2.0f;
|
| 397 | + matProj._34 = 1.0f;
|
| 398 | + matProj._43 = -1.0f;
|
| 399 | + matProj._44 = 0.0f;
|
| 400 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
|
| 401 | +
|
306 | 402 | break;
|
307 | 403 | default:
|
308 | 404 | break;
|
— | — | @@ -310,6 +406,49 @@ |
311 | 407 |
|
312 | 408 | void RunTestTimed3D(int test)
|
313 | 409 | {
|
| 410 | + POINT p;
|
| 411 | + RECT srcrect,destrect;
|
| 412 | + HRESULT error;
|
| 413 | + D3DMATRIX mat;
|
| 414 | + DDSURFACEDESC2 ddsd;
|
| 415 | + ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
|
| 416 | + if(d3dver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
| 417 | + else ddsd.dwSize = sizeof(DDSURFACEDESC);
|
| 418 | + DDBLTFX bltfx;
|
| 419 | + ZeroMemory(&bltfx,sizeof(DDBLTFX));
|
| 420 | + bltfx.dwSize = sizeof(DDBLTFX);
|
| 421 | + bltfx.dwFillColor = 0;
|
| 422 | + ddsrender->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&bltfx);
|
| 423 | + float time = (float)clock() / (float)CLOCKS_PER_SEC;
|
| 424 | + switch(test)
|
| 425 | + {
|
| 426 | + case 0:
|
| 427 | + mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
|
| 428 | + mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
|
| 429 | + mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
|
| 430 | + mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
|
| 431 | + mat._11 = (FLOAT)cos( (float)time );
|
| 432 | + mat._33 = (FLOAT)cos( (float)time );
|
| 433 | + mat._13 = -(FLOAT)sin( (float)time );
|
| 434 | + mat._31 = (FLOAT)sin( (float)time );
|
| 435 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
|
| 436 | + error = d3d7dev->BeginScene();
|
| 437 | + error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,24,cube_mesh,36,0);
|
| 438 | + break;
|
| 439 | + default:
|
| 440 | + break;
|
| 441 | + }
|
| 442 | + if(fullscreen) ddsurface->Flip(NULL,DDFLIP_WAIT);
|
| 443 | + else
|
| 444 | + {
|
| 445 | + p.x = 0;
|
| 446 | + p.y = 0;
|
| 447 | + ClientToScreen(hWnd,&p);
|
| 448 | + GetClientRect(hWnd,&destrect);
|
| 449 | + OffsetRect(&destrect,p.x,p.y);
|
| 450 | + SetRect(&srcrect,0,0,width,height);
|
| 451 | + if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
|
| 452 | + }
|
314 | 453 | }
|
315 | 454 |
|
316 | 455 | void RunTestLooped3D(int test)
|
Index: dxgltest/dxgltest.cpp |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | }
|
60 | 60 | }
|
61 | 61 | int modenum = 0;
|
62 | | -HRESULT WINAPI EnumModesCallback(LPDDSURFACEDESC ddsd, void *list)
|
| 62 | +HRESULT WINAPI EnumModesCallback8(LPDDSURFACEDESC ddsd, void *list)
|
63 | 63 | {
|
64 | 64 | HWND hWnd = (HWND)list;
|
65 | 65 | tstring resolution;
|
— | — | @@ -88,6 +88,36 @@ |
89 | 89 | modenum = listnum;
|
90 | 90 | return DDENUMRET_OK;
|
91 | 91 | }
|
| 92 | +HRESULT WINAPI EnumModesCallback32(LPDDSURFACEDESC ddsd, void *list)
|
| 93 | +{
|
| 94 | + HWND hWnd = (HWND)list;
|
| 95 | + tstring resolution;
|
| 96 | + int bpp;
|
| 97 | + if(ddsd->ddpfPixelFormat.dwRGBBitCount == 16)
|
| 98 | + {
|
| 99 | + if((ddsd->ddpfPixelFormat.dwRBitMask | ddsd->ddpfPixelFormat.dwGBitMask |
|
| 100 | + ddsd->ddpfPixelFormat.dwBBitMask) == 0x7FFF) bpp = 15;
|
| 101 | + else bpp = 16;
|
| 102 | + }
|
| 103 | + else bpp = ddsd->ddpfPixelFormat.dwRGBBitCount;
|
| 104 | + TCHAR number[16];
|
| 105 | + _itot(ddsd->dwWidth,number,10);
|
| 106 | + resolution.append(number);
|
| 107 | + resolution.append(_T("x"));
|
| 108 | + _itot(ddsd->dwHeight,number,10);
|
| 109 | + resolution.append(number);
|
| 110 | + resolution.append(_T("x"));
|
| 111 | + _itot(bpp,number,10);
|
| 112 | + resolution.append(number);
|
| 113 | + resolution.append(_T(","));
|
| 114 | + _itot(ddsd->dwRefreshRate,number,10);
|
| 115 | + resolution.append(number);
|
| 116 | + resolution.append(_T("Hz"));
|
| 117 | + int listnum = SendMessage(hWnd,LB_ADDSTRING,0,(LPARAM)resolution.c_str());
|
| 118 | + if(ddsd->dwWidth == 640 && ddsd->dwHeight == 480 && ddsd->dwRefreshRate == 60 && ddsd->ddpfPixelFormat.dwRGBBitCount == 32)
|
| 119 | + modenum = listnum;
|
| 120 | + return DDENUMRET_OK;
|
| 121 | +}
|
92 | 122 |
|
93 | 123 | void TranslateResolutionString(LPCTSTR str, int &width, int &height, int &bpp, int &refresh)
|
94 | 124 | {
|
— | — | @@ -265,7 +295,7 @@ |
266 | 296 | error = DirectDrawCreate(NULL,&lpdd,NULL);
|
267 | 297 | if(error == DD_OK)
|
268 | 298 | {
|
269 | | - error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback);
|
| 299 | + error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback8);
|
270 | 300 | lpdd->Release();
|
271 | 301 | }
|
272 | 302 | SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_SETCURSEL,modenum,0);
|
— | — | @@ -470,7 +500,7 @@ |
471 | 501 | error = DirectDrawCreate(NULL,&lpdd,NULL);
|
472 | 502 | if(error == DD_OK)
|
473 | 503 | {
|
474 | | - error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback);
|
| 504 | + error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback32);
|
475 | 505 | lpdd->Release();
|
476 | 506 | }
|
477 | 507 | SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_SETCURSEL,modenum,0);
|