msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / d3d9 / cubetexture.c
blob533770fa529edb955d6bc438298383c50d7d0cce
1 /*
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
23 #include "config.h"
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;
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource9)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
35 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
36 IDirect3DCubeTexture9_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 IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
47 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
52 return ref;
55 static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
56 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
57 ULONG ref = InterlockedDecrement(&This->ref);
59 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
61 if (ref == 0) {
62 TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
64 EnterCriticalSection(&d3d9_cs);
65 IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D9CB_DestroySurface);
66 IDirect3DDevice9Ex_Release(This->parentDevice);
67 LeaveCriticalSection(&d3d9_cs);
69 HeapFree(GetProcessHeap(), 0, This);
71 return ref;
74 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
75 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
76 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
77 HRESULT hr;
78 TRACE("(%p) Relay\n" , This);
80 EnterCriticalSection(&d3d9_cs);
81 hr = IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
82 LeaveCriticalSection(&d3d9_cs);
83 return hr;
86 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
87 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
88 HRESULT hr;
89 TRACE("(%p) Relay\n", This);
91 EnterCriticalSection(&d3d9_cs);
92 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
93 LeaveCriticalSection(&d3d9_cs);
94 return hr;
97 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
98 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
99 HRESULT hr;
100 TRACE("(%p) Relay\n", This);
102 EnterCriticalSection(&d3d9_cs);
103 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
104 LeaveCriticalSection(&d3d9_cs);
105 return hr;
108 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
109 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
110 HRESULT hr;
111 TRACE("(%p) Relay\n", This);
113 EnterCriticalSection(&d3d9_cs);
114 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
115 LeaveCriticalSection(&d3d9_cs);
116 return hr;
119 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
120 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
121 DWORD ret;
122 TRACE("(%p) Relay\n", This);
124 EnterCriticalSection(&d3d9_cs);
125 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
126 LeaveCriticalSection(&d3d9_cs);
127 return ret;
130 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
131 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
132 DWORD ret;
133 TRACE("(%p) Relay\n", This);
135 EnterCriticalSection(&d3d9_cs);
136 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
137 LeaveCriticalSection(&d3d9_cs);
138 return ret;
141 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
142 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
143 TRACE("(%p) Relay\n", This);
145 EnterCriticalSection(&d3d9_cs);
146 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
147 LeaveCriticalSection(&d3d9_cs);
150 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
151 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
152 D3DRESOURCETYPE ret;
153 TRACE("(%p) Relay\n", This);
155 EnterCriticalSection(&d3d9_cs);
156 ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
157 LeaveCriticalSection(&d3d9_cs);
158 return ret;
161 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
162 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
163 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
164 DWORD ret;
165 TRACE("(%p) Relay\n", This);
167 EnterCriticalSection(&d3d9_cs);
168 ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
169 LeaveCriticalSection(&d3d9_cs);
170 return ret;
173 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
174 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
175 DWORD ret;
176 TRACE("(%p) Relay\n", This);
178 EnterCriticalSection(&d3d9_cs);
179 ret = IDirect3DBaseTexture9Impl_GetLOD((LPDIRECT3DBASETEXTURE9) This);
180 LeaveCriticalSection(&d3d9_cs);
181 return ret;
184 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
185 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
186 DWORD ret;
187 TRACE("(%p) Relay\n", This);
189 EnterCriticalSection(&d3d9_cs);
190 ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
191 LeaveCriticalSection(&d3d9_cs);
192 return ret;
195 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
196 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
197 HRESULT hr;
198 TRACE("(%p) Relay\n", This);
200 EnterCriticalSection(&d3d9_cs);
201 hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
202 LeaveCriticalSection(&d3d9_cs);
203 return hr;
206 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
207 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
208 D3DTEXTUREFILTERTYPE ret;
209 TRACE("(%p) Relay\n", This);
211 EnterCriticalSection(&d3d9_cs);
212 ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
213 LeaveCriticalSection(&d3d9_cs);
214 return ret;
217 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
218 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
219 TRACE("(%p) Relay\n", This);
221 EnterCriticalSection(&d3d9_cs);
222 IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
223 LeaveCriticalSection(&d3d9_cs);
226 /* IDirect3DCubeTexture9 Interface follow: */
227 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
228 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
229 WINED3DSURFACE_DESC wined3ddesc;
230 UINT tmpInt = -1;
231 HRESULT hr;
233 TRACE("(%p) Relay\n", This);
235 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
236 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
237 wined3ddesc.Type = (WINED3DRESOURCETYPE *) &pDesc->Type;
238 wined3ddesc.Usage = &pDesc->Usage;
239 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
240 wined3ddesc.Size = &tmpInt;
241 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
242 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
243 wined3ddesc.Width = &pDesc->Width;
244 wined3ddesc.Height = &pDesc->Height;
246 EnterCriticalSection(&d3d9_cs);
247 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
248 LeaveCriticalSection(&d3d9_cs);
249 return hr;
252 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
253 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
254 HRESULT hrc = D3D_OK;
255 IWineD3DSurface *mySurface = NULL;
257 TRACE("(%p) Relay\n", This);
259 EnterCriticalSection(&d3d9_cs);
260 hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
261 if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
262 IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
263 IWineD3DCubeTexture_Release(mySurface);
265 LeaveCriticalSection(&d3d9_cs);
266 return hrc;
269 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
270 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
271 HRESULT hr;
272 TRACE("(%p) Relay\n", This);
274 EnterCriticalSection(&d3d9_cs);
275 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
276 LeaveCriticalSection(&d3d9_cs);
277 return hr;
280 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
281 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
282 HRESULT hr;
283 TRACE("(%p) Relay\n", This);
285 EnterCriticalSection(&d3d9_cs);
286 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
287 LeaveCriticalSection(&d3d9_cs);
288 return hr;
291 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
292 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
293 HRESULT hr;
294 TRACE("(%p) Relay\n", This);
296 EnterCriticalSection(&d3d9_cs);
297 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
298 LeaveCriticalSection(&d3d9_cs);
299 return hr;
303 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
305 /* IUnknown */
306 IDirect3DCubeTexture9Impl_QueryInterface,
307 IDirect3DCubeTexture9Impl_AddRef,
308 IDirect3DCubeTexture9Impl_Release,
309 /* IDirect3DResource9 */
310 IDirect3DCubeTexture9Impl_GetDevice,
311 IDirect3DCubeTexture9Impl_SetPrivateData,
312 IDirect3DCubeTexture9Impl_GetPrivateData,
313 IDirect3DCubeTexture9Impl_FreePrivateData,
314 IDirect3DCubeTexture9Impl_SetPriority,
315 IDirect3DCubeTexture9Impl_GetPriority,
316 IDirect3DCubeTexture9Impl_PreLoad,
317 IDirect3DCubeTexture9Impl_GetType,
318 /* IDirect3DBaseTexture9 */
319 IDirect3DCubeTexture9Impl_SetLOD,
320 IDirect3DCubeTexture9Impl_GetLOD,
321 IDirect3DCubeTexture9Impl_GetLevelCount,
322 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
323 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
324 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
325 IDirect3DCubeTexture9Impl_GetLevelDesc,
326 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
327 IDirect3DCubeTexture9Impl_LockRect,
328 IDirect3DCubeTexture9Impl_UnlockRect,
329 IDirect3DCubeTexture9Impl_AddDirtyRect
335 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
336 HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX iface,
337 UINT EdgeLength, UINT Levels, DWORD Usage,
338 D3DFORMAT Format, D3DPOOL Pool,
339 IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
341 IDirect3DCubeTexture9Impl *object;
342 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
343 HRESULT hr = D3D_OK;
345 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d) Shared(%p)\n", This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
347 /* Allocate the storage for the device */
348 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
350 if (NULL == object) {
351 ERR("(%p) allocation of CubeTexture failed\n", This);
352 return D3DERR_OUTOFVIDEOMEMORY;
354 object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
355 object->ref = 1;
356 EnterCriticalSection(&d3d9_cs);
357 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
358 Format, Pool, &object->wineD3DCubeTexture, pSharedHandle, (IUnknown*)object);
359 LeaveCriticalSection(&d3d9_cs);
361 if (hr != D3D_OK){
363 /* free up object */
364 WARN("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
365 HeapFree(GetProcessHeap(), 0, object);
366 } else {
367 IDirect3DDevice9Ex_AddRef(iface);
368 object->parentDevice = iface;
369 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
370 TRACE("(%p) : Created cube texture %p\n", This, object);
373 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
374 return hr;