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(LPDIRECT3DINDEXBUFFER9 iface
, IDirect3DDevice9
** ppDevice
) {
84 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
85 IWineD3DDevice
*wined3d_device
;
88 TRACE("iface %p, device %p.\n", iface
, ppDevice
);
91 hr
= IWineD3DBuffer_GetDevice(This
->wineD3DIndexBuffer
, &wined3d_device
);
94 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
95 IWineD3DDevice_Release(wined3d_device
);
97 wined3d_mutex_unlock();
102 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
103 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
106 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
107 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
109 wined3d_mutex_lock();
110 hr
= IWineD3DBuffer_SetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, SizeOfData
, Flags
);
111 wined3d_mutex_unlock();
116 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
117 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
120 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
121 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
123 wined3d_mutex_lock();
124 hr
= IWineD3DBuffer_GetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, pSizeOfData
);
125 wined3d_mutex_unlock();
130 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
) {
131 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
134 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
136 wined3d_mutex_lock();
137 hr
= IWineD3DBuffer_FreePrivateData(This
->wineD3DIndexBuffer
, refguid
);
138 wined3d_mutex_unlock();
143 static DWORD WINAPI
IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface
, DWORD PriorityNew
) {
144 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
147 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
149 wined3d_mutex_lock();
150 ret
= IWineD3DBuffer_SetPriority(This
->wineD3DIndexBuffer
, PriorityNew
);
151 wined3d_mutex_unlock();
156 static DWORD WINAPI
IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface
) {
157 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
160 TRACE("iface %p.\n", iface
);
162 wined3d_mutex_lock();
163 ret
= IWineD3DBuffer_GetPriority(This
->wineD3DIndexBuffer
);
164 wined3d_mutex_unlock();
169 static void WINAPI
IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface
) {
170 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
172 TRACE("iface %p.\n", iface
);
174 wined3d_mutex_lock();
175 IWineD3DBuffer_PreLoad(This
->wineD3DIndexBuffer
);
176 wined3d_mutex_unlock();
179 static D3DRESOURCETYPE WINAPI
IDirect3DIndexBuffer9Impl_GetType(IDirect3DIndexBuffer9
*iface
)
181 TRACE("iface %p.\n", iface
);
183 return D3DRTYPE_INDEXBUFFER
;
186 /* IDirect3DIndexBuffer9 Interface follow: */
187 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface
, UINT OffsetToLock
, UINT SizeToLock
, void** ppbData
, DWORD Flags
) {
188 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
191 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
192 iface
, OffsetToLock
, SizeToLock
, ppbData
, Flags
);
194 wined3d_mutex_lock();
195 hr
= IWineD3DBuffer_Map(This
->wineD3DIndexBuffer
, OffsetToLock
, SizeToLock
, (BYTE
**)ppbData
, Flags
);
196 wined3d_mutex_unlock();
201 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface
) {
202 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
205 TRACE("iface %p.\n", iface
);
207 wined3d_mutex_lock();
208 hr
= IWineD3DBuffer_Unmap(This
->wineD3DIndexBuffer
);
209 wined3d_mutex_unlock();
214 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface
, D3DINDEXBUFFER_DESC
*pDesc
) {
215 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
217 WINED3DBUFFER_DESC desc
;
219 TRACE("iface %p, desc %p.\n", iface
, pDesc
);
221 wined3d_mutex_lock();
222 hr
= IWineD3DBuffer_GetDesc(This
->wineD3DIndexBuffer
, &desc
);
223 wined3d_mutex_unlock();
226 pDesc
->Format
= d3dformat_from_wined3dformat(This
->format
);
227 pDesc
->Usage
= desc
.Usage
;
228 pDesc
->Pool
= desc
.Pool
;
229 pDesc
->Size
= desc
.Size
;
230 pDesc
->Type
= D3DRTYPE_INDEXBUFFER
;
237 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl
=
240 IDirect3DIndexBuffer9Impl_QueryInterface
,
241 IDirect3DIndexBuffer9Impl_AddRef
,
242 IDirect3DIndexBuffer9Impl_Release
,
243 /* IDirect3DResource9 */
244 IDirect3DIndexBuffer9Impl_GetDevice
,
245 IDirect3DIndexBuffer9Impl_SetPrivateData
,
246 IDirect3DIndexBuffer9Impl_GetPrivateData
,
247 IDirect3DIndexBuffer9Impl_FreePrivateData
,
248 IDirect3DIndexBuffer9Impl_SetPriority
,
249 IDirect3DIndexBuffer9Impl_GetPriority
,
250 IDirect3DIndexBuffer9Impl_PreLoad
,
251 IDirect3DIndexBuffer9Impl_GetType
,
252 /* IDirect3DIndexBuffer9 */
253 IDirect3DIndexBuffer9Impl_Lock
,
254 IDirect3DIndexBuffer9Impl_Unlock
,
255 IDirect3DIndexBuffer9Impl_GetDesc
258 static void STDMETHODCALLTYPE
d3d9_indexbuffer_wined3d_object_destroyed(void *parent
)
260 HeapFree(GetProcessHeap(), 0, parent
);
263 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops
=
265 d3d9_indexbuffer_wined3d_object_destroyed
,
268 HRESULT
indexbuffer_init(IDirect3DIndexBuffer9Impl
*buffer
, IDirect3DDevice9Impl
*device
,
269 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
273 buffer
->lpVtbl
= &Direct3DIndexBuffer9_Vtbl
;
275 buffer
->format
= wined3dformat_from_d3dformat(format
);
277 wined3d_mutex_lock();
278 hr
= IWineD3DDevice_CreateIndexBuffer(device
->WineD3DDevice
, size
,
279 usage
& WINED3DUSAGE_MASK
, (WINED3DPOOL
)pool
, &buffer
->wineD3DIndexBuffer
,
280 (IUnknown
*)buffer
, &d3d9_indexbuffer_wined3d_parent_ops
);
281 wined3d_mutex_unlock();
284 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
288 buffer
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
289 IDirect3DDevice9Ex_AddRef(buffer
->parentDevice
);