wined3d: Fix the drawStridedSlow callback function calling convention.
[wine.git] / dlls / wined3d / volumetexture.c
blobde0bba7883d4effbcf787b2b72c68c8f9490e11c
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
29 /* *******************************************
30 IWineD3DTexture IUnknown parts follow
31 ******************************************* */
32 static 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_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;
45 *ppobj = NULL;
46 return E_NOINTERFACE;
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);
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);
63 return ref;
66 /* ****************************************************
67 IWineD3DVolumeTexture IWineD3DResource parts follow
68 **************************************************** */
69 static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
70 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
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);
77 static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
78 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
81 static HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
82 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
85 static DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
86 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
89 static DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
90 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
93 static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
94 /* Overrider the IWineD3DResource Preload method */
95 int i;
96 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
97 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
98 BOOL srgb_mode = This->baseTexture.is_srgb;
99 BOOL srgb_was_toggled = FALSE;
101 TRACE("(%p) : About to load texture\n", This);
103 IWineD3DVolumeTexture_BindTexture(iface);
105 if(!device->isInDraw) {
106 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
107 } else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0) {
108 srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
109 srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
110 This->baseTexture.is_srgb = srgb_mode;
112 ENTER_GL();
113 /* If the texture is marked dirty or the srgb sampler setting has changed since the last load then reload the surfaces */
114 if (This->baseTexture.dirty) {
115 for (i = 0; i < This->baseTexture.levels; i++)
116 IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
117 } else if (srgb_was_toggled) {
118 if (This->baseTexture.srgb_mode_change_count < 20)
119 ++This->baseTexture.srgb_mode_change_count;
120 else
121 FIXME("Volumetexture (%p) has been reloaded at least 20 times due to WINED3DSAMP_SRGBTEXTURE changes on it\'s sampler\n", This);
123 for (i = 0; i < This->baseTexture.levels; i++) {
124 IWineD3DVolume_AddDirtyBox(This->volumes[i], NULL);
125 IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
127 } else {
128 TRACE("(%p) Texture not dirty, nothing to do\n" , iface);
130 LEAVE_GL();
132 /* No longer dirty */
133 This->baseTexture.dirty = FALSE;
135 return ;
138 static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface) {
139 unsigned int i;
140 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
141 TRACE("(%p)\n", This);
143 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
144 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
145 * surface is fine
147 for (i = 0; i < This->baseTexture.levels; i++) {
148 IWineD3DVolume_UnLoad(This->volumes[i]);
151 IWineD3DBaseTextureImpl_UnLoad((IWineD3DBaseTexture *) iface);
154 static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
155 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
158 static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
159 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
162 /* ******************************************************
163 IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
164 ****************************************************** */
165 static DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
166 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
169 static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
170 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
173 static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
174 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
177 static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
178 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
181 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
182 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
185 static void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
186 IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
189 /* Internal function, No d3d mapping */
190 static BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
191 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
194 static BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
195 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
198 static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface) {
199 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
200 TRACE("(%p) : relay to BaseTexture\n", This);
201 return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
204 static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnBindTexture(IWineD3DVolumeTexture *iface) {
205 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
206 TRACE("(%p) : relay to BaseTexture\n", This);
207 return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
210 static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
211 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
212 TRACE("(%p)\n", This);
213 return GL_TEXTURE_3D;
216 static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface) {
217 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
218 TRACE("(%p)\n", This);
220 return FALSE;
223 static void WINAPI IWineD3DVolumeTextureImpl_ApplyStateChanges(IWineD3DVolumeTexture *iface,
224 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
225 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
226 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
227 TRACE("(%p) : nothing to do, passing to base texture\n", This);
228 IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
232 /* *******************************************
233 IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
234 ******************************************* */
235 static void WINAPI IWineD3DVolumeTextureImpl_Destroy(IWineD3DVolumeTexture *iface, D3DCB_DESTROYVOLUMEFN D3DCB_DestroyVolume) {
236 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
237 int i;
238 TRACE("(%p) : Cleaning up\n",This);
239 for (i = 0; i < This->baseTexture.levels; i++) {
240 if (This->volumes[i] != NULL) {
241 /* Cleanup the container */
242 IWineD3DVolume_SetContainer(This->volumes[i], 0);
243 D3DCB_DestroyVolume(This->volumes[i]);
246 IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *) iface);
247 HeapFree(GetProcessHeap(), 0, This);
250 static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
251 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
252 if (Level < This->baseTexture.levels) {
253 TRACE("(%p) Level (%d)\n", This, Level);
254 return IWineD3DVolume_GetDesc(This->volumes[Level], pDesc);
255 } else {
256 FIXME("(%p) Level (%d)\n", This, Level);
258 return WINED3D_OK;
260 static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
261 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
262 if (Level < This->baseTexture.levels) {
263 *ppVolumeLevel = This->volumes[Level];
264 IWineD3DVolume_AddRef(*ppVolumeLevel);
265 TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
266 } else {
267 FIXME("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
268 return WINED3DERR_INVALIDCALL;
270 return WINED3D_OK;
273 static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
274 HRESULT hr;
275 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
277 if (Level < This->baseTexture.levels) {
278 hr = IWineD3DVolume_LockBox(This->volumes[Level], pLockedVolume, pBox, Flags);
279 TRACE("(%p) Level (%d) success(%u)\n", This, Level, hr);
281 } else {
282 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
283 return WINED3DERR_INVALIDCALL;
285 return hr;
288 static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
289 HRESULT hr;
290 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
292 if (Level < This->baseTexture.levels) {
293 hr = IWineD3DVolume_UnlockBox(This->volumes[Level]);
294 TRACE("(%p) -> level(%d) success(%u)\n", This, Level, hr);
296 } else {
297 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
298 return WINED3DERR_INVALIDCALL;
300 return hr;
303 static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
304 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
305 This->baseTexture.dirty = TRUE;
306 TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
307 return IWineD3DVolume_AddDirtyBox(This->volumes[0], pDirtyBox);
310 const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
312 /* IUnknown */
313 IWineD3DVolumeTextureImpl_QueryInterface,
314 IWineD3DVolumeTextureImpl_AddRef,
315 IWineD3DVolumeTextureImpl_Release,
316 /* resource */
317 IWineD3DVolumeTextureImpl_GetParent,
318 IWineD3DVolumeTextureImpl_GetDevice,
319 IWineD3DVolumeTextureImpl_SetPrivateData,
320 IWineD3DVolumeTextureImpl_GetPrivateData,
321 IWineD3DVolumeTextureImpl_FreePrivateData,
322 IWineD3DVolumeTextureImpl_SetPriority,
323 IWineD3DVolumeTextureImpl_GetPriority,
324 IWineD3DVolumeTextureImpl_PreLoad,
325 IWineD3DVolumeTextureImpl_UnLoad,
326 IWineD3DVolumeTextureImpl_GetType,
327 /* BaseTexture */
328 IWineD3DVolumeTextureImpl_SetLOD,
329 IWineD3DVolumeTextureImpl_GetLOD,
330 IWineD3DVolumeTextureImpl_GetLevelCount,
331 IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
332 IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
333 IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
334 IWineD3DVolumeTextureImpl_SetDirty,
335 IWineD3DVolumeTextureImpl_GetDirty,
336 /* not in d3d */
337 IWineD3DVolumeTextureImpl_BindTexture,
338 IWineD3DVolumeTextureImpl_UnBindTexture,
339 IWineD3DVolumeTextureImpl_GetTextureDimensions,
340 IWineD3DVolumeTextureImpl_IsCondNP2,
341 IWineD3DVolumeTextureImpl_ApplyStateChanges,
342 /* volume texture */
343 IWineD3DVolumeTextureImpl_Destroy,
344 IWineD3DVolumeTextureImpl_GetLevelDesc,
345 IWineD3DVolumeTextureImpl_GetVolumeLevel,
346 IWineD3DVolumeTextureImpl_LockBox,
347 IWineD3DVolumeTextureImpl_UnlockBox,
348 IWineD3DVolumeTextureImpl_AddDirtyBox