Remove function prototypes, make functions static.
[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     IUnknown_AddRef(This->resource.parent);
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((IWineD3DSurface *) This->volumes[i]);
65             }
66         }
67         if(This->baseTexture.textureName != 0){
68             ENTER_GL();
69             TRACE("Deleting texture %d\n", This->baseTexture.textureName);
70             glDeleteTextures(1, &This->baseTexture.textureName);
71             LEAVE_GL(); 
72         }
73         HeapFree(GetProcessHeap(), 0, This);
74     } else {
75         IUnknown_Release(This->resource.parent);  /* Released the reference to the d3dx object */
76     }
77     return ref;
78 }
79
80 /* ****************************************************
81    IWineD3DVolumeTexture IWineD3DResource parts follow
82    **************************************************** */
83 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
84     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
85 }
86
87 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
88     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
89 }
90
91 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
92     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
93 }
94
95 HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
96     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
97 }
98
99 DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
100     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
101 }
102
103 DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
104     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
105 }
106
107 void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
108     /* Overrider the IWineD3DResource Preload method */
109     UINT i;
110     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
111     
112     TRACE("(%p) : About to load texture\n", This);
113
114     ENTER_GL();
115 #if 0 /* TODO: context manager support */
116      IWineD3DContextManager_PushState(This->contextManager, GL_TEXTURE_3D, ENABLED, NOW /* make sure the state is applied now */);
117 #endif
118     glEnable(GL_TEXTURE_3D); /* make sure texture support is enabled in this context */
119
120     /* Generate a texture name if we don't already have one */
121     if (This->baseTexture.textureName == 0) {
122         glGenTextures(1, &This->baseTexture.textureName);
123         checkGLcall("glGenTextures");
124         TRACE("Generated texture %d\n", This->baseTexture.textureName);
125          if (This->baseTexture.pool == D3DPOOL_DEFAULT) {
126             /* Tell opengl to try and keep this texture in video ram (well mostly) */
127             GLclampf tmp;
128             tmp = 0.9f;
129             glPrioritizeTextures(1, &This->baseTexture.textureName, &tmp);
130          }        
131     }
132
133    /* Bind the texture */
134     if (This->baseTexture.textureName != 0) {
135         glBindTexture(GL_TEXTURE_3D, This->baseTexture.textureName);
136         checkGLcall("glBindTexture");
137     } else { /* this only happened if we've run out of openGL textures */
138         WARN("This texture doesn't have an openGL texture assigned to it\n");
139         return;
140     }
141     
142     /* If were dirty then reload the volumes */
143     if(This->baseTexture.dirty != FALSE) {
144         for (i = 0; i < This->baseTexture.levels; i++) {
145             IWineD3DVolume_LoadTexture(This->volumes[i], i);
146         }
147         
148         /* No longer dirty */
149         This->baseTexture.dirty = FALSE;        
150     }
151     
152
153     TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
154     glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
155     checkGLcall("glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
156     LEAVE_GL();
157
158     return ;
159 }
160
161 D3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
162     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
163 }
164
165 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
166     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
167 }
168
169 /* ******************************************************
170    IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
171    ****************************************************** */
172 DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
173     return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
174 }
175
176 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
177     return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
178 }
179
180 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
181     return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
182 }
183
184 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
185   return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
186 }
187
188 D3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
189   return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
190 }
191
192 void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
193   return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
194 }
195
196 /* Internal function, No d3d mapping */
197 BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
198     return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
199 }
200
201 BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
202     return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
203 }
204
205 HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface) {
206     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
207     TRACE("(%p) : %d \n", This, This->baseTexture.textureName);    
208     /* make sure that there is a texture to bind */
209     IWineD3DVolumeTexture_PreLoad(iface);
210     ENTER_GL();    
211     glEnable(GL_TEXTURE_3D);    /* all this enable disable stuff is a bit of a mess */
212     /* FIXME: change to use this->textureName */
213     glBindTexture(GL_TEXTURE_3D, This->baseTexture.textureName);
214     LEAVE_GL();    
215     return D3D_OK;
216 }
217
218 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnBindTexture(IWineD3DVolumeTexture *iface) {
219     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
220     TRACE("(%p) \n", This);    
221     ENTER_GL();    
222     glBindTexture(GL_TEXTURE_3D, 0);
223     glDisable(GL_TEXTURE_3D);
224     LEAVE_GL();    
225     return D3D_OK;
226 }
227
228 UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
229     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
230     TRACE("(%p) \n", This);    
231     return GL_TEXTURE_3D;
232 }
233
234 /* *******************************************
235    IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
236    ******************************************* */
237 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
238     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
239     if (Level < This->baseTexture.levels) {
240         TRACE("(%p) Level (%d)\n", This, Level);
241         return IWineD3DVolume_GetDesc((IWineD3DVolume *) This->volumes[Level], pDesc);
242     } else {
243         FIXME("(%p) Level (%d)\n", This, Level);
244     }
245     return D3D_OK;
246 }
247 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
248     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
249     if (Level < This->baseTexture.levels) {
250       *ppVolumeLevel = (IWineD3DVolume *)This->volumes[Level];
251       IWineD3DVolume_AddRef((IWineD3DVolume *) *ppVolumeLevel);
252       TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
253     } else {
254       FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
255       return D3DERR_INVALIDCALL;
256     }
257     return D3D_OK;
258
259 }
260 HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
261     HRESULT hr;
262     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
263
264     if (Level < This->baseTexture.levels) {
265       hr = IWineD3DVolume_LockBox((IWineD3DVolume *)This->volumes[Level], pLockedVolume, pBox, Flags);
266       TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
267
268     } else {
269       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
270       return D3DERR_INVALIDCALL;
271     }
272     return hr;
273 }
274
275 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
276     HRESULT hr;
277     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
278
279     if (Level < This->baseTexture.levels) {
280       hr = IWineD3DVolume_UnlockBox((IWineD3DVolume*) This->volumes[Level]);
281       TRACE("(%p) -> level(%d) success(%lu)\n", This, Level, hr);
282
283     } else {
284       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
285       return D3DERR_INVALIDCALL;
286     }
287     return hr;
288 }
289
290 HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST D3DBOX* pDirtyBox) {
291     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
292     This->baseTexture.dirty = TRUE;
293     TRACE("(%p) : dirtyfication of volume Level (0)\n", This);    
294     return IWineD3DVolume_AddDirtyBox((IWineD3DVolume *) This->volumes[0], pDirtyBox);
295 }
296
297 IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
298 {
299     /* IUnknown */
300     IWineD3DVolumeTextureImpl_QueryInterface,
301     IWineD3DVolumeTextureImpl_AddRef,
302     IWineD3DVolumeTextureImpl_Release,
303     /* resource */
304     IWineD3DVolumeTextureImpl_GetParent,
305     IWineD3DVolumeTextureImpl_GetDevice,
306     IWineD3DVolumeTextureImpl_SetPrivateData,
307     IWineD3DVolumeTextureImpl_GetPrivateData,
308     IWineD3DVolumeTextureImpl_FreePrivateData,
309     IWineD3DVolumeTextureImpl_SetPriority,
310     IWineD3DVolumeTextureImpl_GetPriority,
311     IWineD3DVolumeTextureImpl_PreLoad,
312     IWineD3DVolumeTextureImpl_GetType,
313     /* BaseTexture */
314     IWineD3DVolumeTextureImpl_SetLOD,
315     IWineD3DVolumeTextureImpl_GetLOD,
316     IWineD3DVolumeTextureImpl_GetLevelCount,
317     IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
318     IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
319     IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
320     IWineD3DVolumeTextureImpl_SetDirty,
321     IWineD3DVolumeTextureImpl_GetDirty,
322     /* not in d3d */
323     IWineD3DVolumeTextureImpl_BindTexture,
324     IWineD3DVolumeTextureImpl_UnBindTexture,
325     IWineD3DVolumeTextureImpl_GetTextureDimensions,
326     /* volume texture */
327     IWineD3DVolumeTextureImpl_GetLevelDesc,
328     IWineD3DVolumeTextureImpl_GetVolumeLevel,
329     IWineD3DVolumeTextureImpl_LockBox,
330     IWineD3DVolumeTextureImpl_UnlockBox,
331     IWineD3DVolumeTextureImpl_AddDirtyBox
332 };