VirtualBox

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

Last change on this file since 23571 was 23571, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.30

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

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