volumetexture.c 10.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * IDirect3DVolumeTexture8 implementation
 *
 * Copyright 2002 Jason Edmeades
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

21
#include "config.h"
22

23 24
#include <stdarg.h>

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "wingdi.h"
#include "wine/debug.h"

#include "d3d8_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(d3d);

/* IDirect3DVolumeTexture8 IUnknown parts follow: */
HRESULT WINAPI IDirect3DVolumeTexture8Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE8 iface,REFIID riid,LPVOID *ppobj)
{
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);

    TRACE("(%p) : QueryInterface\n", This);
    if (IsEqualGUID(riid, &IID_IUnknown)
42 43 44
	|| IsEqualGUID(riid, &IID_IDirect3DResource8)
	|| IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
	|| IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)) {
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        IDirect3DVolumeTexture8Impl_AddRef(iface);
        *ppobj = This;
        return D3D_OK;
    }

    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
    return E_NOINTERFACE;
}

ULONG WINAPI IDirect3DVolumeTexture8Impl_AddRef(LPDIRECT3DVOLUMETEXTURE8 iface) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
    TRACE("(%p) : AddRef from %ld\n", This, This->ref);
    return ++(This->ref);
}

ULONG WINAPI IDirect3DVolumeTexture8Impl_Release(LPDIRECT3DVOLUMETEXTURE8 iface) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
    ULONG ref = --This->ref;
63
    UINT  i;
64

65
    TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
66
    if (ref == 0) {
67
        for (i = 0; i < This->levels; i++) {
68 69 70 71 72
            if (This->volumes[i] != NULL) {
                TRACE("(%p) : Releasing volume %p\n", This, This->volumes[i]);
                IDirect3DVolume8Impl_Release((LPDIRECT3DVOLUME8) This->volumes[i]);
            }
        }
73
        HeapFree(GetProcessHeap(), 0, This);
74
    }
75 76 77 78 79 80 81 82
    return ref;
}

/* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE8 iface, IDirect3DDevice8** ppDevice) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
    TRACE("(%p) : returning %p\n", This, This->Device);
    *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
83 84 85 86 87
    /**
     * Note  Calling this method will increase the internal reference count 
     * on the IDirect3DDevice8 interface. 
     */
    IDirect3DDevice8Impl_AddRef(*ppDevice);
88 89 90 91
    return D3D_OK;
}
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
92 93
    FIXME("(%p) : stub\n", This);
    return D3D_OK;
94 95 96
}
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
97 98
    FIXME("(%p) : stub\n", This);
    return D3D_OK;
99 100 101
}
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
102 103
    FIXME("(%p) : stub\n", This);
    return D3D_OK;
104 105 106
}
DWORD    WINAPI        IDirect3DVolumeTexture8Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE8 iface, DWORD PriorityNew) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
107 108
    FIXME("(%p) : stub returning 0\n", This);    
    return 0;
109 110 111
}
DWORD    WINAPI        IDirect3DVolumeTexture8Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE8 iface) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
112 113
    FIXME("(%p) : stub returning 0\n", This);    
    return 0;
114 115
}
void     WINAPI        IDirect3DVolumeTexture8Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE8 iface) {
116 117 118
    int i;
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
    TRACE("(%p) : About to load texture\n", This);
119 120 121

    ENTER_GL();

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    for (i = 0; i < This->levels; i++) {
      if (i == 0 && This->volumes[i]->textureName != 0 && This->Dirty == FALSE) {
	glBindTexture(GL_TEXTURE_3D, This->volumes[i]->textureName);
	checkGLcall("glBindTexture");
	TRACE("Texture %p (level %d) given name %d\n", This->volumes[i], i, This->volumes[i]->textureName);
	/* No need to walk through all mip-map levels, since already all assigned */
	i = This->levels;
      } else {
	if (i == 0) {
	  if (This->volumes[i]->textureName == 0) {
	    glGenTextures(1, &This->volumes[i]->textureName);
	    checkGLcall("glGenTextures");
	    TRACE("Texture %p (level %d) given name %d\n", This->volumes[i], i, This->volumes[i]->textureName);
	  }
	  
	  glBindTexture(GL_TEXTURE_3D, This->volumes[i]->textureName);
	  checkGLcall("glBindTexture");
	  
	  TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
	  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, This->levels - 1); 
	  checkGLcall("glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
	}
144 145 146 147

	TRACE("Calling glTexImage3D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
	      GL_TEXTURE_3D, 
	      i, 
Raphael Junqueira's avatar
Raphael Junqueira committed
148
	      D3DFmt2GLIntFmt(This->Device, This->format), 
149 150
	      This->volumes[i]->myDesc.Width, 
	      This->volumes[i]->myDesc.Height, 
151
	      This->volumes[i]->myDesc.Depth,
152
	      0, 
Raphael Junqueira's avatar
Raphael Junqueira committed
153 154
	      D3DFmt2GLFmt(This->Device, This->format), 
	      D3DFmt2GLType(This->Device, This->format),
155 156 157
	      This->volumes[i]->allocatedMemory);
	glTexImage3D(GL_TEXTURE_3D, 
		     i,
Raphael Junqueira's avatar
Raphael Junqueira committed
158
		     D3DFmt2GLIntFmt(This->Device, This->format),
159 160 161 162
		     This->volumes[i]->myDesc.Width,
		     This->volumes[i]->myDesc.Height,
		     This->volumes[i]->myDesc.Depth,
		     0,
Raphael Junqueira's avatar
Raphael Junqueira committed
163 164
		     D3DFmt2GLFmt(This->Device, This->format),
		     D3DFmt2GLType(This->Device, This->format),
165 166
		     This->volumes[i]->allocatedMemory);
	checkGLcall("glTexImage3D");
167

168 169 170 171
	/* Removed glTexParameterf now TextureStageStates are initialized at startup */
	This->Dirty = FALSE;
      }
    }
172 173 174

    LEAVE_GL();

175
    return ;
176 177 178 179 180 181 182
}
D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture8Impl_GetType(LPDIRECT3DVOLUMETEXTURE8 iface) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
    TRACE("(%p) : returning %d\n", This, This->ResourceType);
    return This->ResourceType;
}

183
/* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */
184 185
DWORD    WINAPI        IDirect3DVolumeTexture8Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE8 iface, DWORD LODNew) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
186 187
    FIXME("(%p) : stub returning 0\n", This);    
    return 0;
188 189 190
}
DWORD    WINAPI        IDirect3DVolumeTexture8Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE8 iface) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
191 192
    FIXME("(%p) : stub returning 0\n", This);    
    return 0;
193 194 195
}
DWORD    WINAPI        IDirect3DVolumeTexture8Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE8 iface) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
196 197
    TRACE("(%p) : returning %d\n", This, This->levels);
    return This->levels;
198 199 200 201 202
}

/* IDirect3DVolumeTexture8 */
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level,D3DVOLUME_DESC *pDesc) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
203 204
    if (Level < This->levels) {
        TRACE("(%p) Level (%d)\n", This, Level);
205
        return IDirect3DVolume8Impl_GetDesc((LPDIRECT3DVOLUME8) This->volumes[Level], pDesc);
206 207 208 209
    } else {
        FIXME("(%p) Level (%d)\n", This, Level);
    }
    return D3D_OK;
210
}
211
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, IDirect3DVolume8** ppVolumeLevel) {
212
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
213 214 215 216 217 218 219 220
    if (Level < This->levels) {
      *ppVolumeLevel = (LPDIRECT3DVOLUME8)This->volumes[Level];
      IDirect3DVolume8Impl_AddRef((LPDIRECT3DVOLUME8) *ppVolumeLevel);
      TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
    } else {
      FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->levels);
      return D3DERR_INVALIDCALL;
    }
221
    return D3D_OK;
222

223
}
224 225
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_LockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
    HRESULT hr;
226
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
227
    if (Level < This->levels) {
228 229 230 231 232 233
      /**
       * Not dirtified while Surfaces don't notify dirtification
       * This->Dirty = TRUE;
       */
      hr = IDirect3DVolume8Impl_LockBox((LPDIRECT3DVOLUME8) This->volumes[Level], pLockedVolume, pBox, Flags);
      TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
234
    } else {
235 236
      FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
      return D3DERR_INVALIDCALL;
237
    }
238
    return hr;
239 240
}
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level) {
241
    HRESULT hr;
242
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
243
    if (Level < This->levels) {
244 245
      hr = IDirect3DVolume8Impl_UnlockBox((LPDIRECT3DVOLUME8) This->volumes[Level]);
      TRACE("(%p) -> level(%d) success(%lu)\n", This, Level, hr);
246 247 248 249
    } else {
      FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
      return D3DERR_INVALIDCALL;
    }
250
    return hr;
251 252 253
}
HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE8 iface, CONST D3DBOX* pDirtyBox) {
    ICOM_THIS(IDirect3DVolumeTexture8Impl,iface);
254
    This->Dirty = TRUE;
255 256
    TRACE("(%p) : dirtyfication of volume Level (0)\n", This);    
    return IDirect3DVolume8Impl_AddDirtyBox((LPDIRECT3DVOLUME8) This->volumes[0], pDirtyBox);
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
}


ICOM_VTABLE(IDirect3DVolumeTexture8) Direct3DVolumeTexture8_Vtbl =
{
    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    IDirect3DVolumeTexture8Impl_QueryInterface,
    IDirect3DVolumeTexture8Impl_AddRef,
    IDirect3DVolumeTexture8Impl_Release,
    IDirect3DVolumeTexture8Impl_GetDevice,
    IDirect3DVolumeTexture8Impl_SetPrivateData,
    IDirect3DVolumeTexture8Impl_GetPrivateData,
    IDirect3DVolumeTexture8Impl_FreePrivateData,
    IDirect3DVolumeTexture8Impl_SetPriority,
    IDirect3DVolumeTexture8Impl_GetPriority,
    IDirect3DVolumeTexture8Impl_PreLoad,
    IDirect3DVolumeTexture8Impl_GetType,
    IDirect3DVolumeTexture8Impl_SetLOD,
    IDirect3DVolumeTexture8Impl_GetLOD,
    IDirect3DVolumeTexture8Impl_GetLevelCount,
    IDirect3DVolumeTexture8Impl_GetLevelDesc,
    IDirect3DVolumeTexture8Impl_GetVolumeLevel,
    IDirect3DVolumeTexture8Impl_LockBox,
    IDirect3DVolumeTexture8Impl_UnlockBox,
    IDirect3DVolumeTexture8Impl_AddDirtyBox
};