2 * IWineD3DTexture implementation
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
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.
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.
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
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
30 static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
32 /* Override the IWineD3DResource PreLoad method. */
33 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
34 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
35 struct wined3d_context *context = NULL;
40 TRACE("(%p) : About to load texture.\n", This);
49 texture_internal_preload(iface, SRGB_RGB);
57 srgb_mode = This->baseTexture.is_srgb;
60 dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
62 if (!device->isInDraw)
64 /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture,
65 * thus no danger of recursive calls. */
66 context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
69 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
70 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
72 for (i = 0; i < This->baseTexture.levels; ++i)
74 if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[i]))
76 TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
77 /* TODO: This is not necessarily needed with hw palettized texture support. */
78 IWineD3DSurface_LoadLocation(This->surfaces[i], SFLAG_INSYSMEM, NULL);
79 /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
80 IWineD3DSurface_ModifyLocation(This->surfaces[i], SFLAG_INTEXTURE, FALSE);
85 /* If the texture is marked dirty or the srgb sampler setting has changed
86 * since the last load then reload the surfaces. */
89 for (i = 0; i < This->baseTexture.levels; ++i)
91 IWineD3DSurface_LoadTexture(This->surfaces[i], srgb_mode);
96 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
99 if (context) context_release(context);
101 /* No longer dirty. */
105 static void texture_cleanup(IWineD3DTextureImpl *This)
109 TRACE("(%p) : Cleaning up\n", This);
111 for (i = 0; i < This->baseTexture.levels; ++i)
113 if (This->surfaces[i])
115 /* Clean out the texture name we gave to the surface so that the
116 * surface doesn't try and release it */
117 surface_set_texture_name(This->surfaces[i], 0, TRUE);
118 surface_set_texture_name(This->surfaces[i], 0, FALSE);
119 surface_set_texture_target(This->surfaces[i], 0);
120 IWineD3DSurface_SetContainer(This->surfaces[i], 0);
121 IWineD3DSurface_Release(This->surfaces[i]);
125 TRACE("(%p) : Cleaning up base texture\n", This);
126 basetexture_cleanup((IWineD3DBaseTexture *)This);
129 /* *******************************************
130 IWineD3DTexture IUnknown parts follow
131 ******************************************* */
133 static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
135 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
136 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
137 if (IsEqualGUID(riid, &IID_IUnknown)
138 || IsEqualGUID(riid, &IID_IWineD3DBase)
139 || IsEqualGUID(riid, &IID_IWineD3DResource)
140 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
141 || IsEqualGUID(riid, &IID_IWineD3DTexture)){
142 IUnknown_AddRef(iface);
147 return E_NOINTERFACE;
150 static ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
151 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
152 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
153 return InterlockedIncrement(&This->resource.ref);
156 static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
157 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
159 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
160 ref = InterlockedDecrement(&This->resource.ref);
163 texture_cleanup(This);
164 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
165 HeapFree(GetProcessHeap(), 0, This);
171 /* ****************************************************
172 IWineD3DTexture IWineD3DResource parts follow
173 **************************************************** */
174 static HRESULT WINAPI IWineD3DTextureImpl_GetDevice(IWineD3DTexture *iface, IWineD3DDevice** ppDevice) {
175 return resource_get_device((IWineD3DResource *)iface, ppDevice);
178 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
179 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
182 static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
183 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
186 static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
187 return resource_free_private_data((IWineD3DResource *)iface, refguid);
190 static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
191 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
194 static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
195 return resource_get_priority((IWineD3DResource *)iface);
198 static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
199 texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
202 static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
204 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
205 TRACE("(%p)\n", This);
207 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
208 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
211 for (i = 0; i < This->baseTexture.levels; i++) {
212 IWineD3DSurface_UnLoad(This->surfaces[i]);
213 surface_set_texture_name(This->surfaces[i], 0, FALSE); /* Delete rgb name */
214 surface_set_texture_name(This->surfaces[i], 0, TRUE); /* delete srgb name */
217 basetexture_unload((IWineD3DBaseTexture *)iface);
220 static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
221 return resource_get_type((IWineD3DResource *)iface);
224 static HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
225 return resource_get_parent((IWineD3DResource *)iface, pParent);
228 /* ******************************************************
229 IWineD3DTexture IWineD3DBaseTexture parts follow
230 ****************************************************** */
231 static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
232 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
235 static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
236 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
239 static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
240 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
243 static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
244 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
247 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
248 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
251 static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
252 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
255 /* Internal function, No d3d mapping */
256 static BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
257 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
260 static BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
261 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
264 /* Context activation is done by the caller. */
265 static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
266 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
267 BOOL set_gl_texture_desc;
270 TRACE("(%p) : relay to BaseTexture\n", This);
272 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
273 if (set_gl_texture_desc && SUCCEEDED(hr)) {
275 struct gl_texture *gl_tex;
277 if(This->baseTexture.is_srgb) {
278 gl_tex = &This->baseTexture.texture_srgb;
280 gl_tex = &This->baseTexture.texture_rgb;
283 for (i = 0; i < This->baseTexture.levels; ++i) {
284 surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb);
286 /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
287 * partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something
288 * that prevents us from hitting the accelerated codepath. Thus manually set the GL state. The same applies to filtering.
289 * Even if the texture has only one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW fallback on macos.
291 if(IWineD3DBaseTexture_IsCondNP2(iface)) {
293 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
294 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
295 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
296 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
297 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
298 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
299 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
300 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
302 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
303 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
304 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
305 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
306 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
313 static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
314 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
315 TRACE("(%p)\n", This);
320 static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
321 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
322 TRACE("(%p)\n", This);
324 return This->cond_np2;
327 /* *******************************************
328 IWineD3DTexture IWineD3DTexture parts follow
329 ******************************************* */
330 static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
331 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
333 if (Level < This->baseTexture.levels) {
334 TRACE("(%p) Level (%d)\n", This, Level);
335 return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc);
337 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
338 return WINED3DERR_INVALIDCALL;
341 static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
342 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
343 HRESULT hr = WINED3DERR_INVALIDCALL;
345 if (Level < This->baseTexture.levels) {
346 *ppSurfaceLevel = This->surfaces[Level];
347 IWineD3DSurface_AddRef(This->surfaces[Level]);
349 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
351 if (WINED3D_OK != hr) {
352 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
353 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
358 static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
359 CONST RECT *pRect, DWORD Flags) {
360 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
361 HRESULT hr = WINED3DERR_INVALIDCALL;
363 if (Level < This->baseTexture.levels) {
364 hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags);
366 if (WINED3D_OK == hr) {
367 TRACE("(%p) Level (%d) success\n", This, Level);
369 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
375 static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
376 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
377 HRESULT hr = WINED3DERR_INVALIDCALL;
379 if (Level < This->baseTexture.levels) {
380 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
382 if ( WINED3D_OK == hr) {
383 TRACE("(%p) Level (%d) success\n", This, Level);
385 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
390 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
391 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
392 This->baseTexture.texture_rgb.dirty = TRUE;
393 This->baseTexture.texture_srgb.dirty = TRUE;
394 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
395 surface_add_dirty_rect(This->surfaces[0], pDirtyRect);
400 static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
403 IWineD3DTextureImpl_QueryInterface,
404 IWineD3DTextureImpl_AddRef,
405 IWineD3DTextureImpl_Release,
406 /* IWineD3DResource */
407 IWineD3DTextureImpl_GetParent,
408 IWineD3DTextureImpl_GetDevice,
409 IWineD3DTextureImpl_SetPrivateData,
410 IWineD3DTextureImpl_GetPrivateData,
411 IWineD3DTextureImpl_FreePrivateData,
412 IWineD3DTextureImpl_SetPriority,
413 IWineD3DTextureImpl_GetPriority,
414 IWineD3DTextureImpl_PreLoad,
415 IWineD3DTextureImpl_UnLoad,
416 IWineD3DTextureImpl_GetType,
417 /* IWineD3DBaseTexture */
418 IWineD3DTextureImpl_SetLOD,
419 IWineD3DTextureImpl_GetLOD,
420 IWineD3DTextureImpl_GetLevelCount,
421 IWineD3DTextureImpl_SetAutoGenFilterType,
422 IWineD3DTextureImpl_GetAutoGenFilterType,
423 IWineD3DTextureImpl_GenerateMipSubLevels,
424 IWineD3DTextureImpl_SetDirty,
425 IWineD3DTextureImpl_GetDirty,
426 IWineD3DTextureImpl_BindTexture,
427 IWineD3DTextureImpl_GetTextureDimensions,
428 IWineD3DTextureImpl_IsCondNP2,
429 /* IWineD3DTexture */
430 IWineD3DTextureImpl_GetLevelDesc,
431 IWineD3DTextureImpl_GetSurfaceLevel,
432 IWineD3DTextureImpl_LockRect,
433 IWineD3DTextureImpl_UnlockRect,
434 IWineD3DTextureImpl_AddDirtyRect
437 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
438 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
439 IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
441 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
442 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
443 UINT pow2_width, pow2_height;
448 /* TODO: It should only be possible to create textures for formats
449 * that are reported as supported. */
450 if (WINED3DFMT_UNKNOWN >= format)
452 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
453 return WINED3DERR_INVALIDCALL;
456 /* Non-power2 support. */
457 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
460 pow2_height = height;
464 /* Find the nearest pow2 match. */
465 pow2_width = pow2_height = 1;
466 while (pow2_width < width) pow2_width <<= 1;
467 while (pow2_height < height) pow2_height <<= 1;
469 if (pow2_width != width || pow2_height != height)
473 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
474 return WINED3DERR_INVALIDCALL;
480 /* Calculate levels for mip mapping. */
481 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
483 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
485 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
486 return WINED3DERR_INVALIDCALL;
491 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
492 return WINED3DERR_INVALIDCALL;
499 levels = wined3d_log2i(max(width, height)) + 1;
500 TRACE("Calculated levels = %u.\n", levels);
503 texture->lpVtbl = &IWineD3DTexture_Vtbl;
505 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
506 device, 0, usage, format_desc, pool, parent, parent_ops);
509 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
513 /* Precalculated scaling for 'faked' non power of two texture coords.
514 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
515 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
516 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
517 if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
519 texture->baseTexture.pow2Matrix[0] = 1.0f;
520 texture->baseTexture.pow2Matrix[5] = 1.0f;
521 texture->baseTexture.pow2Matrix[10] = 1.0f;
522 texture->baseTexture.pow2Matrix[15] = 1.0f;
523 texture->target = GL_TEXTURE_2D;
524 texture->cond_np2 = TRUE;
525 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
527 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
528 && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
529 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
531 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
533 texture->baseTexture.pow2Matrix[0] = (float)width;
534 texture->baseTexture.pow2Matrix[5] = (float)height;
535 texture->baseTexture.pow2Matrix[10] = 1.0f;
536 texture->baseTexture.pow2Matrix[15] = 1.0f;
537 texture->target = GL_TEXTURE_RECTANGLE_ARB;
538 texture->cond_np2 = TRUE;
540 if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
542 texture->baseTexture.minMipLookup = minMipLookup_noMip;
546 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
551 if ((width != pow2_width) || (height != pow2_height))
553 texture->baseTexture.pow2Matrix_identity = FALSE;
554 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
555 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
559 texture->baseTexture.pow2Matrix[0] = 1.0f;
560 texture->baseTexture.pow2Matrix[5] = 1.0f;
563 texture->baseTexture.pow2Matrix[10] = 1.0f;
564 texture->baseTexture.pow2Matrix[15] = 1.0f;
565 texture->target = GL_TEXTURE_2D;
566 texture->cond_np2 = FALSE;
568 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
570 /* Generate all the surfaces. */
573 for (i = 0; i < texture->baseTexture.levels; ++i)
575 /* Use the callback to create the texture surface. */
576 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
577 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
578 if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
580 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
581 texture->surfaces[i] = NULL;
582 texture_cleanup(texture);
586 IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
587 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
588 surface_set_texture_target(texture->surfaces[i], texture->target);
589 /* Calculate the next mipmap level. */
590 tmp_w = max(1, tmp_w >> 1);
591 tmp_h = max(1, tmp_h >> 1);
593 texture->baseTexture.internal_preload = texture_internal_preload;