VirtualBox

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

Last change on this file since 22652 was 22496, checked in by vboxsync, 16 years ago

crOpenGL: update wine to 1.1.27 and better fix for depthstencil surface refcounting

  • 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 *
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 struct 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, NULL, 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 struct 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 /* Is NP2 support for volumes needed? */
163 texture->baseTexture.pow2Matrix[0] = 1.0f;
164 texture->baseTexture.pow2Matrix[5] = 1.0f;
165 texture->baseTexture.pow2Matrix[10] = 1.0f;
166 texture->baseTexture.pow2Matrix[15] = 1.0f;
167
168 /* Generate all the surfaces. */
169 tmp_w = width;
170 tmp_h = height;
171 tmp_d = depth;
172
173 for (i = 0; i < texture->baseTexture.levels; ++i)
174 {
175 /* Create the volume. */
176 hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
177 tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
178 if (FAILED(hr))
179 {
180 ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
181 texture->volumes[i] = NULL;
182 volumetexture_cleanup(texture, D3DCB_DefaultDestroyVolume);
183 return hr;
184 }
185
186 /* Set its container to this texture. */
187 IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
188
189 /* Calculate the next mipmap level. */
190 tmp_w = max(1, tmp_w >> 1);
191 tmp_h = max(1, tmp_h >> 1);
192 tmp_d = max(1, tmp_d >> 1);
193 }
194 texture->baseTexture.internal_preload = volumetexture_internal_preload;
195
196 return WINED3D_OK;
197}
198
199#undef GLINFO_LOCATION
200
201/* *******************************************
202 IWineD3DTexture IUnknown parts follow
203 ******************************************* */
204
205#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
206
207static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
208{
209 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
210 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
211 if (IsEqualGUID(riid, &IID_IUnknown)
212 || IsEqualGUID(riid, &IID_IWineD3DBase)
213 || IsEqualGUID(riid, &IID_IWineD3DResource)
214 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
215 || IsEqualGUID(riid, &IID_IWineD3DVolumeTexture)) {
216 IUnknown_AddRef(iface);
217 *ppobj = This;
218 return S_OK;
219 }
220 *ppobj = NULL;
221 return E_NOINTERFACE;
222}
223
224static ULONG WINAPI IWineD3DVolumeTextureImpl_AddRef(IWineD3DVolumeTexture *iface) {
225 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
226 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
227 return InterlockedIncrement(&This->resource.ref);
228}
229
230static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
231 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
232 ULONG ref;
233 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
234 ref = InterlockedDecrement(&This->resource.ref);
235 if (ref == 0) {
236 IWineD3DVolumeTexture_Destroy(iface, D3DCB_DefaultDestroyVolume);
237 }
238 return ref;
239}
240
241/* ****************************************************
242 IWineD3DVolumeTexture IWineD3DResource parts follow
243 **************************************************** */
244static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
245 return resource_get_device((IWineD3DResource *)iface, ppDevice);
246}
247
248static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
249 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
250}
251
252static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
253 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
254}
255
256static HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
257 return resource_free_private_data((IWineD3DResource *)iface, refguid);
258}
259
260static DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
261 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
262}
263
264static DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
265 return resource_get_priority((IWineD3DResource *)iface);
266}
267
268static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
269 volumetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
270}
271
272static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface) {
273 unsigned int i;
274 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
275 TRACE("(%p)\n", This);
276
277 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
278 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
279 * surface is fine
280 */
281 for (i = 0; i < This->baseTexture.levels; i++) {
282 IWineD3DVolume_UnLoad(This->volumes[i]);
283 }
284
285 basetexture_unload((IWineD3DBaseTexture *)iface);
286}
287
288static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
289 return resource_get_type((IWineD3DResource *)iface);
290}
291
292static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
293 return resource_get_parent((IWineD3DResource *)iface, pParent);
294}
295
296/* ******************************************************
297 IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
298 ****************************************************** */
299static DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
300 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
301}
302
303static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
304 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
305}
306
307static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
308 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
309}
310
311static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
312 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
313}
314
315static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
316 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
317}
318
319static void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
320 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
321}
322
323/* Internal function, No d3d mapping */
324static BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
325 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
326}
327
328static BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
329 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
330}
331
332/* Context activation is done by the caller. */
333static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb) {
334 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
335 BOOL dummy;
336 TRACE("(%p) : relay to BaseTexture\n", This);
337 return basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &dummy);
338}
339
340static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
341 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
342 TRACE("(%p)\n", This);
343 return GL_TEXTURE_3D;
344}
345
346static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface) {
347 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
348 TRACE("(%p)\n", This);
349
350 return FALSE;
351}
352
353/* *******************************************
354 IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
355 ******************************************* */
356static void WINAPI IWineD3DVolumeTextureImpl_Destroy(IWineD3DVolumeTexture *iface, D3DCB_DESTROYVOLUMEFN D3DCB_DestroyVolume) {
357 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
358
359 volumetexture_cleanup(This, D3DCB_DestroyVolume);
360
361 HeapFree(GetProcessHeap(), 0, This);
362}
363
364static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
365 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
366 if (Level < This->baseTexture.levels) {
367 TRACE("(%p) Level (%d)\n", This, Level);
368 return IWineD3DVolume_GetDesc(This->volumes[Level], pDesc);
369 } else {
370 WARN("(%p) Level (%d)\n", This, Level);
371 }
372 return WINED3D_OK;
373}
374static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
375 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
376 if (Level < This->baseTexture.levels) {
377 *ppVolumeLevel = This->volumes[Level];
378 IWineD3DVolume_AddRef(*ppVolumeLevel);
379 TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
380 } else {
381 WARN("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
382 return WINED3DERR_INVALIDCALL;
383 }
384 return WINED3D_OK;
385
386}
387static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
388 HRESULT hr;
389 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
390
391 if (Level < This->baseTexture.levels) {
392 hr = IWineD3DVolume_LockBox(This->volumes[Level], pLockedVolume, pBox, Flags);
393 TRACE("(%p) Level (%d) success(%u)\n", This, Level, hr);
394
395 } else {
396 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
397 return WINED3DERR_INVALIDCALL;
398 }
399 return hr;
400}
401
402static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
403 HRESULT hr;
404 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
405
406 if (Level < This->baseTexture.levels) {
407 hr = IWineD3DVolume_UnlockBox(This->volumes[Level]);
408 TRACE("(%p) -> level(%d) success(%u)\n", This, Level, hr);
409
410 } else {
411 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
412 return WINED3DERR_INVALIDCALL;
413 }
414 return hr;
415}
416
417static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
418 IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
419 This->baseTexture.dirty = TRUE;
420 TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
421 volume_add_dirty_box(This->volumes[0], pDirtyBox);
422
423 return WINED3D_OK;
424}
425
426const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
427{
428 /* IUnknown */
429 IWineD3DVolumeTextureImpl_QueryInterface,
430 IWineD3DVolumeTextureImpl_AddRef,
431 IWineD3DVolumeTextureImpl_Release,
432 /* resource */
433 IWineD3DVolumeTextureImpl_GetParent,
434 IWineD3DVolumeTextureImpl_GetDevice,
435 IWineD3DVolumeTextureImpl_SetPrivateData,
436 IWineD3DVolumeTextureImpl_GetPrivateData,
437 IWineD3DVolumeTextureImpl_FreePrivateData,
438 IWineD3DVolumeTextureImpl_SetPriority,
439 IWineD3DVolumeTextureImpl_GetPriority,
440 IWineD3DVolumeTextureImpl_PreLoad,
441 IWineD3DVolumeTextureImpl_UnLoad,
442 IWineD3DVolumeTextureImpl_GetType,
443 /* BaseTexture */
444 IWineD3DVolumeTextureImpl_SetLOD,
445 IWineD3DVolumeTextureImpl_GetLOD,
446 IWineD3DVolumeTextureImpl_GetLevelCount,
447 IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
448 IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
449 IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
450 IWineD3DVolumeTextureImpl_SetDirty,
451 IWineD3DVolumeTextureImpl_GetDirty,
452 /* not in d3d */
453 IWineD3DVolumeTextureImpl_BindTexture,
454 IWineD3DVolumeTextureImpl_GetTextureDimensions,
455 IWineD3DVolumeTextureImpl_IsCondNP2,
456 /* volume texture */
457 IWineD3DVolumeTextureImpl_Destroy,
458 IWineD3DVolumeTextureImpl_GetLevelDesc,
459 IWineD3DVolumeTextureImpl_GetVolumeLevel,
460 IWineD3DVolumeTextureImpl_LockBox,
461 IWineD3DVolumeTextureImpl_UnlockBox,
462 IWineD3DVolumeTextureImpl_AddDirtyBox
463};
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