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);
54 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
56 IWineD3DCubeTexture_AddRef(This
->wineD3DCubeTexture
);
57 wined3d_mutex_unlock();
63 static ULONG WINAPI
IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface
) {
64 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
65 ULONG ref
= InterlockedDecrement(&This
->ref
);
67 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
70 TRACE("Releasing child %p\n", This
->wineD3DCubeTexture
);
72 IDirect3DDevice9Ex_Release(This
->parentDevice
);
74 IWineD3DCubeTexture_Release(This
->wineD3DCubeTexture
);
75 wined3d_mutex_unlock();
80 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
81 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface
, IDirect3DDevice9
** ppDevice
) {
82 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
83 IWineD3DDevice
*wined3d_device
;
85 TRACE("(%p) Relay\n" , This
);
88 hr
= IWineD3DCubeTexture_GetDevice(This
->wineD3DCubeTexture
, &wined3d_device
);
91 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
92 IWineD3DDevice_Release(wined3d_device
);
94 wined3d_mutex_unlock();
99 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
100 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
102 TRACE("(%p) Relay\n", This
);
104 wined3d_mutex_lock();
105 hr
= IWineD3DCubeTexture_SetPrivateData(This
->wineD3DCubeTexture
,refguid
,pData
,SizeOfData
,Flags
);
106 wined3d_mutex_unlock();
111 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
112 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
114 TRACE("(%p) Relay\n", This
);
116 wined3d_mutex_lock();
117 hr
= IWineD3DCubeTexture_GetPrivateData(This
->wineD3DCubeTexture
,refguid
,pData
,pSizeOfData
);
118 wined3d_mutex_unlock();
123 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface
, REFGUID refguid
) {
124 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
126 TRACE("(%p) Relay\n", This
);
128 wined3d_mutex_lock();
129 hr
= IWineD3DCubeTexture_FreePrivateData(This
->wineD3DCubeTexture
,refguid
);
130 wined3d_mutex_unlock();
135 static DWORD WINAPI
IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface
, DWORD PriorityNew
) {
136 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
138 TRACE("(%p) Relay\n", This
);
140 wined3d_mutex_lock();
141 ret
= IWineD3DCubeTexture_SetPriority(This
->wineD3DCubeTexture
, PriorityNew
);
142 wined3d_mutex_unlock();
147 static DWORD WINAPI
IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface
) {
148 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
150 TRACE("(%p) Relay\n", This
);
152 wined3d_mutex_lock();
153 ret
= IWineD3DCubeTexture_GetPriority(This
->wineD3DCubeTexture
);
154 wined3d_mutex_unlock();
159 static void WINAPI
IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface
) {
160 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
161 TRACE("(%p) Relay\n", This
);
163 wined3d_mutex_lock();
164 IWineD3DCubeTexture_PreLoad(This
->wineD3DCubeTexture
);
165 wined3d_mutex_unlock();
168 static D3DRESOURCETYPE WINAPI
IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface
) {
169 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
171 TRACE("(%p) Relay\n", This
);
173 wined3d_mutex_lock();
174 ret
= IWineD3DCubeTexture_GetType(This
->wineD3DCubeTexture
);
175 wined3d_mutex_unlock();
180 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
181 static DWORD WINAPI
IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface
, DWORD LODNew
) {
182 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
184 TRACE("(%p) Relay\n", This
);
186 wined3d_mutex_lock();
187 ret
= IWineD3DCubeTexture_SetLOD(This
->wineD3DCubeTexture
, LODNew
);
188 wined3d_mutex_unlock();
193 static DWORD WINAPI
IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface
) {
194 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
196 TRACE("(%p) Relay\n", This
);
198 wined3d_mutex_lock();
199 ret
= IWineD3DCubeTexture_GetLOD(This
->wineD3DCubeTexture
);
200 wined3d_mutex_unlock();
205 static DWORD WINAPI
IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface
) {
206 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
208 TRACE("(%p) Relay\n", This
);
210 wined3d_mutex_lock();
211 ret
= IWineD3DCubeTexture_GetLevelCount(This
->wineD3DCubeTexture
);
212 wined3d_mutex_unlock();
217 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface
, D3DTEXTUREFILTERTYPE FilterType
) {
218 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
220 TRACE("(%p) Relay\n", This
);
222 wined3d_mutex_lock();
223 hr
= IWineD3DCubeTexture_SetAutoGenFilterType(This
->wineD3DCubeTexture
, (WINED3DTEXTUREFILTERTYPE
) FilterType
);
224 wined3d_mutex_unlock();
229 static D3DTEXTUREFILTERTYPE WINAPI
IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface
) {
230 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
231 D3DTEXTUREFILTERTYPE ret
;
232 TRACE("(%p) Relay\n", This
);
234 wined3d_mutex_lock();
235 ret
= (D3DTEXTUREFILTERTYPE
) IWineD3DCubeTexture_GetAutoGenFilterType(This
->wineD3DCubeTexture
);
236 wined3d_mutex_unlock();
241 static void WINAPI
IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface
) {
242 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
243 TRACE("(%p) Relay\n", This
);
245 wined3d_mutex_lock();
246 IWineD3DCubeTexture_GenerateMipSubLevels(This
->wineD3DCubeTexture
);
247 wined3d_mutex_unlock();
250 /* IDirect3DCubeTexture9 Interface follow: */
251 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface
, UINT Level
, D3DSURFACE_DESC
* pDesc
) {
252 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
253 WINED3DSURFACE_DESC wined3ddesc
;
256 TRACE("(%p) Relay\n", This
);
258 wined3d_mutex_lock();
259 hr
= IWineD3DCubeTexture_GetLevelDesc(This
->wineD3DCubeTexture
, Level
, &wined3ddesc
);
260 wined3d_mutex_unlock();
264 pDesc
->Format
= d3dformat_from_wined3dformat(wined3ddesc
.format
);
265 pDesc
->Type
= wined3ddesc
.resource_type
;
266 pDesc
->Usage
= wined3ddesc
.usage
;
267 pDesc
->Pool
= wined3ddesc
.pool
;
268 pDesc
->MultiSampleType
= wined3ddesc
.multisample_type
;
269 pDesc
->MultiSampleQuality
= wined3ddesc
.multisample_quality
;
270 pDesc
->Width
= wined3ddesc
.width
;
271 pDesc
->Height
= wined3ddesc
.height
;
277 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
, IDirect3DSurface9
** ppCubeMapSurface
) {
278 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
279 HRESULT hrc
= D3D_OK
;
280 IWineD3DSurface
*mySurface
= NULL
;
282 TRACE("(%p) Relay\n", This
);
284 wined3d_mutex_lock();
285 hrc
= IWineD3DCubeTexture_GetCubeMapSurface(This
->wineD3DCubeTexture
, (WINED3DCUBEMAP_FACES
) FaceType
, Level
, &mySurface
);
286 if (hrc
== D3D_OK
&& NULL
!= ppCubeMapSurface
) {
287 IWineD3DCubeTexture_GetParent(mySurface
, (IUnknown
**)ppCubeMapSurface
);
288 IWineD3DCubeTexture_Release(mySurface
);
290 wined3d_mutex_unlock();
295 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
) {
296 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
298 TRACE("(%p) Relay\n", This
);
300 wined3d_mutex_lock();
301 hr
= IWineD3DCubeTexture_LockRect(This
->wineD3DCubeTexture
, (WINED3DCUBEMAP_FACES
) FaceType
, Level
, (WINED3DLOCKED_RECT
*) pLockedRect
, pRect
, Flags
);
302 wined3d_mutex_unlock();
307 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
) {
308 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
310 TRACE("(%p) Relay\n", This
);
312 wined3d_mutex_lock();
313 hr
= IWineD3DCubeTexture_UnlockRect(This
->wineD3DCubeTexture
, (WINED3DCUBEMAP_FACES
) FaceType
, Level
);
314 wined3d_mutex_unlock();
319 static HRESULT WINAPI
IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface
, D3DCUBEMAP_FACES FaceType
, CONST RECT
* pDirtyRect
) {
320 IDirect3DCubeTexture9Impl
*This
= (IDirect3DCubeTexture9Impl
*)iface
;
322 TRACE("(%p) Relay\n", This
);
324 wined3d_mutex_lock();
325 hr
= IWineD3DCubeTexture_AddDirtyRect(This
->wineD3DCubeTexture
, (WINED3DCUBEMAP_FACES
) FaceType
, pDirtyRect
);
326 wined3d_mutex_unlock();
332 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl
=
335 IDirect3DCubeTexture9Impl_QueryInterface
,
336 IDirect3DCubeTexture9Impl_AddRef
,
337 IDirect3DCubeTexture9Impl_Release
,
338 /* IDirect3DResource9 */
339 IDirect3DCubeTexture9Impl_GetDevice
,
340 IDirect3DCubeTexture9Impl_SetPrivateData
,
341 IDirect3DCubeTexture9Impl_GetPrivateData
,
342 IDirect3DCubeTexture9Impl_FreePrivateData
,
343 IDirect3DCubeTexture9Impl_SetPriority
,
344 IDirect3DCubeTexture9Impl_GetPriority
,
345 IDirect3DCubeTexture9Impl_PreLoad
,
346 IDirect3DCubeTexture9Impl_GetType
,
347 /* IDirect3DBaseTexture9 */
348 IDirect3DCubeTexture9Impl_SetLOD
,
349 IDirect3DCubeTexture9Impl_GetLOD
,
350 IDirect3DCubeTexture9Impl_GetLevelCount
,
351 IDirect3DCubeTexture9Impl_SetAutoGenFilterType
,
352 IDirect3DCubeTexture9Impl_GetAutoGenFilterType
,
353 IDirect3DCubeTexture9Impl_GenerateMipSubLevels
,
354 IDirect3DCubeTexture9Impl_GetLevelDesc
,
355 IDirect3DCubeTexture9Impl_GetCubeMapSurface
,
356 IDirect3DCubeTexture9Impl_LockRect
,
357 IDirect3DCubeTexture9Impl_UnlockRect
,
358 IDirect3DCubeTexture9Impl_AddDirtyRect
361 static void STDMETHODCALLTYPE
cubetexture_wined3d_object_destroyed(void *parent
)
363 HeapFree(GetProcessHeap(), 0, parent
);
366 static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops
=
368 cubetexture_wined3d_object_destroyed
,
371 HRESULT
cubetexture_init(IDirect3DCubeTexture9Impl
*texture
, IDirect3DDevice9Impl
*device
,
372 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
376 texture
->lpVtbl
= &Direct3DCubeTexture9_Vtbl
;
379 wined3d_mutex_lock();
380 hr
= IWineD3DDevice_CreateCubeTexture(device
->WineD3DDevice
, edge_length
, levels
, usage
,
381 wined3dformat_from_d3dformat(format
), pool
, &texture
->wineD3DCubeTexture
,
382 (IUnknown
*)texture
, &d3d9_cubetexture_wined3d_parent_ops
);
383 wined3d_mutex_unlock();
386 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr
);
390 texture
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
391 IDirect3DDevice9Ex_AddRef(texture
->parentDevice
);