bbd171ea62aacfffc60c665f49d4df22ee99c05c
[reactos.git] / reactos / dll / directx / wine / d3d9 / cubetexture.c
1 /*
2 * IDirect3DCubeTexture9 implementation
3 *
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28
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;
39 }
40
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
47 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
49
50 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
51
52 return ref;
53 }
54
55 static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
56 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
57 ULONG ref = InterlockedDecrement(&This->ref);
58
59 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
60
61 if (ref == 0) {
62 TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
63
64 EnterCriticalSection(&d3d9_cs);
65 IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D9CB_DestroySurface);
66 IDirect3DDevice9Ex_Release(This->parentDevice);
67 LeaveCriticalSection(&d3d9_cs);
68
69 HeapFree(GetProcessHeap(), 0, This);
70 }
71 return ref;
72 }
73
74 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
75 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
76 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
77 IWineD3DDevice *wined3d_device;
78 HRESULT hr;
79 TRACE("(%p) Relay\n" , This);
80
81 EnterCriticalSection(&d3d9_cs);
82 hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
83 if (SUCCEEDED(hr))
84 {
85 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
86 IWineD3DDevice_Release(wined3d_device);
87 }
88 LeaveCriticalSection(&d3d9_cs);
89 return hr;
90 }
91
92 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
93 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
94 HRESULT hr;
95 TRACE("(%p) Relay\n", This);
96
97 EnterCriticalSection(&d3d9_cs);
98 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
99 LeaveCriticalSection(&d3d9_cs);
100 return hr;
101 }
102
103 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
104 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
105 HRESULT hr;
106 TRACE("(%p) Relay\n", This);
107
108 EnterCriticalSection(&d3d9_cs);
109 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
110 LeaveCriticalSection(&d3d9_cs);
111 return hr;
112 }
113
114 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
115 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
116 HRESULT hr;
117 TRACE("(%p) Relay\n", This);
118
119 EnterCriticalSection(&d3d9_cs);
120 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
121 LeaveCriticalSection(&d3d9_cs);
122 return hr;
123 }
124
125 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
126 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
127 DWORD ret;
128 TRACE("(%p) Relay\n", This);
129
130 EnterCriticalSection(&d3d9_cs);
131 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
132 LeaveCriticalSection(&d3d9_cs);
133 return ret;
134 }
135
136 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
137 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
138 DWORD ret;
139 TRACE("(%p) Relay\n", This);
140
141 EnterCriticalSection(&d3d9_cs);
142 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
143 LeaveCriticalSection(&d3d9_cs);
144 return ret;
145 }
146
147 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
148 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
149 TRACE("(%p) Relay\n", This);
150
151 EnterCriticalSection(&d3d9_cs);
152 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
153 LeaveCriticalSection(&d3d9_cs);
154 }
155
156 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
157 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
158 D3DRESOURCETYPE ret;
159 TRACE("(%p) Relay\n", This);
160
161 EnterCriticalSection(&d3d9_cs);
162 ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
163 LeaveCriticalSection(&d3d9_cs);
164 return ret;
165 }
166
167 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
168 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
169 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
170 DWORD ret;
171 TRACE("(%p) Relay\n", This);
172
173 EnterCriticalSection(&d3d9_cs);
174 ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
175 LeaveCriticalSection(&d3d9_cs);
176 return ret;
177 }
178
179 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
180 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
181 DWORD ret;
182 TRACE("(%p) Relay\n", This);
183
184 EnterCriticalSection(&d3d9_cs);
185 ret = IWineD3DCubeTexture_GetLOD(This->wineD3DCubeTexture);
186 LeaveCriticalSection(&d3d9_cs);
187 return ret;
188 }
189
190 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
191 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
192 DWORD ret;
193 TRACE("(%p) Relay\n", This);
194
195 EnterCriticalSection(&d3d9_cs);
196 ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
197 LeaveCriticalSection(&d3d9_cs);
198 return ret;
199 }
200
201 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
202 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
203 HRESULT hr;
204 TRACE("(%p) Relay\n", This);
205
206 EnterCriticalSection(&d3d9_cs);
207 hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
208 LeaveCriticalSection(&d3d9_cs);
209 return hr;
210 }
211
212 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
213 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
214 D3DTEXTUREFILTERTYPE ret;
215 TRACE("(%p) Relay\n", This);
216
217 EnterCriticalSection(&d3d9_cs);
218 ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
219 LeaveCriticalSection(&d3d9_cs);
220 return ret;
221 }
222
223 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
224 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
225 TRACE("(%p) Relay\n", This);
226
227 EnterCriticalSection(&d3d9_cs);
228 IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
229 LeaveCriticalSection(&d3d9_cs);
230 }
231
232 /* IDirect3DCubeTexture9 Interface follow: */
233 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
234 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
235 WINED3DSURFACE_DESC wined3ddesc;
236 UINT tmpInt = -1;
237 WINED3DFORMAT format;
238 HRESULT hr;
239
240 TRACE("(%p) Relay\n", This);
241
242 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
243 wined3ddesc.Format = &format;
244 wined3ddesc.Type = (WINED3DRESOURCETYPE *) &pDesc->Type;
245 wined3ddesc.Usage = &pDesc->Usage;
246 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
247 wined3ddesc.Size = &tmpInt;
248 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
249 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
250 wined3ddesc.Width = &pDesc->Width;
251 wined3ddesc.Height = &pDesc->Height;
252
253 EnterCriticalSection(&d3d9_cs);
254 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
255 LeaveCriticalSection(&d3d9_cs);
256
257 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
258
259 return hr;
260 }
261
262 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
263 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
264 HRESULT hrc = D3D_OK;
265 IWineD3DSurface *mySurface = NULL;
266
267 TRACE("(%p) Relay\n", This);
268
269 EnterCriticalSection(&d3d9_cs);
270 hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
271 if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
272 IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
273 IWineD3DCubeTexture_Release(mySurface);
274 }
275 LeaveCriticalSection(&d3d9_cs);
276 return hrc;
277 }
278
279 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
280 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
281 HRESULT hr;
282 TRACE("(%p) Relay\n", This);
283
284 EnterCriticalSection(&d3d9_cs);
285 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
286 LeaveCriticalSection(&d3d9_cs);
287 return hr;
288 }
289
290 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
291 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
292 HRESULT hr;
293 TRACE("(%p) Relay\n", This);
294
295 EnterCriticalSection(&d3d9_cs);
296 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
297 LeaveCriticalSection(&d3d9_cs);
298 return hr;
299 }
300
301 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
302 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
303 HRESULT hr;
304 TRACE("(%p) Relay\n", This);
305
306 EnterCriticalSection(&d3d9_cs);
307 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
308 LeaveCriticalSection(&d3d9_cs);
309 return hr;
310 }
311
312
313 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
314 {
315 /* IUnknown */
316 IDirect3DCubeTexture9Impl_QueryInterface,
317 IDirect3DCubeTexture9Impl_AddRef,
318 IDirect3DCubeTexture9Impl_Release,
319 /* IDirect3DResource9 */
320 IDirect3DCubeTexture9Impl_GetDevice,
321 IDirect3DCubeTexture9Impl_SetPrivateData,
322 IDirect3DCubeTexture9Impl_GetPrivateData,
323 IDirect3DCubeTexture9Impl_FreePrivateData,
324 IDirect3DCubeTexture9Impl_SetPriority,
325 IDirect3DCubeTexture9Impl_GetPriority,
326 IDirect3DCubeTexture9Impl_PreLoad,
327 IDirect3DCubeTexture9Impl_GetType,
328 /* IDirect3DBaseTexture9 */
329 IDirect3DCubeTexture9Impl_SetLOD,
330 IDirect3DCubeTexture9Impl_GetLOD,
331 IDirect3DCubeTexture9Impl_GetLevelCount,
332 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
333 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
334 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
335 IDirect3DCubeTexture9Impl_GetLevelDesc,
336 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
337 IDirect3DCubeTexture9Impl_LockRect,
338 IDirect3DCubeTexture9Impl_UnlockRect,
339 IDirect3DCubeTexture9Impl_AddDirtyRect
340 };
341
342
343
344
345 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
346 HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX iface,
347 UINT EdgeLength, UINT Levels, DWORD Usage,
348 D3DFORMAT Format, D3DPOOL Pool,
349 IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
350
351 IDirect3DCubeTexture9Impl *object;
352 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
353 HRESULT hr = D3D_OK;
354
355 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d) Shared(%p)\n", This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
356
357 /* Allocate the storage for the device */
358 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
359
360 if (NULL == object) {
361 ERR("(%p) allocation of CubeTexture failed\n", This);
362 return D3DERR_OUTOFVIDEOMEMORY;
363 }
364 object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
365 object->ref = 1;
366 EnterCriticalSection(&d3d9_cs);
367 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
368 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
369 LeaveCriticalSection(&d3d9_cs);
370
371 if (hr != D3D_OK){
372
373 /* free up object */
374 WARN("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
375 HeapFree(GetProcessHeap(), 0, object);
376 } else {
377 IDirect3DDevice9Ex_AddRef(iface);
378 object->parentDevice = iface;
379 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
380 TRACE("(%p) : Created cube texture %p\n", This, object);
381 }
382
383 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
384 return hr;
385 }