2 * Copyright 2002-2004 Jason Edmeades
3 * Copyright 2002-2004 Raphael Junqueira
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 "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
26 static HRESULT WINAPI
d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9
*iface
, REFIID riid
, void **object
)
28 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
30 if (IsEqualGUID(riid
, &IID_IDirect3DVertexBuffer9
)
31 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
32 || IsEqualGUID(riid
, &IID_IUnknown
))
34 IDirect3DVertexBuffer9_AddRef(iface
);
39 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
45 static ULONG WINAPI
d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9
*iface
)
47 IDirect3DVertexBuffer9Impl
*buffer
= (IDirect3DVertexBuffer9Impl
*)iface
;
48 ULONG refcount
= InterlockedIncrement(&buffer
->ref
);
50 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
54 IDirect3DDevice9Ex_AddRef(buffer
->parentDevice
);
56 IWineD3DBuffer_AddRef(buffer
->wineD3DVertexBuffer
);
57 wined3d_mutex_unlock();
63 static ULONG WINAPI
d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9
*iface
)
65 IDirect3DVertexBuffer9Impl
*buffer
= (IDirect3DVertexBuffer9Impl
*)iface
;
66 ULONG refcount
= InterlockedDecrement(&buffer
->ref
);
68 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
72 IDirect3DDevice9Ex
*device
= buffer
->parentDevice
;
75 IWineD3DBuffer_Release(buffer
->wineD3DVertexBuffer
);
76 wined3d_mutex_unlock();
78 /* Release the device last, as it may cause the device to be destroyed. */
79 IDirect3DDevice9Ex_Release(device
);
85 static HRESULT WINAPI
d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9
*iface
, IDirect3DDevice9
**device
)
87 TRACE("iface %p, device %p.\n", iface
, device
);
89 *device
= (IDirect3DDevice9
*)((IDirect3DVertexBuffer9Impl
*)iface
)->parentDevice
;
90 IDirect3DDevice9_AddRef(*device
);
92 TRACE("Returning device %p.\n", *device
);
97 static HRESULT WINAPI
d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9
*iface
,
98 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
102 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
103 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
105 wined3d_mutex_lock();
106 hr
= IWineD3DBuffer_SetPrivateData(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
,
107 guid
, data
, data_size
, flags
);
108 wined3d_mutex_unlock();
113 static HRESULT WINAPI
d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9
*iface
,
114 REFGUID guid
, void *data
, DWORD
*data_size
)
118 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
119 iface
, debugstr_guid(guid
), data
, data_size
);
121 wined3d_mutex_lock();
122 hr
= IWineD3DBuffer_GetPrivateData(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
,
123 guid
, data
, data_size
);
124 wined3d_mutex_unlock();
129 static HRESULT WINAPI
d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9
*iface
, REFGUID guid
)
133 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
135 wined3d_mutex_lock();
136 hr
= IWineD3DBuffer_FreePrivateData(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
, guid
);
137 wined3d_mutex_unlock();
142 static DWORD WINAPI
d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9
*iface
, DWORD priority
)
146 TRACE("iface %p, priority %u.\n", iface
, priority
);
148 wined3d_mutex_lock();
149 previous
= IWineD3DBuffer_SetPriority(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
, priority
);
150 wined3d_mutex_unlock();
155 static DWORD WINAPI
d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9
*iface
)
159 TRACE("iface %p.\n", iface
);
161 wined3d_mutex_lock();
162 priority
= IWineD3DBuffer_GetPriority(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
);
163 wined3d_mutex_unlock();
168 static void WINAPI
d3d9_vertexbuffer_PreLoad(IDirect3DVertexBuffer9
*iface
)
170 TRACE("iface %p.\n", iface
);
172 wined3d_mutex_lock();
173 IWineD3DBuffer_PreLoad(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
);
174 wined3d_mutex_unlock();
177 static D3DRESOURCETYPE WINAPI
d3d9_vertexbuffer_GetType(IDirect3DVertexBuffer9
*iface
)
179 TRACE("iface %p.\n", iface
);
181 return D3DRTYPE_VERTEXBUFFER
;
184 static HRESULT WINAPI
d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9
*iface
,
185 UINT offset
, UINT size
, void **data
, DWORD flags
)
189 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
190 iface
, offset
, size
, data
, flags
);
192 wined3d_mutex_lock();
193 hr
= IWineD3DBuffer_Map(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
,
194 offset
, size
, (BYTE
**)data
, flags
);
195 wined3d_mutex_unlock();
200 static HRESULT WINAPI
d3d9_vertexbuffer_Unlock(IDirect3DVertexBuffer9
*iface
)
202 TRACE("iface %p.\n", iface
);
204 wined3d_mutex_lock();
205 IWineD3DBuffer_Unmap(((IDirect3DVertexBuffer9Impl
*)iface
)->wineD3DVertexBuffer
);
206 wined3d_mutex_unlock();
211 static HRESULT WINAPI
d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9
*iface
, D3DVERTEXBUFFER_DESC
*desc
)
213 IDirect3DVertexBuffer9Impl
*buffer
= (IDirect3DVertexBuffer9Impl
*)iface
;
214 WINED3DBUFFER_DESC wined3d_desc
;
216 TRACE("iface %p, desc %p.\n", iface
, desc
);
218 wined3d_mutex_lock();
219 IWineD3DBuffer_GetDesc(buffer
->wineD3DVertexBuffer
, &wined3d_desc
);
220 wined3d_mutex_unlock();
222 desc
->Format
= D3DFMT_VERTEXDATA
;
223 desc
->Usage
= wined3d_desc
.Usage
;
224 desc
->Pool
= wined3d_desc
.Pool
;
225 desc
->Size
= wined3d_desc
.Size
;
226 desc
->Type
= D3DRTYPE_VERTEXBUFFER
;
227 desc
->FVF
= buffer
->fvf
;
232 static const IDirect3DVertexBuffer9Vtbl d3d9_vertexbuffer_vtbl
=
235 d3d9_vertexbuffer_QueryInterface
,
236 d3d9_vertexbuffer_AddRef
,
237 d3d9_vertexbuffer_Release
,
238 /* IDirect3DResource9 */
239 d3d9_vertexbuffer_GetDevice
,
240 d3d9_vertexbuffer_SetPrivateData
,
241 d3d9_vertexbuffer_GetPrivateData
,
242 d3d9_vertexbuffer_FreePrivateData
,
243 d3d9_vertexbuffer_SetPriority
,
244 d3d9_vertexbuffer_GetPriority
,
245 d3d9_vertexbuffer_PreLoad
,
246 d3d9_vertexbuffer_GetType
,
247 /* IDirect3DVertexBuffer9 */
248 d3d9_vertexbuffer_Lock
,
249 d3d9_vertexbuffer_Unlock
,
250 d3d9_vertexbuffer_GetDesc
,
253 static void STDMETHODCALLTYPE
d3d9_vertexbuffer_wined3d_object_destroyed(void *parent
)
255 HeapFree(GetProcessHeap(), 0, parent
);
258 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops
=
260 d3d9_vertexbuffer_wined3d_object_destroyed
,
263 HRESULT
vertexbuffer_init(IDirect3DVertexBuffer9Impl
*buffer
, IDirect3DDevice9Impl
*device
,
264 UINT size
, UINT usage
, DWORD fvf
, D3DPOOL pool
)
268 buffer
->lpVtbl
= &d3d9_vertexbuffer_vtbl
;
272 wined3d_mutex_lock();
273 hr
= IWineD3DDevice_CreateVertexBuffer(device
->WineD3DDevice
, size
, usage
& WINED3DUSAGE_MASK
,
274 (WINED3DPOOL
)pool
, buffer
, &d3d9_vertexbuffer_wined3d_parent_ops
, &buffer
->wineD3DVertexBuffer
);
275 wined3d_mutex_unlock();
278 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
282 buffer
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
283 IDirect3DDevice9Ex_AddRef(buffer
->parentDevice
);
288 static HRESULT WINAPI
d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9
*iface
, REFIID riid
, void **object
)
290 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
292 if (IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer9
)
293 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
294 || IsEqualGUID(riid
, &IID_IUnknown
))
296 IDirect3DIndexBuffer9_AddRef(iface
);
301 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
304 return E_NOINTERFACE
;
307 static ULONG WINAPI
d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9
*iface
)
309 IDirect3DIndexBuffer9Impl
*buffer
= (IDirect3DIndexBuffer9Impl
*)iface
;
310 ULONG refcount
= InterlockedIncrement(&buffer
->ref
);
312 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
316 IDirect3DDevice9Ex_AddRef(buffer
->parentDevice
);
317 wined3d_mutex_lock();
318 IWineD3DBuffer_AddRef(buffer
->wineD3DIndexBuffer
);
319 wined3d_mutex_unlock();
325 static ULONG WINAPI
d3d9_indexbuffer_Release(IDirect3DIndexBuffer9
*iface
)
327 IDirect3DIndexBuffer9Impl
*buffer
= (IDirect3DIndexBuffer9Impl
*)iface
;
328 ULONG refcount
= InterlockedDecrement(&buffer
->ref
);
330 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
334 IDirect3DDevice9Ex
*device
= buffer
->parentDevice
;
336 wined3d_mutex_lock();
337 IWineD3DBuffer_Release(buffer
->wineD3DIndexBuffer
);
338 wined3d_mutex_unlock();
340 /* Release the device last, as it may cause the device to be destroyed. */
341 IDirect3DDevice9Ex_Release(device
);
347 static HRESULT WINAPI
d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9
*iface
, IDirect3DDevice9
**device
)
349 TRACE("iface %p, device %p.\n", iface
, device
);
351 *device
= (IDirect3DDevice9
*)((IDirect3DIndexBuffer9Impl
*)iface
)->parentDevice
;
352 IDirect3DDevice9_AddRef(*device
);
354 TRACE("Returning device %p.\n", *device
);
359 static HRESULT WINAPI
d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9
*iface
,
360 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
364 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
365 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
367 wined3d_mutex_lock();
368 hr
= IWineD3DBuffer_SetPrivateData(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
,
369 guid
, data
, data_size
, flags
);
370 wined3d_mutex_unlock();
375 static HRESULT WINAPI
d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9
*iface
,
376 REFGUID guid
, void *data
, DWORD
*data_size
)
380 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
381 iface
, debugstr_guid(guid
), data
, data_size
);
383 wined3d_mutex_lock();
384 hr
= IWineD3DBuffer_GetPrivateData(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
,
385 guid
, data
, data_size
);
386 wined3d_mutex_unlock();
391 static HRESULT WINAPI
d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9
*iface
, REFGUID guid
)
395 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
397 wined3d_mutex_lock();
398 hr
= IWineD3DBuffer_FreePrivateData(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
, guid
);
399 wined3d_mutex_unlock();
404 static DWORD WINAPI
d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9
*iface
, DWORD priority
)
408 TRACE("iface %p, priority %u.\n", iface
, priority
);
410 wined3d_mutex_lock();
411 previous
= IWineD3DBuffer_SetPriority(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
, priority
);
412 wined3d_mutex_unlock();
417 static DWORD WINAPI
d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9
*iface
)
421 TRACE("iface %p.\n", iface
);
423 wined3d_mutex_lock();
424 priority
= IWineD3DBuffer_GetPriority(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
);
425 wined3d_mutex_unlock();
430 static void WINAPI
d3d9_indexbuffer_PreLoad(IDirect3DIndexBuffer9
*iface
)
432 TRACE("iface %p.\n", iface
);
434 wined3d_mutex_lock();
435 IWineD3DBuffer_PreLoad(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
);
436 wined3d_mutex_unlock();
439 static D3DRESOURCETYPE WINAPI
d3d9_indexbuffer_GetType(IDirect3DIndexBuffer9
*iface
)
441 TRACE("iface %p.\n", iface
);
443 return D3DRTYPE_INDEXBUFFER
;
446 static HRESULT WINAPI
d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9
*iface
,
447 UINT offset
, UINT size
, void **data
, DWORD flags
)
451 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
452 iface
, offset
, size
, data
, flags
);
454 wined3d_mutex_lock();
455 hr
= IWineD3DBuffer_Map(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
,
456 offset
, size
, (BYTE
**)data
, flags
);
457 wined3d_mutex_unlock();
462 static HRESULT WINAPI
d3d9_indexbuffer_Unlock(IDirect3DIndexBuffer9
*iface
)
464 TRACE("iface %p.\n", iface
);
466 wined3d_mutex_lock();
467 IWineD3DBuffer_Unmap(((IDirect3DIndexBuffer9Impl
*)iface
)->wineD3DIndexBuffer
);
468 wined3d_mutex_unlock();
473 static HRESULT WINAPI
d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9
*iface
, D3DINDEXBUFFER_DESC
*desc
)
475 IDirect3DIndexBuffer9Impl
*buffer
= (IDirect3DIndexBuffer9Impl
*)iface
;
476 WINED3DBUFFER_DESC wined3d_desc
;
478 TRACE("iface %p, desc %p.\n", iface
, desc
);
480 wined3d_mutex_lock();
481 IWineD3DBuffer_GetDesc(buffer
->wineD3DIndexBuffer
, &wined3d_desc
);
482 wined3d_mutex_unlock();
484 desc
->Format
= d3dformat_from_wined3dformat(buffer
->format
);
485 desc
->Usage
= wined3d_desc
.Usage
;
486 desc
->Pool
= wined3d_desc
.Pool
;
487 desc
->Size
= wined3d_desc
.Size
;
488 desc
->Type
= D3DRTYPE_INDEXBUFFER
;
493 static const IDirect3DIndexBuffer9Vtbl d3d9_indexbuffer_vtbl
=
496 d3d9_indexbuffer_QueryInterface
,
497 d3d9_indexbuffer_AddRef
,
498 d3d9_indexbuffer_Release
,
499 /* IDirect3DResource9 */
500 d3d9_indexbuffer_GetDevice
,
501 d3d9_indexbuffer_SetPrivateData
,
502 d3d9_indexbuffer_GetPrivateData
,
503 d3d9_indexbuffer_FreePrivateData
,
504 d3d9_indexbuffer_SetPriority
,
505 d3d9_indexbuffer_GetPriority
,
506 d3d9_indexbuffer_PreLoad
,
507 d3d9_indexbuffer_GetType
,
508 /* IDirect3DIndexBuffer9 */
509 d3d9_indexbuffer_Lock
,
510 d3d9_indexbuffer_Unlock
,
511 d3d9_indexbuffer_GetDesc
,
514 static void STDMETHODCALLTYPE
d3d9_indexbuffer_wined3d_object_destroyed(void *parent
)
516 HeapFree(GetProcessHeap(), 0, parent
);
519 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops
=
521 d3d9_indexbuffer_wined3d_object_destroyed
,
524 HRESULT
indexbuffer_init(IDirect3DIndexBuffer9Impl
*buffer
, IDirect3DDevice9Impl
*device
,
525 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
529 buffer
->lpVtbl
= &d3d9_indexbuffer_vtbl
;
531 buffer
->format
= wined3dformat_from_d3dformat(format
);
533 wined3d_mutex_lock();
534 hr
= IWineD3DDevice_CreateIndexBuffer(device
->WineD3DDevice
, size
, usage
& WINED3DUSAGE_MASK
,
535 (WINED3DPOOL
)pool
, buffer
, &d3d9_indexbuffer_wined3d_parent_ops
, &buffer
->wineD3DIndexBuffer
);
536 wined3d_mutex_unlock();
539 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
543 buffer
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
544 IDirect3DDevice9Ex_AddRef(buffer
->parentDevice
);