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(IDirect3DIndexBuffer8
*iface
, IDirect3DDevice8
**device
)
84 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
86 TRACE("iface %p, device %p.\n", iface
, device
);
88 *device
= (IDirect3DDevice8
*)This
->parentDevice
;
89 IDirect3DDevice8_AddRef(*device
);
91 TRACE("Returning device %p.\n", *device
);
96 static HRESULT WINAPI
IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
97 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
100 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
101 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
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
;
114 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
115 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
117 wined3d_mutex_lock();
118 hr
= IWineD3DBuffer_GetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, pSizeOfData
);
119 wined3d_mutex_unlock();
124 static HRESULT WINAPI
IDirect3DIndexBuffer8Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER8 iface
, REFGUID refguid
) {
125 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
128 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
130 wined3d_mutex_lock();
131 hr
= IWineD3DBuffer_FreePrivateData(This
->wineD3DIndexBuffer
, refguid
);
132 wined3d_mutex_unlock();
137 static DWORD WINAPI
IDirect3DIndexBuffer8Impl_SetPriority(LPDIRECT3DINDEXBUFFER8 iface
, DWORD PriorityNew
) {
138 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
141 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
143 wined3d_mutex_lock();
144 ret
= IWineD3DBuffer_SetPriority(This
->wineD3DIndexBuffer
, PriorityNew
);
145 wined3d_mutex_unlock();
150 static DWORD WINAPI
IDirect3DIndexBuffer8Impl_GetPriority(LPDIRECT3DINDEXBUFFER8 iface
) {
151 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
154 TRACE("iface %p.\n", iface
);
156 wined3d_mutex_lock();
157 ret
= IWineD3DBuffer_GetPriority(This
->wineD3DIndexBuffer
);
158 wined3d_mutex_unlock();
163 static void WINAPI
IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface
) {
164 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
166 TRACE("iface %p.\n", iface
);
168 wined3d_mutex_lock();
169 IWineD3DBuffer_PreLoad(This
->wineD3DIndexBuffer
);
170 wined3d_mutex_unlock();
173 static D3DRESOURCETYPE WINAPI
IDirect3DIndexBuffer8Impl_GetType(IDirect3DIndexBuffer8
*iface
)
175 TRACE("iface %p.\n", iface
);
177 return D3DRTYPE_INDEXBUFFER
;
180 /* IDirect3DIndexBuffer8 Interface follow: */
181 static HRESULT WINAPI
IDirect3DIndexBuffer8Impl_Lock(LPDIRECT3DINDEXBUFFER8 iface
, UINT OffsetToLock
, UINT SizeToLock
, BYTE
**ppbData
, DWORD Flags
) {
182 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
185 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
186 iface
, OffsetToLock
, SizeToLock
, ppbData
, Flags
);
188 wined3d_mutex_lock();
189 hr
= IWineD3DBuffer_Map(This
->wineD3DIndexBuffer
, OffsetToLock
, SizeToLock
, ppbData
, Flags
);
190 wined3d_mutex_unlock();
195 static HRESULT WINAPI
IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface
) {
196 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
199 TRACE("iface %p.\n", iface
);
201 wined3d_mutex_lock();
202 hr
= IWineD3DBuffer_Unmap(This
->wineD3DIndexBuffer
);
203 wined3d_mutex_unlock();
208 static HRESULT WINAPI
IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface
, D3DINDEXBUFFER_DESC
*pDesc
) {
209 IDirect3DIndexBuffer8Impl
*This
= (IDirect3DIndexBuffer8Impl
*)iface
;
211 WINED3DBUFFER_DESC desc
;
213 TRACE("iface %p, desc %p.\n", iface
, pDesc
);
215 wined3d_mutex_lock();
216 hr
= IWineD3DBuffer_GetDesc(This
->wineD3DIndexBuffer
, &desc
);
217 wined3d_mutex_unlock();
220 pDesc
->Format
= d3dformat_from_wined3dformat(This
->format
);
221 pDesc
->Type
= D3DRTYPE_INDEXBUFFER
;
222 pDesc
->Usage
= desc
.Usage
;
223 pDesc
->Pool
= desc
.Pool
;
224 pDesc
->Size
= desc
.Size
;
230 static const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl
=
233 IDirect3DIndexBuffer8Impl_QueryInterface
,
234 IDirect3DIndexBuffer8Impl_AddRef
,
235 IDirect3DIndexBuffer8Impl_Release
,
236 /* IDirect3DResource8 */
237 IDirect3DIndexBuffer8Impl_GetDevice
,
238 IDirect3DIndexBuffer8Impl_SetPrivateData
,
239 IDirect3DIndexBuffer8Impl_GetPrivateData
,
240 IDirect3DIndexBuffer8Impl_FreePrivateData
,
241 IDirect3DIndexBuffer8Impl_SetPriority
,
242 IDirect3DIndexBuffer8Impl_GetPriority
,
243 IDirect3DIndexBuffer8Impl_PreLoad
,
244 IDirect3DIndexBuffer8Impl_GetType
,
245 /* IDirect3DIndexBuffer8 */
246 IDirect3DIndexBuffer8Impl_Lock
,
247 IDirect3DIndexBuffer8Impl_Unlock
,
248 IDirect3DIndexBuffer8Impl_GetDesc
251 static void STDMETHODCALLTYPE
d3d8_indexbuffer_wined3d_object_destroyed(void *parent
)
253 HeapFree(GetProcessHeap(), 0, parent
);
256 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops
=
258 d3d8_indexbuffer_wined3d_object_destroyed
,
261 HRESULT
indexbuffer_init(IDirect3DIndexBuffer8Impl
*buffer
, IDirect3DDevice8Impl
*device
,
262 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
266 buffer
->lpVtbl
= &Direct3DIndexBuffer8_Vtbl
;
268 buffer
->format
= wined3dformat_from_d3dformat(format
);
270 wined3d_mutex_lock();
271 hr
= IWineD3DDevice_CreateIndexBuffer(device
->WineD3DDevice
, size
,
272 usage
& WINED3DUSAGE_MASK
, (WINED3DPOOL
)pool
, &buffer
->wineD3DIndexBuffer
,
273 (IUnknown
*)buffer
, &d3d8_indexbuffer_wined3d_parent_ops
);
274 wined3d_mutex_unlock();
277 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
281 buffer
->parentDevice
= (IDirect3DDevice8
*)device
;
282 IUnknown_AddRef(buffer
->parentDevice
);