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
21 #include "d3d9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
25 static inline struct d3d9_vertexbuffer
*impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9
*iface
)
27 return CONTAINING_RECORD(iface
, struct d3d9_vertexbuffer
, IDirect3DVertexBuffer9_iface
);
30 static HRESULT WINAPI
d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9
*iface
, REFIID riid
, void **out
)
32 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
34 if (IsEqualGUID(riid
, &IID_IDirect3DVertexBuffer9
)
35 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
36 || IsEqualGUID(riid
, &IID_IUnknown
))
38 IDirect3DVertexBuffer9_AddRef(iface
);
43 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
49 static ULONG WINAPI
d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9
*iface
)
51 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
52 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
54 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
58 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
59 if (buffer
->draw_buffer
)
60 wined3d_buffer_incref(buffer
->draw_buffer
);
62 wined3d_buffer_incref(buffer
->wined3d_buffer
);
68 static ULONG WINAPI
d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9
*iface
)
70 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
71 ULONG refcount
= InterlockedDecrement(&buffer
->resource
.refcount
);
73 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
77 struct wined3d_buffer
*draw_buffer
= buffer
->draw_buffer
;
78 IDirect3DDevice9Ex
*device
= buffer
->parent_device
;
81 wined3d_buffer_decref(draw_buffer
);
83 wined3d_buffer_decref(buffer
->wined3d_buffer
);
85 /* Release the device last, as it may cause the device to be destroyed. */
86 IDirect3DDevice9Ex_Release(device
);
92 static HRESULT WINAPI
d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9
*iface
, IDirect3DDevice9
**device
)
94 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
96 TRACE("iface %p, device %p.\n", iface
, device
);
98 *device
= (IDirect3DDevice9
*)buffer
->parent_device
;
99 IDirect3DDevice9_AddRef(*device
);
101 TRACE("Returning device %p.\n", *device
);
106 static HRESULT WINAPI
d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9
*iface
,
107 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
109 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
110 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
111 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
113 return d3d9_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
116 static HRESULT WINAPI
d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9
*iface
,
117 REFGUID guid
, void *data
, DWORD
*data_size
)
119 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
120 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
121 iface
, debugstr_guid(guid
), data
, data_size
);
123 return d3d9_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
126 static HRESULT WINAPI
d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9
*iface
, REFGUID guid
)
128 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
129 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
131 return d3d9_resource_free_private_data(&buffer
->resource
, guid
);
134 static DWORD WINAPI
d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9
*iface
, DWORD priority
)
136 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
137 struct wined3d_resource
*resource
;
140 TRACE("iface %p, priority %u.\n", iface
, priority
);
142 wined3d_mutex_lock();
143 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
144 previous
= wined3d_resource_set_priority(resource
, priority
);
145 wined3d_mutex_unlock();
150 static DWORD WINAPI
d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9
*iface
)
152 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
153 const struct wined3d_resource
*resource
;
156 TRACE("iface %p.\n", iface
);
158 wined3d_mutex_lock();
159 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
160 priority
= wined3d_resource_get_priority(resource
);
161 wined3d_mutex_unlock();
166 static void WINAPI
d3d9_vertexbuffer_PreLoad(IDirect3DVertexBuffer9
*iface
)
168 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
170 TRACE("iface %p.\n", iface
);
172 wined3d_mutex_lock();
173 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
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
, UINT offset
, UINT size
,
185 void **data
, DWORD flags
)
187 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
188 struct wined3d_resource
*wined3d_resource
;
189 struct wined3d_map_desc wined3d_map_desc
;
190 struct wined3d_box wined3d_box
;
193 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
194 iface
, offset
, size
, data
, flags
);
196 wined3d_box_set(&wined3d_box
, offset
, 0, offset
+ size
, 1, 0, 1);
198 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
199 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
200 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
201 *data
= wined3d_map_desc
.data
;
206 static HRESULT WINAPI
d3d9_vertexbuffer_Unlock(IDirect3DVertexBuffer9
*iface
)
208 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
210 TRACE("iface %p.\n", iface
);
212 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
217 static HRESULT WINAPI
d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9
*iface
,
218 D3DVERTEXBUFFER_DESC
*desc
)
220 struct d3d9_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer9(iface
);
221 struct wined3d_resource_desc wined3d_desc
;
222 struct wined3d_resource
*wined3d_resource
;
224 TRACE("iface %p, desc %p.\n", iface
, desc
);
226 wined3d_mutex_lock();
227 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
228 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
229 wined3d_mutex_unlock();
231 desc
->Format
= D3DFMT_VERTEXDATA
;
232 desc
->Type
= D3DRTYPE_VERTEXBUFFER
;
233 desc
->Usage
= buffer
->usage
;
234 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
235 desc
->Size
= wined3d_desc
.size
;
236 desc
->FVF
= buffer
->fvf
;
241 static const IDirect3DVertexBuffer9Vtbl d3d9_vertexbuffer_vtbl
=
244 d3d9_vertexbuffer_QueryInterface
,
245 d3d9_vertexbuffer_AddRef
,
246 d3d9_vertexbuffer_Release
,
247 /* IDirect3DResource9 */
248 d3d9_vertexbuffer_GetDevice
,
249 d3d9_vertexbuffer_SetPrivateData
,
250 d3d9_vertexbuffer_GetPrivateData
,
251 d3d9_vertexbuffer_FreePrivateData
,
252 d3d9_vertexbuffer_SetPriority
,
253 d3d9_vertexbuffer_GetPriority
,
254 d3d9_vertexbuffer_PreLoad
,
255 d3d9_vertexbuffer_GetType
,
256 /* IDirect3DVertexBuffer9 */
257 d3d9_vertexbuffer_Lock
,
258 d3d9_vertexbuffer_Unlock
,
259 d3d9_vertexbuffer_GetDesc
,
262 static void STDMETHODCALLTYPE
d3d9_vertexbuffer_wined3d_object_destroyed(void *parent
)
264 struct d3d9_vertexbuffer
*buffer
= parent
;
266 if (buffer
->draw_buffer
)
267 wined3d_buffer_decref(buffer
->wined3d_buffer
);
268 d3d9_resource_cleanup(&buffer
->resource
);
272 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops
=
274 d3d9_vertexbuffer_wined3d_object_destroyed
,
277 HRESULT
vertexbuffer_init(struct d3d9_vertexbuffer
*buffer
, struct d3d9_device
*device
,
278 UINT size
, UINT usage
, DWORD fvf
, D3DPOOL pool
)
280 const struct wined3d_parent_ops
*parent_ops
= &d3d9_null_wined3d_parent_ops
;
281 struct wined3d_buffer_desc desc
;
284 if (pool
== D3DPOOL_SCRATCH
)
286 WARN("Vertex buffer with D3DPOOL_SCRATCH requested.\n");
287 return D3DERR_INVALIDCALL
;
290 if (pool
== D3DPOOL_MANAGED
&& device
->d3d_parent
->extended
)
292 WARN("Managed resources are not supported by d3d9ex devices.\n");
293 return D3DERR_INVALIDCALL
;
296 /* In d3d9, buffers can't be used as rendertarget or depth/stencil buffer. */
297 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
298 return D3DERR_INVALIDCALL
;
300 buffer
->IDirect3DVertexBuffer9_iface
.lpVtbl
= &d3d9_vertexbuffer_vtbl
;
302 buffer
->usage
= usage
;
303 d3d9_resource_init(&buffer
->resource
);
305 desc
.byte_width
= size
;
306 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
308 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
309 /* Buffers are always readable. */
310 if (pool
!= D3DPOOL_DEFAULT
)
311 desc
.access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
313 desc
.structure_byte_stride
= 0;
315 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
317 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
318 parent_ops
= &d3d9_vertexbuffer_wined3d_parent_ops
;
321 wined3d_mutex_lock();
322 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
323 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
325 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
326 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
327 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
328 &d3d9_vertexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
329 wined3d_buffer_decref(buffer
->wined3d_buffer
);
331 wined3d_mutex_unlock();
334 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
338 buffer
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
339 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
344 struct d3d9_vertexbuffer
*unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9
*iface
)
348 assert(iface
->lpVtbl
== &d3d9_vertexbuffer_vtbl
);
350 return impl_from_IDirect3DVertexBuffer9(iface
);
353 static inline struct d3d9_indexbuffer
*impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9
*iface
)
355 return CONTAINING_RECORD(iface
, struct d3d9_indexbuffer
, IDirect3DIndexBuffer9_iface
);
358 static HRESULT WINAPI
d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9
*iface
, REFIID riid
, void **out
)
360 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
362 if (IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer9
)
363 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
364 || IsEqualGUID(riid
, &IID_IUnknown
))
366 IDirect3DIndexBuffer9_AddRef(iface
);
371 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
374 return E_NOINTERFACE
;
377 static ULONG WINAPI
d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9
*iface
)
379 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
380 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
382 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
386 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
387 if (buffer
->draw_buffer
)
388 wined3d_buffer_incref(buffer
->draw_buffer
);
390 wined3d_buffer_incref(buffer
->wined3d_buffer
);
396 static ULONG WINAPI
d3d9_indexbuffer_Release(IDirect3DIndexBuffer9
*iface
)
398 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
399 ULONG refcount
= InterlockedDecrement(&buffer
->resource
.refcount
);
401 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
405 struct wined3d_buffer
*draw_buffer
= buffer
->draw_buffer
;
406 IDirect3DDevice9Ex
*device
= buffer
->parent_device
;
409 wined3d_buffer_decref(draw_buffer
);
411 wined3d_buffer_decref(buffer
->wined3d_buffer
);
413 /* Release the device last, as it may cause the device to be destroyed. */
414 IDirect3DDevice9Ex_Release(device
);
420 static HRESULT WINAPI
d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9
*iface
, IDirect3DDevice9
**device
)
422 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
424 TRACE("iface %p, device %p.\n", iface
, device
);
426 *device
= (IDirect3DDevice9
*)buffer
->parent_device
;
427 IDirect3DDevice9_AddRef(*device
);
429 TRACE("Returning device %p.\n", *device
);
434 static HRESULT WINAPI
d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9
*iface
,
435 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
437 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
438 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
439 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
441 return d3d9_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
444 static HRESULT WINAPI
d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9
*iface
,
445 REFGUID guid
, void *data
, DWORD
*data_size
)
447 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
448 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
449 iface
, debugstr_guid(guid
), data
, data_size
);
451 return d3d9_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
454 static HRESULT WINAPI
d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9
*iface
, REFGUID guid
)
456 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
457 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
459 return d3d9_resource_free_private_data(&buffer
->resource
, guid
);
462 static DWORD WINAPI
d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9
*iface
, DWORD priority
)
464 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
465 struct wined3d_resource
*resource
;
468 TRACE("iface %p, priority %u.\n", iface
, priority
);
470 wined3d_mutex_lock();
471 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
472 previous
= wined3d_resource_set_priority(resource
, priority
);
473 wined3d_mutex_unlock();
478 static DWORD WINAPI
d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9
*iface
)
480 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
481 const struct wined3d_resource
*resource
;
484 TRACE("iface %p.\n", iface
);
486 wined3d_mutex_lock();
487 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
488 priority
= wined3d_resource_get_priority(resource
);
489 wined3d_mutex_unlock();
494 static void WINAPI
d3d9_indexbuffer_PreLoad(IDirect3DIndexBuffer9
*iface
)
496 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
498 TRACE("iface %p.\n", iface
);
500 wined3d_mutex_lock();
501 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
502 wined3d_mutex_unlock();
505 static D3DRESOURCETYPE WINAPI
d3d9_indexbuffer_GetType(IDirect3DIndexBuffer9
*iface
)
507 TRACE("iface %p.\n", iface
);
509 return D3DRTYPE_INDEXBUFFER
;
512 static HRESULT WINAPI
d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9
*iface
,
513 UINT offset
, UINT size
, void **data
, DWORD flags
)
515 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
516 struct wined3d_resource
*wined3d_resource
;
517 struct wined3d_map_desc wined3d_map_desc
;
518 struct wined3d_box wined3d_box
;
521 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
522 iface
, offset
, size
, data
, flags
);
524 wined3d_box_set(&wined3d_box
, offset
, 0, offset
+ size
, 1, 0, 1);
526 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
527 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
528 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
529 *data
= wined3d_map_desc
.data
;
534 static HRESULT WINAPI
d3d9_indexbuffer_Unlock(IDirect3DIndexBuffer9
*iface
)
536 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
538 TRACE("iface %p.\n", iface
);
540 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
545 static HRESULT WINAPI
d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9
*iface
, D3DINDEXBUFFER_DESC
*desc
)
547 struct d3d9_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer9(iface
);
548 struct wined3d_resource_desc wined3d_desc
;
549 struct wined3d_resource
*wined3d_resource
;
551 TRACE("iface %p, desc %p.\n", iface
, desc
);
553 wined3d_mutex_lock();
554 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
555 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
556 wined3d_mutex_unlock();
558 desc
->Format
= d3dformat_from_wined3dformat(buffer
->format
);
559 desc
->Type
= D3DRTYPE_INDEXBUFFER
;
560 desc
->Usage
= buffer
->usage
;
561 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
562 desc
->Size
= wined3d_desc
.size
;
567 static const IDirect3DIndexBuffer9Vtbl d3d9_indexbuffer_vtbl
=
570 d3d9_indexbuffer_QueryInterface
,
571 d3d9_indexbuffer_AddRef
,
572 d3d9_indexbuffer_Release
,
573 /* IDirect3DResource9 */
574 d3d9_indexbuffer_GetDevice
,
575 d3d9_indexbuffer_SetPrivateData
,
576 d3d9_indexbuffer_GetPrivateData
,
577 d3d9_indexbuffer_FreePrivateData
,
578 d3d9_indexbuffer_SetPriority
,
579 d3d9_indexbuffer_GetPriority
,
580 d3d9_indexbuffer_PreLoad
,
581 d3d9_indexbuffer_GetType
,
582 /* IDirect3DIndexBuffer9 */
583 d3d9_indexbuffer_Lock
,
584 d3d9_indexbuffer_Unlock
,
585 d3d9_indexbuffer_GetDesc
,
588 static void STDMETHODCALLTYPE
d3d9_indexbuffer_wined3d_object_destroyed(void *parent
)
590 struct d3d9_indexbuffer
*buffer
= parent
;
592 if (buffer
->draw_buffer
)
593 wined3d_buffer_decref(buffer
->wined3d_buffer
);
594 d3d9_resource_cleanup(&buffer
->resource
);
598 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops
=
600 d3d9_indexbuffer_wined3d_object_destroyed
,
603 HRESULT
indexbuffer_init(struct d3d9_indexbuffer
*buffer
, struct d3d9_device
*device
,
604 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
606 const struct wined3d_parent_ops
*parent_ops
= &d3d9_null_wined3d_parent_ops
;
607 struct wined3d_buffer_desc desc
;
610 if (pool
== D3DPOOL_SCRATCH
)
611 return D3DERR_INVALIDCALL
;
613 if (pool
== D3DPOOL_MANAGED
&& device
->d3d_parent
->extended
)
615 WARN("Managed resources are not supported by d3d9ex devices.\n");
616 return D3DERR_INVALIDCALL
;
619 /* In d3d9, buffers can't be used as rendertarget or depth/stencil buffer. */
620 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
621 return D3DERR_INVALIDCALL
;
623 desc
.byte_width
= size
;
624 desc
.usage
= (usage
& WINED3DUSAGE_MASK
) | WINED3DUSAGE_STATICDECL
;
626 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
627 /* Buffers are always readable. */
628 if (pool
!= D3DPOOL_DEFAULT
)
629 desc
.access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
631 desc
.structure_byte_stride
= 0;
633 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
635 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
636 parent_ops
= &d3d9_indexbuffer_wined3d_parent_ops
;
639 buffer
->IDirect3DIndexBuffer9_iface
.lpVtbl
= &d3d9_indexbuffer_vtbl
;
640 buffer
->format
= wined3dformat_from_d3dformat(format
);
641 buffer
->usage
= usage
;
642 d3d9_resource_init(&buffer
->resource
);
644 wined3d_mutex_lock();
645 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
646 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
648 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
649 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
650 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
651 &d3d9_indexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
652 wined3d_buffer_decref(buffer
->wined3d_buffer
);
654 wined3d_mutex_unlock();
657 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
661 buffer
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
662 IDirect3DDevice9Ex_AddRef(buffer
->parent_device
);
667 struct d3d9_indexbuffer
*unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9
*iface
)
671 assert(iface
->lpVtbl
== &d3d9_indexbuffer_vtbl
);
673 return impl_from_IDirect3DIndexBuffer9(iface
);