VirtualBox

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

Last change on this file since 39016 was 38982, checked in by vboxsync, 13 years ago

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

  • Property svn:eol-style set to native
File size: 24.0 KB
Line 
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_SetDontDeleteGl(IWineD3DCubeTexture *iface) {
249 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl*)iface;
250 HRESULT hr = IWineD3DResourceImpl_SetDontDeleteGl((IWineD3DResource*)iface);
251 unsigned int i, j;
252
253 if (FAILED(hr))
254 {
255 ERR("IWineD3DResource_SetDontDeleteGl 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_SetDontDeleteGl((IWineD3DResource*)This->surfaces[j][i]);
263 Assert(tmpHr == S_OK);
264 }
265 }
266 }
267
268 return WINED3D_OK;
269}
270#endif
271
272/* ******************************************************
273 IWineD3DCubeTexture IWineD3DBaseTexture parts follow
274 ****************************************************** */
275static DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
276 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
277}
278
279static DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
280 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
281}
282
283static DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface) {
284 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
285}
286
287static HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
288 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
289}
290
291static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface) {
292 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
293}
294
295static void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
296 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
297}
298
299/* Internal function, No d3d mapping */
300static BOOL WINAPI IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture *iface, BOOL dirty) {
301 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
302}
303
304/* Internal function, No d3d mapping */
305static BOOL WINAPI IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture *iface) {
306 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
307}
308
309/* Context activation is done by the caller. */
310static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface, BOOL srgb) {
311 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
312 BOOL set_gl_texture_desc;
313 HRESULT hr;
314
315 TRACE("(%p) : relay to BaseTexture\n", This);
316
317 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
318 if (set_gl_texture_desc && SUCCEEDED(hr)) {
319 UINT i, j;
320 for (i = 0; i < This->baseTexture.levels; ++i) {
321 for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
322 if(This->baseTexture.is_srgb) {
323 surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_srgb.name, TRUE);
324 } else {
325 surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_rgb.name, FALSE);
326 }
327 }
328 }
329 }
330
331 return hr;
332}
333
334static UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface)
335{
336 TRACE("iface %p.\n", iface);
337
338 return GL_TEXTURE_CUBE_MAP_ARB;
339}
340
341static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
342{
343 TRACE("iface %p.\n", iface);
344
345 return FALSE;
346}
347
348/* *******************************************
349 IWineD3DCubeTexture IWineD3DCubeTexture parts follow
350 ******************************************* */
351static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
352 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
353
354 if (Level < This->baseTexture.levels) {
355 TRACE("(%p) level (%d)\n", This, Level);
356 return IWineD3DSurface_GetDesc(This->surfaces[0][Level], pDesc);
357 }
358 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
359 return WINED3DERR_INVALIDCALL;
360}
361
362static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
363 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
364 HRESULT hr = WINED3DERR_INVALIDCALL;
365
366 if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
367 *ppCubeMapSurface = This->surfaces[FaceType][Level];
368 IWineD3DSurface_AddRef(*ppCubeMapSurface);
369
370 hr = WINED3D_OK;
371 }
372 if (WINED3D_OK == hr) {
373 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p\n", This, FaceType, Level, This->surfaces[FaceType][Level]);
374 } else {
375 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
376 }
377
378 return hr;
379}
380
381static HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
382 HRESULT hr = WINED3DERR_INVALIDCALL;
383 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
384
385 if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
386 hr = IWineD3DSurface_LockRect(This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
387 }
388
389 if (WINED3D_OK == hr) {
390 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%u)\n", This, FaceType, Level, pLockedRect->pBits, hr);
391 } else {
392 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
393 }
394
395 return hr;
396}
397
398static HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level) {
399 HRESULT hr = WINED3DERR_INVALIDCALL;
400 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
401
402 if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
403 hr = IWineD3DSurface_UnlockRect(This->surfaces[FaceType][Level]);
404 }
405
406 if (WINED3D_OK == hr) {
407 TRACE("(%p) -> faceType(%d) level(%d) success(%u)\n", This, FaceType, Level, hr);
408 } else {
409 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
410 }
411 return hr;
412}
413
414static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
415 HRESULT hr = WINED3DERR_INVALIDCALL;
416 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
417 This->baseTexture.texture_rgb.dirty = TRUE;
418 This->baseTexture.texture_srgb.dirty = TRUE;
419 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
420 if (FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
421 surface_add_dirty_rect(This->surfaces[FaceType][0], pDirtyRect);
422 hr = WINED3D_OK;
423 } else {
424 WARN("(%p) overflow FaceType(%d)\n", This, FaceType);
425 }
426 return hr;
427}
428
429static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
430{
431 /* IUnknown */
432 IWineD3DCubeTextureImpl_QueryInterface,
433 IWineD3DCubeTextureImpl_AddRef,
434 IWineD3DCubeTextureImpl_Release,
435 /* IWineD3DResource */
436 IWineD3DCubeTextureImpl_GetParent,
437 IWineD3DCubeTextureImpl_SetPrivateData,
438 IWineD3DCubeTextureImpl_GetPrivateData,
439 IWineD3DCubeTextureImpl_FreePrivateData,
440 IWineD3DCubeTextureImpl_SetPriority,
441 IWineD3DCubeTextureImpl_GetPriority,
442 IWineD3DCubeTextureImpl_PreLoad,
443 IWineD3DCubeTextureImpl_UnLoad,
444 IWineD3DCubeTextureImpl_GetType,
445#ifdef VBOX_WITH_WDDM
446 IWineD3DCubeTextureImpl_SetDontDeleteGl,
447#endif
448 /* IWineD3DBaseTexture */
449 IWineD3DCubeTextureImpl_SetLOD,
450 IWineD3DCubeTextureImpl_GetLOD,
451 IWineD3DCubeTextureImpl_GetLevelCount,
452 IWineD3DCubeTextureImpl_SetAutoGenFilterType,
453 IWineD3DCubeTextureImpl_GetAutoGenFilterType,
454 IWineD3DCubeTextureImpl_GenerateMipSubLevels,
455 IWineD3DCubeTextureImpl_SetDirty,
456 IWineD3DCubeTextureImpl_GetDirty,
457 IWineD3DCubeTextureImpl_BindTexture,
458 IWineD3DCubeTextureImpl_GetTextureDimensions,
459 IWineD3DCubeTextureImpl_IsCondNP2,
460 /* IWineD3DCubeTexture */
461 IWineD3DCubeTextureImpl_GetLevelDesc,
462 IWineD3DCubeTextureImpl_GetCubeMapSurface,
463 IWineD3DCubeTextureImpl_LockRect,
464 IWineD3DCubeTextureImpl_UnlockRect,
465 IWineD3DCubeTextureImpl_AddDirtyRect
466};
467
468HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
469 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
470 IUnknown *parent, const struct wined3d_parent_ops *parent_ops
471#ifdef VBOX_WITH_WDDM
472 , HANDLE *shared_handle
473 , void **pavClientMem
474#endif
475 )
476{
477 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
478 const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
479 UINT pow2_edge_length;
480 unsigned int i, j;
481 UINT tmp_w;
482 HRESULT hr;
483
484 /* TODO: It should only be possible to create textures for formats
485 * that are reported as supported. */
486 if (WINED3DFMT_UNKNOWN >= format)
487 {
488 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
489 return WINED3DERR_INVALIDCALL;
490 }
491
492 if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH)
493 {
494 WARN("(%p) : Tried to create not supported cube texture.\n", texture);
495 return WINED3DERR_INVALIDCALL;
496 }
497
498 /* Calculate levels for mip mapping */
499 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
500 {
501 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
502 {
503 WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
504 return WINED3DERR_INVALIDCALL;
505 }
506
507 if (levels > 1)
508 {
509 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
510 return WINED3DERR_INVALIDCALL;
511 }
512
513 levels = 1;
514 }
515 else if (!levels)
516 {
517 levels = wined3d_log2i(edge_length) + 1;
518 TRACE("Calculated levels = %u.\n", levels);
519 }
520
521 texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
522
523 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_CUBETEXTURE,
524 device, 0, usage, format_desc, pool, parent, parent_ops
525#ifdef VBOX_WITH_WDDM
526 , shared_handle, pavClientMem
527#endif
528 );
529 if (FAILED(hr))
530 {
531 WARN("Failed to initialize basetexture, returning %#x\n", hr);
532 return hr;
533 }
534
535 /* Find the nearest pow2 match. */
536 pow2_edge_length = 1;
537 while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
538
539 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || (edge_length == pow2_edge_length))
540 {
541 /* Precalculated scaling for 'faked' non power of two texture coords. */
542 texture->baseTexture.pow2Matrix[0] = 1.0f;
543 texture->baseTexture.pow2Matrix[5] = 1.0f;
544 texture->baseTexture.pow2Matrix[10] = 1.0f;
545 texture->baseTexture.pow2Matrix[15] = 1.0f;
546 }
547 else
548 {
549 /* Precalculated scaling for 'faked' non power of two texture coords. */
550 texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
551 texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
552 texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
553 texture->baseTexture.pow2Matrix[15] = 1.0f;
554 texture->baseTexture.pow2Matrix_identity = FALSE;
555 }
556
557 /* Generate all the surfaces. */
558 tmp_w = edge_length;
559 for (i = 0; i < texture->baseTexture.levels; ++i)
560 {
561 /* Create the 6 faces. */
562 for (j = 0; j < 6; ++j)
563 {
564 static const GLenum cube_targets[6] =
565 {
566 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
567 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
568 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
569 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
570 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
571 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
572 };
573
574#ifdef VBOX_WITH_WDDM
575 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
576 format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
577 , NULL, pavClientMem ? pavClientMem[i * 6 + j] : NULL
578 );
579#else
580 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
581 format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
582 );
583#endif
584 if (FAILED(hr))
585 {
586 FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
587 texture->surfaces[j][i] = NULL;
588 cubetexture_cleanup(texture);
589 return hr;
590 }
591
592 IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
593 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
594 surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
595 }
596 tmp_w = max(1, tmp_w >> 1);
597 }
598 texture->baseTexture.internal_preload = cubetexture_internal_preload;
599
600#ifdef VBOX_WITH_WDDM
601 if (VBOXSHRC_IS_SHARED(texture))
602 {
603 Assert(shared_handle);
604 for (i = 0; i < texture->baseTexture.levels; ++i)
605 {
606 for (j = 0; j < 6; ++j)
607 {
608 VBOXSHRC_COPY_SHAREDATA((IWineD3DSurfaceImpl*)texture->surfaces[j][i], texture);
609 }
610 }
611#ifdef DEBUG
612 for (i = 0; i < texture->baseTexture.levels; ++i)
613 {
614 for (j = 0; j < 6; ++j)
615 {
616 Assert(!((IWineD3DSurfaceImpl*)texture->surfaces[j][i])->texture_name);
617 }
618 }
619#endif
620 IWineD3DSurface_LoadLocation(texture->surfaces[0][0], SFLAG_INTEXTURE, NULL);
621 if (!VBOXSHRC_IS_SHARED_OPENED(texture))
622 {
623 Assert(!(*shared_handle));
624 *shared_handle = VBOXSHRC_GET_SHAREHANDLE(texture);
625 }
626 else
627 {
628 Assert(*shared_handle);
629 Assert(*shared_handle == VBOXSHRC_GET_SHAREHANDLE(texture));
630 }
631#ifdef DEBUG
632 for (i = 0; i < texture->baseTexture.levels; ++i)
633 {
634 for (j = 0; j < 6; ++j)
635 {
636 Assert((*shared_handle) == (HANDLE)((IWineD3DSurfaceImpl*)texture->surfaces[j][i])->texture_name);
637 }
638 }
639#endif
640 }
641 else
642 {
643 Assert(!shared_handle);
644 }
645#endif
646
647 return WINED3D_OK;
648}
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