VirtualBox

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

Last change on this file since 33836 was 33836, checked in by vboxsync, 14 years ago

wddm/3d: add cube textures support

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