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 "d3d8_private.h"
21 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
23 static inline struct d3d8_vertexbuffer
*impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8
*iface
)
25 return CONTAINING_RECORD(iface
, struct d3d8_vertexbuffer
, IDirect3DVertexBuffer8_iface
);
28 static HRESULT WINAPI
d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8
*iface
, REFIID riid
, void **object
)
30 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
32 if (IsEqualGUID(riid
, &IID_IDirect3DVertexBuffer8
)
33 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
34 || IsEqualGUID(riid
, &IID_IUnknown
))
36 IDirect3DVertexBuffer8_AddRef(iface
);
41 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
47 static ULONG WINAPI
d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8
*iface
)
49 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
50 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
52 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
56 IDirect3DDevice8_AddRef(buffer
->parent_device
);
58 if (buffer
->draw_buffer
)
59 wined3d_buffer_incref(buffer
->draw_buffer
);
61 wined3d_buffer_incref(buffer
->wined3d_buffer
);
62 wined3d_mutex_unlock();
68 static ULONG WINAPI
d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8
*iface
)
70 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(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 IDirect3DDevice8
*device
= buffer
->parent_device
;
82 wined3d_buffer_decref(draw_buffer
);
84 wined3d_buffer_decref(buffer
->wined3d_buffer
);
85 wined3d_mutex_unlock();
87 /* Release the device last, as it may cause the device to be destroyed. */
88 IDirect3DDevice8_Release(device
);
94 static HRESULT WINAPI
d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8
*iface
,
95 IDirect3DDevice8
**device
)
97 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
99 TRACE("iface %p, device %p.\n", iface
, device
);
101 *device
= buffer
->parent_device
;
102 IDirect3DDevice8_AddRef(*device
);
104 TRACE("Returning device %p.\n", *device
);
109 static HRESULT WINAPI
d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8
*iface
,
110 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
112 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
113 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
114 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
116 return d3d8_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
119 static HRESULT WINAPI
d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8
*iface
,
120 REFGUID guid
, void *data
, DWORD
*data_size
)
122 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
123 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
124 iface
, debugstr_guid(guid
), data
, data_size
);
126 return d3d8_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
129 static HRESULT WINAPI
d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8
*iface
, REFGUID guid
)
131 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
132 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
134 return d3d8_resource_free_private_data(&buffer
->resource
, guid
);
137 static DWORD WINAPI
d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8
*iface
, DWORD priority
)
139 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
140 struct wined3d_resource
*resource
;
143 TRACE("iface %p, priority %u.\n", iface
, priority
);
145 wined3d_mutex_lock();
146 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
147 previous
= wined3d_resource_set_priority(resource
, priority
);
148 wined3d_mutex_unlock();
153 static DWORD WINAPI
d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8
*iface
)
155 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
156 const struct wined3d_resource
*resource
;
159 TRACE("iface %p.\n", iface
);
161 wined3d_mutex_lock();
162 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
163 priority
= wined3d_resource_get_priority(resource
);
164 wined3d_mutex_unlock();
169 static void WINAPI
d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8
*iface
)
171 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
173 TRACE("iface %p.\n", iface
);
175 wined3d_mutex_lock();
176 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
177 wined3d_mutex_unlock();
180 static D3DRESOURCETYPE WINAPI
d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8
*iface
)
182 TRACE("iface %p.\n", iface
);
184 return D3DRTYPE_VERTEXBUFFER
;
187 static HRESULT WINAPI
d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8
*iface
, UINT offset
, UINT size
,
188 BYTE
**data
, DWORD flags
)
190 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
191 struct wined3d_resource
*wined3d_resource
;
192 struct wined3d_map_desc wined3d_map_desc
;
193 struct wined3d_box wined3d_box
= {0};
196 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
197 iface
, offset
, size
, data
, flags
);
199 wined3d_box
.left
= offset
;
200 wined3d_box
.right
= offset
+ size
;
201 wined3d_mutex_lock();
202 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
203 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
204 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
205 wined3d_mutex_unlock();
206 *data
= wined3d_map_desc
.data
;
211 static HRESULT WINAPI
d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8
*iface
)
213 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
215 TRACE("iface %p.\n", iface
);
217 wined3d_mutex_lock();
218 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
219 wined3d_mutex_unlock();
224 static HRESULT WINAPI
d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8
*iface
,
225 D3DVERTEXBUFFER_DESC
*desc
)
227 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
228 struct wined3d_resource_desc wined3d_desc
;
229 struct wined3d_resource
*wined3d_resource
;
231 TRACE("iface %p, desc %p.\n", iface
, desc
);
233 wined3d_mutex_lock();
234 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
235 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
236 wined3d_mutex_unlock();
238 desc
->Format
= D3DFMT_VERTEXDATA
;
239 desc
->Type
= D3DRTYPE_VERTEXBUFFER
;
240 desc
->Usage
= buffer
->usage
;
241 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
242 desc
->Size
= wined3d_desc
.size
;
243 desc
->FVF
= buffer
->fvf
;
248 static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl
=
251 d3d8_vertexbuffer_QueryInterface
,
252 d3d8_vertexbuffer_AddRef
,
253 d3d8_vertexbuffer_Release
,
254 /* IDirect3DResource8 */
255 d3d8_vertexbuffer_GetDevice
,
256 d3d8_vertexbuffer_SetPrivateData
,
257 d3d8_vertexbuffer_GetPrivateData
,
258 d3d8_vertexbuffer_FreePrivateData
,
259 d3d8_vertexbuffer_SetPriority
,
260 d3d8_vertexbuffer_GetPriority
,
261 d3d8_vertexbuffer_PreLoad
,
262 d3d8_vertexbuffer_GetType
,
263 /* IDirect3DVertexBuffer8 */
264 d3d8_vertexbuffer_Lock
,
265 d3d8_vertexbuffer_Unlock
,
266 d3d8_vertexbuffer_GetDesc
,
269 static void STDMETHODCALLTYPE
d3d8_vertexbuffer_wined3d_object_destroyed(void *parent
)
271 struct d3d8_vertexbuffer
*buffer
= parent
;
273 if (buffer
->draw_buffer
)
274 wined3d_buffer_decref(buffer
->wined3d_buffer
);
275 d3d8_resource_cleanup(&buffer
->resource
);
279 static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops
=
281 d3d8_vertexbuffer_wined3d_object_destroyed
,
284 HRESULT
vertexbuffer_init(struct d3d8_vertexbuffer
*buffer
, struct d3d8_device
*device
,
285 UINT size
, DWORD usage
, DWORD fvf
, D3DPOOL pool
)
287 const struct wined3d_parent_ops
*parent_ops
= &d3d8_null_wined3d_parent_ops
;
288 struct wined3d_buffer_desc desc
;
291 if (pool
== D3DPOOL_SCRATCH
)
293 WARN("Vertex buffer with D3DPOOL_SCRATCH requested.\n");
294 return D3DERR_INVALIDCALL
;
297 /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */
298 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
299 return D3DERR_INVALIDCALL
;
301 buffer
->IDirect3DVertexBuffer8_iface
.lpVtbl
= &Direct3DVertexBuffer8_Vtbl
;
302 d3d8_resource_init(&buffer
->resource
);
304 buffer
->usage
= usage
;
306 desc
.byte_width
= size
;
307 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
309 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
310 /* Buffers are always readable. */
311 if (pool
!= D3DPOOL_DEFAULT
)
312 desc
.access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
314 desc
.structure_byte_stride
= 0;
316 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
318 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
319 parent_ops
= &d3d8_vertexbuffer_wined3d_parent_ops
;
322 wined3d_mutex_lock();
323 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
324 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
326 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
327 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
328 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
329 &d3d8_vertexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
330 wined3d_buffer_decref(buffer
->wined3d_buffer
);
332 wined3d_mutex_unlock();
335 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
339 buffer
->parent_device
= &device
->IDirect3DDevice8_iface
;
340 IDirect3DDevice8_AddRef(buffer
->parent_device
);
345 struct d3d8_vertexbuffer
*unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8
*iface
)
349 assert(iface
->lpVtbl
== &Direct3DVertexBuffer8_Vtbl
);
351 return impl_from_IDirect3DVertexBuffer8(iface
);
354 static inline struct d3d8_indexbuffer
*impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8
*iface
)
356 return CONTAINING_RECORD(iface
, struct d3d8_indexbuffer
, IDirect3DIndexBuffer8_iface
);
359 static HRESULT WINAPI
d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8
*iface
, REFIID riid
, void **object
)
361 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
363 if (IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer8
)
364 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
365 || IsEqualGUID(riid
, &IID_IUnknown
))
367 IDirect3DIndexBuffer8_AddRef(iface
);
372 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
375 return E_NOINTERFACE
;
378 static ULONG WINAPI
d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8
*iface
)
380 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
381 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
383 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
387 IDirect3DDevice8_AddRef(buffer
->parent_device
);
388 wined3d_mutex_lock();
389 if (buffer
->draw_buffer
)
390 wined3d_buffer_incref(buffer
->draw_buffer
);
392 wined3d_buffer_incref(buffer
->wined3d_buffer
);
393 wined3d_mutex_unlock();
399 static ULONG WINAPI
d3d8_indexbuffer_Release(IDirect3DIndexBuffer8
*iface
)
401 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(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 IDirect3DDevice8
*device
= buffer
->parent_device
;
411 wined3d_mutex_lock();
413 wined3d_buffer_decref(draw_buffer
);
415 wined3d_buffer_decref(buffer
->wined3d_buffer
);
416 wined3d_mutex_unlock();
418 /* Release the device last, as it may cause the device to be destroyed. */
419 IDirect3DDevice8_Release(device
);
425 static HRESULT WINAPI
d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8
*iface
,
426 IDirect3DDevice8
**device
)
428 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
430 TRACE("iface %p, device %p.\n", iface
, device
);
432 *device
= buffer
->parent_device
;
433 IDirect3DDevice8_AddRef(*device
);
435 TRACE("Returning device %p.\n", *device
);
440 static HRESULT WINAPI
d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8
*iface
,
441 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
443 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
444 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
445 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
447 return d3d8_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
450 static HRESULT WINAPI
d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8
*iface
,
451 REFGUID guid
, void *data
, DWORD
*data_size
)
453 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
454 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
455 iface
, debugstr_guid(guid
), data
, data_size
);
457 return d3d8_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
460 static HRESULT WINAPI
d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8
*iface
, REFGUID guid
)
462 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
463 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
465 return d3d8_resource_free_private_data(&buffer
->resource
, guid
);
468 static DWORD WINAPI
d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8
*iface
, DWORD priority
)
470 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
471 struct wined3d_resource
*resource
;
474 TRACE("iface %p, priority %u.\n", iface
, priority
);
476 wined3d_mutex_lock();
477 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
478 previous
= wined3d_resource_set_priority(resource
, priority
);
479 wined3d_mutex_unlock();
484 static DWORD WINAPI
d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8
*iface
)
486 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
487 const struct wined3d_resource
*resource
;
490 TRACE("iface %p.\n", iface
);
492 wined3d_mutex_lock();
493 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
494 priority
= wined3d_resource_get_priority(resource
);
495 wined3d_mutex_unlock();
500 static void WINAPI
d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8
*iface
)
502 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
504 TRACE("iface %p.\n", iface
);
506 wined3d_mutex_lock();
507 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
508 wined3d_mutex_unlock();
511 static D3DRESOURCETYPE WINAPI
d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8
*iface
)
513 TRACE("iface %p.\n", iface
);
515 return D3DRTYPE_INDEXBUFFER
;
518 static HRESULT WINAPI
d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8
*iface
, UINT offset
, UINT size
,
519 BYTE
**data
, DWORD flags
)
521 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
522 struct wined3d_resource
*wined3d_resource
;
523 struct wined3d_map_desc wined3d_map_desc
;
524 struct wined3d_box wined3d_box
= {0};
527 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
528 iface
, offset
, size
, data
, flags
);
530 wined3d_box
.left
= offset
;
531 wined3d_box
.right
= offset
+ size
;
532 wined3d_mutex_lock();
533 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
534 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
535 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
536 wined3d_mutex_unlock();
537 *data
= wined3d_map_desc
.data
;
542 static HRESULT WINAPI
d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8
*iface
)
544 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
546 TRACE("iface %p.\n", iface
);
548 wined3d_mutex_lock();
549 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
550 wined3d_mutex_unlock();
555 static HRESULT WINAPI
d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8
*iface
,
556 D3DINDEXBUFFER_DESC
*desc
)
558 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
559 struct wined3d_resource_desc wined3d_desc
;
560 struct wined3d_resource
*wined3d_resource
;
562 TRACE("iface %p, desc %p.\n", iface
, desc
);
564 wined3d_mutex_lock();
565 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
566 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
567 wined3d_mutex_unlock();
569 desc
->Format
= d3dformat_from_wined3dformat(buffer
->format
);
570 desc
->Type
= D3DRTYPE_INDEXBUFFER
;
571 desc
->Usage
= buffer
->usage
;
572 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
573 desc
->Size
= wined3d_desc
.size
;
578 static const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl
=
581 d3d8_indexbuffer_QueryInterface
,
582 d3d8_indexbuffer_AddRef
,
583 d3d8_indexbuffer_Release
,
584 /* IDirect3DResource8 */
585 d3d8_indexbuffer_GetDevice
,
586 d3d8_indexbuffer_SetPrivateData
,
587 d3d8_indexbuffer_GetPrivateData
,
588 d3d8_indexbuffer_FreePrivateData
,
589 d3d8_indexbuffer_SetPriority
,
590 d3d8_indexbuffer_GetPriority
,
591 d3d8_indexbuffer_PreLoad
,
592 d3d8_indexbuffer_GetType
,
593 /* IDirect3DIndexBuffer8 */
594 d3d8_indexbuffer_Lock
,
595 d3d8_indexbuffer_Unlock
,
596 d3d8_indexbuffer_GetDesc
,
599 static void STDMETHODCALLTYPE
d3d8_indexbuffer_wined3d_object_destroyed(void *parent
)
601 struct d3d8_indexbuffer
*buffer
= parent
;
603 if (buffer
->draw_buffer
)
604 wined3d_buffer_decref(buffer
->wined3d_buffer
);
605 d3d8_resource_cleanup(&buffer
->resource
);
609 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops
=
611 d3d8_indexbuffer_wined3d_object_destroyed
,
614 HRESULT
indexbuffer_init(struct d3d8_indexbuffer
*buffer
, struct d3d8_device
*device
,
615 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
617 const struct wined3d_parent_ops
*parent_ops
= &d3d8_null_wined3d_parent_ops
;
618 struct wined3d_buffer_desc desc
;
621 if (pool
== D3DPOOL_SCRATCH
)
622 return D3DERR_INVALIDCALL
;
624 /* In d3d8, 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
);
632 /* Buffers are always readable. */
633 if (pool
!= D3DPOOL_DEFAULT
)
634 desc
.access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
636 desc
.structure_byte_stride
= 0;
638 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
640 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
641 parent_ops
= &d3d8_indexbuffer_wined3d_parent_ops
;
644 buffer
->IDirect3DIndexBuffer8_iface
.lpVtbl
= &d3d8_indexbuffer_vtbl
;
645 d3d8_resource_init(&buffer
->resource
);
646 buffer
->format
= wined3dformat_from_d3dformat(format
);
647 buffer
->usage
= usage
;
649 wined3d_mutex_lock();
650 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
651 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
653 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
654 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
655 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
656 &d3d8_indexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
657 wined3d_buffer_decref(buffer
->wined3d_buffer
);
659 wined3d_mutex_unlock();
662 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
666 buffer
->parent_device
= &device
->IDirect3DDevice8_iface
;
667 IDirect3DDevice8_AddRef(buffer
->parent_device
);
672 struct d3d8_indexbuffer
*unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8
*iface
)
676 assert(iface
->lpVtbl
== &d3d8_indexbuffer_vtbl
);
678 return impl_from_IDirect3DIndexBuffer8(iface
);