VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c@ 40388

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

wddm/3d: shared resource destroy handling fixes

  • 屬性 svn:eol-style 設為 native
檔案大小: 24.2 KB
 
1/*
2 * IWineD3DCubeTexture implementation
3 *
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
7 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
8 * Copyright 2009 Henri Verbeet for CodeWeavers
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
27 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
28 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
29 * a choice of LGPL license versions is made available with the language indicating
30 * that LGPLv2 or any later version may be used, or where a choice of which version
31 * of the LGPL is applied is otherwise unspecified.
32 */
33
34#include "config.h"
35#include "wined3d_private.h"
36
37WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
38
39static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
40{
41 /* Override the IWineD3DResource Preload method. */
42 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
43 IWineD3DDeviceImpl *device = This->resource.device;
44 struct wined3d_context *context = NULL;
45 unsigned int i, j;
46 BOOL srgb_mode;
47 BOOL *dirty;
48
49 switch (srgb)
50 {
51 case SRGB_RGB:
52 srgb_mode = FALSE;
53 break;
54
55 case SRGB_BOTH:
56 cubetexture_internal_preload(iface, SRGB_RGB);
57 /* Fallthrough */
58
59 case SRGB_SRGB:
60 srgb_mode = TRUE;
61 break;
62
63 default:
64 srgb_mode = This->baseTexture.is_srgb;
65 break;
66 }
67 dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
68
69 TRACE("(%p) : About to load texture: dirtified(%u).\n", This, *dirty);
70
71 /* We only have to activate a context for gl when we're not drawing.
72 * In most cases PreLoad will be called during draw and a context was
73 * activated at the beginning of drawPrimitive. */
74 if (!device->isInDraw)
75 {
76 /* No danger of recursive calls, context_acquire() sets isInDraw to true
77 * when loading offscreen render targets into their texture. */
78 context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
79 }
80
81 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
82 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
83 {
84 for (i = 0; i < This->baseTexture.levels; ++i)
85 {
86 for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j)
87 {
88 if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[j][i]))
89 {
90 TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
91 /* TODO: This is not necessarily needed with hw palettized texture support. */
92 IWineD3DSurface_LoadLocation(This->surfaces[j][i], SFLAG_INSYSMEM, NULL);
93 /* Make sure the texture is reloaded because of the palette change,
94 * this kills performance though :( */
95 IWineD3DSurface_ModifyLocation(This->surfaces[j][i], SFLAG_INTEXTURE, FALSE);
96 }
97 }
98 }
99 }
100
101 /* If the texture is marked dirty or the srgb sampler setting has changed
102 * since the last load then reload the surfaces. */
103 if (*dirty)
104 {
105 for (i = 0; i < This->baseTexture.levels; ++i)
106 {
107 for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j)
108 {
109 IWineD3DSurface_LoadTexture(This->surfaces[j][i], srgb_mode);
110 }
111 }
112 }
113 else
114 {
115 TRACE("(%p) Texture not dirty, nothing to do.\n" , iface);
116 }
117
118 /* No longer dirty. */
119 *dirty = FALSE;
120
121 if (context) context_release(context);
122}
123
124static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This)
125{
126 unsigned int i, j;
127
128 TRACE("(%p) : Cleaning up.\n", This);
129
130 for (i = 0; i < This->baseTexture.levels; ++i)
131 {
132 for (j = 0; j < 6; ++j)
133 {
134 IWineD3DSurface *surface = This->surfaces[j][i];
135
136 if (surface)
137 {
138 /* Clean out the texture name we gave to the surface so that the
139 * surface doesn't try and release it. */
140 surface_set_texture_name(surface, 0, TRUE);
141 surface_set_texture_name(surface, 0, FALSE);
142 surface_set_texture_target(surface, 0);
143 IWineD3DSurface_SetContainer(surface, NULL);
144 IWineD3DSurface_Release(surface);
145 }
146 }
147 }
148 basetexture_cleanup((IWineD3DBaseTexture *)This);
149}
150
151/* *******************************************
152 IWineD3DCubeTexture IUnknown parts follow
153 ******************************************* */
154
155static HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DCubeTexture *iface, REFIID riid, LPVOID *ppobj)
156{
157 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
158 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
159 if (IsEqualGUID(riid, &IID_IUnknown)
160 || IsEqualGUID(riid, &IID_IWineD3DBase)
161 || IsEqualGUID(riid, &IID_IWineD3DResource)
162 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
163 || IsEqualGUID(riid, &IID_IWineD3DCubeTexture)) {
164 IUnknown_AddRef(iface);
165 *ppobj = This;
166 return S_OK;
167 }
168 *ppobj = NULL;
169 return E_NOINTERFACE;
170}
171
172static ULONG WINAPI IWineD3DCubeTextureImpl_AddRef(IWineD3DCubeTexture *iface) {
173 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
174 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
175 return InterlockedIncrement(&This->resource.ref);
176}
177
178static ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DCubeTexture *iface) {
179 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
180 ULONG ref;
181 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
182 ref = InterlockedDecrement(&This->resource.ref);
183 if (!ref)
184 {
185 cubetexture_cleanup(This);
186 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
187 HeapFree(GetProcessHeap(), 0, This);
188 }
189 return ref;
190}
191
192/* ****************************************************
193 IWineD3DCubeTexture IWineD3DResource parts follow
194 **************************************************** */
195static HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
196 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
197}
198
199static HRESULT WINAPI IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
200 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
201}
202
203static HRESULT WINAPI IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture *iface, REFGUID refguid) {
204 return resource_free_private_data((IWineD3DResource *)iface, refguid);
205}
206
207static DWORD WINAPI IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture *iface, DWORD PriorityNew) {
208 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
209}
210
211static DWORD WINAPI IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture *iface) {
212 return resource_get_priority((IWineD3DResource *)iface);
213}
214
215static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
216 cubetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
217}
218
219static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface) {
220 unsigned int i, j;
221 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
222 TRACE("(%p)\n", This);
223
224 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
225 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
226 * surface is fine
227 */
228 for (i = 0; i < This->baseTexture.levels; i++) {
229 for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) {
230 IWineD3DSurface_UnLoad(This->surfaces[j][i]);
231 surface_set_texture_name(This->surfaces[j][i], 0, TRUE);
232 surface_set_texture_name(This->surfaces[j][i], 0, FALSE);
233 }
234 }
235
236 basetexture_unload((IWineD3DBaseTexture *)iface);
237}
238
239static WINED3DRESOURCETYPE WINAPI IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture *iface) {
240 return resource_get_type((IWineD3DResource *)iface);
241}
242
243static HRESULT WINAPI IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture *iface, IUnknown **pParent) {
244 return resource_get_parent((IWineD3DResource *)iface, pParent);
245}
246
247#ifdef VBOX_WITH_WDDM
248static HRESULT WINAPI IWineD3DCubeTextureImpl_SetShRcState(IWineD3DCubeTexture *iface, VBOXWINEEX_SHRC_STATE enmState) {
249 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl*)iface;
250 HRESULT hr = IWineD3DResourceImpl_SetShRcState((IWineD3DResource*)iface, enmState);
251 unsigned int i, j;
252
253 if (FAILED(hr))
254 {
255 ERR("IWineD3DResource_SetShRcState failed");
256 return hr;
257 }
258
259 for (i = 0; i < This->baseTexture.levels; ++i) {
260 for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
261 if (This->surfaces[j][i]) {
262 HRESULT tmpHr = IWineD3DResource_SetShRcState((IWineD3DResource*)This->surfaces[j][i], enmState);
263 Assert(tmpHr == S_OK);
264 }
265 }
266 }
267
268 device_cleanup_durtify_texture_target(This->resource.device, ((IWineD3DSurfaceImpl*)This->surfaces[j][i])->texture_target);
269
270 return WINED3D_OK;
271}
272#endif
273
274/* ******************************************************
275 IWineD3DCubeTexture IWineD3DBaseTexture parts follow
276 ****************************************************** */
277static DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
278 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
279}
280
281static DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
282 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
283}
284
285static DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface) {
286 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
287}
288
289static HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
290 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
291}
292
293static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface) {
294 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
295}
296
297static void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
298 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
299}
300
301/* Internal function, No d3d mapping */
302static BOOL WINAPI IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture *iface, BOOL dirty) {
303 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
304}
305
306/* Internal function, No d3d mapping */
307static BOOL WINAPI IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture *iface) {
308 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
309}
310
311/* Context activation is done by the caller. */
312static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface, BOOL srgb) {
313 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
314 BOOL set_gl_texture_desc;
315 HRESULT hr;
316
317 TRACE("(%p) : relay to BaseTexture\n", This);
318
319 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
320 if (set_gl_texture_desc && SUCCEEDED(hr)) {
321 UINT i, j;
322 for (i = 0; i < This->baseTexture.levels; ++i) {
323 for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
324 if(This->baseTexture.is_srgb) {
325 surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_srgb.name, TRUE);
326 } else {
327 surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_rgb.name, FALSE);
328 }
329 }
330 }
331 }
332
333 return hr;
334}
335
336static UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface)
337{
338 TRACE("iface %p.\n", iface);
339
340 return GL_TEXTURE_CUBE_MAP_ARB;
341}
342
343static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
344{
345 TRACE("iface %p.\n", iface);
346
347 return FALSE;
348}
349
350/* *******************************************
351 IWineD3DCubeTexture IWineD3DCubeTexture parts follow
352 ******************************************* */
353static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
354 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
355
356 if (Level < This->baseTexture.levels) {
357 TRACE("(%p) level (%d)\n", This, Level);
358 return IWineD3DSurface_GetDesc(This->surfaces[0][Level], pDesc);
359 }
360 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
361 return WINED3DERR_INVALIDCALL;
362}
363
364static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
365 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
366 HRESULT hr = WINED3DERR_INVALIDCALL;
367
368 if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
369 *ppCubeMapSurface = This->surfaces[FaceType][Level];
370 IWineD3DSurface_AddRef(*ppCubeMapSurface);
371
372 hr = WINED3D_OK;
373 }
374 if (WINED3D_OK == hr) {
375 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p\n", This, FaceType, Level, This->surfaces[FaceType][Level]);
376 } else {
377 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
378 }
379
380 return hr;
381}
382
383static HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
384 HRESULT hr = WINED3DERR_INVALIDCALL;
385 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
386
387 if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
388 hr = IWineD3DSurface_LockRect(This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
389 }
390
391 if (WINED3D_OK == hr) {
392 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%u)\n", This, FaceType, Level, pLockedRect->pBits, hr);
393 } else {
394 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
395 }
396
397 return hr;
398}
399
400static HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level) {
401 HRESULT hr = WINED3DERR_INVALIDCALL;
402 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
403
404 if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
405 hr = IWineD3DSurface_UnlockRect(This->surfaces[FaceType][Level]);
406 }
407
408 if (WINED3D_OK == hr) {
409 TRACE("(%p) -> faceType(%d) level(%d) success(%u)\n", This, FaceType, Level, hr);
410 } else {
411 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
412 }
413 return hr;
414}
415
416static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
417 HRESULT hr = WINED3DERR_INVALIDCALL;
418 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
419 This->baseTexture.texture_rgb.dirty = TRUE;
420 This->baseTexture.texture_srgb.dirty = TRUE;
421 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
422 if (FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
423 surface_add_dirty_rect(This->surfaces[FaceType][0], pDirtyRect);
424 hr = WINED3D_OK;
425 } else {
426 WARN("(%p) overflow FaceType(%d)\n", This, FaceType);
427 }
428 return hr;
429}
430
431static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
432{
433 /* IUnknown */
434 IWineD3DCubeTextureImpl_QueryInterface,
435 IWineD3DCubeTextureImpl_AddRef,
436 IWineD3DCubeTextureImpl_Release,
437 /* IWineD3DResource */
438 IWineD3DCubeTextureImpl_GetParent,
439 IWineD3DCubeTextureImpl_SetPrivateData,
440 IWineD3DCubeTextureImpl_GetPrivateData,
441 IWineD3DCubeTextureImpl_FreePrivateData,
442 IWineD3DCubeTextureImpl_SetPriority,
443 IWineD3DCubeTextureImpl_GetPriority,
444 IWineD3DCubeTextureImpl_PreLoad,
445 IWineD3DCubeTextureImpl_UnLoad,
446 IWineD3DCubeTextureImpl_GetType,
447#ifdef VBOX_WITH_WDDM
448 IWineD3DCubeTextureImpl_SetShRcState,
449#endif
450 /* IWineD3DBaseTexture */
451 IWineD3DCubeTextureImpl_SetLOD,
452 IWineD3DCubeTextureImpl_GetLOD,
453 IWineD3DCubeTextureImpl_GetLevelCount,
454 IWineD3DCubeTextureImpl_SetAutoGenFilterType,
455 IWineD3DCubeTextureImpl_GetAutoGenFilterType,
456 IWineD3DCubeTextureImpl_GenerateMipSubLevels,
457 IWineD3DCubeTextureImpl_SetDirty,
458 IWineD3DCubeTextureImpl_GetDirty,
459 IWineD3DCubeTextureImpl_BindTexture,
460 IWineD3DCubeTextureImpl_GetTextureDimensions,
461 IWineD3DCubeTextureImpl_IsCondNP2,
462 /* IWineD3DCubeTexture */
463 IWineD3DCubeTextureImpl_GetLevelDesc,
464 IWineD3DCubeTextureImpl_GetCubeMapSurface,
465 IWineD3DCubeTextureImpl_LockRect,
466 IWineD3DCubeTextureImpl_UnlockRect,
467 IWineD3DCubeTextureImpl_AddDirtyRect
468};
469
470HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
471 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
472 IUnknown *parent, const struct wined3d_parent_ops *parent_ops
473#ifdef VBOX_WITH_WDDM
474 , HANDLE *shared_handle
475 , void **pavClientMem
476#endif
477 )
478{
479 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
480 const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
481 UINT pow2_edge_length;
482 unsigned int i, j;
483 UINT tmp_w;
484 HRESULT hr;
485
486 /* TODO: It should only be possible to create textures for formats
487 * that are reported as supported. */
488 if (WINED3DFMT_UNKNOWN >= format)
489 {
490 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
491 return WINED3DERR_INVALIDCALL;
492 }
493
494 if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH)
495 {
496 WARN("(%p) : Tried to create not supported cube texture.\n", texture);
497 return WINED3DERR_INVALIDCALL;
498 }
499
500 /* Calculate levels for mip mapping */
501 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
502 {
503 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
504 {
505 WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
506 return WINED3DERR_INVALIDCALL;
507 }
508
509 if (levels > 1)
510 {
511 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
512 return WINED3DERR_INVALIDCALL;
513 }
514
515 levels = 1;
516 }
517 else if (!levels)
518 {
519 levels = wined3d_log2i(edge_length) + 1;
520 TRACE("Calculated levels = %u.\n", levels);
521 }
522
523 texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
524
525 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_CUBETEXTURE,
526 device, 0, usage, format_desc, pool, parent, parent_ops
527#ifdef VBOX_WITH_WDDM
528 , shared_handle, pavClientMem
529#endif
530 );
531 if (FAILED(hr))
532 {
533 WARN("Failed to initialize basetexture, returning %#x\n", hr);
534 return hr;
535 }
536
537 /* Find the nearest pow2 match. */
538 pow2_edge_length = 1;
539 while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
540
541 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || (edge_length == pow2_edge_length))
542 {
543 /* Precalculated scaling for 'faked' non power of two texture coords. */
544 texture->baseTexture.pow2Matrix[0] = 1.0f;
545 texture->baseTexture.pow2Matrix[5] = 1.0f;
546 texture->baseTexture.pow2Matrix[10] = 1.0f;
547 texture->baseTexture.pow2Matrix[15] = 1.0f;
548 }
549 else
550 {
551 /* Precalculated scaling for 'faked' non power of two texture coords. */
552 texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
553 texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
554 texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
555 texture->baseTexture.pow2Matrix[15] = 1.0f;
556 texture->baseTexture.pow2Matrix_identity = FALSE;
557 }
558
559 /* Generate all the surfaces. */
560 tmp_w = edge_length;
561 for (i = 0; i < texture->baseTexture.levels; ++i)
562 {
563 /* Create the 6 faces. */
564 for (j = 0; j < 6; ++j)
565 {
566 static const GLenum cube_targets[6] =
567 {
568 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
569 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
570 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
571 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
572 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
573 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
574 };
575
576#ifdef VBOX_WITH_WDDM
577 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
578 format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
579 , NULL, pavClientMem ? pavClientMem[i * 6 + j] : NULL
580 );
581#else
582 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
583 format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
584 );
585#endif
586 if (FAILED(hr))
587 {
588 FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
589 texture->surfaces[j][i] = NULL;
590 cubetexture_cleanup(texture);
591 return hr;
592 }
593
594 IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
595 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
596 surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
597 }
598 tmp_w = max(1, tmp_w >> 1);
599 }
600 texture->baseTexture.internal_preload = cubetexture_internal_preload;
601
602#ifdef VBOX_WITH_WDDM
603 if (VBOXSHRC_IS_SHARED(texture))
604 {
605 Assert(shared_handle);
606 for (i = 0; i < texture->baseTexture.levels; ++i)
607 {
608 for (j = 0; j < 6; ++j)
609 {
610 VBOXSHRC_COPY_SHAREDATA((IWineD3DSurfaceImpl*)texture->surfaces[j][i], texture);
611 }
612 }
613#ifdef DEBUG
614 for (i = 0; i < texture->baseTexture.levels; ++i)
615 {
616 for (j = 0; j < 6; ++j)
617 {
618 Assert(!((IWineD3DSurfaceImpl*)texture->surfaces[j][i])->texture_name);
619 }
620 }
621#endif
622 IWineD3DSurface_LoadLocation(texture->surfaces[0][0], SFLAG_INTEXTURE, NULL);
623 if (!VBOXSHRC_IS_SHARED_OPENED(texture))
624 {
625 Assert(!(*shared_handle));
626 *shared_handle = VBOXSHRC_GET_SHAREHANDLE(texture);
627 }
628 else
629 {
630 Assert(*shared_handle);
631 Assert(*shared_handle == VBOXSHRC_GET_SHAREHANDLE(texture));
632 }
633#ifdef DEBUG
634 for (i = 0; i < texture->baseTexture.levels; ++i)
635 {
636 for (j = 0; j < 6; ++j)
637 {
638 Assert((*shared_handle) == (HANDLE)((IWineD3DSurfaceImpl*)texture->surfaces[j][i])->texture_name);
639 }
640 }
641#endif
642 }
643 else
644 {
645 Assert(!shared_handle);
646 }
647#endif
648
649 return WINED3D_OK;
650}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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