From 32d7bebf7cb85a61b2915fb7c237503245f50358 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 29 Oct 2008 16:34:21 +0100 Subject: [PATCH] d3dx8: Implement ID3DXMatrixStack_Push() and ID3DXMatrixStack_Pop(). Based on a patchset by David Adam. --- dlls/d3dx8/math.c | 49 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c index eedc1159b6..20d63648f7 100644 --- a/dlls/d3dx8/math.c +++ b/dlls/d3dx8/math.c @@ -691,15 +691,56 @@ static HRESULT WINAPI ID3DXMatrixStackImpl_MultMatrixLocal(ID3DXMatrixStack *ifa static HRESULT WINAPI ID3DXMatrixStackImpl_Pop(ID3DXMatrixStack *iface) { ID3DXMatrixStackImpl *This = (ID3DXMatrixStackImpl *)iface; - FIXME("(%p) : stub\n",This); - return E_NOTIMPL; + + TRACE("iface %p\n", iface); + + /* Popping the last element on the stack returns D3D_OK, but does nothing. */ + if (!This->current) return D3D_OK; + + if (This->current <= This->stack_size / 4 && This->stack_size >= INITIAL_STACK_SIZE * 2) + { + unsigned int new_size; + D3DXMATRIX *new_stack; + + new_size = This->stack_size / 2; + new_stack = HeapReAlloc(GetProcessHeap(), 0, This->stack, new_size * sizeof(D3DXMATRIX)); + if (new_stack) + { + This->stack_size = new_size; + This->stack = new_stack; + } + } + + --This->current; + + return D3D_OK; } static HRESULT WINAPI ID3DXMatrixStackImpl_Push(ID3DXMatrixStack *iface) { ID3DXMatrixStackImpl *This = (ID3DXMatrixStackImpl *)iface; - FIXME("(%p) : stub\n",This); - return E_NOTIMPL; + + TRACE("iface %p\n", iface); + + if (This->current == This->stack_size - 1) + { + unsigned int new_size; + D3DXMATRIX *new_stack; + + if (This->stack_size > UINT_MAX / 2) return E_OUTOFMEMORY; + + new_size = This->stack_size * 2; + new_stack = HeapReAlloc(GetProcessHeap(), 0, This->stack, new_size * sizeof(D3DXMATRIX)); + if (!new_stack) return E_OUTOFMEMORY; + + This->stack_size = new_size; + This->stack = new_stack; + } + + ++This->current; + This->stack[This->current] = This->stack[This->current - 1]; + + return D3D_OK; } static HRESULT WINAPI ID3DXMatrixStackImpl_RotateAxis(ID3DXMatrixStack *iface, CONST D3DXVECTOR3 *pv, FLOAT angle)