/* * IWineD3DDevice implementation * * Copyright 2002-2004 Jason Edmeades * Copyright 2003-2004 Raphael Junqueira * Copyright 2004 Christian Costa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "wined3d_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d); WINE_DECLARE_DEBUG_CHANNEL(d3d_caps); /********************************************************** * Utility functions follow **********************************************************/ /********************************************************** * IWineD3DDevice implementation follows **********************************************************/ HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IWineD3DVertexBuffer** ppVertexBuffer, HANDLE *sharedHandle) { IWineD3DVertexBufferImpl *object; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; /* Allocate the storage for the device */ object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DVertexBufferImpl)); object->lpVtbl = &IWineD3DVertexBuffer_Vtbl; object->resource.wineD3DDevice= iface; object->resource.resourceType = D3DRTYPE_VERTEXBUFFER; object->resource.ref = 1; object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size); object->currentDesc.Usage = Usage; object->currentDesc.Pool = Pool; object->currentDesc.FVF = FVF; object->currentDesc.Size = Size; TRACE("(%p) : Size=%d, Usage=%ld, FVF=%lx, Pool=%d - Memory@%p, Iface@%p\n", This, Size, Usage, FVF, Pool, object->allocatedMemory, object); *ppVertexBuffer = (IWineD3DVertexBuffer *)object; return D3D_OK; } HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, D3DSTATEBLOCKTYPE Type, IWineD3DStateBlock** ppStateBlock) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DStateBlockImpl *object; /* Allocate Storage for the state block */ object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DStateBlockImpl)); object->lpVtbl = &IWineD3DStateBlock_Vtbl; object->wineD3DDevice = iface; object->ref = 1; object->blockType = Type; *ppStateBlock = (IWineD3DStateBlock *)object; /* Special case - Used during initialization to produce a placeholder stateblock so other functions called can update a state block */ if (Type == (D3DSTATEBLOCKTYPE) 0) { /* Don't bother increasing the reference count otherwise a device will never be freed due to circular dependencies */ return D3D_OK; } /* Otherwise, might as well set the whole state block to the appropriate values */ IWineD3DDevice_AddRef(iface); memcpy(object, This->stateBlock, sizeof(IWineD3DStateBlockImpl)); FIXME("unfinished - needs to set up changed and set attributes\n"); return D3D_OK; } /***** * Get / Set FVF *****/ HRESULT WINAPI IWineD3DDeviceImpl_SetFVF(IWineD3DDevice *iface, DWORD fvf) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; /* Update the current statte block */ This->updateStateBlock->fvf = fvf; This->updateStateBlock->changed.fvf = TRUE; This->updateStateBlock->set.fvf = TRUE; TRACE("(%p) : FVF Shader FVF set to %lx\n", This, fvf); /* No difference if recording or not */ return D3D_OK; } HRESULT WINAPI IWineD3DDeviceImpl_GetFVF(IWineD3DDevice *iface, DWORD *pfvf) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; TRACE("(%p) : GetFVF returning %lx\n", This, This->stateBlock->fvf); *pfvf = This->stateBlock->fvf; return D3D_OK; } /********************************************************** * IUnknown parts follows **********************************************************/ HRESULT WINAPI IWineD3DDeviceImpl_QueryInterface(IWineD3DDevice *iface,REFIID riid,LPVOID *ppobj) { return E_NOINTERFACE; } ULONG WINAPI IWineD3DDeviceImpl_AddRef(IWineD3DDevice *iface) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref); return InterlockedIncrement(&This->ref); } ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; ULONG ref; TRACE("(%p) : Releasing from %ld\n", This, This->ref); ref = InterlockedDecrement(&This->ref); if (ref == 0) { IWineD3D_Release(This->WineD3D); HeapFree(GetProcessHeap(), 0, This); } return ref; } /********************************************************** * IWineD3DDevice VTbl follows **********************************************************/ IWineD3DDeviceVtbl IWineD3DDevice_Vtbl = { IWineD3DDeviceImpl_QueryInterface, IWineD3DDeviceImpl_AddRef, IWineD3DDeviceImpl_Release, IWineD3DDeviceImpl_CreateVertexBuffer, IWineD3DDeviceImpl_CreateStateBlock, IWineD3DDeviceImpl_SetFVF, IWineD3DDeviceImpl_GetFVF };