Assorted spelling fixes.
[wine.git] / dlls / d3d8 / buffer.c
blob4a0e587b409b34cef119b1ad7f224287f820de10
1 /*
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
19 #include "config.h"
20 #include "d3d8_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
24 static inline struct d3d8_vertexbuffer *impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface)
26 return CONTAINING_RECORD(iface, struct d3d8_vertexbuffer, IDirect3DVertexBuffer8_iface);
29 static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *iface, REFIID riid, void **object)
31 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
33 if (IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)
34 || IsEqualGUID(riid, &IID_IDirect3DResource8)
35 || IsEqualGUID(riid, &IID_IUnknown))
37 IDirect3DVertexBuffer8_AddRef(iface);
38 *object = iface;
39 return S_OK;
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
44 *object = NULL;
45 return E_NOINTERFACE;
48 static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
50 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
51 ULONG refcount = InterlockedIncrement(&buffer->resource.refcount);
53 TRACE("%p increasing refcount to %u.\n", iface, refcount);
55 if (refcount == 1)
57 IDirect3DDevice8_AddRef(buffer->parent_device);
58 wined3d_mutex_lock();
59 wined3d_buffer_incref(buffer->wined3d_buffer);
60 wined3d_mutex_unlock();
63 return refcount;
66 static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
68 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
69 ULONG refcount = InterlockedDecrement(&buffer->resource.refcount);
71 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
73 if (!refcount)
75 IDirect3DDevice8 *device = buffer->parent_device;
77 wined3d_mutex_lock();
78 wined3d_buffer_decref(buffer->wined3d_buffer);
79 wined3d_mutex_unlock();
81 /* Release the device last, as it may cause the device to be destroyed. */
82 IDirect3DDevice8_Release(device);
85 return refcount;
88 static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface,
89 IDirect3DDevice8 **device)
91 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
93 TRACE("iface %p, device %p.\n", iface, device);
95 *device = buffer->parent_device;
96 IDirect3DDevice8_AddRef(*device);
98 TRACE("Returning device %p.\n", *device);
100 return D3D_OK;
103 static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *iface,
104 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
106 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
107 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
108 iface, debugstr_guid(guid), data, data_size, flags);
110 return d3d8_resource_set_private_data(&buffer->resource, guid, data, data_size, flags);
113 static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *iface,
114 REFGUID guid, void *data, DWORD *data_size)
116 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
117 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
118 iface, debugstr_guid(guid), data, data_size);
120 return d3d8_resource_get_private_data(&buffer->resource, guid, data, data_size);
123 static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid)
125 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
126 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
128 return d3d8_resource_free_private_data(&buffer->resource, guid);
131 static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, DWORD priority)
133 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
134 struct wined3d_resource *resource;
135 DWORD previous;
137 TRACE("iface %p, priority %u.\n", iface, priority);
139 wined3d_mutex_lock();
140 resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
141 previous = wined3d_resource_set_priority(resource, priority);
142 wined3d_mutex_unlock();
144 return previous;
147 static DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface)
149 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
150 const struct wined3d_resource *resource;
151 DWORD priority;
153 TRACE("iface %p.\n", iface);
155 wined3d_mutex_lock();
156 resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
157 priority = wined3d_resource_get_priority(resource);
158 wined3d_mutex_unlock();
160 return priority;
163 static void WINAPI d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8 *iface)
165 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
167 TRACE("iface %p.\n", iface);
169 wined3d_mutex_lock();
170 wined3d_buffer_preload(buffer->wined3d_buffer);
171 wined3d_mutex_unlock();
174 static D3DRESOURCETYPE WINAPI d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8 *iface)
176 TRACE("iface %p.\n", iface);
178 return D3DRTYPE_VERTEXBUFFER;
181 static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT offset, UINT size,
182 BYTE **data, DWORD flags)
184 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
185 HRESULT hr;
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(buffer->wined3d_buffer, offset, size, data, flags);
192 wined3d_mutex_unlock();
194 return hr;
197 static HRESULT WINAPI d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8 *iface)
199 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
201 TRACE("iface %p.\n", iface);
203 wined3d_mutex_lock();
204 wined3d_buffer_unmap(buffer->wined3d_buffer);
205 wined3d_mutex_unlock();
207 return D3D_OK;
210 static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface,
211 D3DVERTEXBUFFER_DESC *desc)
213 struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
214 struct wined3d_resource_desc wined3d_desc;
215 struct wined3d_resource *wined3d_resource;
217 TRACE("iface %p, desc %p.\n", iface, desc);
219 wined3d_mutex_lock();
220 wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
221 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
222 wined3d_mutex_unlock();
224 desc->Type = D3DRTYPE_VERTEXBUFFER;
225 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
226 desc->Pool = wined3d_desc.pool;
227 desc->Size = wined3d_desc.size;
228 desc->FVF = buffer->fvf;
229 desc->Format = D3DFMT_VERTEXDATA;
231 return D3D_OK;
234 static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
236 /* IUnknown */
237 d3d8_vertexbuffer_QueryInterface,
238 d3d8_vertexbuffer_AddRef,
239 d3d8_vertexbuffer_Release,
240 /* IDirect3DResource8 */
241 d3d8_vertexbuffer_GetDevice,
242 d3d8_vertexbuffer_SetPrivateData,
243 d3d8_vertexbuffer_GetPrivateData,
244 d3d8_vertexbuffer_FreePrivateData,
245 d3d8_vertexbuffer_SetPriority,
246 d3d8_vertexbuffer_GetPriority,
247 d3d8_vertexbuffer_PreLoad,
248 d3d8_vertexbuffer_GetType,
249 /* IDirect3DVertexBuffer8 */
250 d3d8_vertexbuffer_Lock,
251 d3d8_vertexbuffer_Unlock,
252 d3d8_vertexbuffer_GetDesc,
255 static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
257 struct d3d8_vertexbuffer *buffer = parent;
258 d3d8_resource_cleanup(&buffer->resource);
259 HeapFree(GetProcessHeap(), 0, buffer);
262 static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
264 d3d8_vertexbuffer_wined3d_object_destroyed,
267 HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device,
268 UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
270 HRESULT hr;
272 buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl;
273 d3d8_resource_init(&buffer->resource);
274 buffer->fvf = fvf;
276 wined3d_mutex_lock();
277 hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
278 (enum wined3d_pool)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
279 wined3d_mutex_unlock();
280 if (FAILED(hr))
282 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
283 return hr;
286 buffer->parent_device = &device->IDirect3DDevice8_iface;
287 IDirect3DDevice8_AddRef(buffer->parent_device);
289 return D3D_OK;
292 struct d3d8_vertexbuffer *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface)
294 if (!iface)
295 return NULL;
296 assert(iface->lpVtbl == &Direct3DVertexBuffer8_Vtbl);
298 return impl_from_IDirect3DVertexBuffer8(iface);
301 static inline struct d3d8_indexbuffer *impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface)
303 return CONTAINING_RECORD(iface, struct d3d8_indexbuffer, IDirect3DIndexBuffer8_iface);
306 static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *iface, REFIID riid, void **object)
308 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
310 if (IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)
311 || IsEqualGUID(riid, &IID_IDirect3DResource8)
312 || IsEqualGUID(riid, &IID_IUnknown))
314 IDirect3DIndexBuffer8_AddRef(iface);
315 *object = iface;
316 return S_OK;
319 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
321 *object = NULL;
322 return E_NOINTERFACE;
325 static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
327 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
328 ULONG refcount = InterlockedIncrement(&buffer->resource.refcount);
330 TRACE("%p increasing refcount to %u.\n", iface, refcount);
332 if (refcount == 1)
334 IDirect3DDevice8_AddRef(buffer->parent_device);
335 wined3d_mutex_lock();
336 wined3d_buffer_incref(buffer->wined3d_buffer);
337 wined3d_mutex_unlock();
340 return refcount;
343 static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
345 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
346 ULONG refcount = InterlockedDecrement(&buffer->resource.refcount);
348 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
350 if (!refcount)
352 IDirect3DDevice8 *device = buffer->parent_device;
354 wined3d_mutex_lock();
355 wined3d_buffer_decref(buffer->wined3d_buffer);
356 wined3d_mutex_unlock();
358 /* Release the device last, as it may cause the device to be destroyed. */
359 IDirect3DDevice8_Release(device);
362 return refcount;
365 static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface,
366 IDirect3DDevice8 **device)
368 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
370 TRACE("iface %p, device %p.\n", iface, device);
372 *device = buffer->parent_device;
373 IDirect3DDevice8_AddRef(*device);
375 TRACE("Returning device %p.\n", *device);
377 return D3D_OK;
380 static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *iface,
381 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
383 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
384 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
385 iface, debugstr_guid(guid), data, data_size, flags);
387 return d3d8_resource_set_private_data(&buffer->resource, guid, data, data_size, flags);
390 static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *iface,
391 REFGUID guid, void *data, DWORD *data_size)
393 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
394 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
395 iface, debugstr_guid(guid), data, data_size);
397 return d3d8_resource_get_private_data(&buffer->resource, guid, data, data_size);
400 static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid)
402 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
403 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
405 return d3d8_resource_free_private_data(&buffer->resource, guid);
408 static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, DWORD priority)
410 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
411 struct wined3d_resource *resource;
412 DWORD previous;
414 TRACE("iface %p, priority %u.\n", iface, priority);
416 wined3d_mutex_lock();
417 resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
418 previous = wined3d_resource_set_priority(resource, priority);
419 wined3d_mutex_unlock();
421 return previous;
424 static DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface)
426 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
427 const struct wined3d_resource *resource;
428 DWORD priority;
430 TRACE("iface %p.\n", iface);
432 wined3d_mutex_lock();
433 resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
434 priority = wined3d_resource_get_priority(resource);
435 wined3d_mutex_unlock();
437 return priority;
440 static void WINAPI d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8 *iface)
442 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
444 TRACE("iface %p.\n", iface);
446 wined3d_mutex_lock();
447 wined3d_buffer_preload(buffer->wined3d_buffer);
448 wined3d_mutex_unlock();
451 static D3DRESOURCETYPE WINAPI d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8 *iface)
453 TRACE("iface %p.\n", iface);
455 return D3DRTYPE_INDEXBUFFER;
458 static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT offset, UINT size,
459 BYTE **data, DWORD flags)
461 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
462 HRESULT hr;
464 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
465 iface, offset, size, data, flags);
467 wined3d_mutex_lock();
468 hr = wined3d_buffer_map(buffer->wined3d_buffer, offset, size, data, flags);
469 wined3d_mutex_unlock();
471 return hr;
474 static HRESULT WINAPI d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8 *iface)
476 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
478 TRACE("iface %p.\n", iface);
480 wined3d_mutex_lock();
481 wined3d_buffer_unmap(buffer->wined3d_buffer);
482 wined3d_mutex_unlock();
484 return D3D_OK;
487 static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface,
488 D3DINDEXBUFFER_DESC *desc)
490 struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
491 struct wined3d_resource_desc wined3d_desc;
492 struct wined3d_resource *wined3d_resource;
494 TRACE("iface %p, desc %p.\n", iface, desc);
496 wined3d_mutex_lock();
497 wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
498 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
499 wined3d_mutex_unlock();
501 desc->Format = d3dformat_from_wined3dformat(buffer->format);
502 desc->Type = D3DRTYPE_INDEXBUFFER;
503 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
504 desc->Pool = wined3d_desc.pool;
505 desc->Size = wined3d_desc.size;
507 return D3D_OK;
510 static const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl =
512 /* IUnknown */
513 d3d8_indexbuffer_QueryInterface,
514 d3d8_indexbuffer_AddRef,
515 d3d8_indexbuffer_Release,
516 /* IDirect3DResource8 */
517 d3d8_indexbuffer_GetDevice,
518 d3d8_indexbuffer_SetPrivateData,
519 d3d8_indexbuffer_GetPrivateData,
520 d3d8_indexbuffer_FreePrivateData,
521 d3d8_indexbuffer_SetPriority,
522 d3d8_indexbuffer_GetPriority,
523 d3d8_indexbuffer_PreLoad,
524 d3d8_indexbuffer_GetType,
525 /* IDirect3DIndexBuffer8 */
526 d3d8_indexbuffer_Lock,
527 d3d8_indexbuffer_Unlock,
528 d3d8_indexbuffer_GetDesc,
531 static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
533 struct d3d8_indexbuffer *buffer = parent;
534 d3d8_resource_cleanup(&buffer->resource);
535 HeapFree(GetProcessHeap(), 0, buffer);
538 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
540 d3d8_indexbuffer_wined3d_object_destroyed,
543 HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device,
544 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
546 HRESULT hr;
548 buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl;
549 d3d8_resource_init(&buffer->resource);
550 buffer->format = wined3dformat_from_d3dformat(format);
552 wined3d_mutex_lock();
553 hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
554 (enum wined3d_pool)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
555 wined3d_mutex_unlock();
556 if (FAILED(hr))
558 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
559 return hr;
562 buffer->parent_device = &device->IDirect3DDevice8_iface;
563 IDirect3DDevice8_AddRef(buffer->parent_device);
565 return D3D_OK;
568 struct d3d8_indexbuffer *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface)
570 if (!iface)
571 return NULL;
572 assert(iface->lpVtbl == &d3d8_indexbuffer_vtbl);
574 return impl_from_IDirect3DIndexBuffer8(iface);