2 * IWineD3DDevice implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
29 /**********************************************************
30 * Utility functions follow
31 **********************************************************/
34 /**********************************************************
35 * IWineD3DDevice implementation follows
36 **********************************************************/
37 HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface, UINT Size, DWORD Usage,
38 DWORD FVF, D3DPOOL Pool, IWineD3DVertexBuffer** ppVertexBuffer, HANDLE *sharedHandle) {
40 IWineD3DVertexBufferImpl *object;
41 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
43 /* Allocate the storage for the device */
44 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DVertexBufferImpl));
45 object->lpVtbl = &IWineD3DVertexBuffer_Vtbl;
46 object->resource.wineD3DDevice= iface;
47 object->resource.resourceType = D3DRTYPE_VERTEXBUFFER;
48 object->resource.ref = 1;
49 object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
50 object->currentDesc.Usage = Usage;
51 object->currentDesc.Pool = Pool;
52 object->currentDesc.FVF = FVF;
53 object->currentDesc.Size = Size;
55 TRACE("(%p) : Size=%d, Usage=%ld, FVF=%lx, Pool=%d - Memory@%p, Iface@%p\n", This, Size, Usage, FVF, Pool, object->allocatedMemory, object);
56 *ppVertexBuffer = (IWineD3DVertexBuffer *)object;
61 HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, D3DSTATEBLOCKTYPE Type, IWineD3DStateBlock** ppStateBlock) {
63 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
64 IWineD3DStateBlockImpl *object;
66 /* Allocate Storage for the state block */
67 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DStateBlockImpl));
68 object->lpVtbl = &IWineD3DStateBlock_Vtbl;
69 object->wineD3DDevice = iface;
71 object->blockType = Type;
72 *ppStateBlock = (IWineD3DStateBlock *)object;
74 /* Special case - Used during initialization to produce a placeholder stateblock
75 so other functions called can update a state block */
76 if (Type == (D3DSTATEBLOCKTYPE) 0) {
77 /* Don't bother increasing the reference count otherwise a device will never
78 be freed due to circular dependencies */
82 /* Otherwise, might as well set the whole state block to the appropriate values */
83 IWineD3DDevice_AddRef(iface);
84 memcpy(object, This->stateBlock, sizeof(IWineD3DStateBlockImpl));
85 FIXME("unfinished - needs to set up changed and set attributes\n");
92 HRESULT WINAPI IWineD3DDeviceImpl_SetFVF(IWineD3DDevice *iface, DWORD fvf) {
93 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
95 /* Update the current statte block */
96 This->updateStateBlock->fvf = fvf;
97 This->updateStateBlock->changed.fvf = TRUE;
98 This->updateStateBlock->set.fvf = TRUE;
100 TRACE("(%p) : FVF Shader FVF set to %lx\n", This, fvf);
102 /* No difference if recording or not */
105 HRESULT WINAPI IWineD3DDeviceImpl_GetFVF(IWineD3DDevice *iface, DWORD *pfvf) {
106 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
107 TRACE("(%p) : GetFVF returning %lx\n", This, This->stateBlock->fvf);
108 *pfvf = This->stateBlock->fvf;
112 /**********************************************************
113 * IUnknown parts follows
114 **********************************************************/
116 HRESULT WINAPI IWineD3DDeviceImpl_QueryInterface(IWineD3DDevice *iface,REFIID riid,LPVOID *ppobj)
118 return E_NOINTERFACE;
121 ULONG WINAPI IWineD3DDeviceImpl_AddRef(IWineD3DDevice *iface) {
122 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
123 TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
124 return InterlockedIncrement(&This->ref);
127 ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) {
128 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
130 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
131 ref = InterlockedDecrement(&This->ref);
133 IWineD3D_Release(This->WineD3D);
134 HeapFree(GetProcessHeap(), 0, This);
139 /**********************************************************
140 * IWineD3DDevice VTbl follows
141 **********************************************************/
143 IWineD3DDeviceVtbl IWineD3DDevice_Vtbl =
145 IWineD3DDeviceImpl_QueryInterface,
146 IWineD3DDeviceImpl_AddRef,
147 IWineD3DDeviceImpl_Release,
148 IWineD3DDeviceImpl_CreateVertexBuffer,
149 IWineD3DDeviceImpl_CreateStateBlock,
150 IWineD3DDeviceImpl_SetFVF,
151 IWineD3DDeviceImpl_GetFVF