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);
115 struct wined3d_resource *resource;
118 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
119 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
121 wined3d_mutex_lock();
122 resource = wined3d_texture_get_resource(This->wined3d_texture);
123 hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
124 wined3d_mutex_unlock();
129 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(IDirect3DCubeTexture9 *iface,
130 REFGUID refguid, void *pData, DWORD *pSizeOfData)
132 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
133 struct wined3d_resource *resource;
136 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
137 iface, debugstr_guid(refguid), pData, pSizeOfData);
139 wined3d_mutex_lock();
140 resource = wined3d_texture_get_resource(This->wined3d_texture);
141 hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
142 wined3d_mutex_unlock();
147 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(IDirect3DCubeTexture9 *iface,
150 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
151 struct wined3d_resource *resource;
154 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
156 wined3d_mutex_lock();
157 resource = wined3d_texture_get_resource(This->wined3d_texture);
158 hr = wined3d_resource_free_private_data(resource, refguid);
159 wined3d_mutex_unlock();
164 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(IDirect3DCubeTexture9 *iface,
167 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
170 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
172 wined3d_mutex_lock();
173 ret = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
174 wined3d_mutex_unlock();
179 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(IDirect3DCubeTexture9 *iface)
181 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
184 TRACE("iface %p.\n", iface);
186 wined3d_mutex_lock();
187 ret = wined3d_texture_get_priority(This->wined3d_texture);
188 wined3d_mutex_unlock();
193 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(IDirect3DCubeTexture9 *iface)
195 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
197 TRACE("iface %p.\n", iface);
199 wined3d_mutex_lock();
200 wined3d_texture_preload(This->wined3d_texture);
201 wined3d_mutex_unlock();
204 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(IDirect3DCubeTexture9 *iface)
206 TRACE("iface %p.\n", iface);
208 return D3DRTYPE_CUBETEXTURE;
211 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
212 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(IDirect3DCubeTexture9 *iface, DWORD LODNew)
214 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
217 TRACE("iface %p, lod %u.\n", iface, LODNew);
219 wined3d_mutex_lock();
220 ret = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
221 wined3d_mutex_unlock();
226 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(IDirect3DCubeTexture9 *iface)
228 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
231 TRACE("iface %p.\n", iface);
233 wined3d_mutex_lock();
234 ret = wined3d_texture_get_lod(This->wined3d_texture);
235 wined3d_mutex_unlock();
240 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(IDirect3DCubeTexture9 *iface)
242 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
245 TRACE("iface %p.\n", iface);
247 wined3d_mutex_lock();
248 ret = wined3d_texture_get_level_count(This->wined3d_texture);
249 wined3d_mutex_unlock();
254 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(IDirect3DCubeTexture9 *iface,
255 D3DTEXTUREFILTERTYPE FilterType)
257 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
260 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
262 wined3d_mutex_lock();
263 hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
264 wined3d_mutex_unlock();
269 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(IDirect3DCubeTexture9 *iface)
271 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
272 D3DTEXTUREFILTERTYPE ret;
274 TRACE("iface %p.\n", iface);
276 wined3d_mutex_lock();
277 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(This->wined3d_texture);
278 wined3d_mutex_unlock();
283 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(IDirect3DCubeTexture9 *iface)
285 IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
287 TRACE("iface %p.\n", iface);
289 wined3d_mutex_lock();
290 wined3d_texture_generate_mipmaps(This->wined3d_texture);
291 wined3d_mutex_unlock();
294 /* IDirect3DCubeTexture9 Interface follow: */
295 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(IDirect3DCubeTexture9 *iface,
296 UINT level, D3DSURFACE_DESC *desc)
298 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
299 struct wined3d_resource *sub_resource;
302 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
304 wined3d_mutex_lock();
305 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
306 hr = D3DERR_INVALIDCALL;
309 struct wined3d_resource_desc wined3d_desc;
311 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
312 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
313 desc->Type = wined3d_desc.resource_type;
314 desc->Usage = wined3d_desc.usage;
315 desc->Pool = wined3d_desc.pool;
316 desc->MultiSampleType = wined3d_desc.multisample_type;
317 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
318 desc->Width = wined3d_desc.width;
319 desc->Height = wined3d_desc.height;
321 wined3d_mutex_unlock();
326 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(IDirect3DCubeTexture9 *iface,
327 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface)
329 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
330 struct wined3d_resource *sub_resource;
331 UINT sub_resource_idx;
333 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
335 wined3d_mutex_lock();
336 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
337 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
339 wined3d_mutex_unlock();
340 return D3DERR_INVALIDCALL;
343 *surface = wined3d_resource_get_parent(sub_resource);
344 IDirect3DSurface9_AddRef(*surface);
345 wined3d_mutex_unlock();
350 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(IDirect3DCubeTexture9 *iface,
351 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
354 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
355 struct wined3d_resource *sub_resource;
356 UINT sub_resource_idx;
359 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
360 iface, face, level, locked_rect, rect, flags);
362 wined3d_mutex_lock();
363 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
364 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
365 hr = D3DERR_INVALIDCALL;
367 hr = IDirect3DSurface9_LockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource),
368 locked_rect, rect, flags);
369 wined3d_mutex_unlock();
374 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(IDirect3DCubeTexture9 *iface,
375 D3DCUBEMAP_FACES face, UINT level)
377 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
378 struct wined3d_resource *sub_resource;
379 UINT sub_resource_idx;
382 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
384 wined3d_mutex_lock();
385 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
386 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
387 hr = D3DERR_INVALIDCALL;
389 hr = IDirect3DSurface9_UnlockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource));
390 wined3d_mutex_unlock();
395 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(IDirect3DCubeTexture9 *iface,
396 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
398 IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface);
401 TRACE("iface %p, face %#x, dirty_rect %s.\n",
402 iface, face, wine_dbgstr_rect(dirty_rect));
404 wined3d_mutex_lock();
406 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
409 WINED3DBOX dirty_region;
411 dirty_region.Left = dirty_rect->left;
412 dirty_region.Top = dirty_rect->top;
413 dirty_region.Right = dirty_rect->right;
414 dirty_region.Bottom = dirty_rect->bottom;
415 dirty_region.Front = 0;
416 dirty_region.Back = 1;
417 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
419 wined3d_mutex_unlock();
424 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
427 IDirect3DCubeTexture9Impl_QueryInterface,
428 IDirect3DCubeTexture9Impl_AddRef,
429 IDirect3DCubeTexture9Impl_Release,
430 /* IDirect3DResource9 */
431 IDirect3DCubeTexture9Impl_GetDevice,
432 IDirect3DCubeTexture9Impl_SetPrivateData,
433 IDirect3DCubeTexture9Impl_GetPrivateData,
434 IDirect3DCubeTexture9Impl_FreePrivateData,
435 IDirect3DCubeTexture9Impl_SetPriority,
436 IDirect3DCubeTexture9Impl_GetPriority,
437 IDirect3DCubeTexture9Impl_PreLoad,
438 IDirect3DCubeTexture9Impl_GetType,
439 /* IDirect3DBaseTexture9 */
440 IDirect3DCubeTexture9Impl_SetLOD,
441 IDirect3DCubeTexture9Impl_GetLOD,
442 IDirect3DCubeTexture9Impl_GetLevelCount,
443 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
444 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
445 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
446 IDirect3DCubeTexture9Impl_GetLevelDesc,
447 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
448 IDirect3DCubeTexture9Impl_LockRect,
449 IDirect3DCubeTexture9Impl_UnlockRect,
450 IDirect3DCubeTexture9Impl_AddDirtyRect
453 static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
455 HeapFree(GetProcessHeap(), 0, parent);
458 static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
460 cubetexture_wined3d_object_destroyed,
463 HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
464 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
468 texture->IDirect3DCubeTexture9_iface.lpVtbl = &Direct3DCubeTexture9_Vtbl;
471 wined3d_mutex_lock();
472 hr = wined3d_texture_create_cube(device->wined3d_device, edge_length,
473 levels, usage, wined3dformat_from_d3dformat(format), pool, texture,
474 &d3d9_cubetexture_wined3d_parent_ops, &texture->wined3d_texture);
475 wined3d_mutex_unlock();
478 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
482 texture->parentDevice = &device->IDirect3DDevice9Ex_iface;
483 IDirect3DDevice9Ex_AddRef(texture->parentDevice);