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 "wine/port.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 static inline struct d3d9_vertexbuffer
*impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9
*iface
)
29 return CONTAINING_RECORD(iface
, struct d3d9_vertexbuffer
, IDirect3DVertexBuffer9_iface
);
32 static HRESULT WINAPI
d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9
*iface
, REFIID riid
, void **out
)
34 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
36 if (IsEqualGUID(riid
, &IID_IDirect3DVertexBuffer9
)
37 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
38 || IsEqualGUID(riid
, &IID_IUnknown
))
40 IDirect3DVertexBuffer9_AddRef(iface
);
45 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
51 static ULONG WINAPI
d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9
*iface
)
53 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
54 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
56 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
60 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
62 wined3d_buffer_incref(buffer
->wined3d_buffer
);
63 if (buffer
->draw_buffer
)
64 wined3d_buffer_incref(buffer
->draw_buffer
);
65 wined3d_mutex_unlock();
71 static ULONG WINAPI
d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9
*iface
)
73 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
74 ULONG refcount
= InterlockedDecrement(&buffer
->resource
.refcount
);
76 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
80 struct wined3d_buffer
*draw_buffer
= buffer
->draw_buffer
;
81 IDirect3DDevice9Ex
*device
= buffer
->parent_device
;
84 wined3d_buffer_decref(buffer
->wined3d_buffer
);
86 wined3d_buffer_decref(draw_buffer
);
87 wined3d_mutex_unlock();
89 /* Release the device last, as it may cause the device to be destroyed. */
90 IDirect3DDevice9Ex_Release(device
);
96 static HRESULT WINAPI
d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9
*iface
, IDirect3DDevice9
**device
)
98 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
100 TRACE("iface %p, device %p.\n", iface
, device
);
102 *device
= (IDirect3DDevice9
*)buffer
->parent_device
;
103 IDirect3DDevice9_AddRef(*device
);
105 TRACE("Returning device %p.\n", *device
);
110 static HRESULT WINAPI
d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9
*iface
,
111 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
113 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
114 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
115 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
117 return d3d9_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
120 static HRESULT WINAPI
d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9
*iface
,
121 REFGUID guid
, void *data
, DWORD
*data_size
)
123 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
124 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
125 iface
, debugstr_guid(guid
), data
, data_size
);
127 return d3d9_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
130 static HRESULT WINAPI
d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9
*iface
, REFGUID guid
)
132 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
133 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
135 return d3d9_resource_free_private_data(&buffer
->resource
, guid
);
138 static DWORD WINAPI
d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9
*iface
, DWORD priority
)
140 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
141 struct wined3d_resource
*resource
;
144 TRACE("iface %p, priority %u.\n", iface
, priority
);
146 wined3d_mutex_lock();
147 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
148 previous
= wined3d_resource_set_priority(resource
, priority
);
149 wined3d_mutex_unlock();
154 static DWORD WINAPI
d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9
*iface
)
156 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
157 const struct wined3d_resource
*resource
;
160 TRACE("iface %p.\n", iface
);
162 wined3d_mutex_lock();
163 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
164 priority
= wined3d_resource_get_priority(resource
);
165 wined3d_mutex_unlock();
170 static void WINAPI
d3d9_vertexbuffer_PreLoad(IDirect3DVertexBuffer9
*iface
)
172 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
174 TRACE("iface %p.\n", iface
);
176 wined3d_mutex_lock();
177 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
178 wined3d_mutex_unlock();
181 static D3DRESOURCETYPE WINAPI
d3d9_vertexbuffer_GetType(IDirect3DVertexBuffer9
*iface
)
183 TRACE("iface %p.\n", iface
);
185 return D3DRTYPE_VERTEXBUFFER
;
188 static HRESULT WINAPI
d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9
*iface
, UINT offset
, UINT size
,
189 void **data
, DWORD flags
)
191 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
192 struct wined3d_resource
*wined3d_resource
;
193 struct wined3d_map_desc wined3d_map_desc
;
194 struct wined3d_box wined3d_box
= {0};
197 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
198 iface
, offset
, size
, data
, flags
);
200 wined3d_box
.left
= offset
;
201 wined3d_box
.right
= offset
+ size
;
202 wined3d_mutex_lock();
203 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
204 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
205 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
206 wined3d_mutex_unlock();
207 *data
= wined3d_map_desc
.data
;
212 static HRESULT WINAPI
d3d9_vertexbuffer_Unlock(IDirect3DVertexBuffer9
*iface
)
214 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
216 TRACE("iface %p.\n", iface
);
218 wined3d_mutex_lock();
219 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
220 wined3d_mutex_unlock();
225 static HRESULT WINAPI
d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9
*iface
,
226 D3DVERTEXBUFFER_DESC
*desc
)
228 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
229 struct wined3d_resource_desc wined3d_desc
;
230 struct wined3d_resource
*wined3d_resource
;
232 TRACE("iface %p, desc %p.\n", iface
, desc
);
234 wined3d_mutex_lock();
235 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
236 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
237 wined3d_mutex_unlock();
239 desc
->Format
= D3DFMT_VERTEXDATA
;
240 desc
->Type
= D3DRTYPE_VERTEXBUFFER
;
241 desc
->Usage
= buffer
->usage
;
242 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
243 desc
->Size
= wined3d_desc
.size
;
244 desc
->FVF
= buffer
->fvf
;
249 static const IDirect3DVertexBuffer9Vtbl d3d9_vertexbuffer_vtbl
=
252 d3d9_vertexbuffer_QueryInterface
,
253 d3d9_vertexbuffer_AddRef
,
254 d3d9_vertexbuffer_Release
,
255 /* IDirect3DResource9 */
256 d3d9_vertexbuffer_GetDevice
,
257 d3d9_vertexbuffer_SetPrivateData
,
258 d3d9_vertexbuffer_GetPrivateData
,
259 d3d9_vertexbuffer_FreePrivateData
,
260 d3d9_vertexbuffer_SetPriority
,
261 d3d9_vertexbuffer_GetPriority
,
262 d3d9_vertexbuffer_PreLoad
,
263 d3d9_vertexbuffer_GetType
,
264 /* IDirect3DVertexBuffer9 */
265 d3d9_vertexbuffer_Lock
,
266 d3d9_vertexbuffer_Unlock
,
267 d3d9_vertexbuffer_GetDesc
,
270 static void STDMETHODCALLTYPE
d3d9_vertexbuffer_wined3d_object_destroyed(void *parent
)
272 struct d3d9_vertexbuffer
*buffer
= parent
;
273 d3d9_resource_cleanup(&buffer
->resource
);
277 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops
=
279 d3d9_vertexbuffer_wined3d_object_destroyed
,
282 HRESULT
vertexbuffer_init(struct d3d9_vertexbuffer
*buffer
, struct d3d9_device
*device
,
283 UINT size
, UINT usage
, DWORD fvf
, D3DPOOL pool
)
285 const struct wined3d_parent_ops
*parent_ops
= &d3d9_null_wined3d_parent_ops
;
286 struct wined3d_buffer_desc desc
;
289 if (pool
== D3DPOOL_SCRATCH
)
291 WARN("Vertex buffer with D3DPOOL_SCRATCH requested.\n");
292 return D3DERR_INVALIDCALL
;
295 if (pool
== D3DPOOL_MANAGED
&& device
->d3d_parent
->extended
)
297 WARN("Managed resources are not supported by d3d9ex devices.\n");
298 return D3DERR_INVALIDCALL
;
301 /* In d3d9, buffers can't be used as rendertarget or depth/stencil buffer. */
302 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
303 return D3DERR_INVALIDCALL
;
305 buffer
->IDirect3DVertexBuffer9_iface
.lpVtbl
= &d3d9_vertexbuffer_vtbl
;
307 buffer
->usage
= usage
;
308 d3d9_resource_init(&buffer
->resource
);
310 desc
.byte_width
= size
;
311 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
313 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
315 desc
.structure_byte_stride
= 0;
317 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
319 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
320 parent_ops
= &d3d9_vertexbuffer_wined3d_parent_ops
;
323 wined3d_mutex_lock();
324 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
325 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
327 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
328 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
329 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
330 &d3d9_vertexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
331 wined3d_buffer_decref(buffer
->wined3d_buffer
);
333 wined3d_mutex_unlock();
336 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
340 buffer
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
341 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
346 struct d3d9_vertexbuffer
*unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9
*iface
)
350 assert(iface
->lpVtbl
== &d3d9_vertexbuffer_vtbl
);
352 return impl_from_IDirect3DVertexBuffer9(iface
);
355 static inline struct d3d9_indexbuffer
*impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9
*iface
)
357 return CONTAINING_RECORD(iface
, struct d3d9_indexbuffer
, IDirect3DIndexBuffer9_iface
);
360 static HRESULT WINAPI
d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9
*iface
, REFIID riid
, void **out
)
362 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
364 if (IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer9
)
365 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
366 || IsEqualGUID(riid
, &IID_IUnknown
))
368 IDirect3DIndexBuffer9_AddRef(iface
);
373 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
376 return E_NOINTERFACE
;
379 static ULONG WINAPI
d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9
*iface
)
381 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
382 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
384 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
388 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
389 wined3d_mutex_lock();
390 wined3d_buffer_incref(buffer
->wined3d_buffer
);
391 if (buffer
->draw_buffer
)
392 wined3d_buffer_incref(buffer
->draw_buffer
);
393 wined3d_mutex_unlock();
399 static ULONG WINAPI
d3d9_indexbuffer_Release(IDirect3DIndexBuffer9
*iface
)
401 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
402 ULONG refcount
= InterlockedDecrement(&buffer
->resource
.refcount
);
404 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
408 struct wined3d_buffer
*draw_buffer
= buffer
->draw_buffer
;
409 IDirect3DDevice9Ex
*device
= buffer
->parent_device
;
411 wined3d_mutex_lock();
412 wined3d_buffer_decref(buffer
->wined3d_buffer
);
414 wined3d_buffer_decref(draw_buffer
);
415 wined3d_mutex_unlock();
417 /* Release the device last, as it may cause the device to be destroyed. */
418 IDirect3DDevice9Ex_Release(device
);
424 static HRESULT WINAPI
d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9
*iface
, IDirect3DDevice9
**device
)
426 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
428 TRACE("iface %p, device %p.\n", iface
, device
);
430 *device
= (IDirect3DDevice9
*)buffer
->parent_device
;
431 IDirect3DDevice9_AddRef(*device
);
433 TRACE("Returning device %p.\n", *device
);
438 static HRESULT WINAPI
d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9
*iface
,
439 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
441 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
442 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
443 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
445 return d3d9_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
448 static HRESULT WINAPI
d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9
*iface
,
449 REFGUID guid
, void *data
, DWORD
*data_size
)
451 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
452 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
453 iface
, debugstr_guid(guid
), data
, data_size
);
455 return d3d9_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
458 static HRESULT WINAPI
d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9
*iface
, REFGUID guid
)
460 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
461 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
463 return d3d9_resource_free_private_data(&buffer
->resource
, guid
);
466 static DWORD WINAPI
d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9
*iface
, DWORD priority
)
468 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
469 struct wined3d_resource
*resource
;
472 TRACE("iface %p, priority %u.\n", iface
, priority
);
474 wined3d_mutex_lock();
475 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
476 previous
= wined3d_resource_set_priority(resource
, priority
);
477 wined3d_mutex_unlock();
482 static DWORD WINAPI
d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9
*iface
)
484 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
485 const struct wined3d_resource
*resource
;
488 TRACE("iface %p.\n", iface
);
490 wined3d_mutex_lock();
491 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
492 priority
= wined3d_resource_get_priority(resource
);
493 wined3d_mutex_unlock();
498 static void WINAPI
d3d9_indexbuffer_PreLoad(IDirect3DIndexBuffer9
*iface
)
500 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
502 TRACE("iface %p.\n", iface
);
504 wined3d_mutex_lock();
505 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
506 wined3d_mutex_unlock();
509 static D3DRESOURCETYPE WINAPI
d3d9_indexbuffer_GetType(IDirect3DIndexBuffer9
*iface
)
511 TRACE("iface %p.\n", iface
);
513 return D3DRTYPE_INDEXBUFFER
;
516 static HRESULT WINAPI
d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9
*iface
,
517 UINT offset
, UINT size
, void **data
, DWORD flags
)
519 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
520 struct wined3d_resource
*wined3d_resource
;
521 struct wined3d_map_desc wined3d_map_desc
;
522 struct wined3d_box wined3d_box
= {0};
525 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
526 iface
, offset
, size
, data
, flags
);
528 wined3d_box
.left
= offset
;
529 wined3d_box
.right
= offset
+ size
;
530 wined3d_mutex_lock();
531 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
532 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
533 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
534 wined3d_mutex_unlock();
535 *data
= wined3d_map_desc
.data
;
540 static HRESULT WINAPI
d3d9_indexbuffer_Unlock(IDirect3DIndexBuffer9
*iface
)
542 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
544 TRACE("iface %p.\n", iface
);
546 wined3d_mutex_lock();
547 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
548 wined3d_mutex_unlock();
553 static HRESULT WINAPI
d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9
*iface
, D3DINDEXBUFFER_DESC
*desc
)
555 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
556 struct wined3d_resource_desc wined3d_desc
;
557 struct wined3d_resource
*wined3d_resource
;
559 TRACE("iface %p, desc %p.\n", iface
, desc
);
561 wined3d_mutex_lock();
562 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
563 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
564 wined3d_mutex_unlock();
566 desc
->Format
= d3dformat_from_wined3dformat(buffer
->format
);
567 desc
->Type
= D3DRTYPE_INDEXBUFFER
;
568 desc
->Usage
= buffer
->usage
;
569 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
570 desc
->Size
= wined3d_desc
.size
;
575 static const IDirect3DIndexBuffer9Vtbl d3d9_indexbuffer_vtbl
=
578 d3d9_indexbuffer_QueryInterface
,
579 d3d9_indexbuffer_AddRef
,
580 d3d9_indexbuffer_Release
,
581 /* IDirect3DResource9 */
582 d3d9_indexbuffer_GetDevice
,
583 d3d9_indexbuffer_SetPrivateData
,
584 d3d9_indexbuffer_GetPrivateData
,
585 d3d9_indexbuffer_FreePrivateData
,
586 d3d9_indexbuffer_SetPriority
,
587 d3d9_indexbuffer_GetPriority
,
588 d3d9_indexbuffer_PreLoad
,
589 d3d9_indexbuffer_GetType
,
590 /* IDirect3DIndexBuffer9 */
591 d3d9_indexbuffer_Lock
,
592 d3d9_indexbuffer_Unlock
,
593 d3d9_indexbuffer_GetDesc
,
596 static void STDMETHODCALLTYPE
d3d9_indexbuffer_wined3d_object_destroyed(void *parent
)
598 struct d3d9_indexbuffer
*buffer
= parent
;
599 d3d9_resource_cleanup(&buffer
->resource
);
603 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops
=
605 d3d9_indexbuffer_wined3d_object_destroyed
,
608 HRESULT
indexbuffer_init(struct d3d9_indexbuffer
*buffer
, struct d3d9_device
*device
,
609 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
611 const struct wined3d_parent_ops
*parent_ops
= &d3d9_null_wined3d_parent_ops
;
612 struct wined3d_buffer_desc desc
;
615 if (pool
== D3DPOOL_SCRATCH
)
616 return D3DERR_INVALIDCALL
;
618 if (pool
== D3DPOOL_MANAGED
&& device
->d3d_parent
->extended
)
620 WARN("Managed resources are not supported by d3d9ex devices.\n");
621 return D3DERR_INVALIDCALL
;
624 /* In d3d9, buffers can't be used as rendertarget or depth/stencil buffer. */
625 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
626 return D3DERR_INVALIDCALL
;
628 desc
.byte_width
= size
;
629 desc
.usage
= (usage
& WINED3DUSAGE_MASK
) | WINED3DUSAGE_STATICDECL
;
631 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
633 desc
.structure_byte_stride
= 0;
635 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
637 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
638 parent_ops
= &d3d9_indexbuffer_wined3d_parent_ops
;
641 buffer
->IDirect3DIndexBuffer9_iface
.lpVtbl
= &d3d9_indexbuffer_vtbl
;
642 buffer
->format
= wined3dformat_from_d3dformat(format
);
643 buffer
->usage
= usage
;
644 d3d9_resource_init(&buffer
->resource
);
646 wined3d_mutex_lock();
647 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
648 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
650 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
651 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
652 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
653 &d3d9_indexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
654 wined3d_buffer_decref(buffer
->wined3d_buffer
);
656 wined3d_mutex_unlock();
659 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
663 buffer
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
664 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
669 struct d3d9_indexbuffer
*unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9
*iface
)
673 assert(iface
->lpVtbl
== &d3d9_indexbuffer_vtbl
);
675 return impl_from_IDirect3DIndexBuffer9(iface
);