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 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
33 if (IsEqualGUID(riid
, &IID_IUnknown
)
34 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
35 || IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer9
)) {
36 IDirect3DIndexBuffer9_AddRef(iface
);
41 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
46 static ULONG WINAPI
IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface
) {
47 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
48 ULONG ref
= InterlockedIncrement(&This
->ref
);
50 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
54 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
56 IWineD3DBuffer_AddRef(This
->wineD3DIndexBuffer
);
57 wined3d_mutex_unlock();
63 static ULONG WINAPI
IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface
) {
64 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
65 ULONG ref
= InterlockedDecrement(&This
->ref
);
67 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
70 IDirect3DDevice9Ex
*parentDevice
= This
->parentDevice
;
73 IWineD3DBuffer_Release(This
->wineD3DIndexBuffer
);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice9Ex_Release(parentDevice
);
82 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
83 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetDevice(IDirect3DIndexBuffer9
*iface
, IDirect3DDevice9
**device
)
85 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
87 TRACE("iface %p, device %p.\n", iface
, device
);
89 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
90 IDirect3DDevice9_AddRef(*device
);
92 TRACE("Returning device %p.\n", *device
);
97 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
98 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
101 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
102 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
104 wined3d_mutex_lock();
105 hr
= IWineD3DBuffer_SetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, SizeOfData
, Flags
);
106 wined3d_mutex_unlock();
111 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
112 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
115 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
116 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
118 wined3d_mutex_lock();
119 hr
= IWineD3DBuffer_GetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, pSizeOfData
);
120 wined3d_mutex_unlock();
125 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
) {
126 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
129 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
131 wined3d_mutex_lock();
132 hr
= IWineD3DBuffer_FreePrivateData(This
->wineD3DIndexBuffer
, refguid
);
133 wined3d_mutex_unlock();
138 static DWORD WINAPI
IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface
, DWORD PriorityNew
) {
139 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
142 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
144 wined3d_mutex_lock();
145 ret
= IWineD3DBuffer_SetPriority(This
->wineD3DIndexBuffer
, PriorityNew
);
146 wined3d_mutex_unlock();
151 static DWORD WINAPI
IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface
) {
152 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
155 TRACE("iface %p.\n", iface
);
157 wined3d_mutex_lock();
158 ret
= IWineD3DBuffer_GetPriority(This
->wineD3DIndexBuffer
);
159 wined3d_mutex_unlock();
164 static void WINAPI
IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface
) {
165 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
167 TRACE("iface %p.\n", iface
);
169 wined3d_mutex_lock();
170 IWineD3DBuffer_PreLoad(This
->wineD3DIndexBuffer
);
171 wined3d_mutex_unlock();
174 static D3DRESOURCETYPE WINAPI
IDirect3DIndexBuffer9Impl_GetType(IDirect3DIndexBuffer9
*iface
)
176 TRACE("iface %p.\n", iface
);
178 return D3DRTYPE_INDEXBUFFER
;
181 /* IDirect3DIndexBuffer9 Interface follow: */
182 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface
, UINT OffsetToLock
, UINT SizeToLock
, void** ppbData
, DWORD Flags
) {
183 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
186 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
187 iface
, OffsetToLock
, SizeToLock
, ppbData
, Flags
);
189 wined3d_mutex_lock();
190 hr
= IWineD3DBuffer_Map(This
->wineD3DIndexBuffer
, OffsetToLock
, SizeToLock
, (BYTE
**)ppbData
, Flags
);
191 wined3d_mutex_unlock();
196 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface
) {
197 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
200 TRACE("iface %p.\n", iface
);
202 wined3d_mutex_lock();
203 hr
= IWineD3DBuffer_Unmap(This
->wineD3DIndexBuffer
);
204 wined3d_mutex_unlock();
209 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface
, D3DINDEXBUFFER_DESC
*pDesc
) {
210 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
212 WINED3DBUFFER_DESC desc
;
214 TRACE("iface %p, desc %p.\n", iface
, pDesc
);
216 wined3d_mutex_lock();
217 hr
= IWineD3DBuffer_GetDesc(This
->wineD3DIndexBuffer
, &desc
);
218 wined3d_mutex_unlock();
221 pDesc
->Format
= d3dformat_from_wined3dformat(This
->format
);
222 pDesc
->Usage
= desc
.Usage
;
223 pDesc
->Pool
= desc
.Pool
;
224 pDesc
->Size
= desc
.Size
;
225 pDesc
->Type
= D3DRTYPE_INDEXBUFFER
;
232 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl
=
235 IDirect3DIndexBuffer9Impl_QueryInterface
,
236 IDirect3DIndexBuffer9Impl_AddRef
,
237 IDirect3DIndexBuffer9Impl_Release
,
238 /* IDirect3DResource9 */
239 IDirect3DIndexBuffer9Impl_GetDevice
,
240 IDirect3DIndexBuffer9Impl_SetPrivateData
,
241 IDirect3DIndexBuffer9Impl_GetPrivateData
,
242 IDirect3DIndexBuffer9Impl_FreePrivateData
,
243 IDirect3DIndexBuffer9Impl_SetPriority
,
244 IDirect3DIndexBuffer9Impl_GetPriority
,
245 IDirect3DIndexBuffer9Impl_PreLoad
,
246 IDirect3DIndexBuffer9Impl_GetType
,
247 /* IDirect3DIndexBuffer9 */
248 IDirect3DIndexBuffer9Impl_Lock
,
249 IDirect3DIndexBuffer9Impl_Unlock
,
250 IDirect3DIndexBuffer9Impl_GetDesc
253 static void STDMETHODCALLTYPE
d3d9_indexbuffer_wined3d_object_destroyed(void *parent
)
255 HeapFree(GetProcessHeap(), 0, parent
);
258 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops
=
260 d3d9_indexbuffer_wined3d_object_destroyed
,
263 HRESULT
indexbuffer_init(IDirect3DIndexBuffer9Impl
*buffer
, IDirect3DDevice9Impl
*device
,
264 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
268 buffer
->lpVtbl
= &Direct3DIndexBuffer9_Vtbl
;
270 buffer
->format
= wined3dformat_from_d3dformat(format
);
272 wined3d_mutex_lock();
273 hr
= IWineD3DDevice_CreateIndexBuffer(device
->WineD3DDevice
, size
,
274 usage
& WINED3DUSAGE_MASK
, (WINED3DPOOL
)pool
, &buffer
->wineD3DIndexBuffer
,
275 (IUnknown
*)buffer
, &d3d9_indexbuffer_wined3d_parent_ops
);
276 wined3d_mutex_unlock();
279 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
283 buffer
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
284 IDirect3DDevice9Ex_AddRef(buffer
->parentDevice
);