2 * IDirect3DCubeTexture8 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
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
26 static inline IDirect3DCubeTexture8Impl
*impl_from_IDirect3DCubeTexture8(IDirect3DCubeTexture8
*iface
)
28 return CONTAINING_RECORD(iface
, IDirect3DCubeTexture8Impl
, IDirect3DCubeTexture8_iface
);
31 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_QueryInterface(IDirect3DCubeTexture8
*iface
,
32 REFIID riid
, void **ppobj
)
34 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
36 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
38 if (IsEqualGUID(riid
, &IID_IUnknown
)
39 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
40 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
41 || IsEqualGUID(riid
, &IID_IDirect3DCubeTexture8
)) {
42 IUnknown_AddRef(iface
);
47 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
52 static ULONG WINAPI
IDirect3DCubeTexture8Impl_AddRef(IDirect3DCubeTexture8
*iface
)
54 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
55 ULONG ref
= InterlockedIncrement(&This
->ref
);
57 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
61 IUnknown_AddRef(This
->parentDevice
);
63 wined3d_texture_incref(This
->wined3d_texture
);
64 wined3d_mutex_unlock();
70 static ULONG WINAPI
IDirect3DCubeTexture8Impl_Release(IDirect3DCubeTexture8
*iface
)
72 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
73 ULONG ref
= InterlockedDecrement(&This
->ref
);
75 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
78 IDirect3DDevice8
*parentDevice
= This
->parentDevice
;
80 TRACE("Releasing child %p.\n", This
->wined3d_texture
);
83 wined3d_texture_decref(This
->wined3d_texture
);
84 wined3d_mutex_unlock();
86 /* Release the device last, as it may cause the device to be destroyed. */
87 IDirect3DDevice8_Release(parentDevice
);
92 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
93 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8
*iface
,
94 IDirect3DDevice8
**device
)
96 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
98 TRACE("iface %p, device %p.\n", iface
, device
);
100 *device
= (IDirect3DDevice8
*)This
->parentDevice
;
101 IDirect3DDevice8_AddRef(*device
);
103 TRACE("Returning device %p.\n", *device
);
108 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_SetPrivateData(IDirect3DCubeTexture8
*iface
,
109 REFGUID refguid
, const void *pData
, DWORD SizeOfData
, DWORD Flags
)
111 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
114 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
115 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
117 wined3d_mutex_lock();
118 hr
= wined3d_texture_set_private_data(This
->wined3d_texture
, refguid
, pData
, SizeOfData
, Flags
);
119 wined3d_mutex_unlock();
124 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_GetPrivateData(IDirect3DCubeTexture8
*iface
,
125 REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
)
127 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
130 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
131 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
133 wined3d_mutex_lock();
134 hr
= wined3d_texture_get_private_data(This
->wined3d_texture
, refguid
, pData
, pSizeOfData
);
135 wined3d_mutex_unlock();
140 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_FreePrivateData(IDirect3DCubeTexture8
*iface
,
143 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
146 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
148 wined3d_mutex_lock();
149 hr
= wined3d_texture_free_private_data(This
->wined3d_texture
, refguid
);
150 wined3d_mutex_unlock();
155 static DWORD WINAPI
IDirect3DCubeTexture8Impl_SetPriority(IDirect3DCubeTexture8
*iface
,
158 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
161 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
163 wined3d_mutex_lock();
164 ret
= wined3d_texture_set_priority(This
->wined3d_texture
, PriorityNew
);
165 wined3d_mutex_unlock();
170 static DWORD WINAPI
IDirect3DCubeTexture8Impl_GetPriority(IDirect3DCubeTexture8
*iface
)
172 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
175 TRACE("iface %p.\n", iface
);
177 wined3d_mutex_lock();
178 ret
= wined3d_texture_get_priority(This
->wined3d_texture
);
179 wined3d_mutex_unlock();
184 static void WINAPI
IDirect3DCubeTexture8Impl_PreLoad(IDirect3DCubeTexture8
*iface
)
186 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
188 TRACE("iface %p.\n", iface
);
190 wined3d_mutex_lock();
191 wined3d_texture_preload(This
->wined3d_texture
);
192 wined3d_mutex_unlock();
195 static D3DRESOURCETYPE WINAPI
IDirect3DCubeTexture8Impl_GetType(IDirect3DCubeTexture8
*iface
)
197 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
198 D3DRESOURCETYPE type
;
200 TRACE("iface %p.\n", iface
);
202 wined3d_mutex_lock();
203 type
= wined3d_texture_get_type(This
->wined3d_texture
);
204 wined3d_mutex_unlock();
209 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
210 static DWORD WINAPI
IDirect3DCubeTexture8Impl_SetLOD(IDirect3DCubeTexture8
*iface
, DWORD LODNew
)
212 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
215 TRACE("iface %p, lod %u.\n", iface
, LODNew
);
217 wined3d_mutex_lock();
218 lod
= wined3d_texture_set_lod(This
->wined3d_texture
, LODNew
);
219 wined3d_mutex_unlock();
224 static DWORD WINAPI
IDirect3DCubeTexture8Impl_GetLOD(IDirect3DCubeTexture8
*iface
)
226 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
229 TRACE("iface %p.\n", iface
);
231 wined3d_mutex_lock();
232 lod
= wined3d_texture_get_lod(This
->wined3d_texture
);
233 wined3d_mutex_unlock();
238 static DWORD WINAPI
IDirect3DCubeTexture8Impl_GetLevelCount(IDirect3DCubeTexture8
*iface
)
240 IDirect3DCubeTexture8Impl
*This
= impl_from_IDirect3DCubeTexture8(iface
);
243 TRACE("iface %p.\n", iface
);
245 wined3d_mutex_lock();
246 cnt
= wined3d_texture_get_level_count(This
->wined3d_texture
);
247 wined3d_mutex_unlock();
252 /* IDirect3DCubeTexture8 Interface follow: */
253 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_GetLevelDesc(IDirect3DCubeTexture8
*iface
,
254 UINT level
, D3DSURFACE_DESC
*desc
)
256 IDirect3DCubeTexture8Impl
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
257 struct wined3d_resource
*sub_resource
;
260 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
262 wined3d_mutex_lock();
263 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
264 hr
= D3DERR_INVALIDCALL
;
267 struct wined3d_resource_desc wined3d_desc
;
269 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
270 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
271 desc
->Type
= wined3d_desc
.resource_type
;
272 desc
->Usage
= wined3d_desc
.usage
;
273 desc
->Pool
= wined3d_desc
.pool
;
274 desc
->Size
= wined3d_desc
.size
;
275 desc
->MultiSampleType
= wined3d_desc
.multisample_type
;
276 desc
->Width
= wined3d_desc
.width
;
277 desc
->Height
= wined3d_desc
.height
;
279 wined3d_mutex_unlock();
284 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_GetCubeMapSurface(IDirect3DCubeTexture8
*iface
,
285 D3DCUBEMAP_FACES face
, UINT level
, IDirect3DSurface8
**surface
)
287 IDirect3DCubeTexture8Impl
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
288 struct wined3d_resource
*sub_resource
;
289 UINT sub_resource_idx
;
291 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface
, face
, level
, surface
);
293 wined3d_mutex_lock();
294 sub_resource_idx
= wined3d_texture_get_level_count(texture
->wined3d_texture
) * face
+ level
;
295 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
297 wined3d_mutex_unlock();
298 return D3DERR_INVALIDCALL
;
301 *surface
= wined3d_resource_get_parent(sub_resource
);
302 IDirect3DSurface8_AddRef(*surface
);
303 wined3d_mutex_unlock();
308 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_LockRect(IDirect3DCubeTexture8
*iface
,
309 D3DCUBEMAP_FACES face
, UINT level
, D3DLOCKED_RECT
*locked_rect
, const RECT
*rect
,
312 IDirect3DCubeTexture8Impl
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
313 struct wined3d_resource
*sub_resource
;
314 UINT sub_resource_idx
;
317 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
318 iface
, face
, level
, locked_rect
, rect
, flags
);
320 wined3d_mutex_lock();
321 sub_resource_idx
= wined3d_texture_get_level_count(texture
->wined3d_texture
) * face
+ level
;
322 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
323 hr
= D3DERR_INVALIDCALL
;
325 hr
= IDirect3DSurface8_LockRect((IDirect3DSurface8
*)wined3d_resource_get_parent(sub_resource
),
326 locked_rect
, rect
, flags
);
327 wined3d_mutex_unlock();
332 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_UnlockRect(IDirect3DCubeTexture8
*iface
,
333 D3DCUBEMAP_FACES face
, UINT level
)
335 IDirect3DCubeTexture8Impl
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
336 struct wined3d_resource
*sub_resource
;
337 UINT sub_resource_idx
;
340 TRACE("iface %p, face %#x, level %u.\n", iface
, face
, level
);
342 wined3d_mutex_lock();
343 sub_resource_idx
= wined3d_texture_get_level_count(texture
->wined3d_texture
) * face
+ level
;
344 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
345 hr
= D3DERR_INVALIDCALL
;
347 hr
= IDirect3DSurface8_UnlockRect((IDirect3DSurface8
*)wined3d_resource_get_parent(sub_resource
));
348 wined3d_mutex_unlock();
353 static HRESULT WINAPI
IDirect3DCubeTexture8Impl_AddDirtyRect(IDirect3DCubeTexture8
*iface
,
354 D3DCUBEMAP_FACES face
, const RECT
*dirty_rect
)
356 IDirect3DCubeTexture8Impl
*texture
= impl_from_IDirect3DCubeTexture8(iface
);
359 TRACE("iface %p, face %#x, dirty_rect %s.\n",
360 iface
, face
, wine_dbgstr_rect(dirty_rect
));
362 wined3d_mutex_lock();
364 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, face
, NULL
);
367 WINED3DBOX dirty_region
;
369 dirty_region
.Left
= dirty_rect
->left
;
370 dirty_region
.Top
= dirty_rect
->top
;
371 dirty_region
.Right
= dirty_rect
->right
;
372 dirty_region
.Bottom
= dirty_rect
->bottom
;
373 dirty_region
.Front
= 0;
374 dirty_region
.Back
= 1;
375 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, face
, &dirty_region
);
377 wined3d_mutex_unlock();
382 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl
=
385 IDirect3DCubeTexture8Impl_QueryInterface
,
386 IDirect3DCubeTexture8Impl_AddRef
,
387 IDirect3DCubeTexture8Impl_Release
,
388 /* IDirect3DResource8 */
389 IDirect3DCubeTexture8Impl_GetDevice
,
390 IDirect3DCubeTexture8Impl_SetPrivateData
,
391 IDirect3DCubeTexture8Impl_GetPrivateData
,
392 IDirect3DCubeTexture8Impl_FreePrivateData
,
393 IDirect3DCubeTexture8Impl_SetPriority
,
394 IDirect3DCubeTexture8Impl_GetPriority
,
395 IDirect3DCubeTexture8Impl_PreLoad
,
396 IDirect3DCubeTexture8Impl_GetType
,
397 /* IDirect3DBaseTexture8 */
398 IDirect3DCubeTexture8Impl_SetLOD
,
399 IDirect3DCubeTexture8Impl_GetLOD
,
400 IDirect3DCubeTexture8Impl_GetLevelCount
,
401 /* IDirect3DCubeTexture8 */
402 IDirect3DCubeTexture8Impl_GetLevelDesc
,
403 IDirect3DCubeTexture8Impl_GetCubeMapSurface
,
404 IDirect3DCubeTexture8Impl_LockRect
,
405 IDirect3DCubeTexture8Impl_UnlockRect
,
406 IDirect3DCubeTexture8Impl_AddDirtyRect
409 static void STDMETHODCALLTYPE
d3d8_cubetexture_wined3d_object_destroyed(void *parent
)
411 HeapFree(GetProcessHeap(), 0, parent
);
414 static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops
=
416 d3d8_cubetexture_wined3d_object_destroyed
,
419 HRESULT
cubetexture_init(IDirect3DCubeTexture8Impl
*texture
, IDirect3DDevice8Impl
*device
,
420 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
424 texture
->IDirect3DCubeTexture8_iface
.lpVtbl
= &Direct3DCubeTexture8_Vtbl
;
427 wined3d_mutex_lock();
428 hr
= IWineD3DDevice_CreateCubeTexture(device
->WineD3DDevice
, edge_length
, levels
,
429 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
, texture
,
430 &d3d8_cubetexture_wined3d_parent_ops
, &texture
->wined3d_texture
);
431 wined3d_mutex_unlock();
434 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr
);
438 texture
->parentDevice
= &device
->IDirect3DDevice8_iface
;
439 IDirect3DDevice8_AddRef(texture
->parentDevice
);