DXGL r119 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r118‎ | r119 | r120 >
Date:15:49, 11 March 2012
Author:admin
Status:new
Tags:
Comment:
Add D3D texture test to dxgltest
Modified paths:
  • /dxgltest/Tests3D.cpp (modified) (history)
  • /dxgltest/dxgltest.cpp (modified) (history)
  • /dxgltest/surfacegen.cpp (modified) (history)

Diff [purge]

Index: dxgltest/Tests3D.cpp
@@ -27,7 +27,7 @@
2828 void InitTest3D(int test);
2929 void RunTestTimed3D(int test);
3030 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);
3232
3333
3434 static MultiDirectDraw *ddinterface;
@@ -34,6 +34,7 @@
3535 static MultiDirectDrawSurface *ddsurface;
3636 static MultiDirectDrawSurface *ddsrender;
3737 static MultiDirectDrawSurface *zbuffer;
 38+static MultiDirectDrawSurface *textures[8];
3839 static IDirect3D7 *d3d7;
3940 static IDirect3DDevice7 *d3d7dev;
4041 static LPDIRECTDRAWCLIPPER ddclipper;
@@ -43,7 +44,7 @@
4445 static HWND hWnd;
4546 static int testnum;
4647 static unsigned int randnum;
47 -static int testtypes[] = {0};
 48+static int testtypes[] = {0,0};
4849
4950 static D3DVECTOR points[256];
5051 static D3DVECTOR normals[256];
@@ -67,6 +68,14 @@
6869 break;
6970 case WM_DESTROY:
7071 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+ }
7180 if(d3d7dev)
7281 {
7382 d3d7dev->Release();
@@ -141,16 +150,18 @@
142151 case WM_XBUTTONUP:
143152 case WM_XBUTTONDBLCLK:
144153 case WM_MOUSEHWHEEL:
145 - RunTestMouse3D(testnum,Msg,wParam,lParam);
146 - if(!fullscreen)
 154+ if(RunTestMouse3D(testnum,Msg,wParam,lParam))
147155 {
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+ }
155166 }
156167 break;
157168 default:
@@ -163,8 +174,10 @@
164175 static int d3dver;
165176 static int ddver;
166177
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+}
169182
170183 const TCHAR wndclassname3d[] = _T("D3DTestWndClass");
171184
@@ -188,6 +201,7 @@
189202 ::testnum = testnum;
190203 randnum = (unsigned int)time(NULL);
191204 ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
 205+ ZeroMemory(textures,8*sizeof(MultiDirectDrawSurface*));
192206 if(apiver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
193207 else ddsd.dwSize = sizeof(DDSURFACEDESC);
194208 ::fullscreen = fullscreen;
@@ -288,7 +302,7 @@
289303 }
290304 }
291305 error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
292 - error = d3d7->EnumZBufferFormats(IID_IDirect3DHALDevice,zcallback,&ddpfz);
 306+ error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice,zcallback,&ddpfz);
293307 error = ddsrender->GetSurfaceDesc(&ddsd);
294308 ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
295309 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
@@ -362,31 +376,77 @@
363377 normals[4] = D3DVECTOR(0.0f,1.0f,0.0f);
364378 normals[5] = D3DVECTOR(0.0f,-10.0f,0.0f);
365379 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);
369383 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);
373387 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);
377391 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);
381395 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);
385399 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);
389403 }
390404
 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+
391451 void InitTest3D(int test)
392452 {
393453 HRESULT error;
@@ -436,6 +496,51 @@
437497 lights[0].dvAttenuation1 = 0.4f;
438498 error = d3d7dev->SetLight(0,&lights[0]);
439499 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;
440545 default:
441546 break;
442547 }
@@ -470,6 +575,27 @@
471576 error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,24,cube_mesh,36,0);
472577 error = d3d7dev->EndScene();
473578 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;
474600 default:
475601 break;
476602 }
Index: dxgltest/dxgltest.cpp
@@ -251,7 +251,8 @@
252252 const int START_3D = __LINE__;
253253 const TEST_ITEM Tests3D[] =
254254 { // 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)")}
256257 };
257258 const int END_3D = __LINE__ - 4;
258259 const int numtests3d = END_3D - START_3D;
Index: dxgltest/surfacegen.cpp
@@ -60,7 +60,8 @@
6161 }
6262 }
6363 }
64 - else
 64+ else if((ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask |
 65+ ddsd.ddpfPixelFormat.dwBBitMask) == 0xFFFF)
6566 {
6667 for(y = 0; y < ddsd.dwHeight; y++)
6768 {
@@ -70,6 +71,16 @@
7172 }
7273 }
7374 }
 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+ }
7485 break;
7586 case 24:
7687 for(y = 0; y < ddsd.dwHeight; y++)