From: David Adam Subject: d3dx9_36 [patch 1/2, try 2]: Implement D3DXCreatePolygon Message-Id: Date: Thu, 5 Jan 2012 13:14:50 +0100 Hello, changes from previous tries: - simplify a computation. - merge a loop inside an other one, since the number of sides could be huge. - following to http://www.winehq.org/pipermail/wine-devel/2011-August/091570.html, D3DLOCK_DISCARD has not to be used. A+
Hello,

changes from previous tries:

- simplify a computation.
- merge a loop inside an other one, since the number of sides could be huge.
- following to http://www.winehq.org/pipermail/wine-devel/2011-August/091570.html, D3DLOCK_DISCARD has not to be used.

A+


From d0ab60dc28846e66b73594859bc88e04b7907380 Mon Sep 17 00:00:00 2001 From: David Adam Date: Thu, 5 Jan 2012 12:58:58 +0100 Subject: Implement D3DXCreatePolygon --- dlls/d3dx9_36/d3dx9_36.spec | 2 +- dlls/d3dx9_36/mesh.c | 85 +++++++++++++++++++++++++++++++++++++++++++ include/d3dx9shape.h | 6 +++ 3 files changed, 92 insertions(+), 1 deletions(-) diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec index 70ff3d9..2240841 100644 --- a/dlls/d3dx9_36/d3dx9_36.spec +++ b/dlls/d3dx9_36/d3dx9_36.spec @@ -76,7 +76,7 @@ @ stub D3DXCreateNPatchMesh(ptr ptr) @ stub D3DXCreatePMeshFromStream(ptr long ptr ptr ptr ptr ptr) @ stub D3DXCreatePatchMesh(ptr long long long ptr ptr ptr) -@ stub D3DXCreatePolygon(ptr long long ptr ptr) +@ stdcall D3DXCreatePolygon(ptr long long ptr ptr) @ stub D3DXCreatePRTBuffer(long long long ptr) @ stub D3DXCreatePRTBufferTex(long long long long ptr) @ stub D3DXCreatePRTCompBuffer(long long long ptr ptr ptr ptr) diff --git a/dlls/d3dx9_36/mesh.c b/dlls/d3dx9_36/mesh.c index 022e66d..9f9ac6a 100644 --- a/dlls/d3dx9_36/mesh.c +++ b/dlls/d3dx9_36/mesh.c @@ -4368,6 +4368,91 @@ HRESULT WINAPI D3DXCreateBox(LPDIRECT3DDEVICE9 device, FLOAT width, FLOAT height return E_NOTIMPL; } +HRESULT WINAPI D3DXCreatePolygon(LPDIRECT3DDEVICE9 device, FLOAT length, UINT sides, LPD3DXMESH *mesh, LPD3DXBUFFER *adjacency) +{ + D3DXVECTOR3 *vertice; + DWORD *buffer; + FLOAT scale; + HRESULT hr; + ID3DXBuffer *adjacency_tmp; + ID3DXMesh *polygon; + UINT i, j; + WORD *index; + + TRACE("(%p, %f, %u, %p, %p)\n", device, length, sides, mesh, adjacency); + + if (!device || !mesh || (length < 0.0f) || (sides == 0)) return D3DERR_INVALIDCALL; + + hr = D3DXCreateMeshFVF(sides, sides + 1, D3DXMESH_MANAGED, D3DFVF_XYZ | D3DFVF_NORMAL, device, &polygon); + if (FAILED(hr)) return hr; + + hr = polygon->lpVtbl->LockVertexBuffer(polygon, 0, (VOID **)&vertice); + if (FAILED(hr)) + { + ERR("LockVertexBuffer failed\n"); + polygon->lpVtbl->Release(polygon); + return hr; + } + + hr = polygon->lpVtbl->LockIndexBuffer(polygon, 0, (VOID **)&index); + if (FAILED(hr)) + { + ERR("LockIndexBuffer failed\n"); + polygon->lpVtbl->UnlockVertexBuffer(polygon); + polygon->lpVtbl->Release(polygon); + return hr; + } + + scale = 0.5f * length / sin(D3DX_PI / sides); + + for (i = 0; i < sides; i++) + { + for (j = 0; j < 3; j++) + index[3 * i + j] = (j == 0) ? 0: i + j; + + vertice[2 * i + 2].x = cos(2.0f * D3DX_PI * i / sides) * scale; + vertice[2 * i + 2].y = sin(2.0f * D3DX_PI * i / sides) * scale; + vertice[2 * i + 2].z = 0.0f; + + vertice[2 * i + 3].x = 0.0f; + vertice[2 * i + 3].y = 0.0f; + vertice[2 * i + 3].z = 1.0f; + } + index[3 * sides -1] = 1; + +/* D3DXCreatePolygon takes in account the center of the polygon */ + vertice[0].x = 0.0f; + vertice[0].y = 0.0f; + vertice[0].z = 0.0f; + vertice[1].x = 0.0f; + vertice[1].y = 0.0f; + vertice[1].z = 1.0f; + + polygon->lpVtbl->UnlockVertexBuffer(polygon); + polygon->lpVtbl->UnlockIndexBuffer(polygon); + + *mesh = polygon; + + if (adjacency) + { + hr = D3DXCreateBuffer(3 * sides * sizeof(DWORD), &adjacency_tmp); + if (FAILED(hr)) return hr; + + buffer = (DWORD *)ID3DXBuffer_GetBufferPointer(adjacency_tmp); + + for (i = 0; i < sides; i++) + { + buffer[3 * i] = i - 1; + buffer[3 * i + 1] = 0xffffffff; + buffer[3 * i + 2] = i + 1; + } + buffer[0] = sides - 1; + *adjacency = adjacency_tmp; + } + + return D3D_OK; +} + struct vertex { D3DXVECTOR3 position; diff --git a/include/d3dx9shape.h b/include/d3dx9shape.h index 690b183..51b2430 100644 --- a/include/d3dx9shape.h +++ b/include/d3dx9shape.h @@ -32,6 +32,12 @@ HRESULT WINAPI D3DXCreateBox(LPDIRECT3DDEVICE9 device, LPD3DXMESH* mesh, LPD3DXBUFFER* adjacency); +HRESULT WINAPI D3DXCreatePolygon(LPDIRECT3DDEVICE9 device, + FLOAT length, + UINT sides, + LPD3DXMESH* mesh, + LPD3DXBUFFER* adjacency); + HRESULT WINAPI D3DXCreateSphere(LPDIRECT3DDEVICE9 device, FLOAT radius, UINT slices, -- 1.7.6