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
20 #include "d3d8_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
24 static inline struct d3d8_texture
*impl_from_IDirect3DTexture8(IDirect3DTexture8
*iface
)
26 return CONTAINING_RECORD(iface
, struct d3d8_texture
, IDirect3DBaseTexture8_iface
);
29 static inline struct d3d8_texture
*impl_from_IDirect3DCubeTexture8(IDirect3DCubeTexture8
*iface
)
31 return CONTAINING_RECORD(iface
, struct d3d8_texture
, IDirect3DBaseTexture8_iface
);
34 static inline struct d3d8_texture
*impl_from_IDirect3DVolumeTexture8(IDirect3DVolumeTexture8
*iface
)
36 return CONTAINING_RECORD(iface
, struct d3d8_texture
, IDirect3DBaseTexture8_iface
);
39 static HRESULT WINAPI
d3d8_texture_2d_QueryInterface(IDirect3DTexture8
*iface
, REFIID riid
, void **out
)
41 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
43 if (IsEqualGUID(riid
, &IID_IDirect3DTexture8
)
44 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
45 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
46 || IsEqualGUID(riid
, &IID_IUnknown
))
48 IDirect3DTexture8_AddRef(iface
);
53 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
59 static ULONG WINAPI
d3d8_texture_2d_AddRef(IDirect3DTexture8
*iface
)
61 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
62 ULONG ref
= InterlockedIncrement(&texture
->refcount
);
64 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
68 IDirect3DDevice8_AddRef(texture
->parent_device
);
70 wined3d_texture_incref(texture
->wined3d_texture
);
71 wined3d_mutex_unlock();
77 static ULONG WINAPI
d3d8_texture_2d_Release(IDirect3DTexture8
*iface
)
79 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
80 ULONG ref
= InterlockedDecrement(&texture
->refcount
);
82 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
86 IDirect3DDevice8
*parent_device
= texture
->parent_device
;
89 wined3d_texture_decref(texture
->wined3d_texture
);
90 wined3d_mutex_unlock();
92 /* Release the device last, as it may cause the device to be destroyed. */
93 IDirect3DDevice8_Release(parent_device
);
98 static HRESULT WINAPI
d3d8_texture_2d_GetDevice(IDirect3DTexture8
*iface
, IDirect3DDevice8
**device
)
100 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
102 TRACE("iface %p, device %p.\n", iface
, device
);
104 *device
= texture
->parent_device
;
105 IDirect3DDevice8_AddRef(*device
);
107 TRACE("Returning device %p.\n", *device
);
112 static HRESULT WINAPI
d3d8_texture_2d_SetPrivateData(IDirect3DTexture8
*iface
,
113 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
115 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
116 struct wined3d_resource
*resource
;
119 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
120 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
122 wined3d_mutex_lock();
123 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
124 hr
= wined3d_resource_set_private_data(resource
, guid
, data
, data_size
, flags
);
125 wined3d_mutex_unlock();
130 static HRESULT WINAPI
d3d8_texture_2d_GetPrivateData(IDirect3DTexture8
*iface
,
131 REFGUID guid
, void *data
, DWORD
*data_size
)
133 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
134 struct wined3d_resource
*resource
;
137 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
138 iface
, debugstr_guid(guid
), data
, data_size
);
140 wined3d_mutex_lock();
141 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
142 hr
= wined3d_resource_get_private_data(resource
, guid
, data
, data_size
);
143 wined3d_mutex_unlock();
148 static HRESULT WINAPI
d3d8_texture_2d_FreePrivateData(IDirect3DTexture8
*iface
, REFGUID guid
)
150 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
151 struct wined3d_resource
*resource
;
154 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
156 wined3d_mutex_lock();
157 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
158 hr
= wined3d_resource_free_private_data(resource
, guid
);
159 wined3d_mutex_unlock();
164 static DWORD WINAPI
d3d8_texture_2d_SetPriority(IDirect3DTexture8
*iface
, DWORD priority
)
166 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
169 TRACE("iface %p, priority %u.\n", iface
, priority
);
171 wined3d_mutex_lock();
172 ret
= wined3d_texture_set_priority(texture
->wined3d_texture
, priority
);
173 wined3d_mutex_unlock();
178 static DWORD WINAPI
d3d8_texture_2d_GetPriority(IDirect3DTexture8
*iface
)
180 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
183 TRACE("iface %p.\n", iface
);
185 wined3d_mutex_lock();
186 ret
= wined3d_texture_get_priority(texture
->wined3d_texture
);
187 wined3d_mutex_unlock();
192 static void WINAPI
d3d8_texture_2d_PreLoad(IDirect3DTexture8
*iface
)
194 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
196 TRACE("iface %p.\n", iface
);
198 wined3d_mutex_lock();
199 wined3d_texture_preload(texture
->wined3d_texture
);
200 wined3d_mutex_unlock();
203 static D3DRESOURCETYPE WINAPI
d3d8_texture_2d_GetType(IDirect3DTexture8
*iface
)
205 TRACE("iface %p.\n", iface
);
207 return D3DRTYPE_TEXTURE
;
210 static DWORD WINAPI
d3d8_texture_2d_SetLOD(IDirect3DTexture8
*iface
, DWORD lod
)
212 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
215 TRACE("iface %p, lod %u.\n", iface
, lod
);
217 wined3d_mutex_lock();
218 ret
= wined3d_texture_set_lod(texture
->wined3d_texture
, lod
);
219 wined3d_mutex_unlock();
224 static DWORD WINAPI
d3d8_texture_2d_GetLOD(IDirect3DTexture8
*iface
)
226 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
229 TRACE("iface %p.\n", iface
);
231 wined3d_mutex_lock();
232 ret
= wined3d_texture_get_lod(texture
->wined3d_texture
);
233 wined3d_mutex_unlock();
238 static DWORD WINAPI
d3d8_texture_2d_GetLevelCount(IDirect3DTexture8
*iface
)
240 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
243 TRACE("iface %p.\n", iface
);
245 wined3d_mutex_lock();
246 ret
= wined3d_texture_get_level_count(texture
->wined3d_texture
);
247 wined3d_mutex_unlock();
252 static HRESULT WINAPI
d3d8_texture_2d_GetLevelDesc(IDirect3DTexture8
*iface
, UINT level
, D3DSURFACE_DESC
*desc
)
254 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
255 struct wined3d_resource
*sub_resource
;
258 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
260 wined3d_mutex_lock();
261 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
262 hr
= D3DERR_INVALIDCALL
;
265 struct wined3d_resource_desc wined3d_desc
;
267 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
268 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
269 desc
->Type
= wined3d_desc
.resource_type
;
270 desc
->Usage
= wined3d_desc
.usage
& WINED3DUSAGE_MASK
;
271 desc
->Pool
= wined3d_desc
.pool
;
272 desc
->Size
= wined3d_desc
.size
;
273 desc
->MultiSampleType
= wined3d_desc
.multisample_type
;
274 desc
->Width
= wined3d_desc
.width
;
275 desc
->Height
= wined3d_desc
.height
;
277 wined3d_mutex_unlock();
282 static HRESULT WINAPI
d3d8_texture_2d_GetSurfaceLevel(IDirect3DTexture8
*iface
,
283 UINT level
, IDirect3DSurface8
**surface
)
285 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
286 struct wined3d_resource
*sub_resource
;
287 struct d3d8_surface
*surface_impl
;
289 TRACE("iface %p, level %u, surface %p.\n", iface
, level
, surface
);
291 wined3d_mutex_lock();
292 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
294 wined3d_mutex_unlock();
295 return D3DERR_INVALIDCALL
;
298 surface_impl
= wined3d_resource_get_parent(sub_resource
);
299 *surface
= &surface_impl
->IDirect3DSurface8_iface
;
300 IDirect3DSurface8_AddRef(*surface
);
301 wined3d_mutex_unlock();
306 static HRESULT WINAPI
d3d8_texture_2d_LockRect(IDirect3DTexture8
*iface
, UINT level
,
307 D3DLOCKED_RECT
*locked_rect
, const RECT
*rect
, DWORD flags
)
309 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
310 struct wined3d_resource
*sub_resource
;
311 struct d3d8_surface
*surface_impl
;
314 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
315 iface
, level
, locked_rect
, rect
, flags
);
317 wined3d_mutex_lock();
318 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
319 hr
= D3DERR_INVALIDCALL
;
322 surface_impl
= wined3d_resource_get_parent(sub_resource
);
323 hr
= IDirect3DSurface8_LockRect(&surface_impl
->IDirect3DSurface8_iface
, locked_rect
, rect
, flags
);
325 wined3d_mutex_unlock();
330 static HRESULT WINAPI
d3d8_texture_2d_UnlockRect(IDirect3DTexture8
*iface
, UINT level
)
332 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
333 struct wined3d_resource
*sub_resource
;
334 struct d3d8_surface
*surface_impl
;
337 TRACE("iface %p, level %u.\n", iface
, level
);
339 wined3d_mutex_lock();
340 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
341 hr
= D3DERR_INVALIDCALL
;
344 surface_impl
= wined3d_resource_get_parent(sub_resource
);
345 hr
= IDirect3DSurface8_UnlockRect(&surface_impl
->IDirect3DSurface8_iface
);
347 wined3d_mutex_unlock();
352 static HRESULT WINAPI
d3d8_texture_2d_AddDirtyRect(IDirect3DTexture8
*iface
, const RECT
*dirty_rect
)
354 struct d3d8_texture
*texture
= impl_from_IDirect3DTexture8(iface
);
357 TRACE("iface %p, dirty_rect %s.\n",
358 iface
, wine_dbgstr_rect(dirty_rect
));
360 wined3d_mutex_lock();
362 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, NULL
);
365 struct wined3d_box dirty_region
;
367 dirty_region
.left
= dirty_rect
->left
;
368 dirty_region
.top
= dirty_rect
->top
;
369 dirty_region
.right
= dirty_rect
->right
;
370 dirty_region
.bottom
= dirty_rect
->bottom
;
371 dirty_region
.front
= 0;
372 dirty_region
.back
= 1;
373 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, &dirty_region
);
375 wined3d_mutex_unlock();
380 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl
=
383 d3d8_texture_2d_QueryInterface
,
384 d3d8_texture_2d_AddRef
,
385 d3d8_texture_2d_Release
,
386 /* IDirect3DResource8 */
387 d3d8_texture_2d_GetDevice
,
388 d3d8_texture_2d_SetPrivateData
,
389 d3d8_texture_2d_GetPrivateData
,
390 d3d8_texture_2d_FreePrivateData
,
391 d3d8_texture_2d_SetPriority
,
392 d3d8_texture_2d_GetPriority
,
393 d3d8_texture_2d_PreLoad
,
394 d3d8_texture_2d_GetType
,
395 /* IDirect3dBaseTexture8 */
396 d3d8_texture_2d_SetLOD
,
397 d3d8_texture_2d_GetLOD
,
398 d3d8_texture_2d_GetLevelCount
,
399 /* IDirect3DTexture8 */
400 d3d8_texture_2d_GetLevelDesc
,
401 d3d8_texture_2d_GetSurfaceLevel
,
402 d3d8_texture_2d_LockRect
,
403 d3d8_texture_2d_UnlockRect
,
404 d3d8_texture_2d_AddDirtyRect
,
407 static HRESULT WINAPI
d3d8_texture_cube_QueryInterface(IDirect3DCubeTexture8
*iface
, REFIID riid
, void **out
)
409 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
411 if (IsEqualGUID(riid
, &IID_IDirect3DCubeTexture8
)
412 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
413 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
414 || IsEqualGUID(riid
, &IID_IUnknown
))
416 IDirect3DCubeTexture8_AddRef(iface
);
421 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
424 return E_NOINTERFACE
;
427 static ULONG WINAPI
d3d8_texture_cube_AddRef(IDirect3DCubeTexture8
*iface
)
429 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
430 ULONG ref
= InterlockedIncrement(&texture
->refcount
);
432 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
436 IDirect3DDevice8_AddRef(texture
->parent_device
);
437 wined3d_mutex_lock();
438 wined3d_texture_incref(texture
->wined3d_texture
);
439 wined3d_mutex_unlock();
445 static ULONG WINAPI
d3d8_texture_cube_Release(IDirect3DCubeTexture8
*iface
)
447 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
448 ULONG ref
= InterlockedDecrement(&texture
->refcount
);
450 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
454 IDirect3DDevice8
*parent_device
= texture
->parent_device
;
456 TRACE("Releasing child %p.\n", texture
->wined3d_texture
);
458 wined3d_mutex_lock();
459 wined3d_texture_decref(texture
->wined3d_texture
);
460 wined3d_mutex_unlock();
462 /* Release the device last, as it may cause the device to be destroyed. */
463 IDirect3DDevice8_Release(parent_device
);
468 static HRESULT WINAPI
d3d8_texture_cube_GetDevice(IDirect3DCubeTexture8
*iface
, IDirect3DDevice8
**device
)
470 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
472 TRACE("iface %p, device %p.\n", iface
, device
);
474 *device
= texture
->parent_device
;
475 IDirect3DDevice8_AddRef(*device
);
477 TRACE("Returning device %p.\n", *device
);
482 static HRESULT WINAPI
d3d8_texture_cube_SetPrivateData(IDirect3DCubeTexture8
*iface
,
483 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
485 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
486 struct wined3d_resource
*resource
;
489 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
490 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
492 wined3d_mutex_lock();
493 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
494 hr
= wined3d_resource_set_private_data(resource
, guid
, data
, data_size
, flags
);
495 wined3d_mutex_unlock();
500 static HRESULT WINAPI
d3d8_texture_cube_GetPrivateData(IDirect3DCubeTexture8
*iface
,
501 REFGUID guid
, void *data
, DWORD
*data_size
)
503 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
504 struct wined3d_resource
*resource
;
507 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
508 iface
, debugstr_guid(guid
), data
, data_size
);
510 wined3d_mutex_lock();
511 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
512 hr
= wined3d_resource_get_private_data(resource
, guid
, data
, data_size
);
513 wined3d_mutex_unlock();
518 static HRESULT WINAPI
d3d8_texture_cube_FreePrivateData(IDirect3DCubeTexture8
*iface
, REFGUID guid
)
520 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
521 struct wined3d_resource
*resource
;
524 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
526 wined3d_mutex_lock();
527 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
528 hr
= wined3d_resource_free_private_data(resource
, guid
);
529 wined3d_mutex_unlock();
534 static DWORD WINAPI
d3d8_texture_cube_SetPriority(IDirect3DCubeTexture8
*iface
, DWORD priority
)
536 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
539 TRACE("iface %p, priority %u.\n", iface
, priority
);
541 wined3d_mutex_lock();
542 ret
= wined3d_texture_set_priority(texture
->wined3d_texture
, priority
);
543 wined3d_mutex_unlock();
548 static DWORD WINAPI
d3d8_texture_cube_GetPriority(IDirect3DCubeTexture8
*iface
)
550 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
553 TRACE("iface %p.\n", iface
);
555 wined3d_mutex_lock();
556 ret
= wined3d_texture_get_priority(texture
->wined3d_texture
);
557 wined3d_mutex_unlock();
562 static void WINAPI
d3d8_texture_cube_PreLoad(IDirect3DCubeTexture8
*iface
)
564 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
566 TRACE("iface %p.\n", iface
);
568 wined3d_mutex_lock();
569 wined3d_texture_preload(texture
->wined3d_texture
);
570 wined3d_mutex_unlock();
573 static D3DRESOURCETYPE WINAPI
d3d8_texture_cube_GetType(IDirect3DCubeTexture8
*iface
)
575 TRACE("iface %p.\n", iface
);
577 return D3DRTYPE_CUBETEXTURE
;
580 static DWORD WINAPI
d3d8_texture_cube_SetLOD(IDirect3DCubeTexture8
*iface
, DWORD lod
)
582 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
585 TRACE("iface %p, lod %u.\n", iface
, lod
);
587 wined3d_mutex_lock();
588 ret
= wined3d_texture_set_lod(texture
->wined3d_texture
, lod
);
589 wined3d_mutex_unlock();
594 static DWORD WINAPI
d3d8_texture_cube_GetLOD(IDirect3DCubeTexture8
*iface
)
596 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
599 TRACE("iface %p.\n", iface
);
601 wined3d_mutex_lock();
602 ret
= wined3d_texture_get_lod(texture
->wined3d_texture
);
603 wined3d_mutex_unlock();
608 static DWORD WINAPI
d3d8_texture_cube_GetLevelCount(IDirect3DCubeTexture8
*iface
)
610 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
613 TRACE("iface %p.\n", iface
);
615 wined3d_mutex_lock();
616 ret
= wined3d_texture_get_level_count(texture
->wined3d_texture
);
617 wined3d_mutex_unlock();
622 static HRESULT WINAPI
d3d8_texture_cube_GetLevelDesc(IDirect3DCubeTexture8
*iface
, UINT level
, D3DSURFACE_DESC
*desc
)
624 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
625 struct wined3d_resource
*sub_resource
;
628 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
630 wined3d_mutex_lock();
631 if (level
>= wined3d_texture_get_level_count(texture
->wined3d_texture
))
633 wined3d_mutex_unlock();
634 return D3DERR_INVALIDCALL
;
637 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
638 hr
= D3DERR_INVALIDCALL
;
641 struct wined3d_resource_desc wined3d_desc
;
643 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
644 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
645 desc
->Type
= wined3d_desc
.resource_type
;
646 desc
->Usage
= wined3d_desc
.usage
& WINED3DUSAGE_MASK
;
647 desc
->Pool
= wined3d_desc
.pool
;
648 desc
->Size
= wined3d_desc
.size
;
649 desc
->MultiSampleType
= wined3d_desc
.multisample_type
;
650 desc
->Width
= wined3d_desc
.width
;
651 desc
->Height
= wined3d_desc
.height
;
653 wined3d_mutex_unlock();
658 static HRESULT WINAPI
d3d8_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture8
*iface
,
659 D3DCUBEMAP_FACES face
, UINT level
, IDirect3DSurface8
**surface
)
661 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
662 struct wined3d_resource
*sub_resource
;
663 struct d3d8_surface
*surface_impl
;
664 UINT sub_resource_idx
;
667 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface
, face
, level
, surface
);
669 wined3d_mutex_lock();
670 level_count
= wined3d_texture_get_level_count(texture
->wined3d_texture
);
671 if (level
>= level_count
)
673 wined3d_mutex_unlock();
674 return D3DERR_INVALIDCALL
;
677 sub_resource_idx
= level_count
* face
+ level
;
678 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
680 wined3d_mutex_unlock();
681 return D3DERR_INVALIDCALL
;
684 surface_impl
= wined3d_resource_get_parent(sub_resource
);
685 *surface
= &surface_impl
->IDirect3DSurface8_iface
;
686 IDirect3DSurface8_AddRef(*surface
);
687 wined3d_mutex_unlock();
692 static HRESULT WINAPI
d3d8_texture_cube_LockRect(IDirect3DCubeTexture8
*iface
,
693 D3DCUBEMAP_FACES face
, UINT level
, D3DLOCKED_RECT
*locked_rect
, const RECT
*rect
,
696 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
697 struct wined3d_resource
*sub_resource
;
698 struct d3d8_surface
*surface_impl
;
699 UINT sub_resource_idx
;
702 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
703 iface
, face
, level
, locked_rect
, rect
, flags
);
705 wined3d_mutex_lock();
706 sub_resource_idx
= wined3d_texture_get_level_count(texture
->wined3d_texture
) * face
+ level
;
707 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
708 hr
= D3DERR_INVALIDCALL
;
711 surface_impl
= wined3d_resource_get_parent(sub_resource
);
712 hr
= IDirect3DSurface8_LockRect(&surface_impl
->IDirect3DSurface8_iface
, locked_rect
, rect
, flags
);
714 wined3d_mutex_unlock();
719 static HRESULT WINAPI
d3d8_texture_cube_UnlockRect(IDirect3DCubeTexture8
*iface
,
720 D3DCUBEMAP_FACES face
, UINT level
)
722 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
723 struct wined3d_resource
*sub_resource
;
724 struct d3d8_surface
*surface_impl
;
725 UINT sub_resource_idx
;
728 TRACE("iface %p, face %#x, level %u.\n", iface
, face
, level
);
730 wined3d_mutex_lock();
731 sub_resource_idx
= wined3d_texture_get_level_count(texture
->wined3d_texture
) * face
+ level
;
732 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
733 hr
= D3DERR_INVALIDCALL
;
736 surface_impl
= wined3d_resource_get_parent(sub_resource
);
737 hr
= IDirect3DSurface8_UnlockRect(&surface_impl
->IDirect3DSurface8_iface
);
739 wined3d_mutex_unlock();
744 static HRESULT WINAPI
d3d8_texture_cube_AddDirtyRect(IDirect3DCubeTexture8
*iface
,
745 D3DCUBEMAP_FACES face
, const RECT
*dirty_rect
)
747 struct d3d8_texture
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
750 TRACE("iface %p, face %#x, dirty_rect %s.\n",
751 iface
, face
, wine_dbgstr_rect(dirty_rect
));
753 wined3d_mutex_lock();
755 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, face
, NULL
);
758 struct wined3d_box dirty_region
;
760 dirty_region
.left
= dirty_rect
->left
;
761 dirty_region
.top
= dirty_rect
->top
;
762 dirty_region
.right
= dirty_rect
->right
;
763 dirty_region
.bottom
= dirty_rect
->bottom
;
764 dirty_region
.front
= 0;
765 dirty_region
.back
= 1;
766 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, face
, &dirty_region
);
768 wined3d_mutex_unlock();
773 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl
=
776 d3d8_texture_cube_QueryInterface
,
777 d3d8_texture_cube_AddRef
,
778 d3d8_texture_cube_Release
,
779 /* IDirect3DResource8 */
780 d3d8_texture_cube_GetDevice
,
781 d3d8_texture_cube_SetPrivateData
,
782 d3d8_texture_cube_GetPrivateData
,
783 d3d8_texture_cube_FreePrivateData
,
784 d3d8_texture_cube_SetPriority
,
785 d3d8_texture_cube_GetPriority
,
786 d3d8_texture_cube_PreLoad
,
787 d3d8_texture_cube_GetType
,
788 /* IDirect3DBaseTexture8 */
789 d3d8_texture_cube_SetLOD
,
790 d3d8_texture_cube_GetLOD
,
791 d3d8_texture_cube_GetLevelCount
,
792 /* IDirect3DCubeTexture8 */
793 d3d8_texture_cube_GetLevelDesc
,
794 d3d8_texture_cube_GetCubeMapSurface
,
795 d3d8_texture_cube_LockRect
,
796 d3d8_texture_cube_UnlockRect
,
797 d3d8_texture_cube_AddDirtyRect
,
800 static HRESULT WINAPI
d3d8_texture_3d_QueryInterface(IDirect3DVolumeTexture8
*iface
, REFIID riid
, void **out
)
802 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
804 if (IsEqualGUID(riid
, &IID_IDirect3DVolumeTexture8
)
805 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
806 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
807 || IsEqualGUID(riid
, &IID_IUnknown
))
809 IDirect3DVolumeTexture8_AddRef(iface
);
814 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
817 return E_NOINTERFACE
;
820 static ULONG WINAPI
d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8
*iface
)
822 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
823 ULONG ref
= InterlockedIncrement(&texture
->refcount
);
825 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
829 IDirect3DDevice8_AddRef(texture
->parent_device
);
830 wined3d_mutex_lock();
831 wined3d_texture_incref(texture
->wined3d_texture
);
832 wined3d_mutex_unlock();
838 static ULONG WINAPI
d3d8_texture_3d_Release(IDirect3DVolumeTexture8
*iface
)
840 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
841 ULONG ref
= InterlockedDecrement(&texture
->refcount
);
843 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
847 IDirect3DDevice8
*parent_device
= texture
->parent_device
;
849 wined3d_mutex_lock();
850 wined3d_texture_decref(texture
->wined3d_texture
);
851 wined3d_mutex_unlock();
853 /* Release the device last, as it may cause the device to be destroyed. */
854 IDirect3DDevice8_Release(parent_device
);
859 static HRESULT WINAPI
d3d8_texture_3d_GetDevice(IDirect3DVolumeTexture8
*iface
, IDirect3DDevice8
**device
)
861 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
863 TRACE("iface %p, device %p.\n", iface
, device
);
865 *device
= texture
->parent_device
;
866 IDirect3DDevice8_AddRef(*device
);
868 TRACE("Returning device %p.\n", *device
);
873 static HRESULT WINAPI
d3d8_texture_3d_SetPrivateData(IDirect3DVolumeTexture8
*iface
,
874 REFGUID guid
, const void *data
, DWORD data_size
, DWORD flags
)
876 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
877 struct wined3d_resource
*resource
;
880 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
881 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
883 wined3d_mutex_lock();
884 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
885 hr
= wined3d_resource_set_private_data(resource
, guid
, data
, data_size
, flags
);
886 wined3d_mutex_unlock();
891 static HRESULT WINAPI
d3d8_texture_3d_GetPrivateData(IDirect3DVolumeTexture8
*iface
,
892 REFGUID guid
, void *data
, DWORD
*data_size
)
894 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
895 struct wined3d_resource
*resource
;
898 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
899 iface
, debugstr_guid(guid
), data
, data_size
);
901 wined3d_mutex_lock();
902 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
903 hr
= wined3d_resource_get_private_data(resource
, guid
, data
, data_size
);
904 wined3d_mutex_unlock();
909 static HRESULT WINAPI
d3d8_texture_3d_FreePrivateData(IDirect3DVolumeTexture8
*iface
, REFGUID guid
)
911 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
912 struct wined3d_resource
*resource
;
915 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
917 wined3d_mutex_lock();
918 resource
= wined3d_texture_get_resource(texture
->wined3d_texture
);
919 hr
= wined3d_resource_free_private_data(resource
, guid
);
920 wined3d_mutex_unlock();
925 static DWORD WINAPI
d3d8_texture_3d_SetPriority(IDirect3DVolumeTexture8
*iface
, DWORD priority
)
927 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
930 TRACE("iface %p, priority %u.\n", iface
, priority
);
932 wined3d_mutex_lock();
933 ret
= wined3d_texture_set_priority(texture
->wined3d_texture
, priority
);
934 wined3d_mutex_unlock();
939 static DWORD WINAPI
d3d8_texture_3d_GetPriority(IDirect3DVolumeTexture8
*iface
)
941 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
944 TRACE("iface %p.\n", iface
);
946 wined3d_mutex_lock();
947 ret
= wined3d_texture_get_priority(texture
->wined3d_texture
);
948 wined3d_mutex_unlock();
953 static void WINAPI
d3d8_texture_3d_PreLoad(IDirect3DVolumeTexture8
*iface
)
955 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
957 TRACE("iface %p.\n", iface
);
959 wined3d_mutex_lock();
960 wined3d_texture_preload(texture
->wined3d_texture
);
961 wined3d_mutex_unlock();
964 static D3DRESOURCETYPE WINAPI
d3d8_texture_3d_GetType(IDirect3DVolumeTexture8
*iface
)
966 TRACE("iface %p.\n", iface
);
968 return D3DRTYPE_VOLUMETEXTURE
;
971 static DWORD WINAPI
d3d8_texture_3d_SetLOD(IDirect3DVolumeTexture8
*iface
, DWORD lod
)
973 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
976 TRACE("iface %p, lod %u.\n", iface
, lod
);
978 wined3d_mutex_lock();
979 ret
= wined3d_texture_set_lod(texture
->wined3d_texture
, lod
);
980 wined3d_mutex_unlock();
985 static DWORD WINAPI
d3d8_texture_3d_GetLOD(IDirect3DVolumeTexture8
*iface
)
987 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
990 TRACE("iface %p.\n", iface
);
992 wined3d_mutex_lock();
993 ret
= wined3d_texture_get_lod(texture
->wined3d_texture
);
994 wined3d_mutex_unlock();
999 static DWORD WINAPI
d3d8_texture_3d_GetLevelCount(IDirect3DVolumeTexture8
*iface
)
1001 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
1004 TRACE("iface %p.\n", iface
);
1006 wined3d_mutex_lock();
1007 ret
= wined3d_texture_get_level_count(texture
->wined3d_texture
);
1008 wined3d_mutex_unlock();
1013 static HRESULT WINAPI
d3d8_texture_3d_GetLevelDesc(IDirect3DVolumeTexture8
*iface
, UINT level
, D3DVOLUME_DESC
*desc
)
1015 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
1016 struct wined3d_resource
*sub_resource
;
1017 HRESULT hr
= D3D_OK
;
1019 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
1021 wined3d_mutex_lock();
1022 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
1023 hr
= D3DERR_INVALIDCALL
;
1026 struct wined3d_resource_desc wined3d_desc
;
1028 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
1029 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
1030 desc
->Type
= wined3d_desc
.resource_type
;
1031 desc
->Usage
= wined3d_desc
.usage
& WINED3DUSAGE_MASK
;
1032 desc
->Pool
= wined3d_desc
.pool
;
1033 desc
->Size
= wined3d_desc
.size
;
1034 desc
->Width
= wined3d_desc
.width
;
1035 desc
->Height
= wined3d_desc
.height
;
1036 desc
->Depth
= wined3d_desc
.depth
;
1038 wined3d_mutex_unlock();
1043 static HRESULT WINAPI
d3d8_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture8
*iface
,
1044 UINT level
, IDirect3DVolume8
**volume
)
1046 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
1047 struct wined3d_resource
*sub_resource
;
1048 struct d3d8_volume
*volume_impl
;
1050 TRACE("iface %p, level %u, volume %p.\n", iface
, level
, volume
);
1052 wined3d_mutex_lock();
1053 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
1055 wined3d_mutex_unlock();
1056 return D3DERR_INVALIDCALL
;
1059 volume_impl
= wined3d_resource_get_parent(sub_resource
);
1060 *volume
= &volume_impl
->IDirect3DVolume8_iface
;
1061 IDirect3DVolume8_AddRef(*volume
);
1062 wined3d_mutex_unlock();
1067 static HRESULT WINAPI
d3d8_texture_3d_LockBox(IDirect3DVolumeTexture8
*iface
,
1068 UINT level
, D3DLOCKED_BOX
*locked_box
, const D3DBOX
*box
, DWORD flags
)
1070 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
1071 struct wined3d_resource
*sub_resource
;
1072 struct d3d8_volume
*volume_impl
;
1075 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1076 iface
, level
, locked_box
, box
, flags
);
1078 wined3d_mutex_lock();
1079 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
1080 hr
= D3DERR_INVALIDCALL
;
1083 volume_impl
= wined3d_resource_get_parent(sub_resource
);
1084 hr
= IDirect3DVolume8_LockBox(&volume_impl
->IDirect3DVolume8_iface
, locked_box
, box
, flags
);
1086 wined3d_mutex_unlock();
1091 static HRESULT WINAPI
d3d8_texture_3d_UnlockBox(IDirect3DVolumeTexture8
*iface
, UINT level
)
1093 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
1094 struct wined3d_resource
*sub_resource
;
1095 struct d3d8_volume
*volume_impl
;
1098 TRACE("iface %p, level %u.\n", iface
, level
);
1100 wined3d_mutex_lock();
1101 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
1102 hr
= D3DERR_INVALIDCALL
;
1105 volume_impl
= wined3d_resource_get_parent(sub_resource
);
1106 hr
= IDirect3DVolume8_UnlockBox(&volume_impl
->IDirect3DVolume8_iface
);
1108 wined3d_mutex_unlock();
1113 static HRESULT WINAPI
d3d8_texture_3d_AddDirtyBox(IDirect3DVolumeTexture8
*iface
, const D3DBOX
*dirty_box
)
1115 struct d3d8_texture
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
1118 TRACE("iface %p, dirty_box %p.\n", iface
, dirty_box
);
1120 wined3d_mutex_lock();
1121 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, (const struct wined3d_box
*)dirty_box
);
1122 wined3d_mutex_unlock();
1127 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl
=
1130 d3d8_texture_3d_QueryInterface
,
1131 d3d8_texture_3d_AddRef
,
1132 d3d8_texture_3d_Release
,
1133 /* IDirect3DResource8 */
1134 d3d8_texture_3d_GetDevice
,
1135 d3d8_texture_3d_SetPrivateData
,
1136 d3d8_texture_3d_GetPrivateData
,
1137 d3d8_texture_3d_FreePrivateData
,
1138 d3d8_texture_3d_SetPriority
,
1139 d3d8_texture_3d_GetPriority
,
1140 d3d8_texture_3d_PreLoad
,
1141 d3d8_texture_3d_GetType
,
1142 /* IDirect3DBaseTexture8 */
1143 d3d8_texture_3d_SetLOD
,
1144 d3d8_texture_3d_GetLOD
,
1145 d3d8_texture_3d_GetLevelCount
,
1146 /* IDirect3DVolumeTexture8 */
1147 d3d8_texture_3d_GetLevelDesc
,
1148 d3d8_texture_3d_GetVolumeLevel
,
1149 d3d8_texture_3d_LockBox
,
1150 d3d8_texture_3d_UnlockBox
,
1151 d3d8_texture_3d_AddDirtyBox
1154 struct d3d8_texture
*unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture8
*iface
)
1158 assert(iface
->lpVtbl
== (const IDirect3DBaseTexture8Vtbl
*)&Direct3DTexture8_Vtbl
1159 || iface
->lpVtbl
== (const IDirect3DBaseTexture8Vtbl
*)&Direct3DCubeTexture8_Vtbl
1160 || iface
->lpVtbl
== (const IDirect3DBaseTexture8Vtbl
*)&Direct3DVolumeTexture8_Vtbl
);
1161 return CONTAINING_RECORD(iface
, struct d3d8_texture
, IDirect3DBaseTexture8_iface
);
1164 static void STDMETHODCALLTYPE
d3d8_texture_wined3d_object_destroyed(void *parent
)
1166 HeapFree(GetProcessHeap(), 0, parent
);
1169 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops
=
1171 d3d8_texture_wined3d_object_destroyed
,
1174 HRESULT
texture_init(struct d3d8_texture
*texture
, struct d3d8_device
*device
,
1175 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
1179 texture
->IDirect3DBaseTexture8_iface
.lpVtbl
= (const IDirect3DBaseTexture8Vtbl
*)&Direct3DTexture8_Vtbl
;
1180 texture
->refcount
= 1;
1182 wined3d_mutex_lock();
1183 hr
= wined3d_texture_create_2d(device
->wined3d_device
, width
, height
, levels
,
1184 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
,
1185 texture
, &d3d8_texture_wined3d_parent_ops
, &texture
->wined3d_texture
);
1186 wined3d_mutex_unlock();
1189 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
1193 texture
->parent_device
= &device
->IDirect3DDevice8_iface
;
1194 IDirect3DDevice8_AddRef(texture
->parent_device
);
1199 HRESULT
cubetexture_init(struct d3d8_texture
*texture
, struct d3d8_device
*device
,
1200 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
1204 texture
->IDirect3DBaseTexture8_iface
.lpVtbl
= (const IDirect3DBaseTexture8Vtbl
*)&Direct3DCubeTexture8_Vtbl
;
1205 texture
->refcount
= 1;
1207 wined3d_mutex_lock();
1208 hr
= wined3d_texture_create_cube(device
->wined3d_device
, edge_length
, levels
,
1209 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
, texture
,
1210 &d3d8_texture_wined3d_parent_ops
, &texture
->wined3d_texture
);
1211 wined3d_mutex_unlock();
1214 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr
);
1218 texture
->parent_device
= &device
->IDirect3DDevice8_iface
;
1219 IDirect3DDevice8_AddRef(texture
->parent_device
);
1224 HRESULT
volumetexture_init(struct d3d8_texture
*texture
, struct d3d8_device
*device
,
1225 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
1229 texture
->IDirect3DBaseTexture8_iface
.lpVtbl
= (const IDirect3DBaseTexture8Vtbl
*)&Direct3DVolumeTexture8_Vtbl
;
1230 texture
->refcount
= 1;
1232 wined3d_mutex_lock();
1233 hr
= wined3d_texture_create_3d(device
->wined3d_device
, width
, height
, depth
, levels
,
1234 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
, texture
,
1235 &d3d8_texture_wined3d_parent_ops
, &texture
->wined3d_texture
);
1236 wined3d_mutex_unlock();
1239 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr
);
1243 texture
->parent_device
= &device
->IDirect3DDevice8_iface
;
1244 IDirect3DDevice8_AddRef(texture
->parent_device
);