2 * IDirect3DIndexBuffer8 implementation
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DIndexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_QueryInterface(LPDIRECT3DINDEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource8)
34 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)) {
35 IUnknown_AddRef(iface);
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
45 static ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRef(LPDIRECT3DINDEXBUFFER8 iface) {
46 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("%p increasing refcount to %u.\n", iface, ref);
53 IDirect3DDevice8_AddRef(This->parentDevice);
55 IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
56 wined3d_mutex_unlock();
62 static ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface) {
63 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
66 TRACE("%p decreasing refcount to %u.\n", iface, ref);
69 IDirect3DDevice8 *parentDevice = This->parentDevice;
72 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
73 wined3d_mutex_unlock();
75 /* Release the device last, as it may cause the device to be destroyed. */
76 IDirect3DDevice8_Release(parentDevice);
81 /* IDirect3DIndexBuffer8 IDirect3DResource8 Interface follow: */
82 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
83 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
84 IWineD3DDevice *wined3d_device;
87 TRACE("iface %p, device %p.\n", iface, ppDevice);
90 hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
93 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
94 IWineD3DDevice_Release(wined3d_device);
96 wined3d_mutex_unlock();
101 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
102 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
105 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
106 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
108 wined3d_mutex_lock();
109 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
110 wined3d_mutex_unlock();
115 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
116 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
119 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
120 iface, debugstr_guid(refguid), pData, pSizeOfData);
122 wined3d_mutex_lock();
123 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
124 wined3d_mutex_unlock();
129 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid) {
130 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
133 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
135 wined3d_mutex_lock();
136 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
137 wined3d_mutex_unlock();
142 static DWORD WINAPI IDirect3DIndexBuffer8Impl_SetPriority(LPDIRECT3DINDEXBUFFER8 iface, DWORD PriorityNew) {
143 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
146 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
148 wined3d_mutex_lock();
149 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
150 wined3d_mutex_unlock();
155 static DWORD WINAPI IDirect3DIndexBuffer8Impl_GetPriority(LPDIRECT3DINDEXBUFFER8 iface) {
156 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
159 TRACE("iface %p.\n", iface);
161 wined3d_mutex_lock();
162 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
163 wined3d_mutex_unlock();
168 static void WINAPI IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface) {
169 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
171 TRACE("iface %p.\n", iface);
173 wined3d_mutex_lock();
174 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
175 wined3d_mutex_unlock();
178 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(IDirect3DIndexBuffer8 *iface)
180 TRACE("iface %p.\n", iface);
182 return D3DRTYPE_INDEXBUFFER;
185 /* IDirect3DIndexBuffer8 Interface follow: */
186 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Lock(LPDIRECT3DINDEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
187 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
190 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
191 iface, OffsetToLock, SizeToLock, ppbData, Flags);
193 wined3d_mutex_lock();
194 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
195 wined3d_mutex_unlock();
200 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface) {
201 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
204 TRACE("iface %p.\n", iface);
206 wined3d_mutex_lock();
207 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
208 wined3d_mutex_unlock();
213 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface, D3DINDEXBUFFER_DESC *pDesc) {
214 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
216 WINED3DBUFFER_DESC desc;
218 TRACE("iface %p, desc %p.\n", iface, pDesc);
220 wined3d_mutex_lock();
221 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
222 wined3d_mutex_unlock();
225 pDesc->Format = d3dformat_from_wined3dformat(This->format);
226 pDesc->Type = D3DRTYPE_INDEXBUFFER;
227 pDesc->Usage = desc.Usage;
228 pDesc->Pool = desc.Pool;
229 pDesc->Size = desc.Size;
235 static const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
238 IDirect3DIndexBuffer8Impl_QueryInterface,
239 IDirect3DIndexBuffer8Impl_AddRef,
240 IDirect3DIndexBuffer8Impl_Release,
241 /* IDirect3DResource8 */
242 IDirect3DIndexBuffer8Impl_GetDevice,
243 IDirect3DIndexBuffer8Impl_SetPrivateData,
244 IDirect3DIndexBuffer8Impl_GetPrivateData,
245 IDirect3DIndexBuffer8Impl_FreePrivateData,
246 IDirect3DIndexBuffer8Impl_SetPriority,
247 IDirect3DIndexBuffer8Impl_GetPriority,
248 IDirect3DIndexBuffer8Impl_PreLoad,
249 IDirect3DIndexBuffer8Impl_GetType,
250 /* IDirect3DIndexBuffer8 */
251 IDirect3DIndexBuffer8Impl_Lock,
252 IDirect3DIndexBuffer8Impl_Unlock,
253 IDirect3DIndexBuffer8Impl_GetDesc
256 static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
258 HeapFree(GetProcessHeap(), 0, parent);
261 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
263 d3d8_indexbuffer_wined3d_object_destroyed,
266 HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
267 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
271 buffer->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
273 buffer->format = wined3dformat_from_d3dformat(format);
275 wined3d_mutex_lock();
276 hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
277 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
278 (IUnknown *)buffer, &d3d8_indexbuffer_wined3d_parent_ops);
279 wined3d_mutex_unlock();
282 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
286 buffer->parentDevice = (IDirect3DDevice8 *)device;
287 IUnknown_AddRef(buffer->parentDevice);