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 /* IDirect3DVolumeTexture9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
31 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DResource9)
35 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
36 || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)) {
37 IDirect3DVolumeTexture9_AddRef(iface);
42 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
47 static ULONG WINAPI IDirect3DVolumeTexture9Impl_AddRef(LPDIRECT3DVOLUMETEXTURE9 iface) {
48 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
49 ULONG ref = InterlockedIncrement(&This->ref);
51 TRACE("%p increasing refcount to %u.\n", iface, ref);
55 IDirect3DDevice9Ex_AddRef(This->parentDevice);
57 IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
58 wined3d_mutex_unlock();
64 static ULONG WINAPI IDirect3DVolumeTexture9Impl_Release(LPDIRECT3DVOLUMETEXTURE9 iface) {
65 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
66 ULONG ref = InterlockedDecrement(&This->ref);
68 TRACE("%p decreasing refcount to %u.\n", iface, ref);
71 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
74 IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
75 wined3d_mutex_unlock();
77 /* Release the device last, as it may cause the device to be destroyed. */
78 IDirect3DDevice9Ex_Release(parentDevice);
83 /* IDirect3DVolumeTexture9 IDirect3DResource9 Interface follow: */
84 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(IDirect3DVolumeTexture9 *iface, IDirect3DDevice9 **device)
86 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
88 TRACE("iface %p, device %p.\n", iface, device);
90 *device = (IDirect3DDevice9 *)This->parentDevice;
91 IDirect3DDevice9_AddRef(*device);
93 TRACE("Returning device %p.\n", *device);
98 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
99 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
102 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
103 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
105 wined3d_mutex_lock();
107 hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
109 wined3d_mutex_unlock();
114 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
115 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
118 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
119 iface, debugstr_guid(refguid), pData, pSizeOfData);
121 wined3d_mutex_lock();
123 hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
125 wined3d_mutex_unlock();
130 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid) {
131 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
134 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
136 wined3d_mutex_lock();
138 hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
140 wined3d_mutex_unlock();
145 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD PriorityNew) {
146 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
149 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
151 wined3d_mutex_lock();
153 priority = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
155 wined3d_mutex_unlock();
160 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE9 iface) {
161 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
164 TRACE("iface %p.\n", iface);
166 wined3d_mutex_lock();
168 priority = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
170 wined3d_mutex_unlock();
175 static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE9 iface) {
176 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
178 TRACE("iface %p.\n", iface);
180 wined3d_mutex_lock();
182 IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
184 wined3d_mutex_unlock();
187 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(LPDIRECT3DVOLUMETEXTURE9 iface) {
188 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
189 D3DRESOURCETYPE type;
191 TRACE("iface %p.\n", iface);
193 wined3d_mutex_lock();
195 type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
197 wined3d_mutex_unlock();
202 /* IDirect3DVolumeTexture9 IDirect3DBaseTexture9 Interface follow: */
203 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD LODNew) {
204 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
207 TRACE("iface %p, lod %u.\n", iface, LODNew);
209 wined3d_mutex_lock();
211 lod = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
213 wined3d_mutex_unlock();
218 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE9 iface) {
219 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
222 TRACE("iface %p.\n", iface);
224 wined3d_mutex_lock();
226 lod = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
228 wined3d_mutex_unlock();
233 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE9 iface) {
234 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
237 TRACE("iface %p.\n", iface);
239 wined3d_mutex_lock();
241 level_count = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
243 wined3d_mutex_unlock();
248 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
249 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
252 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
254 wined3d_mutex_lock();
256 hr = IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
258 wined3d_mutex_unlock();
263 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface) {
264 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
265 D3DTEXTUREFILTERTYPE filter_type;
267 TRACE("iface %p.\n", iface);
269 wined3d_mutex_lock();
271 filter_type = (D3DTEXTUREFILTERTYPE)IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
273 wined3d_mutex_unlock();
278 static void WINAPI IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DVOLUMETEXTURE9 iface) {
279 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
281 TRACE("iface %p.\n", iface);
283 wined3d_mutex_lock();
285 IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
287 wined3d_mutex_unlock();
290 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(IDirect3DVolumeTexture9 *iface,
291 UINT level, D3DVOLUME_DESC *desc)
293 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
294 struct wined3d_resource_desc wined3d_desc;
297 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
299 wined3d_mutex_lock();
301 hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, level, &wined3d_desc);
303 wined3d_mutex_unlock();
307 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
308 desc->Type = wined3d_desc.resource_type;
309 desc->Usage = wined3d_desc.usage;
310 desc->Pool = wined3d_desc.pool;
311 desc->Width = wined3d_desc.width;
312 desc->Height = wined3d_desc.height;
313 desc->Depth = wined3d_desc.depth;
319 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetVolumeLevel(IDirect3DVolumeTexture9 *iface,
320 UINT Level, IDirect3DVolume9 **ppVolumeLevel)
322 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
323 IWineD3DVolume *myVolume = NULL;
326 TRACE("iface %p, level %u, volume %p.\n", iface, Level, ppVolumeLevel);
328 wined3d_mutex_lock();
330 hr = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
331 if (SUCCEEDED(hr) && ppVolumeLevel)
333 *ppVolumeLevel = IWineD3DVolumeTexture_GetParent(myVolume);
334 IDirect3DVolumeTexture9_AddRef(*ppVolumeLevel);
335 IWineD3DVolumeTexture_Release(myVolume);
338 wined3d_mutex_unlock();
343 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_LockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
344 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
347 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
348 iface, Level, pLockedVolume, pBox, Flags);
350 wined3d_mutex_lock();
352 hr = IWineD3DVolumeTexture_Map(This->wineD3DVolumeTexture, Level,
353 (WINED3DLOCKED_BOX *)pLockedVolume, (const WINED3DBOX *)pBox, Flags);
355 wined3d_mutex_unlock();
360 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level) {
361 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
364 TRACE("iface %p, level %u.\n", iface, Level);
366 wined3d_mutex_lock();
368 hr = IWineD3DVolumeTexture_Unmap(This->wineD3DVolumeTexture, Level);
370 wined3d_mutex_unlock();
375 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE9 iface, CONST D3DBOX* pDirtyBox) {
376 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
379 TRACE("iface %p, dirty_box %p.\n", iface, pDirtyBox);
381 wined3d_mutex_lock();
383 hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
385 wined3d_mutex_unlock();
391 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl =
394 IDirect3DVolumeTexture9Impl_QueryInterface,
395 IDirect3DVolumeTexture9Impl_AddRef,
396 IDirect3DVolumeTexture9Impl_Release,
397 /* IDirect3DResource9 */
398 IDirect3DVolumeTexture9Impl_GetDevice,
399 IDirect3DVolumeTexture9Impl_SetPrivateData,
400 IDirect3DVolumeTexture9Impl_GetPrivateData,
401 IDirect3DVolumeTexture9Impl_FreePrivateData,
402 IDirect3DVolumeTexture9Impl_SetPriority,
403 IDirect3DVolumeTexture9Impl_GetPriority,
404 IDirect3DVolumeTexture9Impl_PreLoad,
405 IDirect3DVolumeTexture9Impl_GetType,
406 /* IDirect3DBaseTexture9 */
407 IDirect3DVolumeTexture9Impl_SetLOD,
408 IDirect3DVolumeTexture9Impl_GetLOD,
409 IDirect3DVolumeTexture9Impl_GetLevelCount,
410 IDirect3DVolumeTexture9Impl_SetAutoGenFilterType,
411 IDirect3DVolumeTexture9Impl_GetAutoGenFilterType,
412 IDirect3DVolumeTexture9Impl_GenerateMipSubLevels,
413 /* IDirect3DVolumeTexture9 */
414 IDirect3DVolumeTexture9Impl_GetLevelDesc,
415 IDirect3DVolumeTexture9Impl_GetVolumeLevel,
416 IDirect3DVolumeTexture9Impl_LockBox,
417 IDirect3DVolumeTexture9Impl_UnlockBox,
418 IDirect3DVolumeTexture9Impl_AddDirtyBox
421 static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
423 HeapFree(GetProcessHeap(), 0, parent);
426 static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops =
428 volumetexture_wined3d_object_destroyed,
431 HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
432 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
436 texture->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
439 wined3d_mutex_lock();
440 hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
441 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
442 &d3d9_volumetexture_wined3d_parent_ops, &texture->wineD3DVolumeTexture);
443 wined3d_mutex_unlock();
446 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
450 texture->parentDevice = (IDirect3DDevice9Ex *)device;
451 IDirect3DDevice9Ex_AddRef(texture->parentDevice);