2 * Copyright 2005 Oliver Stieber
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "d3d8_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
24 static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *iface, REFIID riid, void **object)
26 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
28 if (IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)
29 || IsEqualGUID(riid, &IID_IDirect3DResource8)
30 || IsEqualGUID(riid, &IID_IUnknown))
32 IUnknown_AddRef(iface);
37 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
43 static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
45 IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface;
46 ULONG refcount = InterlockedIncrement(&buffer->ref);
48 TRACE("%p increasing refcount to %u.\n", iface, refcount);
52 IDirect3DDevice8_AddRef(buffer->parentDevice);
54 wined3d_buffer_incref(buffer->wineD3DVertexBuffer);
55 wined3d_mutex_unlock();
61 static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
63 IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface;
64 ULONG refcount = InterlockedDecrement(&buffer->ref);
66 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
70 IDirect3DDevice8 *device = buffer->parentDevice;
73 wined3d_buffer_decref(buffer->wineD3DVertexBuffer);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice8_Release(device);
83 static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device)
85 TRACE("iface %p, device %p.\n", iface, device);
87 *device = (IDirect3DDevice8 *)((IDirect3DVertexBuffer8Impl *)iface)->parentDevice;
88 IDirect3DDevice8_AddRef(*device);
90 TRACE("Returning device %p.\n", *device);
95 static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *iface,
96 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
100 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
101 iface, debugstr_guid(guid), data, data_size, flags);
103 wined3d_mutex_lock();
104 hr = wined3d_buffer_set_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer,
105 guid, data, data_size, flags);
106 wined3d_mutex_unlock();
111 static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *iface,
112 REFGUID guid, void *data, DWORD *data_size)
116 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
117 iface, debugstr_guid(guid), data, data_size);
119 wined3d_mutex_lock();
120 hr = wined3d_buffer_get_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer,
121 guid, data, data_size);
122 wined3d_mutex_unlock();
127 static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid)
131 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
133 wined3d_mutex_lock();
134 hr = wined3d_buffer_free_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, guid);
135 wined3d_mutex_unlock();
140 static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, DWORD priority)
144 TRACE("iface %p, priority %u.\n", iface, priority);
146 wined3d_mutex_lock();
147 previous = wined3d_buffer_set_priority(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, priority);
148 wined3d_mutex_unlock();
153 static DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface)
157 TRACE("iface %p.\n", iface);
159 wined3d_mutex_lock();
160 priority = wined3d_buffer_get_priority(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer);
161 wined3d_mutex_unlock();
166 static void WINAPI d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8 *iface)
168 TRACE("iface %p.\n", iface);
170 wined3d_mutex_lock();
171 wined3d_buffer_preload(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer);
172 wined3d_mutex_unlock();
175 static D3DRESOURCETYPE WINAPI d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8 *iface)
177 TRACE("iface %p.\n", iface);
179 return D3DRTYPE_VERTEXBUFFER;
182 static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface,
183 UINT offset, UINT size, BYTE **data, DWORD flags)
187 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
188 iface, offset, size, data, flags);
190 wined3d_mutex_lock();
191 hr = wined3d_buffer_map(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer,
192 offset, size, data, flags);
193 wined3d_mutex_unlock();
198 static HRESULT WINAPI d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8 *iface)
200 TRACE("iface %p.\n", iface);
202 wined3d_mutex_lock();
203 wined3d_buffer_unmap(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer);
204 wined3d_mutex_unlock();
209 static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface, D3DVERTEXBUFFER_DESC *desc)
211 IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface;
212 struct wined3d_resource_desc wined3d_desc;
213 struct wined3d_resource *wined3d_resource;
215 TRACE("iface %p, desc %p.\n", iface, desc);
217 wined3d_mutex_lock();
218 wined3d_resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
219 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
220 wined3d_mutex_unlock();
222 desc->Type = D3DRTYPE_VERTEXBUFFER;
223 desc->Usage = wined3d_desc.usage;
224 desc->Pool = wined3d_desc.pool;
225 desc->Size = wined3d_desc.size;
226 desc->FVF = buffer->fvf;
227 desc->Format = D3DFMT_VERTEXDATA;
232 static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
235 d3d8_vertexbuffer_QueryInterface,
236 d3d8_vertexbuffer_AddRef,
237 d3d8_vertexbuffer_Release,
238 /* IDirect3DResource8 */
239 d3d8_vertexbuffer_GetDevice,
240 d3d8_vertexbuffer_SetPrivateData,
241 d3d8_vertexbuffer_GetPrivateData,
242 d3d8_vertexbuffer_FreePrivateData,
243 d3d8_vertexbuffer_SetPriority,
244 d3d8_vertexbuffer_GetPriority,
245 d3d8_vertexbuffer_PreLoad,
246 d3d8_vertexbuffer_GetType,
247 /* IDirect3DVertexBuffer8 */
248 d3d8_vertexbuffer_Lock,
249 d3d8_vertexbuffer_Unlock,
250 d3d8_vertexbuffer_GetDesc,
253 static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
255 HeapFree(GetProcessHeap(), 0, parent);
258 static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
260 d3d8_vertexbuffer_wined3d_object_destroyed,
263 HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
264 UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
268 buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
272 wined3d_mutex_lock();
273 hr = wined3d_buffer_create_vb(device->WineD3DDevice, size, usage & WINED3DUSAGE_MASK,
274 (WINED3DPOOL)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
275 wined3d_mutex_unlock();
278 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
282 buffer->parentDevice = &device->IDirect3DDevice8_iface;
283 IUnknown_AddRef(buffer->parentDevice);
288 static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *iface, REFIID riid, void **object)
290 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
292 if (IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)
293 || IsEqualGUID(riid, &IID_IDirect3DResource8)
294 || IsEqualGUID(riid, &IID_IUnknown))
296 IUnknown_AddRef(iface);
301 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
304 return E_NOINTERFACE;
307 static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
309 IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface;
310 ULONG refcount = InterlockedIncrement(&buffer->ref);
312 TRACE("%p increasing refcount to %u.\n", iface, refcount);
316 IDirect3DDevice8_AddRef(buffer->parentDevice);
317 wined3d_mutex_lock();
318 wined3d_buffer_incref(buffer->wineD3DIndexBuffer);
319 wined3d_mutex_unlock();
325 static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
327 IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface;
328 ULONG refcount = InterlockedDecrement(&buffer->ref);
330 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
334 IDirect3DDevice8 *device = buffer->parentDevice;
336 wined3d_mutex_lock();
337 wined3d_buffer_decref(buffer->wineD3DIndexBuffer);
338 wined3d_mutex_unlock();
340 /* Release the device last, as it may cause the device to be destroyed. */
341 IDirect3DDevice8_Release(device);
347 static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface, IDirect3DDevice8 **device)
349 TRACE("iface %p, device %p.\n", iface, device);
351 *device = (IDirect3DDevice8 *)((IDirect3DIndexBuffer8Impl *)iface)->parentDevice;
352 IDirect3DDevice8_AddRef(*device);
354 TRACE("Returning device %p.\n", *device);
359 static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *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 = wined3d_buffer_set_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer,
369 guid, data, data_size, flags);
370 wined3d_mutex_unlock();
375 static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *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 = wined3d_buffer_get_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer,
385 guid, data, data_size);
386 wined3d_mutex_unlock();
391 static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid)
395 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
397 wined3d_mutex_lock();
398 hr = wined3d_buffer_free_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, guid);
399 wined3d_mutex_unlock();
404 static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, DWORD priority)
408 TRACE("iface %p, priority %u.\n", iface, priority);
410 wined3d_mutex_lock();
411 previous = wined3d_buffer_set_priority(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, priority);
412 wined3d_mutex_unlock();
417 static DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface)
421 TRACE("iface %p.\n", iface);
423 wined3d_mutex_lock();
424 priority = wined3d_buffer_get_priority(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer);
425 wined3d_mutex_unlock();
430 static void WINAPI d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8 *iface)
432 TRACE("iface %p.\n", iface);
434 wined3d_mutex_lock();
435 wined3d_buffer_preload(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer);
436 wined3d_mutex_unlock();
439 static D3DRESOURCETYPE WINAPI d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8 *iface)
441 TRACE("iface %p.\n", iface);
443 return D3DRTYPE_INDEXBUFFER;
446 static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface,
447 UINT offset, UINT size, BYTE **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 = wined3d_buffer_map(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer,
456 offset, size, data, flags);
457 wined3d_mutex_unlock();
462 static HRESULT WINAPI d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8 *iface)
464 TRACE("iface %p.\n", iface);
466 wined3d_mutex_lock();
467 wined3d_buffer_unmap(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer);
468 wined3d_mutex_unlock();
473 static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface, D3DINDEXBUFFER_DESC *desc)
475 IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface;
476 struct wined3d_resource_desc wined3d_desc;
477 struct wined3d_resource *wined3d_resource;
479 TRACE("iface %p, desc %p.\n", iface, desc);
481 wined3d_mutex_lock();
482 wined3d_resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
483 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
484 wined3d_mutex_unlock();
486 desc->Format = d3dformat_from_wined3dformat(buffer->format);
487 desc->Type = D3DRTYPE_INDEXBUFFER;
488 desc->Usage = wined3d_desc.usage;
489 desc->Pool = wined3d_desc.pool;
490 desc->Size = wined3d_desc.size;
495 static const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl =
498 d3d8_indexbuffer_QueryInterface,
499 d3d8_indexbuffer_AddRef,
500 d3d8_indexbuffer_Release,
501 /* IDirect3DResource8 */
502 d3d8_indexbuffer_GetDevice,
503 d3d8_indexbuffer_SetPrivateData,
504 d3d8_indexbuffer_GetPrivateData,
505 d3d8_indexbuffer_FreePrivateData,
506 d3d8_indexbuffer_SetPriority,
507 d3d8_indexbuffer_GetPriority,
508 d3d8_indexbuffer_PreLoad,
509 d3d8_indexbuffer_GetType,
510 /* IDirect3DIndexBuffer8 */
511 d3d8_indexbuffer_Lock,
512 d3d8_indexbuffer_Unlock,
513 d3d8_indexbuffer_GetDesc,
516 static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
518 HeapFree(GetProcessHeap(), 0, parent);
521 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
523 d3d8_indexbuffer_wined3d_object_destroyed,
526 HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
527 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
531 buffer->lpVtbl = &d3d8_indexbuffer_vtbl;
533 buffer->format = wined3dformat_from_d3dformat(format);
535 wined3d_mutex_lock();
536 hr = wined3d_buffer_create_ib(device->WineD3DDevice, size, usage & WINED3DUSAGE_MASK,
537 (WINED3DPOOL)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer);
538 wined3d_mutex_unlock();
541 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
545 buffer->parentDevice = &device->IDirect3DDevice8_iface;
546 IUnknown_AddRef(buffer->parentDevice);