wined3d: Update the QueryInterface functions of IWineD3DBase subclasses.
[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 D3D_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                 TRACE("(%p) : Releasing volume %p\n", This, This->volumes[i]);
64                 IWineD3DVolume_Release(This->volumes[i]);
65             }
66         }
67         IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *) iface);
68         HeapFree(GetProcessHeap(), 0, This);
69     }
70     return ref;
71 }
72
73 /* ****************************************************
74    IWineD3DVolumeTexture IWineD3DResource parts follow
75    **************************************************** */
76 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
77     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
78 }
79
80 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
81     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
82 }
83
84 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
85     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
86 }
87
88 HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
89     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
90 }
91
92 DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
93     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
94 }
95
96 DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
97     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
98 }
99
100 void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
101     /* Overrider the IWineD3DResource Preload method */
102     UINT i;
103     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
104
105     TRACE("(%p) : About to load texture\n", This);
106
107     IWineD3DVolumeTexture_BindTexture(iface);
108
109     ENTER_GL();
110     /* If were dirty then reload the volumes */
111     if(This->baseTexture.dirty != FALSE) {
112         for (i = 0; i < This->baseTexture.levels; i++) {
113             IWineD3DVolume_LoadTexture(This->volumes[i], i);
114         }
115
116         /* No longer dirty */
117         This->baseTexture.dirty = FALSE;
118     }
119     LEAVE_GL();
120
121     return ;
122 }
123
124 D3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
125     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
126 }
127
128 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
129     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
130 }
131
132 /* ******************************************************
133    IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
134    ****************************************************** */
135 DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
136     return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
137 }
138
139 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
140     return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
141 }
142
143 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
144     return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
145 }
146
147 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
148   return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
149 }
150
151 D3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
152   return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
153 }
154
155 void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
156   return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
157 }
158
159 /* Internal function, No d3d mapping */
160 BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
161     return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
162 }
163
164 BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
165     return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
166 }
167
168 HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface) {
169     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
170     TRACE("(%p) : relay to BaseTexture\n", This);
171     return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
172 }
173
174 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnBindTexture(IWineD3DVolumeTexture *iface) {
175     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
176     TRACE("(%p) : relay to BaseTexture\n", This);
177     return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
178 }
179
180 UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
181     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
182     TRACE("(%p)\n", This);
183     return GL_TEXTURE_3D;
184 }
185
186 void WINAPI IWineD3DVolumeTextureImpl_ApplyStateChanges(IWineD3DVolumeTexture *iface,
187                                                         const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
188                                                         const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
189     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
190     TRACE("(%p) : nothing to do, passing to base texture\n", This);
191     IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
192 }
193
194
195 /* *******************************************
196    IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
197    ******************************************* */
198 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
199     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
200     if (Level < This->baseTexture.levels) {
201         TRACE("(%p) Level (%d)\n", This, Level);
202         return IWineD3DVolume_GetDesc((IWineD3DVolume *) This->volumes[Level], pDesc);
203     } else {
204         FIXME("(%p) Level (%d)\n", This, Level);
205     }
206     return D3D_OK;
207 }
208 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
209     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
210     if (Level < This->baseTexture.levels) {
211       *ppVolumeLevel = (IWineD3DVolume *)This->volumes[Level];
212       IWineD3DVolume_AddRef((IWineD3DVolume *) *ppVolumeLevel);
213       TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
214     } else {
215       FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
216       return D3DERR_INVALIDCALL;
217     }
218     return D3D_OK;
219
220 }
221 HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
222     HRESULT hr;
223     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
224
225     if (Level < This->baseTexture.levels) {
226       hr = IWineD3DVolume_LockBox((IWineD3DVolume *)This->volumes[Level], pLockedVolume, pBox, Flags);
227       TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
228
229     } else {
230       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
231       return D3DERR_INVALIDCALL;
232     }
233     return hr;
234 }
235
236 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
237     HRESULT hr;
238     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
239
240     if (Level < This->baseTexture.levels) {
241       hr = IWineD3DVolume_UnlockBox((IWineD3DVolume*) This->volumes[Level]);
242       TRACE("(%p) -> level(%d) success(%lu)\n", This, Level, hr);
243
244     } else {
245       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
246       return D3DERR_INVALIDCALL;
247     }
248     return hr;
249 }
250
251 HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST D3DBOX* pDirtyBox) {
252     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
253     This->baseTexture.dirty = TRUE;
254     TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
255     return IWineD3DVolume_AddDirtyBox((IWineD3DVolume *) This->volumes[0], pDirtyBox);
256 }
257
258 const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
259 {
260     /* IUnknown */
261     IWineD3DVolumeTextureImpl_QueryInterface,
262     IWineD3DVolumeTextureImpl_AddRef,
263     IWineD3DVolumeTextureImpl_Release,
264     /* resource */
265     IWineD3DVolumeTextureImpl_GetParent,
266     IWineD3DVolumeTextureImpl_GetDevice,
267     IWineD3DVolumeTextureImpl_SetPrivateData,
268     IWineD3DVolumeTextureImpl_GetPrivateData,
269     IWineD3DVolumeTextureImpl_FreePrivateData,
270     IWineD3DVolumeTextureImpl_SetPriority,
271     IWineD3DVolumeTextureImpl_GetPriority,
272     IWineD3DVolumeTextureImpl_PreLoad,
273     IWineD3DVolumeTextureImpl_GetType,
274     /* BaseTexture */
275     IWineD3DVolumeTextureImpl_SetLOD,
276     IWineD3DVolumeTextureImpl_GetLOD,
277     IWineD3DVolumeTextureImpl_GetLevelCount,
278     IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
279     IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
280     IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
281     IWineD3DVolumeTextureImpl_SetDirty,
282     IWineD3DVolumeTextureImpl_GetDirty,
283     /* not in d3d */
284     IWineD3DVolumeTextureImpl_BindTexture,
285     IWineD3DVolumeTextureImpl_UnBindTexture,
286     IWineD3DVolumeTextureImpl_GetTextureDimensions,
287     IWineD3DVolumeTextureImpl_ApplyStateChanges,
288     /* volume texture */
289     IWineD3DVolumeTextureImpl_GetLevelDesc,
290     IWineD3DVolumeTextureImpl_GetVolumeLevel,
291     IWineD3DVolumeTextureImpl_LockBox,
292     IWineD3DVolumeTextureImpl_UnlockBox,
293     IWineD3DVolumeTextureImpl_AddDirtyBox
294 };