| Index: dxgltest/Tests3D.cpp |
| — | — | @@ -27,7 +27,7 @@ |
| 28 | 28 | void InitTest3D(int test);
|
| 29 | 29 | void RunTestTimed3D(int test);
|
| 30 | 30 | void RunTestLooped3D(int test);
|
| 31 | | -void RunTestMouse3D(int test, UINT Msg, WPARAM wParam, LPARAM lParam);
|
| | 31 | +bool RunTestMouse3D(int test, UINT Msg, WPARAM wParam, LPARAM lParam);
|
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 | static MultiDirectDraw *ddinterface;
|
| — | — | @@ -34,6 +34,7 @@ |
| 35 | 35 | static MultiDirectDrawSurface *ddsurface;
|
| 36 | 36 | static MultiDirectDrawSurface *ddsrender;
|
| 37 | 37 | static MultiDirectDrawSurface *zbuffer;
|
| | 38 | +static MultiDirectDrawSurface *textures[8];
|
| 38 | 39 | static IDirect3D7 *d3d7;
|
| 39 | 40 | static IDirect3DDevice7 *d3d7dev;
|
| 40 | 41 | static LPDIRECTDRAWCLIPPER ddclipper;
|
| — | — | @@ -43,7 +44,7 @@ |
| 44 | 45 | static HWND hWnd;
|
| 45 | 46 | static int testnum;
|
| 46 | 47 | static unsigned int randnum;
|
| 47 | | -static int testtypes[] = {0};
|
| | 48 | +static int testtypes[] = {0,0};
|
| 48 | 49 |
|
| 49 | 50 | static D3DVECTOR points[256];
|
| 50 | 51 | static D3DVECTOR normals[256];
|
| — | — | @@ -67,6 +68,14 @@ |
| 68 | 69 | break;
|
| 69 | 70 | case WM_DESTROY:
|
| 70 | 71 | StopTimer();
|
| | 72 | + for(int i = 0; i < 8; i++)
|
| | 73 | + {
|
| | 74 | + if(textures[i])
|
| | 75 | + {
|
| | 76 | + textures[i]->Release();
|
| | 77 | + textures[i] = NULL;
|
| | 78 | + }
|
| | 79 | + }
|
| 71 | 80 | if(d3d7dev)
|
| 72 | 81 | {
|
| 73 | 82 | d3d7dev->Release();
|
| — | — | @@ -141,16 +150,18 @@ |
| 142 | 151 | case WM_XBUTTONUP:
|
| 143 | 152 | case WM_XBUTTONDBLCLK:
|
| 144 | 153 | case WM_MOUSEHWHEEL:
|
| 145 | | - RunTestMouse3D(testnum,Msg,wParam,lParam);
|
| 146 | | - if(!fullscreen)
|
| | 154 | + if(RunTestMouse3D(testnum,Msg,wParam,lParam))
|
| 147 | 155 | {
|
| 148 | | - p.x = 0;
|
| 149 | | - p.y = 0;
|
| 150 | | - ClientToScreen(hWnd,&p);
|
| 151 | | - GetClientRect(hWnd,&destrect);
|
| 152 | | - OffsetRect(&destrect,p.x,p.y);
|
| 153 | | - SetRect(&srcrect,0,0,width,height);
|
| 154 | | - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
|
| | 156 | + if(!fullscreen)
|
| | 157 | + {
|
| | 158 | + p.x = 0;
|
| | 159 | + p.y = 0;
|
| | 160 | + ClientToScreen(hWnd,&p);
|
| | 161 | + GetClientRect(hWnd,&destrect);
|
| | 162 | + OffsetRect(&destrect,p.x,p.y);
|
| | 163 | + SetRect(&srcrect,0,0,width,height);
|
| | 164 | + if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
|
| | 165 | + }
|
| 155 | 166 | }
|
| 156 | 167 | break;
|
| 157 | 168 | default:
|
| — | — | @@ -163,8 +174,10 @@ |
| 164 | 175 | static int d3dver;
|
| 165 | 176 | static int ddver;
|
| 166 | 177 |
|
| 167 | | -void RunTestMouse3D(int test, UINT Msg, WPARAM wParam, LPARAM lParam)
|
| 168 | | -{}
|
| | 178 | +bool RunTestMouse3D(int test, UINT Msg, WPARAM wParam, LPARAM lParam)
|
| | 179 | +{
|
| | 180 | + return false;
|
| | 181 | +}
|
| 169 | 182 |
|
| 170 | 183 | const TCHAR wndclassname3d[] = _T("D3DTestWndClass");
|
| 171 | 184 |
|
| — | — | @@ -188,6 +201,7 @@ |
| 189 | 202 | ::testnum = testnum;
|
| 190 | 203 | randnum = (unsigned int)time(NULL);
|
| 191 | 204 | ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
|
| | 205 | + ZeroMemory(textures,8*sizeof(MultiDirectDrawSurface*));
|
| 192 | 206 | if(apiver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
| 193 | 207 | else ddsd.dwSize = sizeof(DDSURFACEDESC);
|
| 194 | 208 | ::fullscreen = fullscreen;
|
| — | — | @@ -288,7 +302,7 @@ |
| 289 | 303 | }
|
| 290 | 304 | }
|
| 291 | 305 | error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
|
| 292 | | - error = d3d7->EnumZBufferFormats(IID_IDirect3DHALDevice,zcallback,&ddpfz);
|
| | 306 | + error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice,zcallback,&ddpfz);
|
| 293 | 307 | error = ddsrender->GetSurfaceDesc(&ddsd);
|
| 294 | 308 | ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
|
| 295 | 309 | ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
|
| — | — | @@ -362,31 +376,77 @@ |
| 363 | 377 | normals[4] = D3DVECTOR(0.0f,1.0f,0.0f);
|
| 364 | 378 | normals[5] = D3DVECTOR(0.0f,-10.0f,0.0f);
|
| 365 | 379 | vertices[0] = D3DVERTEX(points[0],normals[0],0,0);
|
| 366 | | - vertices[1] = D3DVERTEX(points[1],normals[0],0,0);
|
| 367 | | - vertices[2] = D3DVERTEX(points[2],normals[0],0,0);
|
| 368 | | - vertices[3] = D3DVERTEX(points[3],normals[0],0,0);
|
| | 380 | + vertices[1] = D3DVERTEX(points[1],normals[0],1,0);
|
| | 381 | + vertices[2] = D3DVERTEX(points[2],normals[0],0,1);
|
| | 382 | + vertices[3] = D3DVERTEX(points[3],normals[0],1,1);
|
| 369 | 383 | vertices[4] = D3DVERTEX(points[2],normals[1],0,0);
|
| 370 | | - vertices[5] = D3DVERTEX(points[3],normals[1],0,0);
|
| 371 | | - vertices[6] = D3DVERTEX(points[4],normals[1],0,0);
|
| 372 | | - vertices[7] = D3DVERTEX(points[5],normals[1],0,0);
|
| | 384 | + vertices[5] = D3DVERTEX(points[3],normals[1],1,0);
|
| | 385 | + vertices[6] = D3DVERTEX(points[4],normals[1],0,1);
|
| | 386 | + vertices[7] = D3DVERTEX(points[5],normals[1],1,1);
|
| 373 | 387 | vertices[8] = D3DVERTEX(points[4],normals[2],0,0);
|
| 374 | | - vertices[9] = D3DVERTEX(points[5],normals[2],0,0);
|
| 375 | | - vertices[10] = D3DVERTEX(points[6],normals[2],0,0);
|
| 376 | | - vertices[11] = D3DVERTEX(points[7],normals[2],0,0);
|
| | 388 | + vertices[9] = D3DVERTEX(points[5],normals[2],1,0);
|
| | 389 | + vertices[10] = D3DVERTEX(points[6],normals[2],0,1);
|
| | 390 | + vertices[11] = D3DVERTEX(points[7],normals[2],1,1);
|
| 377 | 391 | vertices[12] = D3DVERTEX(points[6],normals[3],0,0);
|
| 378 | | - vertices[13] = D3DVERTEX(points[7],normals[3],0,0);
|
| 379 | | - vertices[14] = D3DVERTEX(points[0],normals[3],0,0);
|
| 380 | | - vertices[15] = D3DVERTEX(points[1],normals[3],0,0);
|
| | 392 | + vertices[13] = D3DVERTEX(points[7],normals[3],1,0);
|
| | 393 | + vertices[14] = D3DVERTEX(points[0],normals[3],0,1);
|
| | 394 | + vertices[15] = D3DVERTEX(points[1],normals[3],1,1);
|
| 381 | 395 | vertices[16] = D3DVERTEX(points[1],normals[4],0,0);
|
| 382 | | - vertices[17] = D3DVERTEX(points[7],normals[4],0,0);
|
| 383 | | - vertices[18] = D3DVERTEX(points[3],normals[4],0,0);
|
| 384 | | - vertices[19] = D3DVERTEX(points[5],normals[4],0,0);
|
| | 396 | + vertices[17] = D3DVERTEX(points[7],normals[4],1,0);
|
| | 397 | + vertices[18] = D3DVERTEX(points[3],normals[4],0,1);
|
| | 398 | + vertices[19] = D3DVERTEX(points[5],normals[4],1,1);
|
| 385 | 399 | vertices[20] = D3DVERTEX(points[6],normals[5],0,0);
|
| 386 | | - vertices[21] = D3DVERTEX(points[0],normals[5],0,0);
|
| 387 | | - vertices[22] = D3DVERTEX(points[4],normals[5],0,0);
|
| 388 | | - vertices[23] = D3DVERTEX(points[2],normals[5],0,0);
|
| | 400 | + vertices[21] = D3DVERTEX(points[0],normals[5],1,0);
|
| | 401 | + vertices[22] = D3DVERTEX(points[4],normals[5],0,1);
|
| | 402 | + vertices[23] = D3DVERTEX(points[2],normals[5],1,1);
|
| 389 | 403 | }
|
| 390 | 404 |
|
| | 405 | +DDPIXELFORMAT texformats[256];
|
| | 406 | +int texformatindex = 0;
|
| | 407 | +
|
| | 408 | +void cleartexformats()
|
| | 409 | +{
|
| | 410 | + ZeroMemory(texformats,256*sizeof(DDPIXELFORMAT));
|
| | 411 | + texformatindex = 0;
|
| | 412 | +}
|
| | 413 | +
|
| | 414 | +HRESULT CALLBACK gettexformat(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
|
| | 415 | +{
|
| | 416 | + memcpy(&texformats[texformatindex],lpDDPixFmt,sizeof(DDPIXELFORMAT));
|
| | 417 | + texformatindex++;
|
| | 418 | + if(texformatindex >= 256) return D3DENUMRET_CANCEL;
|
| | 419 | + return D3DENUMRET_OK;
|
| | 420 | +}
|
| | 421 | +
|
| | 422 | +static bool gentexture(const DDPIXELFORMAT format, MultiDirectDrawSurface **surface, int width, int height, int pattern)
|
| | 423 | +{
|
| | 424 | + DDSURFACEDESC2 ddsd;
|
| | 425 | + ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
|
| | 426 | + ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
| | 427 | + ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE;
|
| | 428 | + ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
|
| | 429 | + ddsd.dwWidth = width;
|
| | 430 | + ddsd.dwHeight = height;
|
| | 431 | + ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
|
| | 432 | + ddsd.ddpfPixelFormat = format;
|
| | 433 | + HRESULT error = ddinterface->CreateSurface(&ddsd,surface,NULL);
|
| | 434 | + if(error != D3D_OK) return false;
|
| | 435 | + switch(pattern)
|
| | 436 | + {
|
| | 437 | + case 0:
|
| | 438 | + default:
|
| | 439 | + (*surface)->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
|
| | 440 | + DrawPalette(ddsd,(unsigned char *)ddsd.lpSurface);
|
| | 441 | + (*surface)->Unlock(NULL);
|
| | 442 | + }
|
| | 443 | + return true;
|
| | 444 | +}
|
| | 445 | +
|
| | 446 | +static const DDPIXELFORMAT fmt_rgba4444 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0xF00,0xF0,0xF,0xF000};
|
| | 447 | +static const DDPIXELFORMAT fmt_rgba1555 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0x7C00,0x3E0,0x1F,0x8000};
|
| | 448 | +static const DDPIXELFORMAT fmt_rgb565 = {sizeof(DDPIXELFORMAT),DDPF_RGB,0,16,0xF800,0x7E0,0x1F,0};
|
| | 449 | +static const DDPIXELFORMAT fmt_rgba8888 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,32,0xFF0000,0xFF00,0xFF,0xFF000000};
|
| | 450 | +
|
| 391 | 451 | void InitTest3D(int test)
|
| 392 | 452 | {
|
| 393 | 453 | HRESULT error;
|
| — | — | @@ -436,6 +496,51 @@ |
| 437 | 497 | lights[0].dvAttenuation1 = 0.4f;
|
| 438 | 498 | error = d3d7dev->SetLight(0,&lights[0]);
|
| 439 | 499 | break;
|
| | 500 | + case 1:
|
| | 501 | + MakeCube3D(points,normals,vertices);
|
| | 502 | + cleartexformats();
|
| | 503 | + d3d7dev->EnumTextureFormats(gettexformat,NULL);
|
| | 504 | + gentexture(fmt_rgba4444,&textures[0],256,256,0);
|
| | 505 | + gentexture(fmt_rgba1555,&textures[1],256,256,0);
|
| | 506 | + gentexture(fmt_rgb565,&textures[2],256,256,0);
|
| | 507 | + gentexture(fmt_rgba8888,&textures[3],256,256,0);
|
| | 508 | + ZeroMemory(&material,sizeof(D3DMATERIAL7));
|
| | 509 | + material.ambient.r = 1.0f;
|
| | 510 | + material.ambient.g = 1.0f;
|
| | 511 | + material.ambient.b = 1.0f;
|
| | 512 | + material.diffuse.r = 1.0f;
|
| | 513 | + material.diffuse.g = 1.0f;
|
| | 514 | + material.diffuse.b = 1.0f;
|
| | 515 | + error = d3d7dev->SetMaterial(&material);
|
| | 516 | + error = d3d7dev->LightEnable(0,TRUE);
|
| | 517 | + error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
|
| | 518 | + error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xFFFFFFFF);
|
| | 519 | + mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
|
| | 520 | + mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
|
| | 521 | + mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
|
| | 522 | + mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
|
| | 523 | + matWorld = mat;
|
| | 524 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);
|
| | 525 | + matView = mat;
|
| | 526 | + matView._43 = 10.0f;
|
| | 527 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
|
| | 528 | + matProj = mat;
|
| | 529 | + matProj._11 = 2.0f;
|
| | 530 | + matProj._22 = 2.0f;
|
| | 531 | + matProj._34 = 1.0f;
|
| | 532 | + matProj._43 = -1.0f;
|
| | 533 | + matProj._44 = 0.0f;
|
| | 534 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
|
| | 535 | + ZeroMemory(&lights[0],sizeof(D3DLIGHT7));
|
| | 536 | + lights[0].dltType = D3DLIGHT_DIRECTIONAL;
|
| | 537 | + lights[0].dcvDiffuse.r = 1;
|
| | 538 | + lights[0].dcvDiffuse.g = 0;
|
| | 539 | + lights[0].dcvDiffuse.b = 1;
|
| | 540 | + lights[0].dvDirection = D3DVECTOR(5,5,5);
|
| | 541 | + lights[0].dvRange = D3DLIGHT_RANGE_MAX;
|
| | 542 | + lights[0].dvAttenuation1 = 0.4f;
|
| | 543 | + error = d3d7dev->SetLight(0,&lights[0]);
|
| | 544 | + break;
|
| 440 | 545 | default:
|
| 441 | 546 | break;
|
| 442 | 547 | }
|
| — | — | @@ -470,6 +575,27 @@ |
| 471 | 576 | error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,24,cube_mesh,36,0);
|
| 472 | 577 | error = d3d7dev->EndScene();
|
| 473 | 578 | break;
|
| | 579 | + case 1:
|
| | 580 | + mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
|
| | 581 | + mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
|
| | 582 | + mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
|
| | 583 | + mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
|
| | 584 | + mat._11 = (FLOAT)cos( (float)time );
|
| | 585 | + mat._33 = (FLOAT)cos( (float)time );
|
| | 586 | + mat._13 = -(FLOAT)sin( (float)time );
|
| | 587 | + mat._31 = (FLOAT)sin( (float)time );
|
| | 588 | + error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
|
| | 589 | + error = d3d7dev->BeginScene();
|
| | 590 | + d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[0]->GetSurface());
|
| | 591 | + error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices,4,0);
|
| | 592 | + d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[1]->GetSurface());
|
| | 593 | + error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+4,4,0);
|
| | 594 | + d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[2]->GetSurface());
|
| | 595 | + error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+8,4,0);
|
| | 596 | + d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[3]->GetSurface());
|
| | 597 | + error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+12,4,0);
|
| | 598 | + error = d3d7dev->EndScene();
|
| | 599 | + break;
|
| 474 | 600 | default:
|
| 475 | 601 | break;
|
| 476 | 602 | }
|
| Index: dxgltest/dxgltest.cpp |
| — | — | @@ -251,7 +251,8 @@ |
| 252 | 252 | const int START_3D = __LINE__;
|
| 253 | 253 | const TEST_ITEM Tests3D[] =
|
| 254 | 254 | { // minver maxver buffermin max usesfps defaultfps usestexture usesfsaa name
|
| 255 | | - {7, 7, 0, 2, true, 60.0, false, true, _T("DrawIndexedPrimitives cube with one light (DX7)")}
|
| | 255 | + {7, 7, 0, 2, true, 60.0, false, true, _T("DrawIndexedPrimitive cube with directional light (DX7)")},
|
| | 256 | + {7, 7, 0, 2, true, 60.0, true, true, _T("DrawPrimitive textured cube (DX7)")}
|
| 256 | 257 | };
|
| 257 | 258 | const int END_3D = __LINE__ - 4;
|
| 258 | 259 | const int numtests3d = END_3D - START_3D;
|
| Index: dxgltest/surfacegen.cpp |
| — | — | @@ -60,7 +60,8 @@ |
| 61 | 61 | }
|
| 62 | 62 | }
|
| 63 | 63 | }
|
| 64 | | - else
|
| | 64 | + else if((ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask |
|
| | 65 | + ddsd.ddpfPixelFormat.dwBBitMask) == 0xFFFF)
|
| 65 | 66 | {
|
| 66 | 67 | for(y = 0; y < ddsd.dwHeight; y++)
|
| 67 | 68 | {
|
| — | — | @@ -70,6 +71,16 @@ |
| 71 | 72 | }
|
| 72 | 73 | }
|
| 73 | 74 | }
|
| | 75 | + else
|
| | 76 | + {
|
| | 77 | + for(y = 0; y < ddsd.dwHeight; y++)
|
| | 78 | + {
|
| | 79 | + for(x = 0; x < ddsd.dwWidth; x++)
|
| | 80 | + {
|
| | 81 | + buffer16[x+((ddsd.lPitch/2)*y)] = (unsigned short)((x/(ddsd.dwWidth/64.)) + 64*floor((y/(ddsd.dwHeight/64.))));
|
| | 82 | + }
|
| | 83 | + }
|
| | 84 | + }
|
| 74 | 85 | break;
|
| 75 | 86 | case 24:
|
| 76 | 87 | for(y = 0; y < ddsd.dwHeight; y++)
|