2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS ReactX
4 * FILE: dll/directx/d3d9/d3d9_mipmap.c
5 * PURPOSE: d3d9.dll internal mip map surface functions
6 * PROGRAMERS: Gregor Gullwi <gbrunmar (dot) ros (at) gmail (dot) com>
8 #include "d3d9_mipmap.h"
10 #include "d3d9_texture.h"
11 #include "d3d9_device.h"
12 #include "d3d9_helpers.h"
15 #define LOCK_D3DDEVICE9() D3D9BaseObject_LockDevice(&This->BaseTexture.BaseResource.BaseObject)
16 #define UNLOCK_D3DDEVICE9() D3D9BaseObject_UnlockDevice(&This->BaseTexture.BaseResource.BaseObject)
18 /* Convert a IDirect3DTexture9 pointer safely to the internal implementation struct */
19 LPD3D9MIPMAP
IDirect3DTexture9ToImpl(LPDIRECT3DTEXTURE9 iface
)
24 return (LPD3D9MIPMAP
)((ULONG_PTR
)iface
- FIELD_OFFSET(D3D9MipMap
, lpVtbl
));
28 static HRESULT WINAPI
D3D9MipMap_QueryInterface(LPDIRECT3DTEXTURE9 iface
, REFIID riid
, void** ppvObject
)
30 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
32 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
33 IsEqualGUID(riid
, &IID_IDirect3DTexture9
) ||
34 IsEqualGUID(riid
, &IID_IDirect3DBaseTexture9
) ||
35 IsEqualGUID(riid
, &IID_IDirect3DResource9
))
37 IUnknown_AddRef(iface
);
38 *ppvObject
= &This
->lpVtbl
;
46 ULONG WINAPI
D3D9MipMap_AddRef(LPDIRECT3DTEXTURE9 iface
)
48 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
49 return D3D9BaseObject_AddRef(&This
->BaseTexture
.BaseResource
.BaseObject
);
52 ULONG WINAPI
D3D9MipMap_Release(LPDIRECT3DTEXTURE9 iface
)
54 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
55 return D3D9BaseObject_Release(&This
->BaseTexture
.BaseResource
.BaseObject
);
58 /* IDirect3DResource9 */
61 * @name IDirect3DTexture9::GetDevice
64 * The function D3D9MipMap_GetDevice sets the ppDevice argument
65 * to the device connected to create the swap chain.
67 * @param LPDIRECT3DTEXTURE9 iface
68 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture()
70 * @param IDirect3DDevice9** ppDevice
71 * Pointer to a IDirect3DDevice9* structure to be set to the device object.
74 * If the method successfully sets the ppDevice value, the return value is D3D_OK.
75 * If ppDevice is a bad pointer the return value will be D3DERR_INVALIDCALL.
76 * If the texture didn't contain any device, the return value will be D3DERR_INVALIDDEVICE.
79 HRESULT WINAPI
D3D9MipMap_GetDevice(LPDIRECT3DTEXTURE9 iface
, IDirect3DDevice9
** ppDevice
)
81 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
86 DPRINT1("Invalid ppDevice parameter specified");
88 return D3DERR_INVALIDCALL
;
91 if (FAILED(D3D9BaseObject_GetDevice(&This
->BaseTexture
.BaseResource
.BaseObject
, ppDevice
)))
93 DPRINT1("Invalid This parameter speficied");
95 return D3DERR_INVALIDDEVICE
;
102 HRESULT WINAPI
D3D9MipMap_SetPrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
)
108 HRESULT WINAPI
D3D9MipMap_GetPrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
)
114 HRESULT WINAPI
D3D9MipMap_FreePrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
)
120 DWORD WINAPI
D3D9MipMap_SetPriority(LPDIRECT3DTEXTURE9 iface
, DWORD PriorityNew
)
126 DWORD WINAPI
D3D9MipMap_GetPriority(LPDIRECT3DTEXTURE9 iface
)
132 void WINAPI
D3D9MipMap_PreLoad(LPDIRECT3DTEXTURE9 iface
)
137 /* IDirect3DBaseTexture9 */
138 D3DRESOURCETYPE WINAPI
D3D9MipMap_GetType(LPDIRECT3DTEXTURE9 iface
)
141 return D3DRTYPE_TEXTURE
;
144 DWORD WINAPI
D3D9MipMap_SetLOD(LPDIRECT3DTEXTURE9 iface
, DWORD LODNew
)
151 * @name IDirect3DTexture9::GetLOD
154 * The function D3D9MipMap_GetLOD returns the number
155 * max LODs for the specified texture, if it's managed.
157 * @param LPDIRECT3DTEXTURE9 iface
158 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture().
161 * Returns the number of LODs in the specified texture if it's managed.
164 DWORD WINAPI
D3D9MipMap_GetLOD(LPDIRECT3DTEXTURE9 iface
)
166 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
167 return D3D9Texture_GetLOD( (IDirect3DBaseTexture9
*)&This
->BaseTexture
.lpVtbl
);
171 * @name IDirect3DTexture9::GetLevelCount
174 * The function D3D9MipMap_GetLevelCount returns the number of mip map levels
175 * in the specified texture.
177 * @param LPDIRECT3DTEXTURE9 iface
178 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture().
181 * Returns the number of levels in the specified texture.
184 DWORD WINAPI
D3D9MipMap_GetLevelCount(LPDIRECT3DTEXTURE9 iface
)
186 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
187 return D3D9Texture_GetLevelCount( (IDirect3DBaseTexture9
*)&This
->BaseTexture
.lpVtbl
);
190 HRESULT WINAPI
D3D9MipMap_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface
, D3DTEXTUREFILTERTYPE FilterType
)
197 * @name IDirect3DTexture9::GetAutoGenFilterType
200 * The function D3D9MipMap_GetAutoGenFilterType returns filter type
201 * that is used when automated mipmaping is set.
203 * @param LPDIRECT3DTEXTURE9 iface
204 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture().
206 * @return D3DTEXTUREFILTERTYPE
207 * Filter type used when automated mipmaping is set for the specified texture.
210 D3DTEXTUREFILTERTYPE WINAPI
D3D9MipMap_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface
)
212 LPD3D9MIPMAP This
= IDirect3DTexture9ToImpl(iface
);
213 return D3D9Texture_GetAutoGenFilterType( (IDirect3DBaseTexture9
*)&This
->BaseTexture
.lpVtbl
);
216 void WINAPI
D3D9MipMap_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface
)
221 /* IDirect3DTexture9 */
222 HRESULT WINAPI
D3D9MipMap_GetLevelDesc(LPDIRECT3DTEXTURE9 iface
, UINT Level
, D3DSURFACE_DESC
* pDesc
)
228 HRESULT WINAPI
D3D9MipMap_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface
, UINT Level
, IDirect3DSurface9
** ppSurfaceLevel
)
234 HRESULT WINAPI
D3D9MipMap_LockRect(LPDIRECT3DTEXTURE9 iface
, UINT Level
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
)
240 HRESULT WINAPI
D3D9MipMap_UnlockRect(LPDIRECT3DTEXTURE9 iface
, UINT Level
)
246 HRESULT WINAPI
D3D9MipMap_AddDirtyRect(LPDIRECT3DTEXTURE9 iface
, CONST RECT
* pDirtyRect
)
252 #if !defined(__cplusplus) || defined(CINTERFACE)
253 static IDirect3DTexture9Vtbl D3D9MipMap_Vtbl
=
255 /* IUnknown methods */
256 D3D9MipMap_QueryInterface
,
260 /* IDirect3DBaseTexture9 methods */
261 D3D9MipMap_GetDevice
,
262 D3D9MipMap_SetPrivateData
,
263 D3D9MipMap_GetPrivateData
,
264 D3D9MipMap_FreePrivateData
,
265 D3D9MipMap_SetPriority
,
266 D3D9MipMap_GetPriority
,
269 /* IDirect3DBaseTexture9 methods */
273 D3D9MipMap_GetLevelCount
,
274 D3D9MipMap_SetAutoGenFilterType
,
275 D3D9MipMap_GetAutoGenFilterType
,
276 D3D9MipMap_GenerateMipSubLevels
,
278 /* IDirect3DTexture9 methods */
279 D3D9MipMap_GetLevelDesc
,
280 D3D9MipMap_GetSurfaceLevel
,
282 D3D9MipMap_UnlockRect
,
283 D3D9MipMap_AddDirtyRect
,
285 #endif // !defined(__cplusplus) || defined(CINTERFACE)
287 HRESULT
CreateD3D9MipMap(DIRECT3DDEVICE9_INT
* pDevice
, UINT Width
, UINT Height
, UINT Levels
, DWORD Usage
, D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DTexture9
** ppTexture
)
289 LPD3D9MIPMAP pThisTexture
;
290 if (FAILED(AlignedAlloc((LPVOID
*)&pThisTexture
, sizeof(D3D9MipMap
))))
292 DPRINT1("Could not create D3D9MipMap");
293 return E_OUTOFMEMORY
;
296 InitDirect3DBaseTexture9(&pThisTexture
->BaseTexture
, (IDirect3DBaseTexture9Vtbl
*)&D3D9MipMap_Vtbl
, Usage
, Levels
, Format
, Pool
, pDevice
, RT_EXTERNAL
);
298 pThisTexture
->lpVtbl
= &D3D9MipMap_Vtbl
;
300 pThisTexture
->Usage
= Usage
;
301 pThisTexture
->dwWidth
= Width
;
302 pThisTexture
->dwHeight
= Height
;
303 pThisTexture
->Format
= Format
;
305 *ppTexture
= (IDirect3DTexture9
*)&pThisTexture
->lpVtbl
;