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 /* IDirect3DCubeTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource8)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
35 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)) {
36 IUnknown_AddRef(iface);
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
46 static ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
47 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("%p increasing refcount to %u.\n", iface, ref);
54 IUnknown_AddRef(This->parentDevice);
56 IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
57 wined3d_mutex_unlock();
63 static ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
64 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
70 IDirect3DDevice8 *parentDevice = This->parentDevice;
72 TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
75 IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
76 wined3d_mutex_unlock();
78 /* Release the device last, as it may cause the device to be destroyed. */
79 IDirect3DDevice8_Release(parentDevice);
84 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
85 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8 *iface, IDirect3DDevice8 **device)
87 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
89 TRACE("iface %p, device %p.\n", iface, device);
91 *device = (IDirect3DDevice8 *)This->parentDevice;
92 IDirect3DDevice8_AddRef(*device);
94 TRACE("Returning device %p.\n", *device);
99 static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
100 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
103 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
104 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
106 wined3d_mutex_lock();
107 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
108 wined3d_mutex_unlock();
113 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
114 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
117 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
118 iface, debugstr_guid(refguid), pData, pSizeOfData);
120 wined3d_mutex_lock();
121 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
122 wined3d_mutex_unlock();
127 static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
128 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
131 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
133 wined3d_mutex_lock();
134 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
135 wined3d_mutex_unlock();
140 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
141 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
144 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
146 wined3d_mutex_lock();
147 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
148 wined3d_mutex_unlock();
153 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
154 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
157 TRACE("iface %p.\n", iface);
159 wined3d_mutex_lock();
160 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
161 wined3d_mutex_unlock();
166 static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
167 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
169 TRACE("iface %p.\n", iface);
171 wined3d_mutex_lock();
172 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
173 wined3d_mutex_unlock();
176 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
177 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
178 D3DRESOURCETYPE type;
180 TRACE("iface %p.\n", iface);
182 wined3d_mutex_lock();
183 type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
184 wined3d_mutex_unlock();
189 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
190 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
191 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
194 TRACE("iface %p, lod %u.\n", iface, LODNew);
196 wined3d_mutex_lock();
197 lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
198 wined3d_mutex_unlock();
203 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
204 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
207 TRACE("iface %p.\n", iface);
209 wined3d_mutex_lock();
210 lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
211 wined3d_mutex_unlock();
216 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
217 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
220 TRACE("iface %p.\n", iface);
222 wined3d_mutex_lock();
223 cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
224 wined3d_mutex_unlock();
229 /* IDirect3DCubeTexture8 Interface follow: */
230 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
231 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
233 WINED3DSURFACE_DESC wined3ddesc;
235 TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
237 wined3d_mutex_lock();
238 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
239 wined3d_mutex_unlock();
243 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
244 pDesc->Type = wined3ddesc.resource_type;
245 pDesc->Usage = wined3ddesc.usage;
246 pDesc->Pool = wined3ddesc.pool;
247 pDesc->Size = wined3ddesc.size;
248 pDesc->MultiSampleType = wined3ddesc.multisample_type;
249 pDesc->Width = wined3ddesc.width;
250 pDesc->Height = wined3ddesc.height;
256 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(IDirect3DCubeTexture8 *iface,
257 D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface)
259 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
260 IWineD3DSurface *mySurface = NULL;
261 UINT sub_resource_idx;
264 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, FaceType, Level, ppCubeMapSurface);
266 wined3d_mutex_lock();
267 sub_resource_idx = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture) * FaceType + Level;
268 hr = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, sub_resource_idx, &mySurface);
269 if (SUCCEEDED(hr) && ppCubeMapSurface)
271 *ppCubeMapSurface = IWineD3DCubeTexture_GetParent(mySurface);
272 IDirect3DSurface8_AddRef(*ppCubeMapSurface);
273 IWineD3DCubeTexture_Release(mySurface);
275 wined3d_mutex_unlock();
280 static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(IDirect3DCubeTexture8 *iface,
281 D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
283 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
284 UINT sub_resource_idx;
287 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
288 iface, FaceType, Level, pLockedRect, pRect, Flags);
290 wined3d_mutex_lock();
291 sub_resource_idx = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture) * FaceType + Level;
292 hr = IWineD3DCubeTexture_Map(This->wineD3DCubeTexture, sub_resource_idx,
293 (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags);
294 wined3d_mutex_unlock();
299 static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(IDirect3DCubeTexture8 *iface,
300 D3DCUBEMAP_FACES FaceType, UINT Level)
302 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
303 UINT sub_resource_idx;
306 TRACE("iface %p, face %#x, level %u.\n", iface, FaceType, Level);
308 wined3d_mutex_lock();
309 sub_resource_idx = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture) * FaceType + Level;
310 hr = IWineD3DCubeTexture_Unmap(This->wineD3DCubeTexture, sub_resource_idx);
311 wined3d_mutex_unlock();
316 static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT *pDirtyRect) {
317 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
320 TRACE("iface %p, face %#x, dirty_rect %p.\n", iface, FaceType, pDirtyRect);
322 wined3d_mutex_lock();
323 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
324 wined3d_mutex_unlock();
329 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
332 IDirect3DCubeTexture8Impl_QueryInterface,
333 IDirect3DCubeTexture8Impl_AddRef,
334 IDirect3DCubeTexture8Impl_Release,
335 /* IDirect3DResource8 */
336 IDirect3DCubeTexture8Impl_GetDevice,
337 IDirect3DCubeTexture8Impl_SetPrivateData,
338 IDirect3DCubeTexture8Impl_GetPrivateData,
339 IDirect3DCubeTexture8Impl_FreePrivateData,
340 IDirect3DCubeTexture8Impl_SetPriority,
341 IDirect3DCubeTexture8Impl_GetPriority,
342 IDirect3DCubeTexture8Impl_PreLoad,
343 IDirect3DCubeTexture8Impl_GetType,
344 /* IDirect3DBaseTexture8 */
345 IDirect3DCubeTexture8Impl_SetLOD,
346 IDirect3DCubeTexture8Impl_GetLOD,
347 IDirect3DCubeTexture8Impl_GetLevelCount,
348 /* IDirect3DCubeTexture8 */
349 IDirect3DCubeTexture8Impl_GetLevelDesc,
350 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
351 IDirect3DCubeTexture8Impl_LockRect,
352 IDirect3DCubeTexture8Impl_UnlockRect,
353 IDirect3DCubeTexture8Impl_AddDirtyRect
356 static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
358 HeapFree(GetProcessHeap(), 0, parent);
361 static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
363 d3d8_cubetexture_wined3d_object_destroyed,
366 HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
367 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
371 texture->lpVtbl = &Direct3DCubeTexture8_Vtbl;
374 wined3d_mutex_lock();
375 hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels,
376 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
377 &d3d8_cubetexture_wined3d_parent_ops, &texture->wineD3DCubeTexture);
378 wined3d_mutex_unlock();
381 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
385 texture->parentDevice = (IDirect3DDevice8 *)device;
386 IDirect3DDevice8_AddRef(texture->parentDevice);