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
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);
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
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);
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);
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);
74 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
75 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
76 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
77 IWineD3DDevice *wined3d_device;
79 TRACE("(%p) Relay\n" , This);
81 EnterCriticalSection(&d3d9_cs);
82 hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
85 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
86 IWineD3DDevice_Release(wined3d_device);
88 LeaveCriticalSection(&d3d9_cs);
92 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
93 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
95 TRACE("(%p) Relay\n", This);
97 EnterCriticalSection(&d3d9_cs);
98 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
99 LeaveCriticalSection(&d3d9_cs);
103 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
104 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
106 TRACE("(%p) Relay\n", This);
108 EnterCriticalSection(&d3d9_cs);
109 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
110 LeaveCriticalSection(&d3d9_cs);
114 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
115 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
117 TRACE("(%p) Relay\n", This);
119 EnterCriticalSection(&d3d9_cs);
120 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
121 LeaveCriticalSection(&d3d9_cs);
125 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
126 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
128 TRACE("(%p) Relay\n", This);
130 EnterCriticalSection(&d3d9_cs);
131 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
132 LeaveCriticalSection(&d3d9_cs);
136 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
137 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
139 TRACE("(%p) Relay\n", This);
141 EnterCriticalSection(&d3d9_cs);
142 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
143 LeaveCriticalSection(&d3d9_cs);
147 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
148 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
149 TRACE("(%p) Relay\n", This);
151 EnterCriticalSection(&d3d9_cs);
152 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
153 LeaveCriticalSection(&d3d9_cs);
156 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
157 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
159 TRACE("(%p) Relay\n", This);
161 EnterCriticalSection(&d3d9_cs);
162 ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
163 LeaveCriticalSection(&d3d9_cs);
167 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
168 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
169 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
171 TRACE("(%p) Relay\n", This);
173 EnterCriticalSection(&d3d9_cs);
174 ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
175 LeaveCriticalSection(&d3d9_cs);
179 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
180 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
182 TRACE("(%p) Relay\n", This);
184 EnterCriticalSection(&d3d9_cs);
185 ret = IWineD3DCubeTexture_GetLOD(This->wineD3DCubeTexture);
186 LeaveCriticalSection(&d3d9_cs);
190 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
191 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
193 TRACE("(%p) Relay\n", This);
195 EnterCriticalSection(&d3d9_cs);
196 ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
197 LeaveCriticalSection(&d3d9_cs);
201 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
202 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
204 TRACE("(%p) Relay\n", This);
206 EnterCriticalSection(&d3d9_cs);
207 hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
208 LeaveCriticalSection(&d3d9_cs);
212 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
213 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
214 D3DTEXTUREFILTERTYPE ret;
215 TRACE("(%p) Relay\n", This);
217 EnterCriticalSection(&d3d9_cs);
218 ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
219 LeaveCriticalSection(&d3d9_cs);
223 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
224 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
225 TRACE("(%p) Relay\n", This);
227 EnterCriticalSection(&d3d9_cs);
228 IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
229 LeaveCriticalSection(&d3d9_cs);
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;
237 WINED3DFORMAT format;
240 TRACE("(%p) Relay\n", This);
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;
253 EnterCriticalSection(&d3d9_cs);
254 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
255 LeaveCriticalSection(&d3d9_cs);
257 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
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;
267 TRACE("(%p) Relay\n", This);
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);
275 LeaveCriticalSection(&d3d9_cs);
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;
282 TRACE("(%p) Relay\n", This);
284 EnterCriticalSection(&d3d9_cs);
285 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
286 LeaveCriticalSection(&d3d9_cs);
290 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
291 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
293 TRACE("(%p) Relay\n", This);
295 EnterCriticalSection(&d3d9_cs);
296 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
297 LeaveCriticalSection(&d3d9_cs);
301 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
302 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
304 TRACE("(%p) Relay\n", This);
306 EnterCriticalSection(&d3d9_cs);
307 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
308 LeaveCriticalSection(&d3d9_cs);
313 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
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
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) {
351 IDirect3DCubeTexture9Impl *object;
352 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
355 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d) Shared(%p)\n", This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
357 /* Allocate the storage for the device */
358 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
360 if (NULL == object) {
361 ERR("(%p) allocation of CubeTexture failed\n", This);
362 return D3DERR_OUTOFVIDEOMEMORY;
364 object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
366 EnterCriticalSection(&d3d9_cs);
367 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
368 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture,
369 pSharedHandle, (IUnknown*)object);
370 LeaveCriticalSection(&d3d9_cs);
375 WARN("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
376 HeapFree(GetProcessHeap(), 0, object);
378 IDirect3DDevice9Ex_AddRef(iface);
379 object->parentDevice = iface;
380 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
381 TRACE("(%p) : Created cube texture %p\n", This, object);
384 TRACE("(%p) returning %p\n",This, *ppCubeTexture);