2 * IDirect3DVolumeTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DVolumeTexture9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DResource9)
33 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
34 || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)) {
35 IDirect3DVolumeTexture9_AddRef(iface);
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
45 static ULONG WINAPI IDirect3DVolumeTexture9Impl_AddRef(LPDIRECT3DVOLUMETEXTURE9 iface) {
46 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
54 static ULONG WINAPI IDirect3DVolumeTexture9Impl_Release(LPDIRECT3DVOLUMETEXTURE9 iface) {
55 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
56 ULONG ref = InterlockedDecrement(&This->ref);
58 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
61 EnterCriticalSection(&d3d9_cs);
62 IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D9CB_DestroyVolume);
63 LeaveCriticalSection(&d3d9_cs);
64 IDirect3DDevice9Ex_Release(This->parentDevice);
65 HeapFree(GetProcessHeap(), 0, This);
70 /* IDirect3DVolumeTexture9 IDirect3DResource9 Interface follow: */
71 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
72 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
73 IWineD3DDevice *wined3d_device;
76 TRACE("(%p) Relay\n", This);
78 EnterCriticalSection(&d3d9_cs);
79 hr = IWineD3DStateBlock_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
82 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
83 IWineD3DDevice_Release(wined3d_device);
85 LeaveCriticalSection(&d3d9_cs);
90 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
91 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
94 TRACE("(%p) Relay\n", This);
96 EnterCriticalSection(&d3d9_cs);
98 hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
100 LeaveCriticalSection(&d3d9_cs);
105 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
106 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
109 TRACE("(%p) Relay\n", This);
111 EnterCriticalSection(&d3d9_cs);
113 hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
115 LeaveCriticalSection(&d3d9_cs);
120 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid) {
121 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
124 TRACE("(%p) Relay\n", This);
126 EnterCriticalSection(&d3d9_cs);
128 hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
130 LeaveCriticalSection(&d3d9_cs);
135 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD PriorityNew) {
136 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
139 TRACE("(%p) Relay\n", This);
141 EnterCriticalSection(&d3d9_cs);
143 priority = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
145 LeaveCriticalSection(&d3d9_cs);
150 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE9 iface) {
151 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
154 TRACE("(%p) Relay\n", This);
156 EnterCriticalSection(&d3d9_cs);
158 priority = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
160 LeaveCriticalSection(&d3d9_cs);
165 static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE9 iface) {
166 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
168 TRACE("(%p) Relay\n", This);
170 EnterCriticalSection(&d3d9_cs);
172 IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
174 LeaveCriticalSection(&d3d9_cs);
177 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(LPDIRECT3DVOLUMETEXTURE9 iface) {
178 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
179 D3DRESOURCETYPE type;
181 TRACE("(%p) Relay\n", This);
183 EnterCriticalSection(&d3d9_cs);
185 type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
187 LeaveCriticalSection(&d3d9_cs);
192 /* IDirect3DVolumeTexture9 IDirect3DBaseTexture9 Interface follow: */
193 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD LODNew) {
194 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
197 TRACE("(%p) Relay\n", This);
199 EnterCriticalSection(&d3d9_cs);
201 lod = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
203 LeaveCriticalSection(&d3d9_cs);
208 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE9 iface) {
209 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
212 TRACE("(%p) Relay\n", This);
214 EnterCriticalSection(&d3d9_cs);
216 lod = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
218 LeaveCriticalSection(&d3d9_cs);
223 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE9 iface) {
224 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
227 TRACE("(%p) Relay\n", This);
229 EnterCriticalSection(&d3d9_cs);
231 level_count = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
233 LeaveCriticalSection(&d3d9_cs);
238 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
239 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
242 TRACE("(%p) Relay\n", This);
244 EnterCriticalSection(&d3d9_cs);
246 hr = IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
248 LeaveCriticalSection(&d3d9_cs);
253 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface) {
254 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
255 D3DTEXTUREFILTERTYPE filter_type;
257 TRACE("(%p) Relay\n", This);
259 EnterCriticalSection(&d3d9_cs);
261 filter_type = (D3DTEXTUREFILTERTYPE)IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
263 LeaveCriticalSection(&d3d9_cs);
268 static void WINAPI IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DVOLUMETEXTURE9 iface) {
269 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
271 TRACE("(%p) Relay\n", This);
273 EnterCriticalSection(&d3d9_cs);
275 IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
277 LeaveCriticalSection(&d3d9_cs);
280 /* IDirect3DVolumeTexture9 Interface follow: */
281 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DVOLUME_DESC* pDesc) {
282 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
283 WINED3DVOLUME_DESC wined3ddesc;
285 WINED3DFORMAT format;
288 TRACE("(%p) Relay\n", This);
290 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
291 wined3ddesc.Format = &format;
292 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
293 wined3ddesc.Usage = &pDesc->Usage;
294 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
295 wined3ddesc.Size = &tmpInt;
296 wined3ddesc.Width = &pDesc->Width;
297 wined3ddesc.Height = &pDesc->Height;
298 wined3ddesc.Depth = &pDesc->Depth;
300 EnterCriticalSection(&d3d9_cs);
302 hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
304 LeaveCriticalSection(&d3d9_cs);
306 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
311 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, IDirect3DVolume9** ppVolumeLevel) {
312 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
313 HRESULT hrc = D3D_OK;
314 IWineD3DVolume *myVolume = NULL;
316 TRACE("(%p) Relay\n", This);
318 EnterCriticalSection(&d3d9_cs);
320 hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
321 if (hrc == D3D_OK && NULL != ppVolumeLevel) {
322 IWineD3DVolumeTexture_GetParent(myVolume, (IUnknown **)ppVolumeLevel);
323 IWineD3DVolumeTexture_Release(myVolume);
326 LeaveCriticalSection(&d3d9_cs);
331 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_LockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
332 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
335 TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
337 EnterCriticalSection(&d3d9_cs);
339 hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *)pLockedVolume,
340 (const WINED3DBOX *)pBox, Flags);
342 LeaveCriticalSection(&d3d9_cs);
347 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level) {
348 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
351 TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
353 EnterCriticalSection(&d3d9_cs);
355 hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
357 LeaveCriticalSection(&d3d9_cs);
362 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE9 iface, CONST D3DBOX* pDirtyBox) {
363 IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
366 TRACE("(%p) Relay\n", This);
368 EnterCriticalSection(&d3d9_cs);
370 hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
372 LeaveCriticalSection(&d3d9_cs);
378 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl =
381 IDirect3DVolumeTexture9Impl_QueryInterface,
382 IDirect3DVolumeTexture9Impl_AddRef,
383 IDirect3DVolumeTexture9Impl_Release,
384 /* IDirect3DResource9 */
385 IDirect3DVolumeTexture9Impl_GetDevice,
386 IDirect3DVolumeTexture9Impl_SetPrivateData,
387 IDirect3DVolumeTexture9Impl_GetPrivateData,
388 IDirect3DVolumeTexture9Impl_FreePrivateData,
389 IDirect3DVolumeTexture9Impl_SetPriority,
390 IDirect3DVolumeTexture9Impl_GetPriority,
391 IDirect3DVolumeTexture9Impl_PreLoad,
392 IDirect3DVolumeTexture9Impl_GetType,
393 /* IDirect3DBaseTexture9 */
394 IDirect3DVolumeTexture9Impl_SetLOD,
395 IDirect3DVolumeTexture9Impl_GetLOD,
396 IDirect3DVolumeTexture9Impl_GetLevelCount,
397 IDirect3DVolumeTexture9Impl_SetAutoGenFilterType,
398 IDirect3DVolumeTexture9Impl_GetAutoGenFilterType,
399 IDirect3DVolumeTexture9Impl_GenerateMipSubLevels,
400 /* IDirect3DVolumeTexture9 */
401 IDirect3DVolumeTexture9Impl_GetLevelDesc,
402 IDirect3DVolumeTexture9Impl_GetVolumeLevel,
403 IDirect3DVolumeTexture9Impl_LockBox,
404 IDirect3DVolumeTexture9Impl_UnlockBox,
405 IDirect3DVolumeTexture9Impl_AddDirtyBox
409 /* IDirect3DDevice9 IDirect3DVolumeTexture9 Methods follow: */
410 HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9EX iface,
411 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
412 D3DFORMAT Format, D3DPOOL Pool,
413 IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) {
415 IDirect3DVolumeTexture9Impl *object;
416 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
417 HRESULT hrc = D3D_OK;
419 TRACE("(%p) Relay\n", This);
421 /* Allocate the storage for the device */
422 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture9Impl));
423 if (NULL == object) {
424 ERR("(%p) allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n", This);
425 return D3DERR_OUTOFVIDEOMEMORY;
428 object->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
431 EnterCriticalSection(&d3d9_cs);
433 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
434 Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format), Pool,
435 &object->wineD3DVolumeTexture, pSharedHandle, (IUnknown *)object);
437 LeaveCriticalSection(&d3d9_cs);
442 WARN("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
443 HeapFree(GetProcessHeap(), 0, object);
445 IDirect3DDevice9Ex_AddRef(iface);
446 object->parentDevice = iface;
447 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE9) object;
448 TRACE("(%p) : Created volume texture %p\n", This, object);
450 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);