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 /* IDirect3DVolumeTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE8 iface
, REFIID riid
, LPVOID
*ppobj
) {
28 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
30 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
32 if (IsEqualGUID(riid
, &IID_IUnknown
)
33 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
34 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
35 || IsEqualGUID(riid
, &IID_IDirect3DVolumeTexture8
)) {
36 IUnknown_AddRef(iface
);
41 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
46 static ULONG WINAPI
IDirect3DVolumeTexture8Impl_AddRef(LPDIRECT3DVOLUMETEXTURE8 iface
) {
47 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
48 ULONG ref
= InterlockedIncrement(&This
->ref
);
50 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
54 IDirect3DDevice8_AddRef(This
->parentDevice
);
56 IWineD3DVolumeTexture_AddRef(This
->wineD3DVolumeTexture
);
57 wined3d_mutex_unlock();
63 static ULONG WINAPI
IDirect3DVolumeTexture8Impl_Release(LPDIRECT3DVOLUMETEXTURE8 iface
) {
64 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
65 ULONG ref
= InterlockedDecrement(&This
->ref
);
67 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
70 IDirect3DDevice8
*parentDevice
= This
->parentDevice
;
73 IWineD3DVolumeTexture_Release(This
->wineD3DVolumeTexture
);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice8_Release(parentDevice
);
82 /* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */
83 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTexture8
*iface
, IDirect3DDevice8
**device
)
85 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
87 TRACE("iface %p, device %p.\n", iface
, device
);
89 *device
= (IDirect3DDevice8
*)This
->parentDevice
;
90 IDirect3DDevice8_AddRef(*device
);
92 TRACE("Returning device %p.\n", *device
);
97 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
98 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
101 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
102 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
104 wined3d_mutex_lock();
105 hr
= IWineD3DVolumeTexture_SetPrivateData(This
->wineD3DVolumeTexture
, refguid
, pData
, SizeOfData
, Flags
);
106 wined3d_mutex_unlock();
111 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface
, REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
) {
112 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
115 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
116 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
118 wined3d_mutex_lock();
119 hr
= IWineD3DVolumeTexture_GetPrivateData(This
->wineD3DVolumeTexture
, refguid
, pData
, pSizeOfData
);
120 wined3d_mutex_unlock();
125 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE8 iface
, REFGUID refguid
) {
126 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
129 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
131 wined3d_mutex_lock();
132 hr
= IWineD3DVolumeTexture_FreePrivateData(This
->wineD3DVolumeTexture
, refguid
);
133 wined3d_mutex_unlock();
138 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE8 iface
, DWORD PriorityNew
) {
139 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
142 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
144 wined3d_mutex_lock();
145 ret
= IWineD3DVolumeTexture_SetPriority(This
->wineD3DVolumeTexture
, PriorityNew
);
146 wined3d_mutex_unlock();
151 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE8 iface
) {
152 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
155 TRACE("iface %p.\n", iface
);
157 wined3d_mutex_lock();
158 ret
= IWineD3DVolumeTexture_GetPriority(This
->wineD3DVolumeTexture
);
159 wined3d_mutex_unlock();
164 static void WINAPI
IDirect3DVolumeTexture8Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE8 iface
) {
165 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
167 TRACE("iface %p.\n", iface
);
169 wined3d_mutex_lock();
170 IWineD3DVolumeTexture_PreLoad(This
->wineD3DVolumeTexture
);
171 wined3d_mutex_unlock();
174 static D3DRESOURCETYPE WINAPI
IDirect3DVolumeTexture8Impl_GetType(LPDIRECT3DVOLUMETEXTURE8 iface
) {
175 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
176 D3DRESOURCETYPE type
;
178 TRACE("iface %p.\n", iface
);
180 wined3d_mutex_lock();
181 type
= IWineD3DVolumeTexture_GetType(This
->wineD3DVolumeTexture
);
182 wined3d_mutex_unlock();
187 /* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */
188 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE8 iface
, DWORD LODNew
) {
189 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
192 TRACE("iface %p, lod %u.\n", iface
, LODNew
);
194 wined3d_mutex_lock();
195 ret
= IWineD3DVolumeTexture_SetLOD(This
->wineD3DVolumeTexture
, LODNew
);
196 wined3d_mutex_unlock();
201 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE8 iface
) {
202 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
205 TRACE("iface %p.\n", iface
);
207 wined3d_mutex_lock();
208 ret
= IWineD3DVolumeTexture_GetLOD(This
->wineD3DVolumeTexture
);
209 wined3d_mutex_unlock();
214 static DWORD WINAPI
IDirect3DVolumeTexture8Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE8 iface
) {
215 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
218 TRACE("iface %p.\n", iface
);
220 wined3d_mutex_lock();
221 ret
= IWineD3DVolumeTexture_GetLevelCount(This
->wineD3DVolumeTexture
);
222 wined3d_mutex_unlock();
227 /* IDirect3DVolumeTexture8 Interface follow: */
228 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE8 iface
, UINT Level
, D3DVOLUME_DESC
* pDesc
) {
229 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
230 WINED3DVOLUME_DESC wined3ddesc
;
233 TRACE("iface %p, level %u, desc %p.\n", iface
, Level
, pDesc
);
235 wined3d_mutex_lock();
236 hr
= IWineD3DVolumeTexture_GetLevelDesc(This
->wineD3DVolumeTexture
, Level
, &wined3ddesc
);
237 wined3d_mutex_unlock();
241 pDesc
->Format
= d3dformat_from_wined3dformat(wined3ddesc
.Format
);
242 pDesc
->Type
= wined3ddesc
.Type
;
243 pDesc
->Usage
= wined3ddesc
.Usage
;
244 pDesc
->Pool
= wined3ddesc
.Pool
;
245 pDesc
->Size
= wined3ddesc
.Size
;
246 pDesc
->Width
= wined3ddesc
.Width
;
247 pDesc
->Height
= wined3ddesc
.Height
;
248 pDesc
->Depth
= wined3ddesc
.Depth
;
254 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE8 iface
, UINT Level
, IDirect3DVolume8
**ppVolumeLevel
) {
255 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
256 HRESULT hrc
= D3D_OK
;
257 IWineD3DVolume
*myVolume
= NULL
;
259 TRACE("iface %p, level %u, volume %p.\n", iface
, Level
, ppVolumeLevel
);
261 wined3d_mutex_lock();
262 hrc
= IWineD3DVolumeTexture_GetVolumeLevel(This
->wineD3DVolumeTexture
, Level
, &myVolume
);
263 if (hrc
== D3D_OK
&& NULL
!= ppVolumeLevel
) {
264 IWineD3DVolumeTexture_GetParent(myVolume
, (IUnknown
**)ppVolumeLevel
);
265 IWineD3DVolumeTexture_Release(myVolume
);
267 wined3d_mutex_unlock();
272 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_LockBox(LPDIRECT3DVOLUMETEXTURE8 iface
, UINT Level
, D3DLOCKED_BOX
*pLockedVolume
, CONST D3DBOX
*pBox
, DWORD Flags
) {
273 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
276 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
277 iface
, Level
, pLockedVolume
, pBox
, Flags
);
279 wined3d_mutex_lock();
280 hr
= IWineD3DVolumeTexture_LockBox(This
->wineD3DVolumeTexture
, Level
, (WINED3DLOCKED_BOX
*) pLockedVolume
, (CONST WINED3DBOX
*) pBox
, Flags
);
281 wined3d_mutex_unlock();
286 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE8 iface
, UINT Level
) {
287 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
290 TRACE("iface %p, level %u.\n", iface
, Level
);
292 wined3d_mutex_lock();
293 hr
= IWineD3DVolumeTexture_UnlockBox(This
->wineD3DVolumeTexture
, Level
);
294 wined3d_mutex_unlock();
299 static HRESULT WINAPI
IDirect3DVolumeTexture8Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE8 iface
, CONST D3DBOX
*pDirtyBox
) {
300 IDirect3DVolumeTexture8Impl
*This
= (IDirect3DVolumeTexture8Impl
*)iface
;
303 TRACE("iface %p, dirty_box %p.\n", iface
, pDirtyBox
);
305 wined3d_mutex_lock();
306 hr
= IWineD3DVolumeTexture_AddDirtyBox(This
->wineD3DVolumeTexture
, (CONST WINED3DBOX
*) pDirtyBox
);
307 wined3d_mutex_unlock();
312 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl
=
315 IDirect3DVolumeTexture8Impl_QueryInterface
,
316 IDirect3DVolumeTexture8Impl_AddRef
,
317 IDirect3DVolumeTexture8Impl_Release
,
318 /* IDirect3DResource8 */
319 IDirect3DVolumeTexture8Impl_GetDevice
,
320 IDirect3DVolumeTexture8Impl_SetPrivateData
,
321 IDirect3DVolumeTexture8Impl_GetPrivateData
,
322 IDirect3DVolumeTexture8Impl_FreePrivateData
,
323 IDirect3DVolumeTexture8Impl_SetPriority
,
324 IDirect3DVolumeTexture8Impl_GetPriority
,
325 IDirect3DVolumeTexture8Impl_PreLoad
,
326 IDirect3DVolumeTexture8Impl_GetType
,
327 /* IDirect3DBaseTexture8 */
328 IDirect3DVolumeTexture8Impl_SetLOD
,
329 IDirect3DVolumeTexture8Impl_GetLOD
,
330 IDirect3DVolumeTexture8Impl_GetLevelCount
,
331 /* IDirect3DVolumeTexture8 */
332 IDirect3DVolumeTexture8Impl_GetLevelDesc
,
333 IDirect3DVolumeTexture8Impl_GetVolumeLevel
,
334 IDirect3DVolumeTexture8Impl_LockBox
,
335 IDirect3DVolumeTexture8Impl_UnlockBox
,
336 IDirect3DVolumeTexture8Impl_AddDirtyBox
339 static void STDMETHODCALLTYPE
volumetexture_wined3d_object_destroyed(void *parent
)
341 HeapFree(GetProcessHeap(), 0, parent
);
344 static const struct wined3d_parent_ops d3d8_volumetexture_wined3d_parent_ops
=
346 volumetexture_wined3d_object_destroyed
,
349 HRESULT
volumetexture_init(IDirect3DVolumeTexture8Impl
*texture
, IDirect3DDevice8Impl
*device
,
350 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
354 texture
->lpVtbl
= &Direct3DVolumeTexture8_Vtbl
;
357 wined3d_mutex_lock();
358 hr
= IWineD3DDevice_CreateVolumeTexture(device
->WineD3DDevice
, width
, height
, depth
, levels
,
359 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
,
360 &texture
->wineD3DVolumeTexture
, (IUnknown
*)texture
, &d3d8_volumetexture_wined3d_parent_ops
);
361 wined3d_mutex_unlock();
364 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr
);
368 texture
->parentDevice
= (IDirect3DDevice8
*)device
;
369 IDirect3DDevice8_AddRef(texture
->parentDevice
);