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