VirtualBox

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

最後變更 在這個檔案從38982是 38982,由 vboxsync 提交於 13 年 前

wddm: proper ie rendering under win8 (shared resource open & destroy fixes, zero-init resources on creaate, etc.)

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

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