Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / d3d8 / cubetexture.c
blob7e48dab1d79ff3a3910e6d827885a837e726948b
1 /*
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
21 #include "config.h"
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);
37 *ppobj = This;
38 return S_OK;
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
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);
52 if (ref == 1)
54 IUnknown_AddRef(This->parentDevice);
55 wined3d_mutex_lock();
56 IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
57 wined3d_mutex_unlock();
60 return ref;
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);
69 if (ref == 0) {
70 IDirect3DDevice8 *parentDevice = This->parentDevice;
72 TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
74 wined3d_mutex_lock();
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);
81 return ref;
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);
96 return D3D_OK;
99 static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
100 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
101 HRESULT hr;
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();
110 return hr;
113 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
114 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
115 HRESULT hr;
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();
124 return hr;
127 static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
128 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
129 HRESULT hr;
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();
137 return hr;
140 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
141 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
142 DWORD ret;
144 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
146 wined3d_mutex_lock();
147 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
148 wined3d_mutex_unlock();
150 return ret;
153 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
154 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
155 DWORD ret;
157 TRACE("iface %p.\n", iface);
159 wined3d_mutex_lock();
160 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
161 wined3d_mutex_unlock();
163 return ret;
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();
186 return type;
189 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
190 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
191 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
192 DWORD lod;
194 TRACE("iface %p, lod %u.\n", iface, LODNew);
196 wined3d_mutex_lock();
197 lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
198 wined3d_mutex_unlock();
200 return lod;
203 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
204 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
205 DWORD lod;
207 TRACE("iface %p.\n", iface);
209 wined3d_mutex_lock();
210 lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
211 wined3d_mutex_unlock();
213 return lod;
216 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
217 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
218 DWORD cnt;
220 TRACE("iface %p.\n", iface);
222 wined3d_mutex_lock();
223 cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
224 wined3d_mutex_unlock();
226 return cnt;
229 /* IDirect3DCubeTexture8 Interface follow: */
230 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
231 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
232 HRESULT hr;
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();
241 if (SUCCEEDED(hr))
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;
253 return hr;
256 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) {
257 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
258 HRESULT hrc = D3D_OK;
259 IWineD3DSurface *mySurface = NULL;
261 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, FaceType, Level, ppCubeMapSurface);
263 wined3d_mutex_lock();
264 hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
265 if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
266 IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
267 IWineD3DCubeTexture_Release(mySurface);
269 wined3d_mutex_unlock();
271 return hrc;
274 static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT *pRect, DWORD Flags) {
275 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
276 HRESULT hr;
278 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
279 iface, FaceType, Level, pLockedRect, pRect, Flags);
281 wined3d_mutex_lock();
282 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
283 wined3d_mutex_unlock();
285 return hr;
288 static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
289 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
290 HRESULT hr;
292 TRACE("iface %p, face %#x, level %u.\n", iface, FaceType, Level);
294 wined3d_mutex_lock();
295 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
296 wined3d_mutex_unlock();
298 return hr;
301 static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT *pDirtyRect) {
302 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
303 HRESULT hr;
305 TRACE("iface %p, face %#x, dirty_rect %p.\n", iface, FaceType, pDirtyRect);
307 wined3d_mutex_lock();
308 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
309 wined3d_mutex_unlock();
311 return hr;
314 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
316 /* IUnknown */
317 IDirect3DCubeTexture8Impl_QueryInterface,
318 IDirect3DCubeTexture8Impl_AddRef,
319 IDirect3DCubeTexture8Impl_Release,
320 /* IDirect3DResource8 */
321 IDirect3DCubeTexture8Impl_GetDevice,
322 IDirect3DCubeTexture8Impl_SetPrivateData,
323 IDirect3DCubeTexture8Impl_GetPrivateData,
324 IDirect3DCubeTexture8Impl_FreePrivateData,
325 IDirect3DCubeTexture8Impl_SetPriority,
326 IDirect3DCubeTexture8Impl_GetPriority,
327 IDirect3DCubeTexture8Impl_PreLoad,
328 IDirect3DCubeTexture8Impl_GetType,
329 /* IDirect3DBaseTexture8 */
330 IDirect3DCubeTexture8Impl_SetLOD,
331 IDirect3DCubeTexture8Impl_GetLOD,
332 IDirect3DCubeTexture8Impl_GetLevelCount,
333 /* IDirect3DCubeTexture8 */
334 IDirect3DCubeTexture8Impl_GetLevelDesc,
335 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
336 IDirect3DCubeTexture8Impl_LockRect,
337 IDirect3DCubeTexture8Impl_UnlockRect,
338 IDirect3DCubeTexture8Impl_AddDirtyRect
341 static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
343 HeapFree(GetProcessHeap(), 0, parent);
346 static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
348 d3d8_cubetexture_wined3d_object_destroyed,
351 HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
352 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
354 HRESULT hr;
356 texture->lpVtbl = &Direct3DCubeTexture8_Vtbl;
357 texture->ref = 1;
359 wined3d_mutex_lock();
360 hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage & WINED3DUSAGE_MASK,
361 wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
362 (IUnknown *)texture, &d3d8_cubetexture_wined3d_parent_ops);
363 wined3d_mutex_unlock();
364 if (FAILED(hr))
366 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
367 return hr;
370 texture->parentDevice = (IDirect3DDevice8 *)device;
371 IDirect3DDevice8_AddRef(texture->parentDevice);
373 return D3D_OK;