VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c@ 20817

Last change on this file since 20817 was 20612, checked in by vboxsync, 16 years ago

crOpenGL: update wine to 1.1.23

  • Property svn:eol-style set to native
File size: 17.7 KB
Line 
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/*
24 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "wined3d_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
36
37#define GLINFO_LOCATION (*gl_info)
38
39static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
40{
41 /* Override the IWineD3DResource Preload method. */
42 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
43 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
44 const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
45 BOOL srgb_mode = This->baseTexture.is_srgb;
46 BOOL srgb_was_toggled = FALSE;
47 unsigned int i;
48
49 TRACE("(%p) : About to load texture.\n", This);
50
51 if (!device->isInDraw)
52 {
53 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
54 }
55 else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0)
56 {
57 srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
58 srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
59 This->baseTexture.is_srgb = srgb_mode;
60 }
61
62 /* If the texture is marked dirty or the srgb sampler setting has changed
63 * since the last load then reload the volumes. */
64 if (This->baseTexture.dirty)
65 {
66 for (i = 0; i < This->baseTexture.levels; ++i)
67 {
68 IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
69 }
70 }
71 else if (srgb_was_toggled)
72 {
73 for (i = 0; i < This->baseTexture.levels; ++i)
74 {
75 volume_add_dirty_box(This->volumes[i], NULL);
76 IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
77 }
78 }
79 else
80 {
81 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
82 }
83
84 /* No longer dirty */
85 This->baseTexture.dirty = FALSE;
86}
87
88static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This, D3DCB_DESTROYVOLUMEFN volume_destroy_cb)
89{
90 unsigned int i;
91
92 TRACE("(%p) : Cleaning up.\n", This);
93
94 for (i = 0; i < This->baseTexture.levels; ++i)
95 {
96 IWineD3DVolume *volume = This->volumes[i];
97
98 if (volume)
99 {
100 /* Cleanup the container. */
101 IWineD3DVolume_SetContainer(volume, NULL);
102 volume_destroy_cb(volume);
103 }
104 }
105 basetexture_cleanup((IWineD3DBaseTexture *)This);
106}
107
108HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
109 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
110{
111 const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
112 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
113 UINT tmp_w, tmp_h, tmp_d;
114 unsigned int i;
115 HRESULT hr;
116
117 /* TODO: It should only be possible to create textures for formats
118 * that are reported as supported. */
119 if (WINED3DFMT_UNKNOWN >= format)
120 {
121 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
122 return WINED3DERR_INVALIDCALL;
123 }
124
125 if (!GL_SUPPORT(EXT_TEXTURE3D))
126 {
127 WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
128 return WINED3DERR_INVALIDCALL;
129 }
130
131 /* Calculate levels for mip mapping. */
132 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
133 {
134 if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
135 {
136 WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
137 return WINED3DERR_INVALIDCALL;
138 }
139
140 if (levels > 1)
141 {
142 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
143 return WINED3DERR_INVALIDCALL;
144 }
145
146 levels = 1;
147 }
148 else if (!levels)
149 {
150 levels = wined3d_log2i(max(max(width, height), depth)) + 1;
151 TRACE("Calculated levels = %u.\n", levels);
152 }
153
154 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
155 WINED3DRTYPE_VOLUMETEXTURE, device, 0, usage, format_desc, pool, parent);
156 if (FAILED(hr))
157 {
158 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
159 return hr;
160 }
161
162 if (texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
163 {
164 texture->baseTexture.minMipLookup = minMipLookup;
165 texture->baseTexture.magLookup = magLookup;
166 }
167 else
168 {
169 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
170 texture->baseTexture.magLookup = magLookup_noFilter;
171 }
172
173 /* Is NP2 support for volumes needed? */
174 texture->baseTexture.pow2Matrix[0] = 1.0;
175 texture->baseTexture.pow2Matrix[5] = 1.0;
176 texture->baseTexture.pow2Matrix[10] = 1.0;
177 texture->baseTexture.pow2Matrix[15] = 1.0;
178
179 /* Generate all the surfaces. */
180 tmp_w = width;
181 tmp_h = height;
182 tmp_d = depth;
183
184 for (i = 0; i < texture->baseTexture.levels; ++i)
185 {
186 /* Create the volume. */
187 hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
188 tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
189 if (FAILED(hr))
190 {
191 ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
192 texture->volumes[i] = NULL;
193 volumetexture_cleanup(texture, D3DCB_DefaultDestroyVolume);
194 return hr;
195 }
196
197 /* Set its container to this texture. */
198 IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
199
200 /* Calculate the next mipmap level. */
201 tmp_w = max(1, tmp_w >> 1);
202 tmp_h = max(1, tmp_h >> 1);
203 tmp_d = max(1, tmp_d >> 1);
204 }
205 texture->baseTexture.internal_preload = volumetexture_internal_preload;
206
207 return WINED3D_OK;
208}
209
210#undef GLINFO_LOCATION
211
212/* *******************************************
213 IWineD3DTexture IUnknown parts follow
214 ******************************************* */
215
216#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
217
218static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
219{
220 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
221 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
222 if (IsEqualGUID(riid, &IID_IUnknown)
223 || IsEqualGUID(riid, &IID_IWineD3DBase)
224 || IsEqualGUID(riid, &IID_IWineD3DResource)
225 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
226 || IsEqualGUID(riid, &IID_IWineD3DVolumeTexture)) {
227 IUnknown_AddRef(iface);
228 *ppobj = This;
229 return S_OK;
230 }
231 *ppobj = NULL;
232 return E_NOINTERFACE;
233}
234
235static ULONG WINAPI IWineD3DVolumeTextureImpl_AddRef(IWineD3DVolumeTexture *iface) {
236 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
237 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
238 return InterlockedIncrement(&This->resource.ref);
239}
240
241static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
242 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
243 ULONG ref;
244 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
245 ref = InterlockedDecrement(&This->resource.ref);
246 if (ref == 0) {
247 IWineD3DVolumeTexture_Destroy(iface, D3DCB_DefaultDestroyVolume);
248 }
249 return ref;
250}
251
252/* ****************************************************
253 IWineD3DVolumeTexture IWineD3DResource parts follow
254 **************************************************** */
255static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
256 return resource_get_device((IWineD3DResource *)iface, ppDevice);
257}
258
259static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
260 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
261}
262
263static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
264 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
265}
266
267static HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
268 return resource_free_private_data((IWineD3DResource *)iface, refguid);
269}
270
271static DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
272 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
273}
274
275static DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
276 return resource_get_priority((IWineD3DResource *)iface);
277}
278
279static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
280 volumetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
281}
282
283static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface) {
284 unsigned int i;
285 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
286 TRACE("(%p)\n", This);
287
288 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
289 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
290 * surface is fine
291 */
292 for (i = 0; i < This->baseTexture.levels; i++) {
293 IWineD3DVolume_UnLoad(This->volumes[i]);
294 }
295
296 basetexture_unload((IWineD3DBaseTexture *)iface);
297}
298
299static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
300 return resource_get_type((IWineD3DResource *)iface);
301}
302
303static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
304 return resource_get_parent((IWineD3DResource *)iface, pParent);
305}
306
307/* ******************************************************
308 IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
309 ****************************************************** */
310static DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
311 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
312}
313
314static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
315 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
316}
317
318static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
319 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
320}
321
322static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
323 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
324}
325
326static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
327 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
328}
329
330static void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
331 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
332}
333
334/* Internal function, No d3d mapping */
335static BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
336 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
337}
338
339static BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
340 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
341}
342
343static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb) {
344 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
345 BOOL dummy;
346 TRACE("(%p) : relay to BaseTexture\n", This);
347 return basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &dummy);
348}
349
350static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
351 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
352 TRACE("(%p)\n", This);
353 return GL_TEXTURE_3D;
354}
355
356static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface) {
357 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
358 TRACE("(%p)\n", This);
359
360 return FALSE;
361}
362
363/* *******************************************
364 IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
365 ******************************************* */
366static void WINAPI IWineD3DVolumeTextureImpl_Destroy(IWineD3DVolumeTexture *iface, D3DCB_DESTROYVOLUMEFN D3DCB_DestroyVolume) {
367 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
368
369 volumetexture_cleanup(This, D3DCB_DestroyVolume);
370
371 HeapFree(GetProcessHeap(), 0, This);
372}
373
374static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
375 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
376 if (Level < This->baseTexture.levels) {
377 TRACE("(%p) Level (%d)\n", This, Level);
378 return IWineD3DVolume_GetDesc(This->volumes[Level], pDesc);
379 } else {
380 WARN("(%p) Level (%d)\n", This, Level);
381 }
382 return WINED3D_OK;
383}
384static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
385 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
386 if (Level < This->baseTexture.levels) {
387 *ppVolumeLevel = This->volumes[Level];
388 IWineD3DVolume_AddRef(*ppVolumeLevel);
389 TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
390 } else {
391 WARN("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
392 return WINED3DERR_INVALIDCALL;
393 }
394 return WINED3D_OK;
395
396}
397static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
398 HRESULT hr;
399 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
400
401 if (Level < This->baseTexture.levels) {
402 hr = IWineD3DVolume_LockBox(This->volumes[Level], pLockedVolume, pBox, Flags);
403 TRACE("(%p) Level (%d) success(%u)\n", This, Level, hr);
404
405 } else {
406 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
407 return WINED3DERR_INVALIDCALL;
408 }
409 return hr;
410}
411
412static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
413 HRESULT hr;
414 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
415
416 if (Level < This->baseTexture.levels) {
417 hr = IWineD3DVolume_UnlockBox(This->volumes[Level]);
418 TRACE("(%p) -> level(%d) success(%u)\n", This, Level, hr);
419
420 } else {
421 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
422 return WINED3DERR_INVALIDCALL;
423 }
424 return hr;
425}
426
427static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
428 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
429 This->baseTexture.dirty = TRUE;
430 TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
431 volume_add_dirty_box(This->volumes[0], pDirtyBox);
432
433 return WINED3D_OK;
434}
435
436const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
437{
438 /* IUnknown */
439 IWineD3DVolumeTextureImpl_QueryInterface,
440 IWineD3DVolumeTextureImpl_AddRef,
441 IWineD3DVolumeTextureImpl_Release,
442 /* resource */
443 IWineD3DVolumeTextureImpl_GetParent,
444 IWineD3DVolumeTextureImpl_GetDevice,
445 IWineD3DVolumeTextureImpl_SetPrivateData,
446 IWineD3DVolumeTextureImpl_GetPrivateData,
447 IWineD3DVolumeTextureImpl_FreePrivateData,
448 IWineD3DVolumeTextureImpl_SetPriority,
449 IWineD3DVolumeTextureImpl_GetPriority,
450 IWineD3DVolumeTextureImpl_PreLoad,
451 IWineD3DVolumeTextureImpl_UnLoad,
452 IWineD3DVolumeTextureImpl_GetType,
453 /* BaseTexture */
454 IWineD3DVolumeTextureImpl_SetLOD,
455 IWineD3DVolumeTextureImpl_GetLOD,
456 IWineD3DVolumeTextureImpl_GetLevelCount,
457 IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
458 IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
459 IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
460 IWineD3DVolumeTextureImpl_SetDirty,
461 IWineD3DVolumeTextureImpl_GetDirty,
462 /* not in d3d */
463 IWineD3DVolumeTextureImpl_BindTexture,
464 IWineD3DVolumeTextureImpl_GetTextureDimensions,
465 IWineD3DVolumeTextureImpl_IsCondNP2,
466 /* volume texture */
467 IWineD3DVolumeTextureImpl_Destroy,
468 IWineD3DVolumeTextureImpl_GetLevelDesc,
469 IWineD3DVolumeTextureImpl_GetVolumeLevel,
470 IWineD3DVolumeTextureImpl_LockBox,
471 IWineD3DVolumeTextureImpl_UnlockBox,
472 IWineD3DVolumeTextureImpl_AddDirtyBox
473};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette