1 /* 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> 7 */ 8 #include "d3d9_mipmap.h" 9 #include "debug.h" 10 #include "d3d9_texture.h" 11 #include "d3d9_device.h" 12 #include "d3d9_helpers.h" 13 #include <d3d9.h> 14 15 #define LOCK_D3DDEVICE9() D3D9BaseObject_LockDevice(&This->BaseTexture.BaseResource.BaseObject) 16 #define UNLOCK_D3DDEVICE9() D3D9BaseObject_UnlockDevice(&This->BaseTexture.BaseResource.BaseObject) 17 18 /* Convert a IDirect3DTexture9 pointer safely to the internal implementation struct */ 19 LPD3D9MIPMAP IDirect3DTexture9ToImpl(LPDIRECT3DTEXTURE9 iface) 20 { 21 if (NULL == iface) 22 return NULL; 23 24 return (LPD3D9MIPMAP)((ULONG_PTR)iface - FIELD_OFFSET(D3D9MipMap, lpVtbl)); 25 } 26 27 /* IUnknown */ 28 static HRESULT WINAPI D3D9MipMap_QueryInterface(LPDIRECT3DTEXTURE9 iface, REFIID riid, void** ppvObject) 29 { 30 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 31 32 if (IsEqualGUID(riid, &IID_IUnknown) || 33 IsEqualGUID(riid, &IID_IDirect3DTexture9) || 34 IsEqualGUID(riid, &IID_IDirect3DBaseTexture9) || 35 IsEqualGUID(riid, &IID_IDirect3DResource9)) 36 { 37 IUnknown_AddRef(iface); 38 *ppvObject = &This->lpVtbl; 39 return D3D_OK; 40 } 41 42 *ppvObject = NULL; 43 return E_NOINTERFACE; 44 } 45 46 ULONG WINAPI D3D9MipMap_AddRef(LPDIRECT3DTEXTURE9 iface) 47 { 48 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 49 return D3D9BaseObject_AddRef(&This->BaseTexture.BaseResource.BaseObject); 50 } 51 52 ULONG WINAPI D3D9MipMap_Release(LPDIRECT3DTEXTURE9 iface) 53 { 54 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 55 return D3D9BaseObject_Release(&This->BaseTexture.BaseResource.BaseObject); 56 } 57 58 /* IDirect3DResource9 */ 59 60 /*++ 61 * @name IDirect3DTexture9::GetDevice 62 * @implemented 63 * 64 * The function D3D9MipMap_GetDevice sets the ppDevice argument 65 * to the device connected to create the swap chain. 66 * 67 * @param LPDIRECT3DTEXTURE9 iface 68 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture() 69 * 70 * @param IDirect3DDevice9** ppDevice 71 * Pointer to a IDirect3DDevice9* structure to be set to the device object. 72 * 73 * @return HRESULT 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. 77 * 78 */ 79 HRESULT WINAPI D3D9MipMap_GetDevice(LPDIRECT3DTEXTURE9 iface, IDirect3DDevice9** ppDevice) 80 { 81 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 82 LOCK_D3DDEVICE9(); 83 84 if (NULL == ppDevice) 85 { 86 DPRINT1("Invalid ppDevice parameter specified"); 87 UNLOCK_D3DDEVICE9(); 88 return D3DERR_INVALIDCALL; 89 } 90 91 if (FAILED(D3D9BaseObject_GetDevice(&This->BaseTexture.BaseResource.BaseObject, ppDevice))) 92 { 93 DPRINT1("Invalid This parameter specified"); 94 UNLOCK_D3DDEVICE9(); 95 return D3DERR_INVALIDDEVICE; 96 } 97 98 UNLOCK_D3DDEVICE9(); 99 return D3D_OK; 100 } 101 102 HRESULT WINAPI D3D9MipMap_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 103 { 104 UNIMPLEMENTED 105 return D3D_OK; 106 } 107 108 HRESULT WINAPI D3D9MipMap_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) 109 { 110 UNIMPLEMENTED 111 return D3D_OK; 112 } 113 114 HRESULT WINAPI D3D9MipMap_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) 115 { 116 UNIMPLEMENTED 117 return D3D_OK; 118 } 119 120 DWORD WINAPI D3D9MipMap_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) 121 { 122 UNIMPLEMENTED 123 return 0; 124 } 125 126 DWORD WINAPI D3D9MipMap_GetPriority(LPDIRECT3DTEXTURE9 iface) 127 { 128 UNIMPLEMENTED 129 return 0; 130 } 131 132 void WINAPI D3D9MipMap_PreLoad(LPDIRECT3DTEXTURE9 iface) 133 { 134 UNIMPLEMENTED 135 } 136 137 /* IDirect3DBaseTexture9 */ 138 D3DRESOURCETYPE WINAPI D3D9MipMap_GetType(LPDIRECT3DTEXTURE9 iface) 139 { 140 UNIMPLEMENTED 141 return D3DRTYPE_TEXTURE; 142 } 143 144 DWORD WINAPI D3D9MipMap_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) 145 { 146 UNIMPLEMENTED 147 return 0; 148 } 149 150 /*++ 151 * @name IDirect3DTexture9::GetLOD 152 * @implemented 153 * 154 * The function D3D9MipMap_GetLOD returns the number 155 * max LODs for the specified texture, if it's managed. 156 * 157 * @param LPDIRECT3DTEXTURE9 iface 158 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture(). 159 * 160 * @return DWORD 161 * Returns the number of LODs in the specified texture if it's managed. 162 * 163 */ 164 DWORD WINAPI D3D9MipMap_GetLOD(LPDIRECT3DTEXTURE9 iface) 165 { 166 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 167 return D3D9Texture_GetLOD( (IDirect3DBaseTexture9*)&This->BaseTexture.lpVtbl ); 168 } 169 170 /*++ 171 * @name IDirect3DTexture9::GetLevelCount 172 * @implemented 173 * 174 * The function D3D9MipMap_GetLevelCount returns the number of mip map levels 175 * in the specified texture. 176 * 177 * @param LPDIRECT3DTEXTURE9 iface 178 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture(). 179 * 180 * @return DWORD 181 * Returns the number of levels in the specified texture. 182 * 183 */ 184 DWORD WINAPI D3D9MipMap_GetLevelCount(LPDIRECT3DTEXTURE9 iface) 185 { 186 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 187 return D3D9Texture_GetLevelCount( (IDirect3DBaseTexture9*)&This->BaseTexture.lpVtbl ); 188 } 189 190 HRESULT WINAPI D3D9MipMap_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) 191 { 192 UNIMPLEMENTED 193 return D3D_OK; 194 } 195 196 /*++ 197 * @name IDirect3DTexture9::GetAutoGenFilterType 198 * @implemented 199 * 200 * The function D3D9MipMap_GetAutoGenFilterType returns filter type 201 * that is used when automated mipmaping is set. 202 * 203 * @param LPDIRECT3DTEXTURE9 iface 204 * Pointer to a IDirect3DTexture9 object returned from IDirect3D9Device::CreateTexture(). 205 * 206 * @return D3DTEXTUREFILTERTYPE 207 * Filter type used when automated mipmaping is set for the specified texture. 208 * 209 */ 210 D3DTEXTUREFILTERTYPE WINAPI D3D9MipMap_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) 211 { 212 LPD3D9MIPMAP This = IDirect3DTexture9ToImpl(iface); 213 return D3D9Texture_GetAutoGenFilterType( (IDirect3DBaseTexture9*)&This->BaseTexture.lpVtbl ); 214 } 215 216 void WINAPI D3D9MipMap_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) 217 { 218 UNIMPLEMENTED 219 } 220 221 /* IDirect3DTexture9 */ 222 HRESULT WINAPI D3D9MipMap_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) 223 { 224 UNIMPLEMENTED 225 return D3D_OK; 226 } 227 228 HRESULT WINAPI D3D9MipMap_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) 229 { 230 UNIMPLEMENTED 231 return D3D_OK; 232 } 233 234 HRESULT WINAPI D3D9MipMap_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) 235 { 236 UNIMPLEMENTED 237 return D3D_OK; 238 } 239 240 HRESULT WINAPI D3D9MipMap_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) 241 { 242 UNIMPLEMENTED 243 return D3D_OK; 244 } 245 246 HRESULT WINAPI D3D9MipMap_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) 247 { 248 UNIMPLEMENTED 249 return D3D_OK; 250 } 251 252 #if !defined(__cplusplus) || defined(CINTERFACE) 253 static IDirect3DTexture9Vtbl D3D9MipMap_Vtbl = 254 { 255 /* IUnknown methods */ 256 D3D9MipMap_QueryInterface, 257 D3D9MipMap_AddRef, 258 D3D9MipMap_Release, 259 260 /* IDirect3DBaseTexture9 methods */ 261 D3D9MipMap_GetDevice, 262 D3D9MipMap_SetPrivateData, 263 D3D9MipMap_GetPrivateData, 264 D3D9MipMap_FreePrivateData, 265 D3D9MipMap_SetPriority, 266 D3D9MipMap_GetPriority, 267 D3D9MipMap_PreLoad, 268 269 /* IDirect3DBaseTexture9 methods */ 270 D3D9MipMap_GetType, 271 D3D9MipMap_SetLOD, 272 D3D9MipMap_GetLOD, 273 D3D9MipMap_GetLevelCount, 274 D3D9MipMap_SetAutoGenFilterType, 275 D3D9MipMap_GetAutoGenFilterType, 276 D3D9MipMap_GenerateMipSubLevels, 277 278 /* IDirect3DTexture9 methods */ 279 D3D9MipMap_GetLevelDesc, 280 D3D9MipMap_GetSurfaceLevel, 281 D3D9MipMap_LockRect, 282 D3D9MipMap_UnlockRect, 283 D3D9MipMap_AddDirtyRect, 284 }; 285 #endif // !defined(__cplusplus) || defined(CINTERFACE) 286 287 HRESULT CreateD3D9MipMap(DIRECT3DDEVICE9_INT* pDevice, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture) 288 { 289 LPD3D9MIPMAP pThisTexture; 290 if (FAILED(AlignedAlloc((LPVOID*)&pThisTexture, sizeof(D3D9MipMap)))) 291 { 292 DPRINT1("Could not create D3D9MipMap"); 293 return E_OUTOFMEMORY; 294 } 295 296 InitDirect3DBaseTexture9(&pThisTexture->BaseTexture, (IDirect3DBaseTexture9Vtbl*)&D3D9MipMap_Vtbl, Usage, Levels, Format, Pool, pDevice, RT_EXTERNAL); 297 298 pThisTexture->lpVtbl = &D3D9MipMap_Vtbl; 299 300 pThisTexture->Usage = Usage; 301 pThisTexture->dwWidth = Width; 302 pThisTexture->dwHeight = Height; 303 pThisTexture->Format = Format; 304 305 *ppTexture = (IDirect3DTexture9*)&pThisTexture->lpVtbl; 306 307 UNIMPLEMENTED; 308 return D3D_OK; 309 } 310