2 * IDirect3DVolumeTexture8 implementation
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
26 static inline IDirect3DVolumeTexture8Impl
*impl_from_IDirect3DVolumeTexture8(IDirect3DVolumeTexture8
*iface
)
28 return CONTAINING_RECORD(iface
, IDirect3DVolumeTexture8Impl
, IDirect3DVolumeTexture8_iface
);
31 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_QueryInterface(IDirect3DVolumeTexture8
*iface
,
32 REFIID riid
, void **ppobj
)
34 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
36 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
38 if (IsEqualGUID(riid
, &IID_IUnknown
)
39 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
40 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
41 || IsEqualGUID(riid
, &IID_IDirect3DVolumeTexture8
)) {
42 IUnknown_AddRef(iface
);
47 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
52 static ULONG WINAPI
IDirect3DVolumeTexture8Impl_AddRef(IDirect3DVolumeTexture8
*iface
)
54 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
55 ULONG ref
= InterlockedIncrement(&This
->ref
);
57 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
61 IDirect3DDevice8_AddRef(This
->parentDevice
);
63 wined3d_texture_incref(This
->wined3d_texture
);
64 wined3d_mutex_unlock();
70 static ULONG WINAPI
IDirect3DVolumeTexture8Impl_Release(IDirect3DVolumeTexture8
*iface
)
72 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
73 ULONG ref
= InterlockedDecrement(&This
->ref
);
75 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
78 IDirect3DDevice8
*parentDevice
= This
->parentDevice
;
81 wined3d_texture_decref(This
->wined3d_texture
);
82 wined3d_mutex_unlock();
84 /* Release the device last, as it may cause the device to be destroyed. */
85 IDirect3DDevice8_Release(parentDevice
);
90 /* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */
91 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTexture8
*iface
,
92 IDirect3DDevice8
**device
)
94 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
96 TRACE("iface %p, device %p.\n", iface
, device
);
98 *device
= (IDirect3DDevice8
*)This
->parentDevice
;
99 IDirect3DDevice8_AddRef(*device
);
101 TRACE("Returning device %p.\n", *device
);
106 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_SetPrivateData(IDirect3DVolumeTexture8
*iface
,
107 REFGUID refguid
, const void *pData
, DWORD SizeOfData
, DWORD Flags
)
109 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(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
IDirect3DVolumeTexture8Impl_GetPrivateData(IDirect3DVolumeTexture8
*iface
,
123 REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
)
125 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(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
IDirect3DVolumeTexture8Impl_FreePrivateData(IDirect3DVolumeTexture8
*iface
,
141 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(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
IDirect3DVolumeTexture8Impl_SetPriority(IDirect3DVolumeTexture8
*iface
,
156 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
159 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
161 wined3d_mutex_lock();
162 ret
= wined3d_texture_set_priority(This
->wined3d_texture
, PriorityNew
);
163 wined3d_mutex_unlock();
168 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_GetPriority(IDirect3DVolumeTexture8
*iface
)
170 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
173 TRACE("iface %p.\n", iface
);
175 wined3d_mutex_lock();
176 ret
= wined3d_texture_get_priority(This
->wined3d_texture
);
177 wined3d_mutex_unlock();
182 static void WINAPI
IDirect3DVolumeTexture8Impl_PreLoad(IDirect3DVolumeTexture8
*iface
)
184 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(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
IDirect3DVolumeTexture8Impl_GetType(IDirect3DVolumeTexture8
*iface
)
195 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(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 /* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */
208 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_SetLOD(IDirect3DVolumeTexture8
*iface
, DWORD LODNew
)
210 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
213 TRACE("iface %p, lod %u.\n", iface
, LODNew
);
215 wined3d_mutex_lock();
216 ret
= wined3d_texture_set_lod(This
->wined3d_texture
, LODNew
);
217 wined3d_mutex_unlock();
222 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_GetLOD(IDirect3DVolumeTexture8
*iface
)
224 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
227 TRACE("iface %p.\n", iface
);
229 wined3d_mutex_lock();
230 ret
= wined3d_texture_get_lod(This
->wined3d_texture
);
231 wined3d_mutex_unlock();
236 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_GetLevelCount(IDirect3DVolumeTexture8
*iface
)
238 IDirect3DVolumeTexture8Impl
*This
= impl_from_IDirect3DVolumeTexture8(iface
);
241 TRACE("iface %p.\n", iface
);
243 wined3d_mutex_lock();
244 ret
= wined3d_texture_get_level_count(This
->wined3d_texture
);
245 wined3d_mutex_unlock();
250 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetLevelDesc(IDirect3DVolumeTexture8
*iface
,
251 UINT level
, D3DVOLUME_DESC
*desc
)
253 IDirect3DVolumeTexture8Impl
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
254 struct wined3d_resource
*sub_resource
;
257 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
259 wined3d_mutex_lock();
260 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
261 hr
= D3DERR_INVALIDCALL
;
264 struct wined3d_resource_desc wined3d_desc
;
266 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
267 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
268 desc
->Type
= wined3d_desc
.resource_type
;
269 desc
->Usage
= wined3d_desc
.usage
;
270 desc
->Pool
= wined3d_desc
.pool
;
271 desc
->Size
= wined3d_desc
.size
;
272 desc
->Width
= wined3d_desc
.width
;
273 desc
->Height
= wined3d_desc
.height
;
274 desc
->Depth
= wined3d_desc
.depth
;
276 wined3d_mutex_unlock();
281 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetVolumeLevel(IDirect3DVolumeTexture8
*iface
,
282 UINT level
, IDirect3DVolume8
**volume
)
284 IDirect3DVolumeTexture8Impl
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
285 struct wined3d_resource
*sub_resource
;
287 TRACE("iface %p, level %u, volume %p.\n", iface
, level
, volume
);
289 wined3d_mutex_lock();
290 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
292 wined3d_mutex_unlock();
293 return D3DERR_INVALIDCALL
;
296 *volume
= wined3d_resource_get_parent(sub_resource
);
297 IDirect3DVolume8_AddRef(*volume
);
298 wined3d_mutex_unlock();
303 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_LockBox(IDirect3DVolumeTexture8
*iface
,
304 UINT level
, D3DLOCKED_BOX
*locked_box
, const D3DBOX
*box
, DWORD flags
)
306 IDirect3DVolumeTexture8Impl
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
307 struct wined3d_resource
*sub_resource
;
310 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
311 iface
, level
, locked_box
, box
, flags
);
313 wined3d_mutex_lock();
314 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
315 hr
= D3DERR_INVALIDCALL
;
317 hr
= IDirect3DVolume8_LockBox((IDirect3DVolume8
*)wined3d_resource_get_parent(sub_resource
),
318 locked_box
, box
, flags
);
319 wined3d_mutex_unlock();
324 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_UnlockBox(IDirect3DVolumeTexture8
*iface
,
327 IDirect3DVolumeTexture8Impl
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
328 struct wined3d_resource
*sub_resource
;
331 TRACE("iface %p, level %u.\n", iface
, level
);
333 wined3d_mutex_lock();
334 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
335 hr
= D3DERR_INVALIDCALL
;
337 hr
= IDirect3DVolume8_UnlockBox((IDirect3DVolume8
*)wined3d_resource_get_parent(sub_resource
));
338 wined3d_mutex_unlock();
343 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_AddDirtyBox(IDirect3DVolumeTexture8
*iface
,
344 const D3DBOX
*dirty_box
)
346 IDirect3DVolumeTexture8Impl
*texture
= impl_from_IDirect3DVolumeTexture8(iface
);
349 TRACE("iface %p, dirty_box %p.\n", iface
, dirty_box
);
351 wined3d_mutex_lock();
352 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, (const WINED3DBOX
*)dirty_box
);
353 wined3d_mutex_unlock();
358 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl
=
361 IDirect3DVolumeTexture8Impl_QueryInterface
,
362 IDirect3DVolumeTexture8Impl_AddRef
,
363 IDirect3DVolumeTexture8Impl_Release
,
364 /* IDirect3DResource8 */
365 IDirect3DVolumeTexture8Impl_GetDevice
,
366 IDirect3DVolumeTexture8Impl_SetPrivateData
,
367 IDirect3DVolumeTexture8Impl_GetPrivateData
,
368 IDirect3DVolumeTexture8Impl_FreePrivateData
,
369 IDirect3DVolumeTexture8Impl_SetPriority
,
370 IDirect3DVolumeTexture8Impl_GetPriority
,
371 IDirect3DVolumeTexture8Impl_PreLoad
,
372 IDirect3DVolumeTexture8Impl_GetType
,
373 /* IDirect3DBaseTexture8 */
374 IDirect3DVolumeTexture8Impl_SetLOD
,
375 IDirect3DVolumeTexture8Impl_GetLOD
,
376 IDirect3DVolumeTexture8Impl_GetLevelCount
,
377 /* IDirect3DVolumeTexture8 */
378 IDirect3DVolumeTexture8Impl_GetLevelDesc
,
379 IDirect3DVolumeTexture8Impl_GetVolumeLevel
,
380 IDirect3DVolumeTexture8Impl_LockBox
,
381 IDirect3DVolumeTexture8Impl_UnlockBox
,
382 IDirect3DVolumeTexture8Impl_AddDirtyBox
385 static void STDMETHODCALLTYPE
volumetexture_wined3d_object_destroyed(void *parent
)
387 HeapFree(GetProcessHeap(), 0, parent
);
390 static const struct wined3d_parent_ops d3d8_volumetexture_wined3d_parent_ops
=
392 volumetexture_wined3d_object_destroyed
,
395 HRESULT
volumetexture_init(IDirect3DVolumeTexture8Impl
*texture
, IDirect3DDevice8Impl
*device
,
396 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
400 texture
->IDirect3DVolumeTexture8_iface
.lpVtbl
= &Direct3DVolumeTexture8_Vtbl
;
403 wined3d_mutex_lock();
404 hr
= IWineD3DDevice_CreateVolumeTexture(device
->WineD3DDevice
, width
, height
, depth
, levels
,
405 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
, texture
,
406 &d3d8_volumetexture_wined3d_parent_ops
, &texture
->wined3d_texture
);
407 wined3d_mutex_unlock();
410 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr
);
414 texture
->parentDevice
= &device
->IDirect3DDevice8_iface
;
415 IDirect3DDevice8_AddRef(texture
->parentDevice
);