2 * IDirect3DCubeTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
29 static inline IDirect3DCubeTexture9Impl *impl_from_IDirect3DCubeTexture9(IDirect3DCubeTexture9 *iface)
31 return CONTAINING_RECORD(iface, IDirect3DCubeTexture9Impl, IDirect3DCubeTexture9_iface);
34 static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(IDirect3DCubeTexture9 *iface,
35 REFIID riid, void **ppobj)
37 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
39 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
41 if (IsEqualGUID(riid, &IID_IUnknown)
42 || IsEqualGUID(riid, &IID_IDirect3DResource9)
43 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
44 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
45 IDirect3DCubeTexture9_AddRef(iface);
50 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
55 static ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(IDirect3DCubeTexture9 *iface)
57 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
58 ULONG ref = InterlockedIncrement(&This->ref);
60 TRACE("%p increasing refcount to %u.\n", iface, ref);
64 IDirect3DDevice9Ex_AddRef(This->parentDevice);
66 wined3d_texture_incref(This->wined3d_texture);
67 wined3d_mutex_unlock();
73 static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(IDirect3DCubeTexture9 *iface)
75 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
76 ULONG ref = InterlockedDecrement(&This->ref);
78 TRACE("%p decreasing refcount to %u.\n", iface, ref);
81 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
83 TRACE("Releasing child %p.\n", This->wined3d_texture);
86 wined3d_texture_decref(This->wined3d_texture);
87 wined3d_mutex_unlock();
89 /* Release the device last, as it may cause the device to be destroyed. */
90 IDirect3DDevice9Ex_Release(parentDevice);
95 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
96 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(IDirect3DCubeTexture9 *iface,
97 IDirect3DDevice9 **device)
99 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
101 TRACE("iface %p, device %p.\n", iface, device);
103 *device = (IDirect3DDevice9 *)This->parentDevice;
104 IDirect3DDevice9_AddRef(*device);
106 TRACE("Returning device %p.\n", *device);
111 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(IDirect3DCubeTexture9 *iface,
112 REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
114 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
117 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
118 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
120 wined3d_mutex_lock();
121 hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
122 wined3d_mutex_unlock();
127 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(IDirect3DCubeTexture9 *iface,
128 REFGUID refguid, void *pData, DWORD *pSizeOfData)
130 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
133 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
134 iface, debugstr_guid(refguid), pData, pSizeOfData);
136 wined3d_mutex_lock();
137 hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
138 wined3d_mutex_unlock();
143 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(IDirect3DCubeTexture9 *iface,
146 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
149 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
151 wined3d_mutex_lock();
152 hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
153 wined3d_mutex_unlock();
158 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(IDirect3DCubeTexture9 *iface,
161 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
164 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
166 wined3d_mutex_lock();
167 ret = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
168 wined3d_mutex_unlock();
173 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(IDirect3DCubeTexture9 *iface)
175 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
178 TRACE("iface %p.\n", iface);
180 wined3d_mutex_lock();
181 ret = wined3d_texture_get_priority(This->wined3d_texture);
182 wined3d_mutex_unlock();
187 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(IDirect3DCubeTexture9 *iface)
189 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
191 TRACE("iface %p.\n", iface);
193 wined3d_mutex_lock();
194 wined3d_texture_preload(This->wined3d_texture);
195 wined3d_mutex_unlock();
198 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(IDirect3DCubeTexture9 *iface)
200 TRACE("iface %p.\n", iface);
202 return D3DRTYPE_CUBETEXTURE;
205 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
206 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(IDirect3DCubeTexture9 *iface, DWORD LODNew)
208 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
211 TRACE("iface %p, lod %u.\n", iface, LODNew);
213 wined3d_mutex_lock();
214 ret = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
215 wined3d_mutex_unlock();
220 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(IDirect3DCubeTexture9 *iface)
222 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
225 TRACE("iface %p.\n", iface);
227 wined3d_mutex_lock();
228 ret = wined3d_texture_get_lod(This->wined3d_texture);
229 wined3d_mutex_unlock();
234 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(IDirect3DCubeTexture9 *iface)
236 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
239 TRACE("iface %p.\n", iface);
241 wined3d_mutex_lock();
242 ret = wined3d_texture_get_level_count(This->wined3d_texture);
243 wined3d_mutex_unlock();
248 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(IDirect3DCubeTexture9 *iface,
249 D3DTEXTUREFILTERTYPE FilterType)
251 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
254 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
256 wined3d_mutex_lock();
257 hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
258 wined3d_mutex_unlock();
263 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(IDirect3DCubeTexture9 *iface)
265 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
266 D3DTEXTUREFILTERTYPE ret;
268 TRACE("iface %p.\n", iface);
270 wined3d_mutex_lock();
271 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(This->wined3d_texture);
272 wined3d_mutex_unlock();
277 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(IDirect3DCubeTexture9 *iface)
279 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
281 TRACE("iface %p.\n", iface);
283 wined3d_mutex_lock();
284 wined3d_texture_generate_mipmaps(This->wined3d_texture);
285 wined3d_mutex_unlock();
288 /* IDirect3DCubeTexture9 Interface follow: */
289 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(IDirect3DCubeTexture9 *iface,
290 UINT level, D3DSURFACE_DESC *desc)
292 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
293 struct wined3d_resource *sub_resource;
296 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
298 wined3d_mutex_lock();
299 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
300 hr = D3DERR_INVALIDCALL;
303 struct wined3d_resource_desc wined3d_desc;
305 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
306 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
307 desc->Type = wined3d_desc.resource_type;
308 desc->Usage = wined3d_desc.usage;
309 desc->Pool = wined3d_desc.pool;
310 desc->MultiSampleType = wined3d_desc.multisample_type;
311 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
312 desc->Width = wined3d_desc.width;
313 desc->Height = wined3d_desc.height;
315 wined3d_mutex_unlock();
320 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(IDirect3DCubeTexture9 *iface,
321 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface)
323 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
324 struct wined3d_resource *sub_resource;
325 UINT sub_resource_idx;
327 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
329 wined3d_mutex_lock();
330 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
331 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
333 wined3d_mutex_unlock();
334 return D3DERR_INVALIDCALL;
337 *surface = wined3d_resource_get_parent(sub_resource);
338 IDirect3DSurface9_AddRef(*surface);
339 wined3d_mutex_unlock();
344 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(IDirect3DCubeTexture9 *iface,
345 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
348 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
349 struct wined3d_resource *sub_resource;
350 UINT sub_resource_idx;
353 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
354 iface, face, level, locked_rect, rect, flags);
356 wined3d_mutex_lock();
357 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
358 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
359 hr = D3DERR_INVALIDCALL;
361 hr = IDirect3DSurface9_LockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource),
362 locked_rect, rect, flags);
363 wined3d_mutex_unlock();
368 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(IDirect3DCubeTexture9 *iface,
369 D3DCUBEMAP_FACES face, UINT level)
371 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
372 struct wined3d_resource *sub_resource;
373 UINT sub_resource_idx;
376 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
378 wined3d_mutex_lock();
379 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
380 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
381 hr = D3DERR_INVALIDCALL;
383 hr = IDirect3DSurface9_UnlockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource));
384 wined3d_mutex_unlock();
389 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(IDirect3DCubeTexture9 *iface,
390 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
392 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
395 TRACE("iface %p, face %#x, dirty_rect %s.\n",
396 iface, face, wine_dbgstr_rect(dirty_rect));
398 wined3d_mutex_lock();
400 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
403 WINED3DBOX dirty_region;
405 dirty_region.Left = dirty_rect->left;
406 dirty_region.Top = dirty_rect->top;
407 dirty_region.Right = dirty_rect->right;
408 dirty_region.Bottom = dirty_rect->bottom;
409 dirty_region.Front = 0;
410 dirty_region.Back = 1;
411 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
413 wined3d_mutex_unlock();
418 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
421 IDirect3DCubeTexture9Impl_QueryInterface,
422 IDirect3DCubeTexture9Impl_AddRef,
423 IDirect3DCubeTexture9Impl_Release,
424 /* IDirect3DResource9 */
425 IDirect3DCubeTexture9Impl_GetDevice,
426 IDirect3DCubeTexture9Impl_SetPrivateData,
427 IDirect3DCubeTexture9Impl_GetPrivateData,
428 IDirect3DCubeTexture9Impl_FreePrivateData,
429 IDirect3DCubeTexture9Impl_SetPriority,
430 IDirect3DCubeTexture9Impl_GetPriority,
431 IDirect3DCubeTexture9Impl_PreLoad,
432 IDirect3DCubeTexture9Impl_GetType,
433 /* IDirect3DBaseTexture9 */
434 IDirect3DCubeTexture9Impl_SetLOD,
435 IDirect3DCubeTexture9Impl_GetLOD,
436 IDirect3DCubeTexture9Impl_GetLevelCount,
437 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
438 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
439 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
440 IDirect3DCubeTexture9Impl_GetLevelDesc,
441 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
442 IDirect3DCubeTexture9Impl_LockRect,
443 IDirect3DCubeTexture9Impl_UnlockRect,
444 IDirect3DCubeTexture9Impl_AddDirtyRect
447 static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
449 HeapFree(GetProcessHeap(), 0, parent);
452 static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
454 cubetexture_wined3d_object_destroyed,
457 HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
458 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
462 texture->IDirect3DCubeTexture9_iface.lpVtbl = &Direct3DCubeTexture9_Vtbl;
465 wined3d_mutex_lock();
466 hr = wined3d_texture_create_cube(device->wined3d_device, edge_length,
467 levels, usage, wined3dformat_from_d3dformat(format), pool, texture,
468 &d3d9_cubetexture_wined3d_parent_ops, &texture->wined3d_texture);
469 wined3d_mutex_unlock();
472 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
476 texture->parentDevice = &device->IDirect3DDevice9Ex_iface;
477 IDirect3DDevice9Ex_AddRef(texture->parentDevice);