VirtualBox

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

Last change on this file since 42700 was 40481, checked in by vboxsync, 13 years ago

wined3d: shared resource cleanup fixes

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