2 * IWineD3DVolumeTexture implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
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.
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.
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
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
29 /* *******************************************
30 IWineD3DTexture IUnknown parts follow
31 ******************************************* */
32 HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
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);
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);
54 ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
55 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
58 TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
59 ref = InterlockedDecrement(&This->resource.ref);
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]);
67 if(This->baseTexture.textureName != 0){
69 TRACE("Deleting texture %d\n", This->baseTexture.textureName);
70 glDeleteTextures(1, &This->baseTexture.textureName);
73 HeapFree(GetProcessHeap(), 0, This);
75 IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
80 /* ****************************************************
81 IWineD3DVolumeTexture IWineD3DResource parts follow
82 **************************************************** */
83 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
84 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
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);
91 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
92 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
95 HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
96 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
99 DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
100 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
103 DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
104 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
107 void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
108 /* Overrider the IWineD3DResource Preload method */
110 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
112 TRACE("(%p) : About to load texture\n", This);
115 #if 0 /* TODO: context manager support */
116 IWineD3DContextManager_PushState(This->contextManager, GL_TEXTURE_3D, ENABLED, NOW /* make sure the state is applied now */);
118 glEnable(GL_TEXTURE_3D); /* make sure texture support is enabled in this context */
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) */
129 glPrioritizeTextures(1, &This->baseTexture.textureName, &tmp);
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");
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);
148 /* No longer dirty */
149 This->baseTexture.dirty = FALSE;
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)");
161 D3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
162 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
165 HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
166 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
169 /* ******************************************************
170 IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
171 ****************************************************** */
172 DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
173 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
176 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
177 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
180 DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
181 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
184 HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
185 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
188 D3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
189 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
192 void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
193 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
196 /* Internal function, No d3d mapping */
197 BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
198 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
201 BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
202 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
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);
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);
218 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnBindTexture(IWineD3DVolumeTexture *iface) {
219 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
220 TRACE("(%p) \n", This);
222 glBindTexture(GL_TEXTURE_3D, 0);
223 glDisable(GL_TEXTURE_3D);
228 UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
229 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
230 TRACE("(%p) \n", This);
231 return GL_TEXTURE_3D;
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);
243 FIXME("(%p) Level (%d)\n", This, Level);
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);
254 FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
255 return D3DERR_INVALIDCALL;
260 HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
262 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
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);
269 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
270 return D3DERR_INVALIDCALL;
275 HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
277 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
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);
284 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
285 return D3DERR_INVALIDCALL;
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);
297 IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
300 IWineD3DVolumeTextureImpl_QueryInterface,
301 IWineD3DVolumeTextureImpl_AddRef,
302 IWineD3DVolumeTextureImpl_Release,
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,
314 IWineD3DVolumeTextureImpl_SetLOD,
315 IWineD3DVolumeTextureImpl_GetLOD,
316 IWineD3DVolumeTextureImpl_GetLevelCount,
317 IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
318 IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
319 IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
320 IWineD3DVolumeTextureImpl_SetDirty,
321 IWineD3DVolumeTextureImpl_GetDirty,
323 IWineD3DVolumeTextureImpl_BindTexture,
324 IWineD3DVolumeTextureImpl_UnBindTexture,
325 IWineD3DVolumeTextureImpl_GetTextureDimensions,
327 IWineD3DVolumeTextureImpl_GetLevelDesc,
328 IWineD3DVolumeTextureImpl_GetVolumeLevel,
329 IWineD3DVolumeTextureImpl_LockBox,
330 IWineD3DVolumeTextureImpl_UnlockBox,
331 IWineD3DVolumeTextureImpl_AddDirtyBox