comctl32: Fix a regression.
[wine] / dlls / d3d9 / volumetexture.c
1 /*
2  * IDirect3DVolumeTexture9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  *                     Raphael Junqueira
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVolumeTexture9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32     || IsEqualGUID(riid, &IID_IDirect3DResource9)
33     || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
34     || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)) {
35         IUnknown_AddRef(iface);
36         *ppobj = This;
37         return S_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41     *ppobj = NULL;
42     return E_NOINTERFACE;
43 }
44
45 static ULONG WINAPI IDirect3DVolumeTexture9Impl_AddRef(LPDIRECT3DVOLUMETEXTURE9 iface) {
46     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
47     ULONG ref = InterlockedIncrement(&This->ref);
48
49     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
50
51     return ref;
52 }
53
54 static ULONG WINAPI IDirect3DVolumeTexture9Impl_Release(LPDIRECT3DVOLUMETEXTURE9 iface) {
55     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
56     ULONG ref = InterlockedDecrement(&This->ref);
57
58     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
59
60     if (ref == 0) {
61         IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
62         IUnknown_Release(This->parentDevice);
63         HeapFree(GetProcessHeap(), 0, This);
64     }
65     return ref;
66 }
67
68 /* IDirect3DVolumeTexture9 IDirect3DResource9 Interface follow: */
69 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
70     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
71     TRACE("(%p) Relay\n", This);
72     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
73 }
74
75 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
76     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
77     TRACE("(%p) Relay\n", This);
78     return IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
79 }
80
81 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
82     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
83     TRACE("(%p) Relay\n", This);
84     return IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
85 }
86
87 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid) {
88     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
89     TRACE("(%p) Relay\n", This);
90     return IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
91 }
92
93 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD PriorityNew) {
94     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
95     TRACE("(%p) Relay\n", This);
96     return IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
97 }
98
99 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE9 iface) {
100     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
101     TRACE("(%p) Relay\n", This);
102     return IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
103 }
104
105 static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE9 iface) {
106     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
107     TRACE("(%p) Relay\n", This);
108     return IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
109 }
110
111 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(LPDIRECT3DVOLUMETEXTURE9 iface) {
112     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
113     TRACE("(%p) Relay\n", This);
114     return IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
115 }
116
117 /* IDirect3DVolumeTexture9 IDirect3DBaseTexture9 Interface follow: */
118 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD LODNew) {
119     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
120     TRACE("(%p) Relay\n", This);
121     return IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
122 }
123
124 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE9 iface) {
125     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
126     TRACE("(%p) Relay\n", This);
127     return IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
128 }
129
130 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE9 iface) {
131     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
132     TRACE("(%p) Relay\n", This);
133     return IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
134 }
135
136 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
137     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
138     TRACE("(%p) Relay\n", This);
139     return IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
140 }
141
142 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface) {
143     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
144     TRACE("(%p) Relay\n", This);
145     return (D3DTEXTUREFILTERTYPE) IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
146 }
147
148 static void WINAPI IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DVOLUMETEXTURE9 iface) {
149     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
150     TRACE("(%p) Relay\n", This);
151     return IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
152 }
153
154 /* IDirect3DVolumeTexture9 Interface follow: */
155 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DVOLUME_DESC* pDesc) {
156     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
157     WINED3DVOLUME_DESC     wined3ddesc;
158     UINT                   tmpInt = -1;
159
160     TRACE("(%p) Relay\n", This);
161
162     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
163     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
164     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
165     wined3ddesc.Usage               = &pDesc->Usage;
166     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
167     wined3ddesc.Size                = &tmpInt;
168     wined3ddesc.Width               = &pDesc->Width;
169     wined3ddesc.Height              = &pDesc->Height;
170     wined3ddesc.Depth               = &pDesc->Depth;
171
172     return IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
173 }
174
175 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, IDirect3DVolume9** ppVolumeLevel) {
176     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
177     HRESULT hrc = D3D_OK;
178     IWineD3DVolume *myVolume = NULL;
179
180     TRACE("(%p) Relay\n", This);
181
182     hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
183     if (hrc == D3D_OK && NULL != ppVolumeLevel) {
184        IWineD3DVolumeTexture_GetParent(myVolume, (IUnknown **)ppVolumeLevel);
185        IWineD3DVolumeTexture_Release(myVolume);
186     }
187     return hrc;
188 }
189
190 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_LockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
191     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
192     TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
193     return IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *)pLockedVolume, (CONST WINED3DBOX *)pBox, Flags);
194 }
195
196 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level) {
197     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
198     TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
199     return IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
200 }
201
202 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE9 iface, CONST D3DBOX* pDirtyBox) {
203     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
204     TRACE("(%p) Relay\n", This);
205     return IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
206 }
207
208
209 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl =
210 {
211     /* IUnknown */
212     IDirect3DVolumeTexture9Impl_QueryInterface,
213     IDirect3DVolumeTexture9Impl_AddRef,
214     IDirect3DVolumeTexture9Impl_Release,
215     /* IDirect3DResource9 */
216     IDirect3DVolumeTexture9Impl_GetDevice,
217     IDirect3DVolumeTexture9Impl_SetPrivateData,
218     IDirect3DVolumeTexture9Impl_GetPrivateData,
219     IDirect3DVolumeTexture9Impl_FreePrivateData,
220     IDirect3DVolumeTexture9Impl_SetPriority,
221     IDirect3DVolumeTexture9Impl_GetPriority,
222     IDirect3DVolumeTexture9Impl_PreLoad,
223     IDirect3DVolumeTexture9Impl_GetType,
224     /* IDirect3DBaseTexture9 */
225     IDirect3DVolumeTexture9Impl_SetLOD,
226     IDirect3DVolumeTexture9Impl_GetLOD,
227     IDirect3DVolumeTexture9Impl_GetLevelCount,
228     IDirect3DVolumeTexture9Impl_SetAutoGenFilterType,
229     IDirect3DVolumeTexture9Impl_GetAutoGenFilterType,
230     IDirect3DVolumeTexture9Impl_GenerateMipSubLevels,
231     /* IDirect3DVolumeTexture9 */
232     IDirect3DVolumeTexture9Impl_GetLevelDesc,
233     IDirect3DVolumeTexture9Impl_GetVolumeLevel,
234     IDirect3DVolumeTexture9Impl_LockBox,
235     IDirect3DVolumeTexture9Impl_UnlockBox,
236     IDirect3DVolumeTexture9Impl_AddDirtyBox
237 };
238
239
240 /* IDirect3DDevice9 IDirect3DVolumeTexture9 Methods follow: */
241 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9 iface, 
242                                                           UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, 
243                                                           D3DFORMAT Format, D3DPOOL Pool, 
244                                                           IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) {
245
246     IDirect3DVolumeTexture9Impl *object;
247     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
248     HRESULT hrc = D3D_OK;
249
250     TRACE("(%p) Relay\n", This);
251
252     /* Allocate the storage for the device */
253     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture9Impl));
254     if (NULL == object) {
255         FIXME("(%p) allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n", This);
256         return D3DERR_OUTOFVIDEOMEMORY;
257     }
258
259     object->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
260     object->ref = 1;
261     hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, Usage & WINED3DUSAGE_MASK,
262                                  (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DVolumeTexture, pSharedHandle,
263                                  (IUnknown *)object, D3D9CB_CreateVolume);
264
265
266     if (hrc != D3D_OK) {
267
268         /* free up object */
269         FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
270         HeapFree(GetProcessHeap(), 0, object);
271     } else {
272         IUnknown_AddRef(iface);
273         object->parentDevice = iface;
274         *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE9) object;
275         TRACE("(%p) : Created volume texture %p\n", This, object);
276     }
277     TRACE("(%p)  returning %p\n", This , *ppVolumeTexture);
278     return hrc;
279 }