From: David Adam Subject: d3dx9_36 [patch 1/2]: Implement D3DXCreateBox with tests Message-Id: Date: Sat, 18 Dec 2010 04:03:13 +0100 Hello, this patch is partially based on a Tony Wasserka's patch. A+ David Hello,

this patch is partially based on a Tony Wasserka's patch.

A+

David
From 3c60d69fed775a91fb36615056bd878e831c7319 Mon Sep 17 00:00:00 2001 From: David Adam Date: Fri, 17 Dec 2010 20:18:55 +0100 Subject: Implement D3DXCreateBox with tests --- dlls/d3dx9_36/mesh.c | 99 ++++++++++++++++++++++++++++++++++++++++---- dlls/d3dx9_36/tests/mesh.c | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 8 deletions(-) diff --git a/dlls/d3dx9_36/mesh.c b/dlls/d3dx9_36/mesh.c index bbcbf13..515a5b3 100644 --- a/dlls/d3dx9_36/mesh.c +++ b/dlls/d3dx9_36/mesh.c @@ -1055,18 +1055,100 @@ HRESULT WINAPI D3DXCreateMeshFVF(DWORD numfaces, DWORD numvertices, DWORD option return D3DXCreateMesh(numfaces, numvertices, options, declaration, device, mesh); } -HRESULT WINAPI D3DXCreateBox(LPDIRECT3DDEVICE9 device, FLOAT width, FLOAT height, - FLOAT depth, LPD3DXMESH* mesh, LPD3DXBUFFER* adjacency) +/************************************************************************* + * D3DXCreateBox + */ +HRESULT WINAPI D3DXCreateBox(LPDIRECT3DDEVICE9 pDevice, FLOAT fWidth, FLOAT fHeight, FLOAT fDepth, LPD3DXMESH *ppMesh, LPD3DXBUFFER *ppAdjacency) { - FIXME("(%p, %f, %f, %f, %p, %p): stub\n", device, width, height, depth, mesh, adjacency); + DWORD adjacency[36] = { + 6, 9, 1, 2, 10, 0, + 1, 9, 3, 4, 10, 2, + 3, 8, 5, 7, 11, 4, + 0, 11, 7, 5, 8, 6, + 7, 4, 9, 2, 0, 8, + 1, 3, 11, 5, 6, 10, + }; + FLOAT vertices[144] = + { + -0.50f, -0.50f, -0.50f, -1.00f, 0.00f, 0.00f, + -0.50f, -0.50f, 0.50f, -1.00f, 0.00f, 0.00f, + -0.50f, 0.50f, 0.50f, -1.00f, 0.00f, 0.00f, + -0.50f, 0.50f, -0.50f, -1.00f, 0.00f, 0.00f, + -0.50f, 0.50f, -0.50f, 0.00f, 1.00f, 0.00f, + -0.50f, 0.50f, 0.50f, 0.00f, 1.00f, 0.00f, + 0.50f, 0.50f, 0.50f, 0.00f, 1.00f, 0.00f, + 0.50f, 0.50f, -0.50f, 0.00f, 1.00f, 0.00f, + 0.50f, 0.50f, -0.50f, 1.00f, 0.00f, 0.00f, + 0.50f, 0.50f, 0.50f, 1.00f, 0.00f, 0.00f, + 0.50f, -0.50f, 0.50f, 1.00f, 0.00f, 0.00f, + 0.50f, -0.50f, -0.50f, 1.00f, 0.00f, 0.00f, + -0.50f, -0.50f, 0.50f, 0.00f, -1.00f, 0.00f, + -0.50f, -0.50f, -0.50f, 0.00f, -1.00f, 0.00f, + 0.50f, -0.50f, -0.50f, 0.00f, -1.00f, 0.00f, + 0.50f, -0.50f, 0.50f, 0.00f, -1.00f, 0.00f, + -0.50f, -0.50f, 0.50f, 0.00f, 0.00f, 1.00f, + 0.50f, -0.50f, 0.50f, 0.00f, 0.00f, 1.00f, + 0.50f, 0.50f, 0.50f, 0.00f, 0.00f, 1.00f, + -0.50f, 0.50f, 0.50f, 0.00f, 0.00f, 1.00f, + -0.50f, -0.50f, -0.50f, 0.00f, 0.00f, -1.00f, + -0.50f, 0.50f, -0.50f, 0.00f, 0.00f, -1.00f, + 0.50f, 0.50f, -0.50f, 0.00f, 0.00f, -1.00f, + 0.50f, -0.50f, -0.50f, 0.00f, 0.00f, -1.00f, + }; + WORD indices[36] = + { + 0, 1, 2, 2, 3, 0, + 4, 5, 6, 6, 7, 4, + 8, 9, 10, 10, 11, 8, + 12, 13, 14, 14, 15, 12, + 16, 17, 18, 18, 19, 16, + 20, 21, 22, 22, 23, 20, + }; + LPVOID pData; + HRESULT hr; + int i; + + TRACE("pDevice=%p, fWidth=%f, fHeight=%f, fDepth=%f, ppMesh=%p, ppAdjacency=%p\n", pDevice, fWidth, fHeight, fDepth, ppMesh, ppAdjacency); - return E_NOTIMPL; + if( !pDevice || !ppMesh ) return D3DERR_INVALIDCALL; + if(fWidth < 0.0f || fHeight < 0.0f || fDepth < 0.0f) return D3DERR_INVALIDCALL; + + hr = D3DXCreateMeshFVF(12, 24, D3DXMESH_MANAGED, D3DFVF_XYZ | D3DFVF_NORMAL, pDevice, ppMesh); + if(FAILED(hr)) return hr; + + for(i = 0; i < 24; i++) + { + vertices[6 * i ] *= fWidth; + vertices[6 * i + 1] *= fHeight; + vertices[6 * i + 2] *= fDepth; + } + + (*ppMesh)->lpVtbl->LockVertexBuffer(*ppMesh, D3DLOCK_DISCARD, &pData); + memcpy(pData, vertices, sizeof(FLOAT) * 144); + (*ppMesh)->lpVtbl->UnlockVertexBuffer(*ppMesh); + + (*ppMesh)->lpVtbl->LockIndexBuffer(*ppMesh, D3DLOCK_DISCARD, &pData); + memcpy(pData, indices, sizeof(WORD) * 36); + (*ppMesh)->lpVtbl->UnlockIndexBuffer(*ppMesh); + + if(ppAdjacency) + { + D3DXCreateBuffer(sizeof(DWORD) * 36, ppAdjacency); + for(i=0; i<36; i++) + ((DWORD *)ID3DXBuffer_GetBufferPointer(*ppAdjacency))[i] = adjacency[i]; + } + + return D3D_OK; } +/************************************************************************* + * D3DXCreateSphere + */ struct vertex { D3DXVECTOR3 position; D3DXVECTOR3 normal; + }; typedef WORD face[3]; @@ -1117,8 +1199,7 @@ static WORD vertex_index(UINT slices, int slice, int stack) return stack*slices+slice+1; } -HRESULT WINAPI D3DXCreateSphere(LPDIRECT3DDEVICE9 device, FLOAT radius, UINT slices, - UINT stacks, LPD3DXMESH* mesh, LPD3DXBUFFER* adjacency) +HRESULT WINAPI D3DXCreateSphere(LPDIRECT3DDEVICE9 device, FLOAT radius, UINT slices, UINT stacks, LPD3DXMESH* mesh, LPD3DXBUFFER* adjacency) { DWORD number_of_vertices, number_of_faces; HRESULT hr; @@ -1289,8 +1370,10 @@ HRESULT WINAPI D3DXCreateSphere(LPDIRECT3DDEVICE9 device, FLOAT radius, UINT sli return D3D_OK; } -HRESULT WINAPI D3DXCreateCylinder(LPDIRECT3DDEVICE9 device, FLOAT radius1, FLOAT radius2, FLOAT length, UINT slices, - UINT stacks, LPD3DXMESH* mesh, LPD3DXBUFFER* adjacency) +/************************************************************************* + * D3DXCreateCylinder + */ +HRESULT WINAPI D3DXCreateCylinder(LPDIRECT3DDEVICE9 device, FLOAT radius1, FLOAT radius2, FLOAT length, UINT slices, UINT stacks, LPD3DXMESH* mesh, LPD3DXBUFFER* adjacency) { DWORD number_of_vertices, number_of_faces; HRESULT hr; diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c index 6ba7224..a257668 100644 --- a/dlls/d3dx9_36/tests/mesh.c +++ b/dlls/d3dx9_36/tests/mesh.c @@ -1347,6 +1347,84 @@ static void D3DXCreateMeshFVFTest(void) DestroyWindow(wnd); } +static void D3DXCreateBoxTest(void) +{ + HRESULT hr; + HWND wnd; + IDirect3D9* d3d; + IDirect3DDevice9* device; + D3DPRESENT_PARAMETERS d3dpp; + ID3DXMesh* box; + ID3DXBuffer* ppBuffer; + DWORD *buffer, expected_adjacency[36]={6, 9, 1, 2, 10, 0, + 1, 9, 3, 4, 10, 2, + 3, 8, 5, 7, 11, 4, + 0, 11, 7, 5, 8, 6, + 7, 4, 9, 2, 0, 8, + 1, 3, 11, 5, 6, 10, + }; + unsigned int i; + + wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); + d3d = Direct3DCreate9(D3D_SDK_VERSION); + if (!wnd) + { + skip("Couldn't create application window\n"); + return; + } + if (!d3d) + { + skip("Couldn't create IDirect3D9 object\n"); + DestroyWindow(wnd); + return; + } + + ZeroMemory(&d3dpp, sizeof(d3dpp)); + d3dpp.Windowed = TRUE; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device); + if (FAILED(hr)) + { + skip("Failed to create IDirect3DDevice9 object %#x\n", hr); + IDirect3D9_Release(d3d); + DestroyWindow(wnd); + return; + } + + hr = D3DXCreateBox(device,2.0f,20.0f,4.9f,NULL, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x",hr); + + hr = D3DXCreateBox(NULL,22.0f,20.0f,4.9f,&box, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x",hr); + + hr = D3DXCreateBox(device,-2.0f,20.0f,4.9f,&box, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x",hr); + + hr = D3DXCreateBox(device,22.0f,-20.0f,4.9f,&box, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x",hr); + + hr = D3DXCreateBox(device,22.0f,20.0f,-4.9f,&box, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x",hr); + + hr = D3DXCreateBuffer(36*sizeof(DWORD), &ppBuffer); + if(SUCCEEDED(hr)) + { + hr = D3DXCreateBox(device,10.9f,20.0f,4.9f,&box, &ppBuffer); + buffer = ID3DXBuffer_GetBufferPointer(ppBuffer); + ok(hr==D3D_OK,"Expected D3D_OK, recdeived %#x", hr); + + if(SUCCEEDED(hr)) + for(i=0; i<36; i++) + ok(expected_adjacency[i]==buffer[i], "expected adjacency %d: %#x, received %#x\n",i,expected_adjacency[i], buffer[i]); + else skip("D3DXCreateBox failed\n"); + } + else skip("D3DXCreateBuffer failed \n"); + + IDirect3DDevice9_Release(device); + IDirect3D9_Release(d3d); + DestroyWindow(wnd); +} + struct sincos_table { float *sin; @@ -2041,6 +2119,7 @@ START_TEST(mesh) D3DXCreateMeshFVFTest(); D3DXCreateSphereTest(); D3DXCreateCylinderTest(); + D3DXCreateBoxTest(); test_get_decl_length(); test_get_decl_vertex_size(); test_fvf_decl_conversion(); -- 1.7.1