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-2010 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 /* Context activation is done by the caller. */
31 static HRESULT texture_bind(IWineD3DBaseTextureImpl *texture,
32 const struct wined3d_gl_info *gl_info, BOOL srgb)
34 BOOL set_gl_texture_desc;
37 TRACE("texture %p, gl_info %p, srgb %#x.\n", texture, gl_info, srgb);
39 hr = basetexture_bind(texture, gl_info, srgb, &set_gl_texture_desc);
40 if (set_gl_texture_desc && SUCCEEDED(hr))
42 BOOL srgb_tex = !gl_info->supported[EXT_TEXTURE_SRGB_DECODE] && texture->baseTexture.is_srgb;
43 struct gl_texture *gl_tex;
46 gl_tex = basetexture_get_gl_texture(texture, gl_info, srgb_tex);
48 for (i = 0; i < texture->baseTexture.level_count; ++i)
50 IWineD3DSurfaceImpl *surface = surface_from_resource(texture->baseTexture.sub_resources[i]);
51 surface_set_texture_name(surface, gl_tex->name, srgb_tex);
54 /* Conditinal non power of two textures use a different clamping
55 * default. If we're using the GL_WINE_normalized_texrect partial
56 * driver emulation, we're dealing with a GL_TEXTURE_2D texture which
57 * has the address mode set to repeat - something that prevents us
58 * from hitting the accelerated codepath. Thus manually set the GL
59 * state. The same applies to filtering. Even if the texture has only
60 * one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
61 * fallback on macos. */
62 if (IWineD3DBaseTexture_IsCondNP2((IWineD3DBaseTexture *)texture))
64 GLenum target = texture->baseTexture.target;
67 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
68 checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
69 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
70 checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
71 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
72 checkGLcall("glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
73 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
74 checkGLcall("glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
76 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
77 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
78 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
79 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
80 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
87 /* Do not call while under the GL lock. */
88 static void texture_preload(IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb)
90 IWineD3DDeviceImpl *device = texture->resource.device;
91 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
92 struct wined3d_context *context = NULL;
93 struct gl_texture *gl_tex;
97 TRACE("texture %p, srgb %#x.\n", texture, srgb);
106 texture_preload(texture, SRGB_RGB);
114 srgb_mode = texture->baseTexture.is_srgb;
118 gl_tex = basetexture_get_gl_texture(texture, gl_info, srgb_mode);
120 if (!device->isInDraw)
122 /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture,
123 * thus no danger of recursive calls. */
124 context = context_acquire(device, NULL);
127 if (texture->resource.format->id == WINED3DFMT_P8_UINT
128 || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
130 for (i = 0; i < texture->baseTexture.level_count; ++i)
132 IWineD3DSurfaceImpl *surface = surface_from_resource(texture->baseTexture.sub_resources[i]);
133 if (palette9_changed(surface))
135 TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
136 /* TODO: This is not necessarily needed with hw palettized texture support. */
137 surface_load_location(surface, SFLAG_INSYSMEM, NULL);
138 /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
139 surface_modify_location(surface, SFLAG_INTEXTURE, FALSE);
144 /* If the texture is marked dirty or the srgb sampler setting has changed
145 * since the last load then reload the surfaces. */
148 for (i = 0; i < texture->baseTexture.level_count; ++i)
150 surface_load(surface_from_resource(texture->baseTexture.sub_resources[i]), srgb_mode);
155 TRACE("Texture %p not dirty, nothing to do.\n", texture);
158 if (context) context_release(context);
160 /* No longer dirty. */
161 gl_tex->dirty = FALSE;
164 /* Do not call while under the GL lock. */
165 static void texture_unload(struct wined3d_resource *resource)
167 IWineD3DBaseTextureImpl *texture = basetexture_from_resource(resource);
170 TRACE("texture %p.\n", texture);
172 for (i = 0; i < texture->baseTexture.level_count; ++i)
174 struct wined3d_resource *sub_resource = texture->baseTexture.sub_resources[i];
175 IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource);
177 sub_resource->resource_ops->resource_unload(sub_resource);
178 surface_set_texture_name(surface, 0, FALSE); /* Delete rgb name */
179 surface_set_texture_name(surface, 0, TRUE); /* delete srgb name */
182 basetexture_unload(texture);
185 static const struct wined3d_texture_ops texture_ops =
191 static const struct wined3d_resource_ops texture_resource_ops =
196 static void texture_cleanup(IWineD3DTextureImpl *This)
200 TRACE("(%p) : Cleaning up\n", This);
202 for (i = 0; i < This->baseTexture.level_count; ++i)
204 struct wined3d_resource *sub_resource = This->baseTexture.sub_resources[i];
208 IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource);
210 /* Clean out the texture name we gave to the surface so that the
211 * surface doesn't try and release it */
212 surface_set_texture_name(surface, 0, TRUE);
213 surface_set_texture_name(surface, 0, FALSE);
214 surface_set_texture_target(surface, 0);
215 surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
216 IWineD3DSurface_Release((IWineD3DSurface *)surface);
220 TRACE("(%p) : Cleaning up base texture\n", This);
221 basetexture_cleanup((IWineD3DBaseTextureImpl *)This);
224 /* *******************************************
225 IWineD3DTexture IUnknown parts follow
226 ******************************************* */
228 static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
230 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
231 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
232 if (IsEqualGUID(riid, &IID_IUnknown)
233 || IsEqualGUID(riid, &IID_IWineD3DBase)
234 || IsEqualGUID(riid, &IID_IWineD3DResource)
235 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
236 || IsEqualGUID(riid, &IID_IWineD3DTexture)){
237 IUnknown_AddRef(iface);
242 return E_NOINTERFACE;
245 static ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
246 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
247 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
248 return InterlockedIncrement(&This->resource.ref);
251 /* Do not call while under the GL lock. */
252 static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
253 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
255 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
256 ref = InterlockedDecrement(&This->resource.ref);
259 texture_cleanup(This);
260 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
261 HeapFree(GetProcessHeap(), 0, This);
267 /* ****************************************************
268 IWineD3DTexture IWineD3DResource parts follow
269 **************************************************** */
270 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface,
271 REFGUID riid, const void *data, DWORD data_size, DWORD flags)
273 return resource_set_private_data(&((IWineD3DTextureImpl *)iface)->resource, riid, data, data_size, flags);
276 static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface,
277 REFGUID guid, void *data, DWORD *data_size)
279 return resource_get_private_data(&((IWineD3DTextureImpl *)iface)->resource, guid, data, data_size);
282 static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid)
284 return resource_free_private_data(&((IWineD3DTextureImpl *)iface)->resource, refguid);
287 static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD priority)
289 return resource_set_priority(&((IWineD3DTextureImpl *)iface)->resource, priority);
292 static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface)
294 return resource_get_priority(&((IWineD3DTextureImpl *)iface)->resource);
297 /* Do not call while under the GL lock. */
298 static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface)
300 texture_preload((IWineD3DBaseTextureImpl *)iface, SRGB_ANY);
303 static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface)
305 return resource_get_type(&((IWineD3DTextureImpl *)iface)->resource);
308 static void * WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface)
310 TRACE("iface %p.\n", iface);
312 return ((IWineD3DTextureImpl *)iface)->resource.parent;
315 /* ******************************************************
316 IWineD3DTexture IWineD3DBaseTexture parts follow
317 ****************************************************** */
318 static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
319 return basetexture_set_lod((IWineD3DBaseTextureImpl *)iface, LODNew);
322 static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
323 return basetexture_get_lod((IWineD3DBaseTextureImpl *)iface);
326 static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface)
328 return basetexture_get_level_count((IWineD3DBaseTextureImpl *)iface);
331 static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface,
332 WINED3DTEXTUREFILTERTYPE FilterType)
334 return basetexture_set_autogen_filter_type((IWineD3DBaseTextureImpl *)iface, FilterType);
337 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface)
339 return basetexture_get_autogen_filter_type((IWineD3DBaseTextureImpl *)iface);
342 static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface)
344 basetexture_generate_mipmaps((IWineD3DBaseTextureImpl *)iface);
347 static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
348 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
349 TRACE("(%p)\n", This);
351 return This->cond_np2;
354 static HRESULT WINAPI IWineD3DTextureImpl_GetSubResourceDesc(IWineD3DTexture *iface,
355 UINT sub_resource_idx, struct wined3d_resource_desc *desc)
357 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
358 struct wined3d_resource *sub_resource;
360 TRACE("iface %p, sub_resource_idx %u, desc %p.\n", iface, sub_resource_idx, desc);
362 if (!(sub_resource = basetexture_get_sub_resource(texture, sub_resource_idx)))
364 WARN("Failed to get sub-resource.\n");
365 return WINED3DERR_INVALIDCALL;
368 IWineD3DSurface_GetDesc((IWineD3DSurface *)surface_from_resource(sub_resource), desc);
373 static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface,
374 UINT sub_resource_idx, IWineD3DSurface **surface)
376 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
377 struct wined3d_resource *sub_resource;
379 TRACE("iface %p, sub_resource_idx %u, surface %p.\n", iface, sub_resource_idx, surface);
381 if (!(sub_resource = basetexture_get_sub_resource(texture, sub_resource_idx)))
383 WARN("Failed to get sub-resource.\n");
384 return WINED3DERR_INVALIDCALL;
387 *surface = (IWineD3DSurface *)surface_from_resource(sub_resource);
388 IWineD3DSurface_AddRef(*surface);
390 TRACE("Returning surface %p.\n", *surface);
395 static HRESULT WINAPI IWineD3DTextureImpl_Map(IWineD3DTexture *iface,
396 UINT sub_resource_idx, WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
398 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
399 struct wined3d_resource *sub_resource;
401 TRACE("iface %p, sub_resource_idx %u, locked_rect %p, rect %s, flags %#x.\n",
402 iface, sub_resource_idx, locked_rect, wine_dbgstr_rect(rect), flags);
404 if (!(sub_resource = basetexture_get_sub_resource(texture, sub_resource_idx)))
406 WARN("Failed to get sub-resource.\n");
407 return WINED3DERR_INVALIDCALL;
410 return IWineD3DSurface_Map((IWineD3DSurface *)surface_from_resource(sub_resource), locked_rect, rect, flags);
413 static HRESULT WINAPI IWineD3DTextureImpl_Unmap(IWineD3DTexture *iface, UINT sub_resource_idx)
415 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
416 struct wined3d_resource *sub_resource;
418 TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx);
420 if (!(sub_resource = basetexture_get_sub_resource(texture, sub_resource_idx)))
422 WARN("Failed to get sub-resource.\n");
423 return WINED3DERR_INVALIDCALL;
426 return IWineD3DSurface_Unmap((IWineD3DSurface *)surface_from_resource(sub_resource));
429 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, const RECT *dirty_rect)
431 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
432 struct wined3d_resource *sub_resource;
434 TRACE("iface %p, dirty_rect %s.\n", iface, wine_dbgstr_rect(dirty_rect));
436 if (!(sub_resource = basetexture_get_sub_resource(texture, 0)))
438 WARN("Failed to get sub-resource.\n");
439 return WINED3DERR_INVALIDCALL;
442 basetexture_set_dirty(texture, TRUE);
443 surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_rect);
448 static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
451 IWineD3DTextureImpl_QueryInterface,
452 IWineD3DTextureImpl_AddRef,
453 IWineD3DTextureImpl_Release,
454 /* IWineD3DResource */
455 IWineD3DTextureImpl_GetParent,
456 IWineD3DTextureImpl_SetPrivateData,
457 IWineD3DTextureImpl_GetPrivateData,
458 IWineD3DTextureImpl_FreePrivateData,
459 IWineD3DTextureImpl_SetPriority,
460 IWineD3DTextureImpl_GetPriority,
461 IWineD3DTextureImpl_PreLoad,
462 IWineD3DTextureImpl_GetType,
463 /* IWineD3DBaseTexture */
464 IWineD3DTextureImpl_SetLOD,
465 IWineD3DTextureImpl_GetLOD,
466 IWineD3DTextureImpl_GetLevelCount,
467 IWineD3DTextureImpl_SetAutoGenFilterType,
468 IWineD3DTextureImpl_GetAutoGenFilterType,
469 IWineD3DTextureImpl_GenerateMipSubLevels,
470 IWineD3DTextureImpl_IsCondNP2,
471 IWineD3DTextureImpl_GetSubResourceDesc,
472 /* IWineD3DTexture */
473 IWineD3DTextureImpl_GetSurfaceLevel,
474 IWineD3DTextureImpl_Map,
475 IWineD3DTextureImpl_Unmap,
476 IWineD3DTextureImpl_AddDirtyRect
479 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
480 IWineD3DDeviceImpl *device, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool,
481 void *parent, const struct wined3d_parent_ops *parent_ops)
483 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
484 const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
485 UINT pow2_width, pow2_height;
490 /* TODO: It should only be possible to create textures for formats
491 * that are reported as supported. */
492 if (WINED3DFMT_UNKNOWN >= format_id)
494 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
495 return WINED3DERR_INVALIDCALL;
498 /* Non-power2 support. */
499 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
502 pow2_height = height;
506 /* Find the nearest pow2 match. */
507 pow2_width = pow2_height = 1;
508 while (pow2_width < width) pow2_width <<= 1;
509 while (pow2_height < height) pow2_height <<= 1;
511 if (pow2_width != width || pow2_height != height)
515 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
516 return WINED3DERR_INVALIDCALL;
522 /* Calculate levels for mip mapping. */
523 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
525 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
527 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
528 return WINED3DERR_INVALIDCALL;
533 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
534 return WINED3DERR_INVALIDCALL;
541 levels = wined3d_log2i(max(width, height)) + 1;
542 TRACE("Calculated levels = %u.\n", levels);
545 texture->lpVtbl = &IWineD3DTexture_Vtbl;
547 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, &texture_ops,
548 1, levels, WINED3DRTYPE_TEXTURE, device, usage, format, pool,
549 parent, parent_ops, &texture_resource_ops);
552 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
556 /* Precalculated scaling for 'faked' non power of two texture coords.
557 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
558 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
559 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
560 if (gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
562 texture->baseTexture.pow2Matrix[0] = 1.0f;
563 texture->baseTexture.pow2Matrix[5] = 1.0f;
564 texture->baseTexture.pow2Matrix[10] = 1.0f;
565 texture->baseTexture.pow2Matrix[15] = 1.0f;
566 texture->baseTexture.target = GL_TEXTURE_2D;
567 texture->cond_np2 = TRUE;
568 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
570 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
571 && !(format->id == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
572 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
574 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
576 texture->baseTexture.pow2Matrix[0] = (float)width;
577 texture->baseTexture.pow2Matrix[5] = (float)height;
578 texture->baseTexture.pow2Matrix[10] = 1.0f;
579 texture->baseTexture.pow2Matrix[15] = 1.0f;
580 texture->baseTexture.target = GL_TEXTURE_RECTANGLE_ARB;
581 texture->cond_np2 = TRUE;
583 if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
585 texture->baseTexture.minMipLookup = minMipLookup_noMip;
589 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
594 if ((width != pow2_width) || (height != pow2_height))
596 texture->baseTexture.pow2Matrix_identity = FALSE;
597 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
598 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
602 texture->baseTexture.pow2Matrix[0] = 1.0f;
603 texture->baseTexture.pow2Matrix[5] = 1.0f;
606 texture->baseTexture.pow2Matrix[10] = 1.0f;
607 texture->baseTexture.pow2Matrix[15] = 1.0f;
608 texture->baseTexture.target = GL_TEXTURE_2D;
609 texture->cond_np2 = FALSE;
611 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
613 /* Generate all the surfaces. */
616 for (i = 0; i < texture->baseTexture.level_count; ++i)
618 IWineD3DSurface *surface;
620 /* Use the callback to create the texture surface. */
621 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h,
622 format->id, usage, pool, i, 0, &surface);
625 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
626 texture_cleanup(texture);
630 surface_set_container((IWineD3DSurfaceImpl *)surface, WINED3D_CONTAINER_TEXTURE, (IWineD3DBase *)texture);
631 surface_set_texture_target((IWineD3DSurfaceImpl *)surface, texture->baseTexture.target);
632 texture->baseTexture.sub_resources[i] = &((IWineD3DSurfaceImpl *)surface)->resource;
633 TRACE("Created surface level %u @ %p.\n", i, surface);
634 /* Calculate the next mipmap level. */
635 tmp_w = max(1, tmp_w >> 1);
636 tmp_h = max(1, tmp_h >> 1);