urlmon: Implement BindAsyncMoniker function.
[wine] / dlls / wined3d / volumetexture.c
1 /*
2  * IWineD3DVolumeTexture implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  * Copyright 2002-2005 Raphael Junqueira
6  * Copyright 2005 Oliver Stieber
7  *
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.
12  *
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.
17  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "wined3d_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
28
29 /* *******************************************
30    IWineD3DTexture IUnknown parts follow
31    ******************************************* */
32 HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
33 {
34     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
35     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
36     if (IsEqualGUID(riid, &IID_IUnknown)
37         || IsEqualGUID(riid, &IID_IWineD3DResource)
38         || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
39         || IsEqualGUID(riid, &IID_IWineD3DVolumeTexture)) {
40         IUnknown_AddRef(iface);
41         *ppobj = This;
42         return D3D_OK;
43     }
44     return E_NOINTERFACE;
45 }
46
47 ULONG WINAPI IWineD3DVolumeTextureImpl_AddRef(IWineD3DVolumeTexture *iface) {
48     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
49     TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
50     return InterlockedIncrement(&This->resource.ref);
51 }
52
53 ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
54     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
55     ULONG ref;
56     int i;
57     TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
58     ref = InterlockedDecrement(&This->resource.ref);
59     if (ref == 0) {
60         for (i = 0; i < This->baseTexture.levels; i++) {
61             if (This->volumes[i] != NULL) {
62                 TRACE("(%p) : Releasing volume %p\n", This, This->volumes[i]);
63                 IWineD3DVolume_Release(This->volumes[i]);
64             }
65         }
66         IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *) iface);
67         HeapFree(GetProcessHeap(), 0, This);
68     }
69     return ref;
70 }
71
72 /* ****************************************************
73    IWineD3DVolumeTexture IWineD3DResource parts follow
74    **************************************************** */
75 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
76     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
77 }
78
79 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
80     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
81 }
82
83 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
84     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
85 }
86
87 HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
88     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
89 }
90
91 DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
92     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
93 }
94
95 DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
96     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
97 }
98
99 void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
100     /* Overrider the IWineD3DResource Preload method */
101     UINT i;
102     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
103
104     TRACE("(%p) : About to load texture\n", This);
105
106     IWineD3DVolumeTexture_BindTexture(iface);
107
108     ENTER_GL();
109     /* If were dirty then reload the volumes */
110     if(This->baseTexture.dirty != FALSE) {
111         for (i = 0; i < This->baseTexture.levels; i++) {
112             IWineD3DVolume_LoadTexture(This->volumes[i], i);
113         }
114
115         /* No longer dirty */
116         This->baseTexture.dirty = FALSE;
117     }
118     LEAVE_GL();
119
120     return ;
121 }
122
123 D3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
124     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
125 }
126
127 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
128     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
129 }
130
131 /* ******************************************************
132    IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
133    ****************************************************** */
134 DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
135     return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
136 }
137
138 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
139     return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
140 }
141
142 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
143     return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
144 }
145
146 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
147   return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
148 }
149
150 D3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
151   return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
152 }
153
154 void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
155   return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
156 }
157
158 /* Internal function, No d3d mapping */
159 BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
160     return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
161 }
162
163 BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
164     return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
165 }
166
167 HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface) {
168     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
169     TRACE("(%p) : relay to BaseTexture\n", This);
170     return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
171 }
172
173 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnBindTexture(IWineD3DVolumeTexture *iface) {
174     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
175     TRACE("(%p) : relay to BaseTexture\n", This);
176     return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
177 }
178
179 UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
180     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
181     TRACE("(%p)\n", This);
182     return GL_TEXTURE_3D;
183 }
184
185 void WINAPI IWineD3DVolumeTextureImpl_ApplyStateChanges(IWineD3DVolumeTexture *iface,
186                                                         const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
187                                                         const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
188     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
189     TRACE("(%p) : nothing to do, passing to base texture\n", This);
190     IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
191 }
192
193
194 /* *******************************************
195    IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
196    ******************************************* */
197 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
198     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
199     if (Level < This->baseTexture.levels) {
200         TRACE("(%p) Level (%d)\n", This, Level);
201         return IWineD3DVolume_GetDesc((IWineD3DVolume *) This->volumes[Level], pDesc);
202     } else {
203         FIXME("(%p) Level (%d)\n", This, Level);
204     }
205     return D3D_OK;
206 }
207 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
208     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
209     if (Level < This->baseTexture.levels) {
210       *ppVolumeLevel = (IWineD3DVolume *)This->volumes[Level];
211       IWineD3DVolume_AddRef((IWineD3DVolume *) *ppVolumeLevel);
212       TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
213     } else {
214       FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
215       return D3DERR_INVALIDCALL;
216     }
217     return D3D_OK;
218
219 }
220 HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
221     HRESULT hr;
222     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
223
224     if (Level < This->baseTexture.levels) {
225       hr = IWineD3DVolume_LockBox((IWineD3DVolume *)This->volumes[Level], pLockedVolume, pBox, Flags);
226       TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
227
228     } else {
229       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
230       return D3DERR_INVALIDCALL;
231     }
232     return hr;
233 }
234
235 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
236     HRESULT hr;
237     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
238
239     if (Level < This->baseTexture.levels) {
240       hr = IWineD3DVolume_UnlockBox((IWineD3DVolume*) This->volumes[Level]);
241       TRACE("(%p) -> level(%d) success(%lu)\n", This, Level, hr);
242
243     } else {
244       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
245       return D3DERR_INVALIDCALL;
246     }
247     return hr;
248 }
249
250 HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST D3DBOX* pDirtyBox) {
251     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
252     This->baseTexture.dirty = TRUE;
253     TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
254     return IWineD3DVolume_AddDirtyBox((IWineD3DVolume *) This->volumes[0], pDirtyBox);
255 }
256
257 const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
258 {
259     /* IUnknown */
260     IWineD3DVolumeTextureImpl_QueryInterface,
261     IWineD3DVolumeTextureImpl_AddRef,
262     IWineD3DVolumeTextureImpl_Release,
263     /* resource */
264     IWineD3DVolumeTextureImpl_GetParent,
265     IWineD3DVolumeTextureImpl_GetDevice,
266     IWineD3DVolumeTextureImpl_SetPrivateData,
267     IWineD3DVolumeTextureImpl_GetPrivateData,
268     IWineD3DVolumeTextureImpl_FreePrivateData,
269     IWineD3DVolumeTextureImpl_SetPriority,
270     IWineD3DVolumeTextureImpl_GetPriority,
271     IWineD3DVolumeTextureImpl_PreLoad,
272     IWineD3DVolumeTextureImpl_GetType,
273     /* BaseTexture */
274     IWineD3DVolumeTextureImpl_SetLOD,
275     IWineD3DVolumeTextureImpl_GetLOD,
276     IWineD3DVolumeTextureImpl_GetLevelCount,
277     IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
278     IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
279     IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
280     IWineD3DVolumeTextureImpl_SetDirty,
281     IWineD3DVolumeTextureImpl_GetDirty,
282     /* not in d3d */
283     IWineD3DVolumeTextureImpl_BindTexture,
284     IWineD3DVolumeTextureImpl_UnBindTexture,
285     IWineD3DVolumeTextureImpl_GetTextureDimensions,
286     IWineD3DVolumeTextureImpl_ApplyStateChanges,
287     /* volume texture */
288     IWineD3DVolumeTextureImpl_GetLevelDesc,
289     IWineD3DVolumeTextureImpl_GetVolumeLevel,
290     IWineD3DVolumeTextureImpl_LockBox,
291     IWineD3DVolumeTextureImpl_UnlockBox,
292     IWineD3DVolumeTextureImpl_AddDirtyBox
293 };