wined3d: Add WINED3DBOX to wined3d_types.h.
[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_IWineD3DBase)
38         || IsEqualGUID(riid, &IID_IWineD3DResource)
39         || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
40         || IsEqualGUID(riid, &IID_IWineD3DVolumeTexture)) {
41         IUnknown_AddRef(iface);
42         *ppobj = This;
43         return WINED3D_OK;
44     }
45     return E_NOINTERFACE;
46 }
47
48 ULONG WINAPI IWineD3DVolumeTextureImpl_AddRef(IWineD3DVolumeTexture *iface) {
49     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
50     TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
51     return InterlockedIncrement(&This->resource.ref);
52 }
53
54 ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
55     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
56     ULONG ref;
57     int i;
58     TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
59     ref = InterlockedDecrement(&This->resource.ref);
60     if (ref == 0) {
61         for (i = 0; i < This->baseTexture.levels; i++) {
62             if (This->volumes[i] != NULL) {
63                 /* Since the volumes were created by callback, the texture is
64                  * keeping the reference to the parent, so the texture should
65                  * release it. */
66                 IUnknown *volumeParent = NULL;
67
68                 TRACE("(%p) : Releasing volume %p\n", This, This->volumes[i]);
69
70                 /* Cleanup the container */
71                 IWineD3DVolume_SetContainer(This->volumes[i], 0);
72                 /* Now, release the parent, which will take care of cleaning up the volume for us */
73                 IWineD3DVolume_GetParent(This->volumes[i], &volumeParent);
74                 IUnknown_Release(volumeParent); /* Once for the reference GetParent added */
75                 IUnknown_Release(volumeParent); /* Once for the reference we're keeping */
76             }
77         }
78         IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *) iface);
79         HeapFree(GetProcessHeap(), 0, This);
80     }
81     return ref;
82 }
83
84 /* ****************************************************
85    IWineD3DVolumeTexture IWineD3DResource parts follow
86    **************************************************** */
87 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
88     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
89 }
90
91 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
92     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
93 }
94
95 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
96     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
97 }
98
99 HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
100     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
101 }
102
103 DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
104     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
105 }
106
107 DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
108     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
109 }
110
111 void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
112     /* Overrider the IWineD3DResource Preload method */
113     UINT i;
114     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
115
116     TRACE("(%p) : About to load texture\n", This);
117
118     IWineD3DVolumeTexture_BindTexture(iface);
119
120     ENTER_GL();
121     /* If were dirty then reload the volumes */
122     if(This->baseTexture.dirty != FALSE) {
123         for (i = 0; i < This->baseTexture.levels; i++) {
124             IWineD3DVolume_LoadTexture(This->volumes[i], i);
125         }
126
127         /* No longer dirty */
128         This->baseTexture.dirty = FALSE;
129     }
130     LEAVE_GL();
131
132     return ;
133 }
134
135 WINED3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
136     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
137 }
138
139 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
140     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
141 }
142
143 /* ******************************************************
144    IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
145    ****************************************************** */
146 DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
147     return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
148 }
149
150 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
151     return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
152 }
153
154 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
155     return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
156 }
157
158 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
159   return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
160 }
161
162 WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
163   return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
164 }
165
166 void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
167   return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
168 }
169
170 /* Internal function, No d3d mapping */
171 BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
172     return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
173 }
174
175 BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
176     return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
177 }
178
179 HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface) {
180     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
181     TRACE("(%p) : relay to BaseTexture\n", This);
182     return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
183 }
184
185 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnBindTexture(IWineD3DVolumeTexture *iface) {
186     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
187     TRACE("(%p) : relay to BaseTexture\n", This);
188     return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
189 }
190
191 UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
192     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
193     TRACE("(%p)\n", This);
194     return GL_TEXTURE_3D;
195 }
196
197 void WINAPI IWineD3DVolumeTextureImpl_ApplyStateChanges(IWineD3DVolumeTexture *iface,
198                                                         const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
199                                                         const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
200     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
201     TRACE("(%p) : nothing to do, passing to base texture\n", This);
202     IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
203 }
204
205
206 /* *******************************************
207    IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
208    ******************************************* */
209 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
210     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
211     if (Level < This->baseTexture.levels) {
212         TRACE("(%p) Level (%d)\n", This, Level);
213         return IWineD3DVolume_GetDesc((IWineD3DVolume *) This->volumes[Level], pDesc);
214     } else {
215         FIXME("(%p) Level (%d)\n", This, Level);
216     }
217     return WINED3D_OK;
218 }
219 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
220     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
221     if (Level < This->baseTexture.levels) {
222       *ppVolumeLevel = (IWineD3DVolume *)This->volumes[Level];
223       IWineD3DVolume_AddRef((IWineD3DVolume *) *ppVolumeLevel);
224       TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
225     } else {
226       FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
227       return WINED3DERR_INVALIDCALL;
228     }
229     return WINED3D_OK;
230
231 }
232 HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
233     HRESULT hr;
234     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
235
236     if (Level < This->baseTexture.levels) {
237       hr = IWineD3DVolume_LockBox((IWineD3DVolume *)This->volumes[Level], pLockedVolume, pBox, Flags);
238       TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
239
240     } else {
241       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
242       return WINED3DERR_INVALIDCALL;
243     }
244     return hr;
245 }
246
247 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
248     HRESULT hr;
249     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
250
251     if (Level < This->baseTexture.levels) {
252       hr = IWineD3DVolume_UnlockBox((IWineD3DVolume*) This->volumes[Level]);
253       TRACE("(%p) -> level(%d) success(%lu)\n", This, Level, hr);
254
255     } else {
256       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
257       return WINED3DERR_INVALIDCALL;
258     }
259     return hr;
260 }
261
262 HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
263     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
264     This->baseTexture.dirty = TRUE;
265     TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
266     return IWineD3DVolume_AddDirtyBox((IWineD3DVolume *) This->volumes[0], pDirtyBox);
267 }
268
269 const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
270 {
271     /* IUnknown */
272     IWineD3DVolumeTextureImpl_QueryInterface,
273     IWineD3DVolumeTextureImpl_AddRef,
274     IWineD3DVolumeTextureImpl_Release,
275     /* resource */
276     IWineD3DVolumeTextureImpl_GetParent,
277     IWineD3DVolumeTextureImpl_GetDevice,
278     IWineD3DVolumeTextureImpl_SetPrivateData,
279     IWineD3DVolumeTextureImpl_GetPrivateData,
280     IWineD3DVolumeTextureImpl_FreePrivateData,
281     IWineD3DVolumeTextureImpl_SetPriority,
282     IWineD3DVolumeTextureImpl_GetPriority,
283     IWineD3DVolumeTextureImpl_PreLoad,
284     IWineD3DVolumeTextureImpl_GetType,
285     /* BaseTexture */
286     IWineD3DVolumeTextureImpl_SetLOD,
287     IWineD3DVolumeTextureImpl_GetLOD,
288     IWineD3DVolumeTextureImpl_GetLevelCount,
289     IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
290     IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
291     IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
292     IWineD3DVolumeTextureImpl_SetDirty,
293     IWineD3DVolumeTextureImpl_GetDirty,
294     /* not in d3d */
295     IWineD3DVolumeTextureImpl_BindTexture,
296     IWineD3DVolumeTextureImpl_UnBindTexture,
297     IWineD3DVolumeTextureImpl_GetTextureDimensions,
298     IWineD3DVolumeTextureImpl_ApplyStateChanges,
299     /* volume texture */
300     IWineD3DVolumeTextureImpl_GetLevelDesc,
301     IWineD3DVolumeTextureImpl_GetVolumeLevel,
302     IWineD3DVolumeTextureImpl_LockBox,
303     IWineD3DVolumeTextureImpl_UnlockBox,
304     IWineD3DVolumeTextureImpl_AddDirtyBox
305 };