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 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)) {
33 IUnknown_AddRef(iface);
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43 static ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRef(LPDIRECT3DINDEXBUFFER8 iface) {
44 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
45 ULONG ref = InterlockedIncrement(&This->ref);
47 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
51 IDirect3DDevice8_AddRef(This->parentDevice);
53 IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
54 wined3d_mutex_unlock();
60 static ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface) {
61 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
62 ULONG ref = InterlockedDecrement(&This->ref);
64 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
67 IDirect3DDevice8 *parentDevice = This->parentDevice;
70 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
71 wined3d_mutex_unlock();
73 /* Release the device last, as it may cause the device to be destroyed. */
74 IDirect3DDevice8_Release(parentDevice);
79 /* IDirect3DIndexBuffer8 IDirect3DResource8 Interface follow: */
80 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
81 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
82 IWineD3DDevice *wined3d_device;
84 TRACE("(%p) Relay\n", This);
87 hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
90 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
91 IWineD3DDevice_Release(wined3d_device);
93 wined3d_mutex_unlock();
98 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
99 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
101 TRACE("(%p) Relay\n", This);
103 wined3d_mutex_lock();
104 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
105 wined3d_mutex_unlock();
110 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
111 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
113 TRACE("(%p) Relay\n", This);
115 wined3d_mutex_lock();
116 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
117 wined3d_mutex_unlock();
122 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid) {
123 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
125 TRACE("(%p) Relay\n", This);
127 wined3d_mutex_lock();
128 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
129 wined3d_mutex_unlock();
134 static DWORD WINAPI IDirect3DIndexBuffer8Impl_SetPriority(LPDIRECT3DINDEXBUFFER8 iface, DWORD PriorityNew) {
135 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
137 TRACE("(%p) Relay\n", This);
139 wined3d_mutex_lock();
140 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
141 wined3d_mutex_unlock();
146 static DWORD WINAPI IDirect3DIndexBuffer8Impl_GetPriority(LPDIRECT3DINDEXBUFFER8 iface) {
147 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
149 TRACE("(%p) Relay\n", This);
151 wined3d_mutex_lock();
152 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
153 wined3d_mutex_unlock();
158 static void WINAPI IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface) {
159 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
160 TRACE("(%p) Relay\n", This);
162 wined3d_mutex_lock();
163 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
164 wined3d_mutex_unlock();
167 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(LPDIRECT3DINDEXBUFFER8 iface) {
168 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
169 TRACE("(%p)\n", This);
171 return D3DRTYPE_INDEXBUFFER;
174 /* IDirect3DIndexBuffer8 Interface follow: */
175 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Lock(LPDIRECT3DINDEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
176 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
178 TRACE("(%p) Relay\n", This);
180 wined3d_mutex_lock();
181 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
182 wined3d_mutex_unlock();
187 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface) {
188 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
190 TRACE("(%p) Relay\n", This);
192 wined3d_mutex_lock();
193 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
194 wined3d_mutex_unlock();
199 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface, D3DINDEXBUFFER_DESC *pDesc) {
200 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
202 WINED3DBUFFER_DESC desc;
203 TRACE("(%p) Relay\n", This);
205 wined3d_mutex_lock();
206 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
207 wined3d_mutex_unlock();
210 pDesc->Format = d3dformat_from_wined3dformat(This->format);
211 pDesc->Type = D3DRTYPE_INDEXBUFFER;
212 pDesc->Usage = desc.Usage;
213 pDesc->Pool = desc.Pool;
214 pDesc->Size = desc.Size;
220 static const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
223 IDirect3DIndexBuffer8Impl_QueryInterface,
224 IDirect3DIndexBuffer8Impl_AddRef,
225 IDirect3DIndexBuffer8Impl_Release,
226 /* IDirect3DResource8 */
227 IDirect3DIndexBuffer8Impl_GetDevice,
228 IDirect3DIndexBuffer8Impl_SetPrivateData,
229 IDirect3DIndexBuffer8Impl_GetPrivateData,
230 IDirect3DIndexBuffer8Impl_FreePrivateData,
231 IDirect3DIndexBuffer8Impl_SetPriority,
232 IDirect3DIndexBuffer8Impl_GetPriority,
233 IDirect3DIndexBuffer8Impl_PreLoad,
234 IDirect3DIndexBuffer8Impl_GetType,
235 /* IDirect3DIndexBuffer8 */
236 IDirect3DIndexBuffer8Impl_Lock,
237 IDirect3DIndexBuffer8Impl_Unlock,
238 IDirect3DIndexBuffer8Impl_GetDesc
241 static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
243 HeapFree(GetProcessHeap(), 0, parent);
246 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
248 d3d8_indexbuffer_wined3d_object_destroyed,
251 HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
252 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
256 buffer->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
258 buffer->format = wined3dformat_from_d3dformat(format);
260 wined3d_mutex_lock();
261 hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
262 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
263 (IUnknown *)buffer, &d3d8_indexbuffer_wined3d_parent_ops);
264 wined3d_mutex_unlock();
267 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
271 buffer->parentDevice = (IDirect3DDevice8 *)device;
272 IUnknown_AddRef(buffer->parentDevice);