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 %lu.\n", iface
, refcount
);
56 IDirect3DDevice8_AddRef(buffer
->parent_device
);
57 if (buffer
->draw_buffer
)
58 wined3d_buffer_incref(buffer
->draw_buffer
);
60 wined3d_buffer_incref(buffer
->wined3d_buffer
);
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 %lu.\n", iface
, refcount
);
75 struct wined3d_buffer
*draw_buffer
= buffer
->draw_buffer
;
76 IDirect3DDevice8
*device
= buffer
->parent_device
;
79 wined3d_buffer_decref(draw_buffer
);
81 wined3d_buffer_decref(buffer
->wined3d_buffer
);
83 /* Release the device last, as it may cause the device to be destroyed. */
84 IDirect3DDevice8_Release(device
);
90 static HRESULT WINAPI
d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8
*iface
,
91 IDirect3DDevice8
**device
)
93 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
95 TRACE("iface %p, device %p.\n", iface
, device
);
97 *device
= buffer
->parent_device
;
98 IDirect3DDevice8_AddRef(*device
);
100 TRACE("Returning device %p.\n", *device
);
105 static HRESULT WINAPI
d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8
*iface
,
106 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
108 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
109 TRACE("iface %p, guid %s, data %p, data_size %lu, flags %#lx.\n",
110 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
112 return d3d8_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
115 static HRESULT WINAPI
d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8
*iface
,
116 REFGUID guid
, void *data
, DWORD
*data_size
)
118 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
119 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
120 iface
, debugstr_guid(guid
), data
, data_size
);
122 return d3d8_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
125 static HRESULT WINAPI
d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8
*iface
, REFGUID guid
)
127 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
128 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
130 return d3d8_resource_free_private_data(&buffer
->resource
, guid
);
133 static DWORD WINAPI
d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8
*iface
, DWORD priority
)
135 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
136 struct wined3d_resource
*resource
;
139 TRACE("iface %p, priority %lu.\n", iface
, priority
);
141 wined3d_mutex_lock();
142 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
143 previous
= wined3d_resource_set_priority(resource
, priority
);
144 wined3d_mutex_unlock();
149 static DWORD WINAPI
d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8
*iface
)
151 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
152 const struct wined3d_resource
*resource
;
155 TRACE("iface %p.\n", iface
);
157 wined3d_mutex_lock();
158 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
159 priority
= wined3d_resource_get_priority(resource
);
160 wined3d_mutex_unlock();
165 static void WINAPI
d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8
*iface
)
167 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
169 TRACE("iface %p.\n", iface
);
171 wined3d_mutex_lock();
172 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
173 wined3d_mutex_unlock();
176 static D3DRESOURCETYPE WINAPI
d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8
*iface
)
178 TRACE("iface %p.\n", iface
);
180 return D3DRTYPE_VERTEXBUFFER
;
183 static HRESULT WINAPI
d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8
*iface
, UINT offset
, UINT size
,
184 BYTE
**data
, DWORD flags
)
186 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
187 struct wined3d_resource
*wined3d_resource
;
188 struct wined3d_map_desc wined3d_map_desc
;
189 struct wined3d_box wined3d_box
= {0};
192 TRACE("iface %p, offset %u, size %u, data %p, flags %#lx.\n",
193 iface
, offset
, size
, data
, flags
);
195 if (buffer
->discarded
)
196 flags
&= ~D3DLOCK_DISCARD
;
197 if (flags
& D3DLOCK_DISCARD
)
198 buffer
->discarded
= true;
200 wined3d_box
.left
= offset
;
201 wined3d_box
.right
= offset
+ size
;
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 *data
= wined3d_map_desc
.data
;
210 static HRESULT WINAPI
d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8
*iface
)
212 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
214 TRACE("iface %p.\n", iface
);
216 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
221 static HRESULT WINAPI
d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8
*iface
,
222 D3DVERTEXBUFFER_DESC
*desc
)
224 struct d3d8_vertexbuffer
*buffer
= impl_from_IDirect3DVertexBuffer8(iface
);
225 struct wined3d_resource_desc wined3d_desc
;
226 struct wined3d_resource
*wined3d_resource
;
228 TRACE("iface %p, desc %p.\n", iface
, desc
);
230 wined3d_mutex_lock();
231 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
232 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
233 wined3d_mutex_unlock();
235 desc
->Format
= D3DFMT_VERTEXDATA
;
236 desc
->Type
= D3DRTYPE_VERTEXBUFFER
;
237 desc
->Usage
= buffer
->usage
;
238 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
239 desc
->Size
= wined3d_desc
.size
;
240 desc
->FVF
= buffer
->fvf
;
245 static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl
=
248 d3d8_vertexbuffer_QueryInterface
,
249 d3d8_vertexbuffer_AddRef
,
250 d3d8_vertexbuffer_Release
,
251 /* IDirect3DResource8 */
252 d3d8_vertexbuffer_GetDevice
,
253 d3d8_vertexbuffer_SetPrivateData
,
254 d3d8_vertexbuffer_GetPrivateData
,
255 d3d8_vertexbuffer_FreePrivateData
,
256 d3d8_vertexbuffer_SetPriority
,
257 d3d8_vertexbuffer_GetPriority
,
258 d3d8_vertexbuffer_PreLoad
,
259 d3d8_vertexbuffer_GetType
,
260 /* IDirect3DVertexBuffer8 */
261 d3d8_vertexbuffer_Lock
,
262 d3d8_vertexbuffer_Unlock
,
263 d3d8_vertexbuffer_GetDesc
,
266 static void STDMETHODCALLTYPE
d3d8_vertexbuffer_wined3d_object_destroyed(void *parent
)
268 struct d3d8_vertexbuffer
*buffer
= parent
;
270 if (buffer
->draw_buffer
)
271 wined3d_buffer_decref(buffer
->wined3d_buffer
);
272 d3d8_resource_cleanup(&buffer
->resource
);
276 static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops
=
278 d3d8_vertexbuffer_wined3d_object_destroyed
,
281 HRESULT
vertexbuffer_init(struct d3d8_vertexbuffer
*buffer
, struct d3d8_device
*device
,
282 UINT size
, DWORD usage
, DWORD fvf
, D3DPOOL pool
)
284 const struct wined3d_parent_ops
*parent_ops
= &d3d8_null_wined3d_parent_ops
;
285 struct wined3d_buffer_desc desc
;
288 if (pool
== D3DPOOL_SCRATCH
)
290 WARN("Vertex buffer with D3DPOOL_SCRATCH requested.\n");
291 return D3DERR_INVALIDCALL
;
294 /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */
295 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
296 return D3DERR_INVALIDCALL
;
298 buffer
->IDirect3DVertexBuffer8_iface
.lpVtbl
= &Direct3DVertexBuffer8_Vtbl
;
299 d3d8_resource_init(&buffer
->resource
);
301 buffer
->usage
= usage
;
303 desc
.byte_width
= size
;
304 desc
.usage
= wined3d_usage_from_d3d(pool
, usage
);
306 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
307 /* Buffers are always readable. */
308 if (pool
!= D3DPOOL_DEFAULT
)
309 desc
.access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
311 desc
.structure_byte_stride
= 0;
313 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
315 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
316 parent_ops
= &d3d8_vertexbuffer_wined3d_parent_ops
;
319 wined3d_mutex_lock();
320 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
, parent_ops
, &buffer
->wined3d_buffer
);
321 if (SUCCEEDED(hr
) && !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
))
323 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
324 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
325 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
326 &d3d8_vertexbuffer_wined3d_parent_ops
, &buffer
->draw_buffer
)))
327 wined3d_buffer_decref(buffer
->wined3d_buffer
);
329 wined3d_mutex_unlock();
332 WARN("Failed to create wined3d buffer, hr %#lx.\n", hr
);
336 buffer
->parent_device
= &device
->IDirect3DDevice8_iface
;
337 IDirect3DDevice8_AddRef(buffer
->parent_device
);
342 struct d3d8_vertexbuffer
*unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8
*iface
)
346 assert(iface
->lpVtbl
== &Direct3DVertexBuffer8_Vtbl
);
348 return impl_from_IDirect3DVertexBuffer8(iface
);
351 static inline struct d3d8_indexbuffer
*impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8
*iface
)
353 return CONTAINING_RECORD(iface
, struct d3d8_indexbuffer
, IDirect3DIndexBuffer8_iface
);
356 static HRESULT WINAPI
d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8
*iface
, REFIID riid
, void **object
)
358 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
360 if (IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer8
)
361 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
362 || IsEqualGUID(riid
, &IID_IUnknown
))
364 IDirect3DIndexBuffer8_AddRef(iface
);
369 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
372 return E_NOINTERFACE
;
375 static ULONG WINAPI
d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8
*iface
)
377 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
378 ULONG refcount
= InterlockedIncrement(&buffer
->resource
.refcount
);
380 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
384 IDirect3DDevice8_AddRef(buffer
->parent_device
);
385 wined3d_buffer_incref(buffer
->wined3d_buffer
);
391 static ULONG WINAPI
d3d8_indexbuffer_Release(IDirect3DIndexBuffer8
*iface
)
393 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
394 ULONG refcount
= InterlockedDecrement(&buffer
->resource
.refcount
);
396 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
400 IDirect3DDevice8
*device
= buffer
->parent_device
;
402 wined3d_buffer_decref(buffer
->wined3d_buffer
);
404 /* Release the device last, as it may cause the device to be destroyed. */
405 IDirect3DDevice8_Release(device
);
411 static HRESULT WINAPI
d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8
*iface
,
412 IDirect3DDevice8
**device
)
414 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
416 TRACE("iface %p, device %p.\n", iface
, device
);
418 *device
= buffer
->parent_device
;
419 IDirect3DDevice8_AddRef(*device
);
421 TRACE("Returning device %p.\n", *device
);
426 static HRESULT WINAPI
d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8
*iface
,
427 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
429 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
430 TRACE("iface %p, guid %s, data %p, data_size %lu, flags %#lx.\n",
431 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
433 return d3d8_resource_set_private_data(&buffer
->resource
, guid
, data
, data_size
, flags
);
436 static HRESULT WINAPI
d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8
*iface
,
437 REFGUID guid
, void *data
, DWORD
*data_size
)
439 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
440 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
441 iface
, debugstr_guid(guid
), data
, data_size
);
443 return d3d8_resource_get_private_data(&buffer
->resource
, guid
, data
, data_size
);
446 static HRESULT WINAPI
d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8
*iface
, REFGUID guid
)
448 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
449 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
451 return d3d8_resource_free_private_data(&buffer
->resource
, guid
);
454 static DWORD WINAPI
d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8
*iface
, DWORD priority
)
456 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
457 struct wined3d_resource
*resource
;
460 TRACE("iface %p, priority %lu.\n", iface
, priority
);
462 wined3d_mutex_lock();
463 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
464 previous
= wined3d_resource_set_priority(resource
, priority
);
465 wined3d_mutex_unlock();
470 static DWORD WINAPI
d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8
*iface
)
472 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
473 const struct wined3d_resource
*resource
;
476 TRACE("iface %p.\n", iface
);
478 wined3d_mutex_lock();
479 resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
480 priority
= wined3d_resource_get_priority(resource
);
481 wined3d_mutex_unlock();
486 static void WINAPI
d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8
*iface
)
488 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
490 TRACE("iface %p.\n", iface
);
492 wined3d_mutex_lock();
493 wined3d_resource_preload(wined3d_buffer_get_resource(buffer
->wined3d_buffer
));
494 wined3d_mutex_unlock();
497 static D3DRESOURCETYPE WINAPI
d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8
*iface
)
499 TRACE("iface %p.\n", iface
);
501 return D3DRTYPE_INDEXBUFFER
;
504 static HRESULT WINAPI
d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8
*iface
, UINT offset
, UINT size
,
505 BYTE
**data
, DWORD flags
)
507 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
508 struct wined3d_resource
*wined3d_resource
;
509 struct wined3d_map_desc wined3d_map_desc
;
510 struct wined3d_box wined3d_box
= {0};
513 TRACE("iface %p, offset %u, size %u, data %p, flags %#lx.\n",
514 iface
, offset
, size
, data
, flags
);
516 if (buffer
->discarded
)
517 flags
&= ~D3DLOCK_DISCARD
;
518 if (flags
& D3DLOCK_DISCARD
)
519 buffer
->discarded
= true;
521 wined3d_box
.left
= offset
;
522 wined3d_box
.right
= offset
+ size
;
523 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
524 hr
= wined3d_resource_map(wined3d_resource
, 0, &wined3d_map_desc
, &wined3d_box
,
525 wined3dmapflags_from_d3dmapflags(flags
, buffer
->usage
));
526 *data
= wined3d_map_desc
.data
;
531 static HRESULT WINAPI
d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8
*iface
)
533 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
535 TRACE("iface %p.\n", iface
);
537 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer
->wined3d_buffer
), 0);
542 static HRESULT WINAPI
d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8
*iface
,
543 D3DINDEXBUFFER_DESC
*desc
)
545 struct d3d8_indexbuffer
*buffer
= impl_from_IDirect3DIndexBuffer8(iface
);
546 struct wined3d_resource_desc wined3d_desc
;
547 struct wined3d_resource
*wined3d_resource
;
549 TRACE("iface %p, desc %p.\n", iface
, desc
);
551 wined3d_mutex_lock();
552 wined3d_resource
= wined3d_buffer_get_resource(buffer
->wined3d_buffer
);
553 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
554 wined3d_mutex_unlock();
556 desc
->Format
= d3dformat_from_wined3dformat(buffer
->format
);
557 desc
->Type
= D3DRTYPE_INDEXBUFFER
;
558 desc
->Usage
= buffer
->usage
;
559 desc
->Pool
= d3dpool_from_wined3daccess(wined3d_desc
.access
, wined3d_desc
.usage
);
560 desc
->Size
= wined3d_desc
.size
;
565 static const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl
=
568 d3d8_indexbuffer_QueryInterface
,
569 d3d8_indexbuffer_AddRef
,
570 d3d8_indexbuffer_Release
,
571 /* IDirect3DResource8 */
572 d3d8_indexbuffer_GetDevice
,
573 d3d8_indexbuffer_SetPrivateData
,
574 d3d8_indexbuffer_GetPrivateData
,
575 d3d8_indexbuffer_FreePrivateData
,
576 d3d8_indexbuffer_SetPriority
,
577 d3d8_indexbuffer_GetPriority
,
578 d3d8_indexbuffer_PreLoad
,
579 d3d8_indexbuffer_GetType
,
580 /* IDirect3DIndexBuffer8 */
581 d3d8_indexbuffer_Lock
,
582 d3d8_indexbuffer_Unlock
,
583 d3d8_indexbuffer_GetDesc
,
586 static void STDMETHODCALLTYPE
d3d8_indexbuffer_wined3d_object_destroyed(void *parent
)
588 struct d3d8_indexbuffer
*buffer
= parent
;
590 d3d8_resource_cleanup(&buffer
->resource
);
594 static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops
=
596 d3d8_indexbuffer_wined3d_object_destroyed
,
599 HRESULT
indexbuffer_init(struct d3d8_indexbuffer
*buffer
, struct d3d8_device
*device
,
600 UINT size
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
602 struct wined3d_buffer_desc desc
;
605 if (pool
== D3DPOOL_SCRATCH
)
606 return D3DERR_INVALIDCALL
;
608 /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */
609 if (usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
))
610 return D3DERR_INVALIDCALL
;
612 desc
.byte_width
= size
;
613 desc
.usage
= wined3d_usage_from_d3d(pool
, usage
) | WINED3DUSAGE_STATICDECL
;
615 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
) | map_access_from_usage(usage
);
616 /* Buffers are always readable. */
617 if (pool
!= D3DPOOL_DEFAULT
)
618 desc
.access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
620 desc
.structure_byte_stride
= 0;
622 if (desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
623 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
625 buffer
->IDirect3DIndexBuffer8_iface
.lpVtbl
= &d3d8_indexbuffer_vtbl
;
626 d3d8_resource_init(&buffer
->resource
);
627 buffer
->format
= wined3dformat_from_d3dformat(format
);
628 buffer
->usage
= usage
;
629 buffer
->sysmem
= !(desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
);
631 wined3d_mutex_lock();
632 hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
, NULL
, buffer
,
633 &d3d8_indexbuffer_wined3d_parent_ops
, &buffer
->wined3d_buffer
);
634 wined3d_mutex_unlock();
637 WARN("Failed to create wined3d buffer, hr %#lx.\n", hr
);
641 buffer
->parent_device
= &device
->IDirect3DDevice8_iface
;
642 IDirect3DDevice8_AddRef(buffer
->parent_device
);
647 struct d3d8_indexbuffer
*unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8
*iface
)
651 assert(iface
->lpVtbl
== &d3d8_indexbuffer_vtbl
);
653 return impl_from_IDirect3DIndexBuffer8(iface
);