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 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DResource9)
33 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
34 || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)) {
35 IDirect3DVolumeTexture9_AddRef(iface);
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
45 static ULONG WINAPI IDirect3DVolumeTexture9Impl_AddRef(LPDIRECT3DVOLUMETEXTURE9 iface) {
46 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
53 IDirect3DDevice9Ex_AddRef(This->parentDevice);
55 IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
56 wined3d_mutex_unlock();
62 static ULONG WINAPI IDirect3DVolumeTexture9Impl_Release(LPDIRECT3DVOLUMETEXTURE9 iface) {
63 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
66 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
69 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
72 IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
73 wined3d_mutex_unlock();
75 /* Release the device last, as it may cause the device to be destroyed. */
76 IDirect3DDevice9Ex_Release(parentDevice);
81 /* IDirect3DVolumeTexture9 IDirect3DResource9 Interface follow: */
82 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
83 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
84 IWineD3DDevice *wined3d_device;
87 TRACE("(%p) Relay\n", This);
90 hr = IWineD3DStateBlock_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
93 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
94 IWineD3DDevice_Release(wined3d_device);
96 wined3d_mutex_unlock();
101 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
102 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
105 TRACE("(%p) Relay\n", This);
107 wined3d_mutex_lock();
109 hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
111 wined3d_mutex_unlock();
116 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
117 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
120 TRACE("(%p) Relay\n", This);
122 wined3d_mutex_lock();
124 hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
126 wined3d_mutex_unlock();
131 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid) {
132 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
135 TRACE("(%p) Relay\n", This);
137 wined3d_mutex_lock();
139 hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
141 wined3d_mutex_unlock();
146 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD PriorityNew) {
147 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
150 TRACE("(%p) Relay\n", This);
152 wined3d_mutex_lock();
154 priority = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
156 wined3d_mutex_unlock();
161 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE9 iface) {
162 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
165 TRACE("(%p) Relay\n", This);
167 wined3d_mutex_lock();
169 priority = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
171 wined3d_mutex_unlock();
176 static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE9 iface) {
177 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
179 TRACE("(%p) Relay\n", This);
181 wined3d_mutex_lock();
183 IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
185 wined3d_mutex_unlock();
188 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(LPDIRECT3DVOLUMETEXTURE9 iface) {
189 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
190 D3DRESOURCETYPE type;
192 TRACE("(%p) Relay\n", This);
194 wined3d_mutex_lock();
196 type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
198 wined3d_mutex_unlock();
203 /* IDirect3DVolumeTexture9 IDirect3DBaseTexture9 Interface follow: */
204 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD LODNew) {
205 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
208 TRACE("(%p) Relay\n", This);
210 wined3d_mutex_lock();
212 lod = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
214 wined3d_mutex_unlock();
219 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE9 iface) {
220 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
223 TRACE("(%p) Relay\n", This);
225 wined3d_mutex_lock();
227 lod = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
229 wined3d_mutex_unlock();
234 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE9 iface) {
235 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
238 TRACE("(%p) Relay\n", This);
240 wined3d_mutex_lock();
242 level_count = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
244 wined3d_mutex_unlock();
249 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
250 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
253 TRACE("(%p) Relay\n", This);
255 wined3d_mutex_lock();
257 hr = IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
259 wined3d_mutex_unlock();
264 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface) {
265 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
266 D3DTEXTUREFILTERTYPE filter_type;
268 TRACE("(%p) Relay\n", This);
270 wined3d_mutex_lock();
272 filter_type = (D3DTEXTUREFILTERTYPE)IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
274 wined3d_mutex_unlock();
279 static void WINAPI IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DVOLUMETEXTURE9 iface) {
280 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
282 TRACE("(%p) Relay\n", This);
284 wined3d_mutex_lock();
286 IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
288 wined3d_mutex_unlock();
291 /* IDirect3DVolumeTexture9 Interface follow: */
292 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DVOLUME_DESC* pDesc) {
293 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
294 WINED3DVOLUME_DESC wined3ddesc;
297 TRACE("(%p) Relay\n", This);
299 wined3d_mutex_lock();
301 hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
303 wined3d_mutex_unlock();
307 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
308 pDesc->Type = wined3ddesc.Type;
309 pDesc->Usage = wined3ddesc.Usage;
310 pDesc->Pool = wined3ddesc.Pool;
311 pDesc->Width = wined3ddesc.Width;
312 pDesc->Height = wined3ddesc.Height;
313 pDesc->Depth = wined3ddesc.Depth;
319 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, IDirect3DVolume9** ppVolumeLevel) {
320 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
321 HRESULT hrc = D3D_OK;
322 IWineD3DVolume *myVolume = NULL;
324 TRACE("(%p) Relay\n", This);
326 wined3d_mutex_lock();
328 hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
329 if (hrc == D3D_OK && NULL != ppVolumeLevel) {
330 IWineD3DVolumeTexture_GetParent(myVolume, (IUnknown **)ppVolumeLevel);
331 IWineD3DVolumeTexture_Release(myVolume);
334 wined3d_mutex_unlock();
339 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_LockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
340 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
343 TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
345 wined3d_mutex_lock();
347 hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *)pLockedVolume,
348 (const WINED3DBOX *)pBox, Flags);
350 wined3d_mutex_unlock();
355 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level) {
356 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
359 TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
361 wined3d_mutex_lock();
363 hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
365 wined3d_mutex_unlock();
370 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE9 iface, CONST D3DBOX* pDirtyBox) {
371 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
374 TRACE("(%p) Relay\n", This);
376 wined3d_mutex_lock();
378 hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
380 wined3d_mutex_unlock();
386 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl =
389 IDirect3DVolumeTexture9Impl_QueryInterface,
390 IDirect3DVolumeTexture9Impl_AddRef,
391 IDirect3DVolumeTexture9Impl_Release,
392 /* IDirect3DResource9 */
393 IDirect3DVolumeTexture9Impl_GetDevice,
394 IDirect3DVolumeTexture9Impl_SetPrivateData,
395 IDirect3DVolumeTexture9Impl_GetPrivateData,
396 IDirect3DVolumeTexture9Impl_FreePrivateData,
397 IDirect3DVolumeTexture9Impl_SetPriority,
398 IDirect3DVolumeTexture9Impl_GetPriority,
399 IDirect3DVolumeTexture9Impl_PreLoad,
400 IDirect3DVolumeTexture9Impl_GetType,
401 /* IDirect3DBaseTexture9 */
402 IDirect3DVolumeTexture9Impl_SetLOD,
403 IDirect3DVolumeTexture9Impl_GetLOD,
404 IDirect3DVolumeTexture9Impl_GetLevelCount,
405 IDirect3DVolumeTexture9Impl_SetAutoGenFilterType,
406 IDirect3DVolumeTexture9Impl_GetAutoGenFilterType,
407 IDirect3DVolumeTexture9Impl_GenerateMipSubLevels,
408 /* IDirect3DVolumeTexture9 */
409 IDirect3DVolumeTexture9Impl_GetLevelDesc,
410 IDirect3DVolumeTexture9Impl_GetVolumeLevel,
411 IDirect3DVolumeTexture9Impl_LockBox,
412 IDirect3DVolumeTexture9Impl_UnlockBox,
413 IDirect3DVolumeTexture9Impl_AddDirtyBox
416 static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
418 HeapFree(GetProcessHeap(), 0, parent);
421 static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops =
423 volumetexture_wined3d_object_destroyed,
426 HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
427 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
431 texture->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
434 wined3d_mutex_lock();
435 hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
436 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
437 &texture->wineD3DVolumeTexture, (IUnknown *)texture, &d3d9_volumetexture_wined3d_parent_ops);
438 wined3d_mutex_unlock();
441 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
445 texture->parentDevice = (IDirect3DDevice9Ex *)device;
446 IDirect3DDevice9Ex_AddRef(texture->parentDevice);