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);
112 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
113 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
115 wined3d_mutex_lock();
116 hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
117 wined3d_mutex_unlock();
122 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(IDirect3DVolumeTexture9 *iface,
123 REFGUID refguid, void *pData, DWORD *pSizeOfData)
125 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
128 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
129 iface, debugstr_guid(refguid), pData, pSizeOfData);
131 wined3d_mutex_lock();
132 hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
133 wined3d_mutex_unlock();
138 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(IDirect3DVolumeTexture9 *iface,
141 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
144 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
146 wined3d_mutex_lock();
147 hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
148 wined3d_mutex_unlock();
153 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetPriority(IDirect3DVolumeTexture9 *iface,
156 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
159 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
161 wined3d_mutex_lock();
162 priority = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
163 wined3d_mutex_unlock();
168 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetPriority(IDirect3DVolumeTexture9 *iface)
170 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
173 TRACE("iface %p.\n", iface);
175 wined3d_mutex_lock();
176 priority = wined3d_texture_get_priority(This->wined3d_texture);
177 wined3d_mutex_unlock();
182 static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(IDirect3DVolumeTexture9 *iface)
184 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
186 TRACE("iface %p.\n", iface);
188 wined3d_mutex_lock();
189 wined3d_texture_preload(This->wined3d_texture);
190 wined3d_mutex_unlock();
193 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(IDirect3DVolumeTexture9 *iface)
195 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
196 D3DRESOURCETYPE type;
198 TRACE("iface %p.\n", iface);
200 wined3d_mutex_lock();
201 type = wined3d_texture_get_type(This->wined3d_texture);
202 wined3d_mutex_unlock();
207 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(IDirect3DVolumeTexture9 *iface, DWORD LODNew)
209 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
212 TRACE("iface %p, lod %u.\n", iface, LODNew);
214 wined3d_mutex_lock();
215 lod = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
216 wined3d_mutex_unlock();
221 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLOD(IDirect3DVolumeTexture9 *iface)
223 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
226 TRACE("iface %p.\n", iface);
228 wined3d_mutex_lock();
229 lod = wined3d_texture_get_lod(This->wined3d_texture);
230 wined3d_mutex_unlock();
235 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLevelCount(IDirect3DVolumeTexture9 *iface)
237 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
240 TRACE("iface %p.\n", iface);
242 wined3d_mutex_lock();
243 level_count = wined3d_texture_get_level_count(This->wined3d_texture);
244 wined3d_mutex_unlock();
249 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(IDirect3DVolumeTexture9 *iface,
250 D3DTEXTUREFILTERTYPE FilterType)
252 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
255 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
257 wined3d_mutex_lock();
258 hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
259 wined3d_mutex_unlock();
264 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(IDirect3DVolumeTexture9 *iface)
266 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
267 D3DTEXTUREFILTERTYPE filter_type;
269 TRACE("iface %p.\n", iface);
271 wined3d_mutex_lock();
272 filter_type = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(This->wined3d_texture);
273 wined3d_mutex_unlock();
278 static void WINAPI IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(IDirect3DVolumeTexture9 *iface)
280 IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
282 TRACE("iface %p.\n", iface);
284 wined3d_mutex_lock();
285 wined3d_texture_generate_mipmaps(This->wined3d_texture);
286 wined3d_mutex_unlock();
289 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(IDirect3DVolumeTexture9 *iface,
290 UINT level, D3DVOLUME_DESC *desc)
292 IDirect3DVolumeTexture9Impl *texture = impl_from_IDirect3DVolumeTexture9(iface);
293 struct wined3d_resource *sub_resource;
296 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
298 wined3d_mutex_lock();
299 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
300 hr = D3DERR_INVALIDCALL;
303 struct wined3d_resource_desc wined3d_desc;
305 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
306 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
307 desc->Type = wined3d_desc.resource_type;
308 desc->Usage = wined3d_desc.usage;
309 desc->Pool = wined3d_desc.pool;
310 desc->Width = wined3d_desc.width;
311 desc->Height = wined3d_desc.height;
312 desc->Depth = wined3d_desc.depth;
314 wined3d_mutex_unlock();
319 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetVolumeLevel(IDirect3DVolumeTexture9 *iface,
320 UINT level, IDirect3DVolume9 **volume)
322 IDirect3DVolumeTexture9Impl *texture = impl_from_IDirect3DVolumeTexture9(iface);
323 struct wined3d_resource *sub_resource;
325 TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
327 wined3d_mutex_lock();
328 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
330 wined3d_mutex_unlock();
331 return D3DERR_INVALIDCALL;
334 *volume = wined3d_resource_get_parent(sub_resource);
335 IDirect3DVolume9_AddRef(*volume);
336 wined3d_mutex_unlock();
341 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_LockBox(IDirect3DVolumeTexture9 *iface,
342 UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
344 IDirect3DVolumeTexture9Impl *texture = impl_from_IDirect3DVolumeTexture9(iface);
345 struct wined3d_resource *sub_resource;
348 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
349 iface, level, locked_box, box, flags);
351 wined3d_mutex_lock();
352 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
353 hr = D3DERR_INVALIDCALL;
355 hr = IDirect3DVolume9_LockBox((IDirect3DVolume9 *)wined3d_resource_get_parent(sub_resource),
356 locked_box, box, flags);
357 wined3d_mutex_unlock();
362 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_UnlockBox(IDirect3DVolumeTexture9 *iface,
365 IDirect3DVolumeTexture9Impl *texture = impl_from_IDirect3DVolumeTexture9(iface);
366 struct wined3d_resource *sub_resource;
369 TRACE("iface %p, level %u.\n", iface, level);
371 wined3d_mutex_lock();
372 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
373 hr = D3DERR_INVALIDCALL;
375 hr = IDirect3DVolume9_UnlockBox((IDirect3DVolume9 *)wined3d_resource_get_parent(sub_resource));
376 wined3d_mutex_unlock();
381 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(IDirect3DVolumeTexture9 *iface,
382 const D3DBOX *dirty_box)
384 IDirect3DVolumeTexture9Impl *texture = impl_from_IDirect3DVolumeTexture9(iface);
387 TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
389 wined3d_mutex_lock();
390 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const WINED3DBOX *)dirty_box);
391 wined3d_mutex_unlock();
397 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl =
400 IDirect3DVolumeTexture9Impl_QueryInterface,
401 IDirect3DVolumeTexture9Impl_AddRef,
402 IDirect3DVolumeTexture9Impl_Release,
403 /* IDirect3DResource9 */
404 IDirect3DVolumeTexture9Impl_GetDevice,
405 IDirect3DVolumeTexture9Impl_SetPrivateData,
406 IDirect3DVolumeTexture9Impl_GetPrivateData,
407 IDirect3DVolumeTexture9Impl_FreePrivateData,
408 IDirect3DVolumeTexture9Impl_SetPriority,
409 IDirect3DVolumeTexture9Impl_GetPriority,
410 IDirect3DVolumeTexture9Impl_PreLoad,
411 IDirect3DVolumeTexture9Impl_GetType,
412 /* IDirect3DBaseTexture9 */
413 IDirect3DVolumeTexture9Impl_SetLOD,
414 IDirect3DVolumeTexture9Impl_GetLOD,
415 IDirect3DVolumeTexture9Impl_GetLevelCount,
416 IDirect3DVolumeTexture9Impl_SetAutoGenFilterType,
417 IDirect3DVolumeTexture9Impl_GetAutoGenFilterType,
418 IDirect3DVolumeTexture9Impl_GenerateMipSubLevels,
419 /* IDirect3DVolumeTexture9 */
420 IDirect3DVolumeTexture9Impl_GetLevelDesc,
421 IDirect3DVolumeTexture9Impl_GetVolumeLevel,
422 IDirect3DVolumeTexture9Impl_LockBox,
423 IDirect3DVolumeTexture9Impl_UnlockBox,
424 IDirect3DVolumeTexture9Impl_AddDirtyBox
427 static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
429 HeapFree(GetProcessHeap(), 0, parent);
432 static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops =
434 volumetexture_wined3d_object_destroyed,
437 HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
438 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
442 texture->IDirect3DVolumeTexture9_iface.lpVtbl = &Direct3DVolumeTexture9_Vtbl;
445 wined3d_mutex_lock();
446 hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
447 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
448 &d3d9_volumetexture_wined3d_parent_ops, &texture->wined3d_texture);
449 wined3d_mutex_unlock();
452 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
456 texture->parentDevice = &device->IDirect3DDevice9Ex_iface;
457 IDirect3DDevice9Ex_AddRef(texture->parentDevice);