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 /* IDirect3DCubeTexture9 IUnknown parts follow: */
30 static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
31 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
33 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
35 if (IsEqualGUID(riid, &IID_IUnknown)
36 || IsEqualGUID(riid, &IID_IDirect3DResource9)
37 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
38 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
39 IDirect3DCubeTexture9_AddRef(iface);
44 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
49 static ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
50 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
51 ULONG ref = InterlockedIncrement(&This->ref);
53 TRACE("%p increasing refcount to %u.\n", iface, ref);
57 IDirect3DDevice9Ex_AddRef(This->parentDevice);
59 wined3d_texture_incref(This->wined3d_texture);
60 wined3d_mutex_unlock();
66 static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
67 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
68 ULONG ref = InterlockedDecrement(&This->ref);
70 TRACE("%p decreasing refcount to %u.\n", iface, ref);
73 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
75 TRACE("Releasing child %p.\n", This->wined3d_texture);
78 wined3d_texture_decref(This->wined3d_texture);
79 wined3d_mutex_unlock();
81 /* Release the device last, as it may cause the device to be destroyed. */
82 IDirect3DDevice9Ex_Release(parentDevice);
87 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
88 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(IDirect3DCubeTexture9 *iface, IDirect3DDevice9 **device)
90 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
92 TRACE("iface %p, device %p.\n", iface, device);
94 *device = (IDirect3DDevice9 *)This->parentDevice;
95 IDirect3DDevice9_AddRef(*device);
97 TRACE("Returning device %p.\n", *device);
102 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
103 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
106 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
107 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
109 wined3d_mutex_lock();
110 hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
111 wined3d_mutex_unlock();
116 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
117 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
120 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
121 iface, debugstr_guid(refguid), pData, pSizeOfData);
123 wined3d_mutex_lock();
124 hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
125 wined3d_mutex_unlock();
130 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
131 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
134 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
136 wined3d_mutex_lock();
137 hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
138 wined3d_mutex_unlock();
143 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
144 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
147 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
149 wined3d_mutex_lock();
150 ret = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
151 wined3d_mutex_unlock();
156 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
157 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
160 TRACE("iface %p.\n", iface);
162 wined3d_mutex_lock();
163 ret = wined3d_texture_get_priority(This->wined3d_texture);
164 wined3d_mutex_unlock();
169 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
170 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
172 TRACE("iface %p.\n", iface);
174 wined3d_mutex_lock();
175 wined3d_texture_preload(This->wined3d_texture);
176 wined3d_mutex_unlock();
179 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
180 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
183 TRACE("iface %p.\n", iface);
185 wined3d_mutex_lock();
186 ret = wined3d_texture_get_type(This->wined3d_texture);
187 wined3d_mutex_unlock();
192 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
193 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
194 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
197 TRACE("iface %p, lod %u.\n", iface, LODNew);
199 wined3d_mutex_lock();
200 ret = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
201 wined3d_mutex_unlock();
206 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
207 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
210 TRACE("iface %p.\n", iface);
212 wined3d_mutex_lock();
213 ret = wined3d_texture_get_lod(This->wined3d_texture);
214 wined3d_mutex_unlock();
219 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
220 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
223 TRACE("iface %p.\n", iface);
225 wined3d_mutex_lock();
226 ret = wined3d_texture_get_level_count(This->wined3d_texture);
227 wined3d_mutex_unlock();
232 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
233 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
236 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
238 wined3d_mutex_lock();
239 hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
240 wined3d_mutex_unlock();
245 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
246 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
247 D3DTEXTUREFILTERTYPE ret;
249 TRACE("iface %p.\n", iface);
251 wined3d_mutex_lock();
252 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(This->wined3d_texture);
253 wined3d_mutex_unlock();
258 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
259 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
261 TRACE("iface %p.\n", iface);
263 wined3d_mutex_lock();
264 wined3d_texture_generate_mipmaps(This->wined3d_texture);
265 wined3d_mutex_unlock();
268 /* IDirect3DCubeTexture9 Interface follow: */
269 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(IDirect3DCubeTexture9 *iface,
270 UINT level, D3DSURFACE_DESC *desc)
272 IDirect3DCubeTexture9Impl *texture = (IDirect3DCubeTexture9Impl *)iface;
273 struct wined3d_resource *sub_resource;
276 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
278 wined3d_mutex_lock();
279 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
280 hr = D3DERR_INVALIDCALL;
283 struct wined3d_resource_desc wined3d_desc;
285 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
286 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
287 desc->Type = wined3d_desc.resource_type;
288 desc->Usage = wined3d_desc.usage;
289 desc->Pool = wined3d_desc.pool;
290 desc->MultiSampleType = wined3d_desc.multisample_type;
291 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
292 desc->Width = wined3d_desc.width;
293 desc->Height = wined3d_desc.height;
295 wined3d_mutex_unlock();
300 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(IDirect3DCubeTexture9 *iface,
301 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface)
303 IDirect3DCubeTexture9Impl *texture = (IDirect3DCubeTexture9Impl *)iface;
304 struct wined3d_resource *sub_resource;
305 UINT sub_resource_idx;
307 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
309 wined3d_mutex_lock();
310 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
311 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
313 wined3d_mutex_unlock();
314 return D3DERR_INVALIDCALL;
317 *surface = wined3d_resource_get_parent(sub_resource);
318 IDirect3DSurface9_AddRef(*surface);
319 wined3d_mutex_unlock();
324 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(IDirect3DCubeTexture9 *iface,
325 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
327 IDirect3DCubeTexture9Impl *texture = (IDirect3DCubeTexture9Impl *)iface;
328 struct wined3d_resource *sub_resource;
329 UINT sub_resource_idx;
332 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
333 iface, face, level, locked_rect, rect, flags);
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)))
338 hr = D3DERR_INVALIDCALL;
340 hr = IDirect3DSurface9_LockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource),
341 locked_rect, rect, flags);
342 wined3d_mutex_unlock();
347 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(IDirect3DCubeTexture9 *iface,
348 D3DCUBEMAP_FACES face, UINT level)
350 IDirect3DCubeTexture9Impl *texture = (IDirect3DCubeTexture9Impl *)iface;
351 struct wined3d_resource *sub_resource;
352 UINT sub_resource_idx;
355 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
357 wined3d_mutex_lock();
358 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
359 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
360 hr = D3DERR_INVALIDCALL;
362 hr = IDirect3DSurface9_UnlockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource));
363 wined3d_mutex_unlock();
368 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(IDirect3DCubeTexture9 *iface,
369 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
371 IDirect3DCubeTexture9Impl *texture = (IDirect3DCubeTexture9Impl *)iface;
374 TRACE("iface %p, face %#x, dirty_rect %s.\n",
375 iface, face, wine_dbgstr_rect(dirty_rect));
377 wined3d_mutex_lock();
379 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
382 WINED3DBOX dirty_region;
384 dirty_region.Left = dirty_rect->left;
385 dirty_region.Top = dirty_rect->top;
386 dirty_region.Right = dirty_rect->right;
387 dirty_region.Bottom = dirty_rect->bottom;
388 dirty_region.Front = 0;
389 dirty_region.Back = 1;
390 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
392 wined3d_mutex_unlock();
397 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
400 IDirect3DCubeTexture9Impl_QueryInterface,
401 IDirect3DCubeTexture9Impl_AddRef,
402 IDirect3DCubeTexture9Impl_Release,
403 /* IDirect3DResource9 */
404 IDirect3DCubeTexture9Impl_GetDevice,
405 IDirect3DCubeTexture9Impl_SetPrivateData,
406 IDirect3DCubeTexture9Impl_GetPrivateData,
407 IDirect3DCubeTexture9Impl_FreePrivateData,
408 IDirect3DCubeTexture9Impl_SetPriority,
409 IDirect3DCubeTexture9Impl_GetPriority,
410 IDirect3DCubeTexture9Impl_PreLoad,
411 IDirect3DCubeTexture9Impl_GetType,
412 /* IDirect3DBaseTexture9 */
413 IDirect3DCubeTexture9Impl_SetLOD,
414 IDirect3DCubeTexture9Impl_GetLOD,
415 IDirect3DCubeTexture9Impl_GetLevelCount,
416 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
417 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
418 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
419 IDirect3DCubeTexture9Impl_GetLevelDesc,
420 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
421 IDirect3DCubeTexture9Impl_LockRect,
422 IDirect3DCubeTexture9Impl_UnlockRect,
423 IDirect3DCubeTexture9Impl_AddDirtyRect
426 static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
428 HeapFree(GetProcessHeap(), 0, parent);
431 static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
433 cubetexture_wined3d_object_destroyed,
436 HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
437 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
441 texture->lpVtbl = &Direct3DCubeTexture9_Vtbl;
444 wined3d_mutex_lock();
445 hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length,
446 levels, usage, wined3dformat_from_d3dformat(format), pool, texture,
447 &d3d9_cubetexture_wined3d_parent_ops, &texture->wined3d_texture);
448 wined3d_mutex_unlock();
451 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
455 texture->parentDevice = (IDirect3DDevice9Ex *)device;
456 IDirect3DDevice9Ex_AddRef(texture->parentDevice);