d3d8: Properly retrieve an interface pointer in d3d8_texture_3d_GetVolumeLevel().
[wine/multimedia.git] / dlls / d3d8 / volumetexture.c
blob05ff065ec95151871b740fe82cc110d91feb1007
1 /*
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
21 #include "config.h"
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 static inline struct d3d8_texture *impl_from_IDirect3DVolumeTexture8(IDirect3DVolumeTexture8 *iface)
28 return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
31 static HRESULT WINAPI d3d8_texture_3d_QueryInterface(IDirect3DVolumeTexture8 *iface, REFIID riid, void **out)
33 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
35 if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)
36 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
37 || IsEqualGUID(riid, &IID_IDirect3DResource8)
38 || IsEqualGUID(riid, &IID_IUnknown))
40 IUnknown_AddRef(iface);
41 *out = iface;
42 return S_OK;
45 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
47 *out = NULL;
48 return E_NOINTERFACE;
51 static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface)
53 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
54 ULONG ref = InterlockedIncrement(&texture->refcount);
56 TRACE("%p increasing refcount to %u.\n", iface, ref);
58 if (ref == 1)
60 IDirect3DDevice8_AddRef(texture->parent_device);
61 wined3d_mutex_lock();
62 wined3d_texture_incref(texture->wined3d_texture);
63 wined3d_mutex_unlock();
66 return ref;
69 static ULONG WINAPI d3d8_texture_3d_Release(IDirect3DVolumeTexture8 *iface)
71 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
72 ULONG ref = InterlockedDecrement(&texture->refcount);
74 TRACE("%p decreasing refcount to %u.\n", iface, ref);
76 if (!ref)
78 IDirect3DDevice8 *parent_device = texture->parent_device;
80 wined3d_mutex_lock();
81 wined3d_texture_decref(texture->wined3d_texture);
82 wined3d_mutex_unlock();
84 /* Release the device last, as it may cause the device to be destroyed. */
85 IDirect3DDevice8_Release(parent_device);
87 return ref;
90 static HRESULT WINAPI d3d8_texture_3d_GetDevice(IDirect3DVolumeTexture8 *iface, IDirect3DDevice8 **device)
92 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
94 TRACE("iface %p, device %p.\n", iface, device);
96 *device = texture->parent_device;
97 IDirect3DDevice8_AddRef(*device);
99 TRACE("Returning device %p.\n", *device);
101 return D3D_OK;
104 static HRESULT WINAPI d3d8_texture_3d_SetPrivateData(IDirect3DVolumeTexture8 *iface,
105 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
107 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
108 struct wined3d_resource *resource;
109 HRESULT hr;
111 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
112 iface, debugstr_guid(guid), data, data_size, flags);
114 wined3d_mutex_lock();
115 resource = wined3d_texture_get_resource(texture->wined3d_texture);
116 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
117 wined3d_mutex_unlock();
119 return hr;
122 static HRESULT WINAPI d3d8_texture_3d_GetPrivateData(IDirect3DVolumeTexture8 *iface,
123 REFGUID guid, void *data, DWORD *data_size)
125 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
126 struct wined3d_resource *resource;
127 HRESULT hr;
129 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
130 iface, debugstr_guid(guid), data, data_size);
132 wined3d_mutex_lock();
133 resource = wined3d_texture_get_resource(texture->wined3d_texture);
134 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
135 wined3d_mutex_unlock();
137 return hr;
140 static HRESULT WINAPI d3d8_texture_3d_FreePrivateData(IDirect3DVolumeTexture8 *iface, REFGUID guid)
142 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
143 struct wined3d_resource *resource;
144 HRESULT hr;
146 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
148 wined3d_mutex_lock();
149 resource = wined3d_texture_get_resource(texture->wined3d_texture);
150 hr = wined3d_resource_free_private_data(resource, guid);
151 wined3d_mutex_unlock();
153 return hr;
156 static DWORD WINAPI d3d8_texture_3d_SetPriority(IDirect3DVolumeTexture8 *iface, DWORD priority)
158 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
159 DWORD ret;
161 TRACE("iface %p, priority %u.\n", iface, priority);
163 wined3d_mutex_lock();
164 ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
165 wined3d_mutex_unlock();
167 return ret;
170 static DWORD WINAPI d3d8_texture_3d_GetPriority(IDirect3DVolumeTexture8 *iface)
172 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
173 DWORD ret;
175 TRACE("iface %p.\n", iface);
177 wined3d_mutex_lock();
178 ret = wined3d_texture_get_priority(texture->wined3d_texture);
179 wined3d_mutex_unlock();
181 return ret;
184 static void WINAPI d3d8_texture_3d_PreLoad(IDirect3DVolumeTexture8 *iface)
186 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
188 TRACE("iface %p.\n", iface);
190 wined3d_mutex_lock();
191 wined3d_texture_preload(texture->wined3d_texture);
192 wined3d_mutex_unlock();
195 static D3DRESOURCETYPE WINAPI d3d8_texture_3d_GetType(IDirect3DVolumeTexture8 *iface)
197 TRACE("iface %p.\n", iface);
199 return D3DRTYPE_VOLUMETEXTURE;
202 static DWORD WINAPI d3d8_texture_3d_SetLOD(IDirect3DVolumeTexture8 *iface, DWORD lod)
204 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
205 DWORD ret;
207 TRACE("iface %p, lod %u.\n", iface, lod);
209 wined3d_mutex_lock();
210 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
211 wined3d_mutex_unlock();
213 return ret;
216 static DWORD WINAPI d3d8_texture_3d_GetLOD(IDirect3DVolumeTexture8 *iface)
218 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
219 DWORD ret;
221 TRACE("iface %p.\n", iface);
223 wined3d_mutex_lock();
224 ret = wined3d_texture_get_lod(texture->wined3d_texture);
225 wined3d_mutex_unlock();
227 return ret;
230 static DWORD WINAPI d3d8_texture_3d_GetLevelCount(IDirect3DVolumeTexture8 *iface)
232 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
233 DWORD ret;
235 TRACE("iface %p.\n", iface);
237 wined3d_mutex_lock();
238 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
239 wined3d_mutex_unlock();
241 return ret;
244 static HRESULT WINAPI d3d8_texture_3d_GetLevelDesc(IDirect3DVolumeTexture8 *iface, UINT level, D3DVOLUME_DESC *desc)
246 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
247 struct wined3d_resource *sub_resource;
248 HRESULT hr = D3D_OK;
250 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
252 wined3d_mutex_lock();
253 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
254 hr = D3DERR_INVALIDCALL;
255 else
257 struct wined3d_resource_desc wined3d_desc;
259 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
260 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
261 desc->Type = wined3d_desc.resource_type;
262 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
263 desc->Pool = wined3d_desc.pool;
264 desc->Size = wined3d_desc.size;
265 desc->Width = wined3d_desc.width;
266 desc->Height = wined3d_desc.height;
267 desc->Depth = wined3d_desc.depth;
269 wined3d_mutex_unlock();
271 return hr;
274 static HRESULT WINAPI d3d8_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture8 *iface,
275 UINT level, IDirect3DVolume8 **volume)
277 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
278 struct wined3d_resource *sub_resource;
279 IDirect3DVolume8Impl *volume_impl;
281 TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
283 wined3d_mutex_lock();
284 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
286 wined3d_mutex_unlock();
287 return D3DERR_INVALIDCALL;
290 volume_impl = wined3d_resource_get_parent(sub_resource);
291 *volume = &volume_impl->IDirect3DVolume8_iface;
292 IDirect3DVolume8_AddRef(*volume);
293 wined3d_mutex_unlock();
295 return D3D_OK;
298 static HRESULT WINAPI d3d8_texture_3d_LockBox(IDirect3DVolumeTexture8 *iface,
299 UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
301 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
302 struct wined3d_resource *sub_resource;
303 HRESULT hr;
305 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
306 iface, level, locked_box, box, flags);
308 wined3d_mutex_lock();
309 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
310 hr = D3DERR_INVALIDCALL;
311 else
312 hr = IDirect3DVolume8_LockBox((IDirect3DVolume8 *)wined3d_resource_get_parent(sub_resource),
313 locked_box, box, flags);
314 wined3d_mutex_unlock();
316 return hr;
319 static HRESULT WINAPI d3d8_texture_3d_UnlockBox(IDirect3DVolumeTexture8 *iface, UINT level)
321 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
322 struct wined3d_resource *sub_resource;
323 HRESULT hr;
325 TRACE("iface %p, level %u.\n", iface, level);
327 wined3d_mutex_lock();
328 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
329 hr = D3DERR_INVALIDCALL;
330 else
331 hr = IDirect3DVolume8_UnlockBox((IDirect3DVolume8 *)wined3d_resource_get_parent(sub_resource));
332 wined3d_mutex_unlock();
334 return hr;
337 static HRESULT WINAPI d3d8_texture_3d_AddDirtyBox(IDirect3DVolumeTexture8 *iface, const D3DBOX *dirty_box)
339 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
340 HRESULT hr;
342 TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
344 wined3d_mutex_lock();
345 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
346 wined3d_mutex_unlock();
348 return hr;
351 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
353 /* IUnknown */
354 d3d8_texture_3d_QueryInterface,
355 d3d8_texture_3d_AddRef,
356 d3d8_texture_3d_Release,
357 /* IDirect3DResource8 */
358 d3d8_texture_3d_GetDevice,
359 d3d8_texture_3d_SetPrivateData,
360 d3d8_texture_3d_GetPrivateData,
361 d3d8_texture_3d_FreePrivateData,
362 d3d8_texture_3d_SetPriority,
363 d3d8_texture_3d_GetPriority,
364 d3d8_texture_3d_PreLoad,
365 d3d8_texture_3d_GetType,
366 /* IDirect3DBaseTexture8 */
367 d3d8_texture_3d_SetLOD,
368 d3d8_texture_3d_GetLOD,
369 d3d8_texture_3d_GetLevelCount,
370 /* IDirect3DVolumeTexture8 */
371 d3d8_texture_3d_GetLevelDesc,
372 d3d8_texture_3d_GetVolumeLevel,
373 d3d8_texture_3d_LockBox,
374 d3d8_texture_3d_UnlockBox,
375 d3d8_texture_3d_AddDirtyBox
378 static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
380 HeapFree(GetProcessHeap(), 0, parent);
383 static const struct wined3d_parent_ops d3d8_volumetexture_wined3d_parent_ops =
385 volumetexture_wined3d_object_destroyed,
388 HRESULT volumetexture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
389 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
391 HRESULT hr;
393 texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl;
394 texture->refcount = 1;
396 wined3d_mutex_lock();
397 hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels,
398 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
399 &d3d8_volumetexture_wined3d_parent_ops, &texture->wined3d_texture);
400 wined3d_mutex_unlock();
401 if (FAILED(hr))
403 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
404 return hr;
407 texture->parent_device = &device->IDirect3DDevice8_iface;
408 IDirect3DDevice8_AddRef(texture->parent_device);
410 return D3D_OK;