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);
52 IDirect3DDevice9Ex_AddRef(This->parentDevice);
54 IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
55 wined3d_mutex_unlock();
61 static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
62 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
63 ULONG ref = InterlockedDecrement(&This->ref);
65 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
68 IDirect3DDevice9Ex_Release(This->parentDevice);
70 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
71 wined3d_mutex_unlock();
76 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
77 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
78 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
79 IWineD3DDevice *wined3d_device;
81 TRACE("(%p) Relay\n", This);
84 hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
87 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
88 IWineD3DDevice_Release(wined3d_device);
90 wined3d_mutex_unlock();
95 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
96 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
98 TRACE("(%p) Relay\n", This);
100 wined3d_mutex_lock();
101 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
102 wined3d_mutex_unlock();
107 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
108 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
110 TRACE("(%p) Relay\n", This);
112 wined3d_mutex_lock();
113 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
114 wined3d_mutex_unlock();
119 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
120 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
122 TRACE("(%p) Relay\n", This);
124 wined3d_mutex_lock();
125 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
126 wined3d_mutex_unlock();
131 static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
132 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
134 TRACE("(%p) Relay\n", This);
136 wined3d_mutex_lock();
137 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
138 wined3d_mutex_unlock();
143 static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
144 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
146 TRACE("(%p) Relay\n", This);
148 wined3d_mutex_lock();
149 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
150 wined3d_mutex_unlock();
155 static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
156 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
157 TRACE("(%p) Relay\n", This);
159 wined3d_mutex_lock();
160 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
161 wined3d_mutex_unlock();
164 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
165 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
166 TRACE("(%p)\n", This);
168 return D3DRTYPE_INDEXBUFFER;
171 /* IDirect3DIndexBuffer9 Interface follow: */
172 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
173 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
175 TRACE("(%p) Relay\n", This);
177 wined3d_mutex_lock();
178 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
179 wined3d_mutex_unlock();
184 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
185 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
187 TRACE("(%p) Relay\n", This);
189 wined3d_mutex_lock();
190 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
191 wined3d_mutex_unlock();
196 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
197 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
199 WINED3DBUFFER_DESC desc;
200 TRACE("(%p) Relay\n", This);
202 wined3d_mutex_lock();
203 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
204 wined3d_mutex_unlock();
207 pDesc->Format = d3dformat_from_wined3dformat(This->format);
208 pDesc->Usage = desc.Usage;
209 pDesc->Pool = desc.Pool;
210 pDesc->Size = desc.Size;
211 pDesc->Type = D3DRTYPE_INDEXBUFFER;
218 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
221 IDirect3DIndexBuffer9Impl_QueryInterface,
222 IDirect3DIndexBuffer9Impl_AddRef,
223 IDirect3DIndexBuffer9Impl_Release,
224 /* IDirect3DResource9 */
225 IDirect3DIndexBuffer9Impl_GetDevice,
226 IDirect3DIndexBuffer9Impl_SetPrivateData,
227 IDirect3DIndexBuffer9Impl_GetPrivateData,
228 IDirect3DIndexBuffer9Impl_FreePrivateData,
229 IDirect3DIndexBuffer9Impl_SetPriority,
230 IDirect3DIndexBuffer9Impl_GetPriority,
231 IDirect3DIndexBuffer9Impl_PreLoad,
232 IDirect3DIndexBuffer9Impl_GetType,
233 /* IDirect3DIndexBuffer9 */
234 IDirect3DIndexBuffer9Impl_Lock,
235 IDirect3DIndexBuffer9Impl_Unlock,
236 IDirect3DIndexBuffer9Impl_GetDesc
239 static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
241 HeapFree(GetProcessHeap(), 0, parent);
244 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
246 d3d9_indexbuffer_wined3d_object_destroyed,
249 HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
250 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
254 buffer->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
256 buffer->format = wined3dformat_from_d3dformat(format);
258 wined3d_mutex_lock();
259 hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
260 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
261 (IUnknown *)buffer, &d3d9_indexbuffer_wined3d_parent_ops);
262 wined3d_mutex_unlock();
265 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
269 buffer->parentDevice = (IDirect3DDevice9Ex *)device;
270 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);