2 * IDirect3DIndexBuffer9 implementation
4 * Copyright 2002-2004 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DIndexBuffer9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DResource9)
33 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
34 IDirect3DIndexBuffer9_AddRef(iface);
39 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
44 static ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
45 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
46 ULONG ref = InterlockedIncrement(&This->ref);
48 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
53 static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
54 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
55 ULONG ref = InterlockedDecrement(&This->ref);
57 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
61 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
62 wined3d_mutex_unlock();
64 IDirect3DDevice9Ex_Release(This->parentDevice);
65 HeapFree(GetProcessHeap(), 0, This);
70 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
71 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
72 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
73 IWineD3DDevice *wined3d_device;
75 TRACE("(%p) Relay\n", This);
78 hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
81 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
82 IWineD3DDevice_Release(wined3d_device);
84 wined3d_mutex_unlock();
89 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
90 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
92 TRACE("(%p) Relay\n", This);
95 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
96 wined3d_mutex_unlock();
101 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
102 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
104 TRACE("(%p) Relay\n", This);
106 wined3d_mutex_lock();
107 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
108 wined3d_mutex_unlock();
113 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
114 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
116 TRACE("(%p) Relay\n", This);
118 wined3d_mutex_lock();
119 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
120 wined3d_mutex_unlock();
125 static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
126 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
128 TRACE("(%p) Relay\n", This);
130 wined3d_mutex_lock();
131 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
132 wined3d_mutex_unlock();
137 static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
138 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
140 TRACE("(%p) Relay\n", This);
142 wined3d_mutex_lock();
143 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
144 wined3d_mutex_unlock();
149 static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
150 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
151 TRACE("(%p) Relay\n", This);
153 wined3d_mutex_lock();
154 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
155 wined3d_mutex_unlock();
158 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
159 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
160 TRACE("(%p)\n", This);
162 return D3DRTYPE_INDEXBUFFER;
165 /* IDirect3DIndexBuffer9 Interface follow: */
166 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
167 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
169 TRACE("(%p) Relay\n", This);
171 wined3d_mutex_lock();
172 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
173 wined3d_mutex_unlock();
178 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
179 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
181 TRACE("(%p) Relay\n", This);
183 wined3d_mutex_lock();
184 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
185 wined3d_mutex_unlock();
190 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
191 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
193 WINED3DBUFFER_DESC desc;
194 TRACE("(%p) Relay\n", This);
196 wined3d_mutex_lock();
197 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
198 wined3d_mutex_unlock();
201 pDesc->Format = d3dformat_from_wined3dformat(This->format);
202 pDesc->Usage = desc.Usage;
203 pDesc->Pool = desc.Pool;
204 pDesc->Size = desc.Size;
205 pDesc->Type = D3DRTYPE_INDEXBUFFER;
212 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
215 IDirect3DIndexBuffer9Impl_QueryInterface,
216 IDirect3DIndexBuffer9Impl_AddRef,
217 IDirect3DIndexBuffer9Impl_Release,
218 /* IDirect3DResource9 */
219 IDirect3DIndexBuffer9Impl_GetDevice,
220 IDirect3DIndexBuffer9Impl_SetPrivateData,
221 IDirect3DIndexBuffer9Impl_GetPrivateData,
222 IDirect3DIndexBuffer9Impl_FreePrivateData,
223 IDirect3DIndexBuffer9Impl_SetPriority,
224 IDirect3DIndexBuffer9Impl_GetPriority,
225 IDirect3DIndexBuffer9Impl_PreLoad,
226 IDirect3DIndexBuffer9Impl_GetType,
227 /* IDirect3DIndexBuffer9 */
228 IDirect3DIndexBuffer9Impl_Lock,
229 IDirect3DIndexBuffer9Impl_Unlock,
230 IDirect3DIndexBuffer9Impl_GetDesc
234 /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
235 HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT Length, DWORD Usage,
236 D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9 **ppIndexBuffer, HANDLE *pSharedHandle)
238 IDirect3DIndexBuffer9Impl *object;
239 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
240 HRESULT hrc = D3D_OK;
242 TRACE("(%p) Relay\n", This);
243 /* Allocate the storage for the device */
244 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
245 if (NULL == object) {
246 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
247 return D3DERR_OUTOFVIDEOMEMORY;
250 object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
252 object->format = wined3dformat_from_d3dformat(Format);
253 TRACE("Calling wined3d create index buffer\n");
255 wined3d_mutex_lock();
256 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
257 (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
258 wined3d_mutex_unlock();
263 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
264 HeapFree(GetProcessHeap(), 0, object);
266 IDirect3DDevice9Ex_AddRef(iface);
267 object->parentDevice = iface;
268 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
269 TRACE("(%p) : Created index buffer %p\n", This, object);