2 * IDirect3DVolumeTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 static inline IDirect3DVolumeTexture9Impl
*impl_from_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9
*iface
)
29 return CONTAINING_RECORD(iface
, IDirect3DVolumeTexture9Impl
, IDirect3DVolumeTexture9_iface
);
32 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_QueryInterface(IDirect3DVolumeTexture9
*iface
,
33 REFIID riid
, void **ppobj
)
35 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
37 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
39 if (IsEqualGUID(riid
, &IID_IUnknown
)
40 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
41 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture9
)
42 || IsEqualGUID(riid
, &IID_IDirect3DVolumeTexture9
)) {
43 IDirect3DVolumeTexture9_AddRef(iface
);
48 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
53 static ULONG WINAPI
IDirect3DVolumeTexture9Impl_AddRef(IDirect3DVolumeTexture9
*iface
)
55 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
56 ULONG ref
= InterlockedIncrement(&This
->ref
);
58 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
62 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
64 wined3d_texture_incref(This
->wined3d_texture
);
65 wined3d_mutex_unlock();
71 static ULONG WINAPI
IDirect3DVolumeTexture9Impl_Release(IDirect3DVolumeTexture9
*iface
)
73 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
74 ULONG ref
= InterlockedDecrement(&This
->ref
);
76 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
79 IDirect3DDevice9Ex
*parentDevice
= This
->parentDevice
;
82 wined3d_texture_decref(This
->wined3d_texture
);
83 wined3d_mutex_unlock();
85 /* Release the device last, as it may cause the device to be destroyed. */
86 IDirect3DDevice9Ex_Release(parentDevice
);
91 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_GetDevice(IDirect3DVolumeTexture9
*iface
,
92 IDirect3DDevice9
**device
)
94 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
96 TRACE("iface %p, device %p.\n", iface
, device
);
98 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
99 IDirect3DDevice9_AddRef(*device
);
101 TRACE("Returning device %p.\n", *device
);
106 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_SetPrivateData(IDirect3DVolumeTexture9
*iface
,
107 REFGUID refguid
, const void *pData
, DWORD SizeOfData
, DWORD Flags
)
109 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
110 struct wined3d_resource
*resource
;
113 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
114 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
116 wined3d_mutex_lock();
117 resource
= wined3d_texture_get_resource(This
->wined3d_texture
);
118 hr
= wined3d_resource_set_private_data(resource
, refguid
, pData
, SizeOfData
, Flags
);
119 wined3d_mutex_unlock();
124 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_GetPrivateData(IDirect3DVolumeTexture9
*iface
,
125 REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
)
127 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
128 struct wined3d_resource
*resource
;
131 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
132 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
134 wined3d_mutex_lock();
135 resource
= wined3d_texture_get_resource(This
->wined3d_texture
);
136 hr
= wined3d_resource_get_private_data(resource
, refguid
, pData
, pSizeOfData
);
137 wined3d_mutex_unlock();
142 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_FreePrivateData(IDirect3DVolumeTexture9
*iface
,
145 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
146 struct wined3d_resource
*resource
;
149 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
151 wined3d_mutex_lock();
152 resource
= wined3d_texture_get_resource(This
->wined3d_texture
);
153 hr
= wined3d_resource_free_private_data(resource
, refguid
);
154 wined3d_mutex_unlock();
159 static DWORD WINAPI
IDirect3DVolumeTexture9Impl_SetPriority(IDirect3DVolumeTexture9
*iface
,
162 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
165 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
167 wined3d_mutex_lock();
168 priority
= wined3d_texture_set_priority(This
->wined3d_texture
, PriorityNew
);
169 wined3d_mutex_unlock();
174 static DWORD WINAPI
IDirect3DVolumeTexture9Impl_GetPriority(IDirect3DVolumeTexture9
*iface
)
176 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
179 TRACE("iface %p.\n", iface
);
181 wined3d_mutex_lock();
182 priority
= wined3d_texture_get_priority(This
->wined3d_texture
);
183 wined3d_mutex_unlock();
188 static void WINAPI
IDirect3DVolumeTexture9Impl_PreLoad(IDirect3DVolumeTexture9
*iface
)
190 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
192 TRACE("iface %p.\n", iface
);
194 wined3d_mutex_lock();
195 wined3d_texture_preload(This
->wined3d_texture
);
196 wined3d_mutex_unlock();
199 static D3DRESOURCETYPE WINAPI
IDirect3DVolumeTexture9Impl_GetType(IDirect3DVolumeTexture9
*iface
)
201 TRACE("iface %p.\n", iface
);
203 return D3DRTYPE_VOLUMETEXTURE
;
206 static DWORD WINAPI
IDirect3DVolumeTexture9Impl_SetLOD(IDirect3DVolumeTexture9
*iface
, DWORD LODNew
)
208 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
211 TRACE("iface %p, lod %u.\n", iface
, LODNew
);
213 wined3d_mutex_lock();
214 lod
= wined3d_texture_set_lod(This
->wined3d_texture
, LODNew
);
215 wined3d_mutex_unlock();
220 static DWORD WINAPI
IDirect3DVolumeTexture9Impl_GetLOD(IDirect3DVolumeTexture9
*iface
)
222 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
225 TRACE("iface %p.\n", iface
);
227 wined3d_mutex_lock();
228 lod
= wined3d_texture_get_lod(This
->wined3d_texture
);
229 wined3d_mutex_unlock();
234 static DWORD WINAPI
IDirect3DVolumeTexture9Impl_GetLevelCount(IDirect3DVolumeTexture9
*iface
)
236 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
239 TRACE("iface %p.\n", iface
);
241 wined3d_mutex_lock();
242 level_count
= wined3d_texture_get_level_count(This
->wined3d_texture
);
243 wined3d_mutex_unlock();
248 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(IDirect3DVolumeTexture9
*iface
,
249 D3DTEXTUREFILTERTYPE FilterType
)
251 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
254 TRACE("iface %p, filter_type %#x.\n", iface
, FilterType
);
256 wined3d_mutex_lock();
257 hr
= wined3d_texture_set_autogen_filter_type(This
->wined3d_texture
, (WINED3DTEXTUREFILTERTYPE
)FilterType
);
258 wined3d_mutex_unlock();
263 static D3DTEXTUREFILTERTYPE WINAPI
IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(IDirect3DVolumeTexture9
*iface
)
265 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
266 D3DTEXTUREFILTERTYPE filter_type
;
268 TRACE("iface %p.\n", iface
);
270 wined3d_mutex_lock();
271 filter_type
= (D3DTEXTUREFILTERTYPE
)wined3d_texture_get_autogen_filter_type(This
->wined3d_texture
);
272 wined3d_mutex_unlock();
277 static void WINAPI
IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(IDirect3DVolumeTexture9
*iface
)
279 IDirect3DVolumeTexture9Impl
*This
= impl_from_IDirect3DVolumeTexture9(iface
);
281 TRACE("iface %p.\n", iface
);
283 wined3d_mutex_lock();
284 wined3d_texture_generate_mipmaps(This
->wined3d_texture
);
285 wined3d_mutex_unlock();
288 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_GetLevelDesc(IDirect3DVolumeTexture9
*iface
,
289 UINT level
, D3DVOLUME_DESC
*desc
)
291 IDirect3DVolumeTexture9Impl
*texture
= impl_from_IDirect3DVolumeTexture9(iface
);
292 struct wined3d_resource
*sub_resource
;
295 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
297 wined3d_mutex_lock();
298 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
299 hr
= D3DERR_INVALIDCALL
;
302 struct wined3d_resource_desc wined3d_desc
;
304 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
305 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
306 desc
->Type
= wined3d_desc
.resource_type
;
307 desc
->Usage
= wined3d_desc
.usage
;
308 desc
->Pool
= wined3d_desc
.pool
;
309 desc
->Width
= wined3d_desc
.width
;
310 desc
->Height
= wined3d_desc
.height
;
311 desc
->Depth
= wined3d_desc
.depth
;
313 wined3d_mutex_unlock();
318 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_GetVolumeLevel(IDirect3DVolumeTexture9
*iface
,
319 UINT level
, IDirect3DVolume9
**volume
)
321 IDirect3DVolumeTexture9Impl
*texture
= impl_from_IDirect3DVolumeTexture9(iface
);
322 struct wined3d_resource
*sub_resource
;
324 TRACE("iface %p, level %u, volume %p.\n", iface
, level
, volume
);
326 wined3d_mutex_lock();
327 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
329 wined3d_mutex_unlock();
330 return D3DERR_INVALIDCALL
;
333 *volume
= wined3d_resource_get_parent(sub_resource
);
334 IDirect3DVolume9_AddRef(*volume
);
335 wined3d_mutex_unlock();
340 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_LockBox(IDirect3DVolumeTexture9
*iface
,
341 UINT level
, D3DLOCKED_BOX
*locked_box
, const D3DBOX
*box
, DWORD flags
)
343 IDirect3DVolumeTexture9Impl
*texture
= impl_from_IDirect3DVolumeTexture9(iface
);
344 struct wined3d_resource
*sub_resource
;
347 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
348 iface
, level
, locked_box
, box
, flags
);
350 wined3d_mutex_lock();
351 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
352 hr
= D3DERR_INVALIDCALL
;
354 hr
= IDirect3DVolume9_LockBox((IDirect3DVolume9
*)wined3d_resource_get_parent(sub_resource
),
355 locked_box
, box
, flags
);
356 wined3d_mutex_unlock();
361 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_UnlockBox(IDirect3DVolumeTexture9
*iface
,
364 IDirect3DVolumeTexture9Impl
*texture
= impl_from_IDirect3DVolumeTexture9(iface
);
365 struct wined3d_resource
*sub_resource
;
368 TRACE("iface %p, level %u.\n", iface
, level
);
370 wined3d_mutex_lock();
371 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
372 hr
= D3DERR_INVALIDCALL
;
374 hr
= IDirect3DVolume9_UnlockBox((IDirect3DVolume9
*)wined3d_resource_get_parent(sub_resource
));
375 wined3d_mutex_unlock();
380 static HRESULT WINAPI
IDirect3DVolumeTexture9Impl_AddDirtyBox(IDirect3DVolumeTexture9
*iface
,
381 const D3DBOX
*dirty_box
)
383 IDirect3DVolumeTexture9Impl
*texture
= impl_from_IDirect3DVolumeTexture9(iface
);
386 TRACE("iface %p, dirty_box %p.\n", iface
, dirty_box
);
388 wined3d_mutex_lock();
389 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, (const WINED3DBOX
*)dirty_box
);
390 wined3d_mutex_unlock();
396 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl
=
399 IDirect3DVolumeTexture9Impl_QueryInterface
,
400 IDirect3DVolumeTexture9Impl_AddRef
,
401 IDirect3DVolumeTexture9Impl_Release
,
402 /* IDirect3DResource9 */
403 IDirect3DVolumeTexture9Impl_GetDevice
,
404 IDirect3DVolumeTexture9Impl_SetPrivateData
,
405 IDirect3DVolumeTexture9Impl_GetPrivateData
,
406 IDirect3DVolumeTexture9Impl_FreePrivateData
,
407 IDirect3DVolumeTexture9Impl_SetPriority
,
408 IDirect3DVolumeTexture9Impl_GetPriority
,
409 IDirect3DVolumeTexture9Impl_PreLoad
,
410 IDirect3DVolumeTexture9Impl_GetType
,
411 /* IDirect3DBaseTexture9 */
412 IDirect3DVolumeTexture9Impl_SetLOD
,
413 IDirect3DVolumeTexture9Impl_GetLOD
,
414 IDirect3DVolumeTexture9Impl_GetLevelCount
,
415 IDirect3DVolumeTexture9Impl_SetAutoGenFilterType
,
416 IDirect3DVolumeTexture9Impl_GetAutoGenFilterType
,
417 IDirect3DVolumeTexture9Impl_GenerateMipSubLevels
,
418 /* IDirect3DVolumeTexture9 */
419 IDirect3DVolumeTexture9Impl_GetLevelDesc
,
420 IDirect3DVolumeTexture9Impl_GetVolumeLevel
,
421 IDirect3DVolumeTexture9Impl_LockBox
,
422 IDirect3DVolumeTexture9Impl_UnlockBox
,
423 IDirect3DVolumeTexture9Impl_AddDirtyBox
426 static void STDMETHODCALLTYPE
volumetexture_wined3d_object_destroyed(void *parent
)
428 HeapFree(GetProcessHeap(), 0, parent
);
431 static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops
=
433 volumetexture_wined3d_object_destroyed
,
436 HRESULT
volumetexture_init(IDirect3DVolumeTexture9Impl
*texture
, IDirect3DDevice9Impl
*device
,
437 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
441 texture
->IDirect3DVolumeTexture9_iface
.lpVtbl
= &Direct3DVolumeTexture9_Vtbl
;
444 wined3d_mutex_lock();
445 hr
= wined3d_texture_create_3d(device
->wined3d_device
, width
, height
, depth
, levels
,
446 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
, texture
,
447 &d3d9_volumetexture_wined3d_parent_ops
, &texture
->wined3d_texture
);
448 wined3d_mutex_unlock();
451 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr
);
455 texture
->parentDevice
= &device
->IDirect3DDevice9Ex_iface
;
456 IDirect3DDevice9Ex_AddRef(texture
->parentDevice
);