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 /* Do not call while under the GL lock. */
31 static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
33 /* Override the IWineD3DResource PreLoad method. */
34 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
35 IWineD3DDeviceImpl *device = This->resource.device;
36 struct wined3d_context *context = NULL;
41 TRACE("(%p) : About to load texture.\n", This);
50 texture_internal_preload(iface, SRGB_RGB);
58 srgb_mode = This->baseTexture.is_srgb;
61 dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
63 if (!device->isInDraw)
65 /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture,
66 * thus no danger of recursive calls. */
67 context = context_acquire(device, NULL);
70 if (This->resource.format->id == WINED3DFMT_P8_UINT
71 || This->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
73 for (i = 0; i < This->baseTexture.level_count; ++i)
75 IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
76 if (palette9_changed(surface))
78 TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
79 /* TODO: This is not necessarily needed with hw palettized texture support. */
80 surface_load_location(surface, SFLAG_INSYSMEM, NULL);
81 /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
82 surface_modify_location(surface, SFLAG_INTEXTURE, FALSE);
87 /* If the texture is marked dirty or the srgb sampler setting has changed
88 * since the last load then reload the surfaces. */
91 for (i = 0; i < This->baseTexture.level_count; ++i)
93 IWineD3DSurface_LoadTexture((IWineD3DSurface *)This->baseTexture.sub_resources[i], srgb_mode);
98 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
101 if (context) context_release(context);
103 /* No longer dirty. */
107 static void texture_cleanup(IWineD3DTextureImpl *This)
111 TRACE("(%p) : Cleaning up\n", This);
113 for (i = 0; i < This->baseTexture.level_count; ++i)
115 IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
118 /* Clean out the texture name we gave to the surface so that the
119 * surface doesn't try and release it */
120 surface_set_texture_name(surface, 0, TRUE);
121 surface_set_texture_name(surface, 0, FALSE);
122 surface_set_texture_target(surface, 0);
123 surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
124 IWineD3DSurface_Release((IWineD3DSurface *)surface);
128 TRACE("(%p) : Cleaning up base texture\n", This);
129 basetexture_cleanup((IWineD3DBaseTextureImpl *)This);
132 /* *******************************************
133 IWineD3DTexture IUnknown parts follow
134 ******************************************* */
136 static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
138 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
139 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
140 if (IsEqualGUID(riid, &IID_IUnknown)
141 || IsEqualGUID(riid, &IID_IWineD3DBase)
142 || IsEqualGUID(riid, &IID_IWineD3DResource)
143 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
144 || IsEqualGUID(riid, &IID_IWineD3DTexture)){
145 IUnknown_AddRef(iface);
150 return E_NOINTERFACE;
153 static ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
154 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
155 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
156 return InterlockedIncrement(&This->resource.ref);
159 /* Do not call while under the GL lock. */
160 static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
161 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
163 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
164 ref = InterlockedDecrement(&This->resource.ref);
167 texture_cleanup(This);
168 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
169 HeapFree(GetProcessHeap(), 0, This);
175 /* ****************************************************
176 IWineD3DTexture IWineD3DResource parts follow
177 **************************************************** */
178 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface,
179 REFGUID riid, const void *data, DWORD data_size, DWORD flags)
181 return resource_set_private_data((IWineD3DResource *)iface, riid, data, data_size, flags);
184 static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
185 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
188 static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
189 return resource_free_private_data((IWineD3DResource *)iface, refguid);
192 static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
193 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
196 static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
197 return resource_get_priority((IWineD3DResource *)iface);
200 /* Do not call while under the GL lock. */
201 static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
202 texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
205 /* Do not call while under the GL lock. */
206 static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
208 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
209 TRACE("(%p)\n", This);
211 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
212 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
215 for (i = 0; i < This->baseTexture.level_count; ++i)
217 IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
218 IWineD3DSurface_UnLoad((IWineD3DSurface *)surface);
219 surface_set_texture_name(surface, 0, FALSE); /* Delete rgb name */
220 surface_set_texture_name(surface, 0, TRUE); /* delete srgb name */
223 basetexture_unload((IWineD3DBaseTextureImpl *)This);
226 static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
227 return resource_get_type((IWineD3DResource *)iface);
230 static void * WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface)
232 TRACE("iface %p.\n", iface);
234 return ((IWineD3DTextureImpl *)iface)->resource.parent;
237 /* ******************************************************
238 IWineD3DTexture IWineD3DBaseTexture parts follow
239 ****************************************************** */
240 static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
241 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
244 static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
245 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
248 static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface)
250 return basetexture_get_level_count((IWineD3DBaseTextureImpl *)iface);
253 static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
254 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
257 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
258 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
261 static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
262 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
265 /* Context activation is done by the caller. */
266 static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
267 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
268 BOOL set_gl_texture_desc;
271 TRACE("(%p) : relay to BaseTexture\n", This);
273 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
274 if (set_gl_texture_desc && SUCCEEDED(hr)) {
276 struct gl_texture *gl_tex;
278 if(This->baseTexture.is_srgb) {
279 gl_tex = &This->baseTexture.texture_srgb;
281 gl_tex = &This->baseTexture.texture_rgb;
284 for (i = 0; i < This->baseTexture.level_count; ++i)
286 IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
287 surface_set_texture_name(surface, gl_tex->name, This->baseTexture.is_srgb);
290 /* Conditinal non power of two textures use a different clamping
291 * default. If we're using the GL_WINE_normalized_texrect partial
292 * driver emulation, we're dealing with a GL_TEXTURE_2D texture which
293 * has the address mode set to repeat - something that prevents us
294 * from hitting the accelerated codepath. Thus manually set the GL
295 * state. The same applies to filtering. Even if the texture has only
296 * one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
297 * fallback on macos. */
298 if (IWineD3DBaseTexture_IsCondNP2(iface))
300 GLenum target = This->baseTexture.target;
303 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
304 checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
305 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
306 checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
307 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
308 checkGLcall("glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
309 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
310 checkGLcall("glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
312 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
313 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
314 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
315 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
316 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
323 static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
324 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
325 TRACE("(%p)\n", This);
327 return This->cond_np2;
330 static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface,
331 UINT sub_resource_idx, WINED3DSURFACE_DESC *desc)
333 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
334 IWineD3DSurface *surface;
336 TRACE("iface %p, sub_resource_idx %u, desc %p.\n", iface, sub_resource_idx, desc);
338 if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
340 WARN("Failed to get sub-resource.\n");
341 return WINED3DERR_INVALIDCALL;
344 IWineD3DSurface_GetDesc(surface, desc);
349 static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface,
350 UINT sub_resource_idx, IWineD3DSurface **surface)
352 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
355 TRACE("iface %p, sub_resource_idx %u, surface %p.\n", iface, sub_resource_idx, surface);
357 if (!(s = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
359 WARN("Failed to get sub-resource.\n");
360 return WINED3DERR_INVALIDCALL;
363 IWineD3DSurface_AddRef(s);
366 TRACE("Returning surface %p.\n", *surface);
371 static HRESULT WINAPI IWineD3DTextureImpl_Map(IWineD3DTexture *iface,
372 UINT sub_resource_idx, WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
374 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
375 IWineD3DSurface *surface;
377 TRACE("iface %p, sub_resource_idx %u, locked_rect %p, rect %s, flags %#x.\n",
378 iface, sub_resource_idx, locked_rect, wine_dbgstr_rect(rect), flags);
380 if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
382 WARN("Failed to get sub-resource.\n");
383 return WINED3DERR_INVALIDCALL;
386 return IWineD3DSurface_Map(surface, locked_rect, rect, flags);
389 static HRESULT WINAPI IWineD3DTextureImpl_Unmap(IWineD3DTexture *iface, UINT sub_resource_idx)
391 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
392 IWineD3DSurface *surface;
394 TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx);
396 if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
398 WARN("Failed to get sub-resource.\n");
399 return WINED3DERR_INVALIDCALL;
402 return IWineD3DSurface_Unmap(surface);
405 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, const RECT *dirty_rect)
407 IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
408 IWineD3DSurfaceImpl *surface;
410 TRACE("iface %p, dirty_rect %s.\n", iface, wine_dbgstr_rect(dirty_rect));
412 if (!(surface = (IWineD3DSurfaceImpl *)basetexture_get_sub_resource(texture, 0)))
414 WARN("Failed to get sub-resource.\n");
415 return WINED3DERR_INVALIDCALL;
418 texture->baseTexture.texture_rgb.dirty = TRUE;
419 texture->baseTexture.texture_srgb.dirty = TRUE;
420 surface_add_dirty_rect(surface, dirty_rect);
425 static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
428 IWineD3DTextureImpl_QueryInterface,
429 IWineD3DTextureImpl_AddRef,
430 IWineD3DTextureImpl_Release,
431 /* IWineD3DResource */
432 IWineD3DTextureImpl_GetParent,
433 IWineD3DTextureImpl_SetPrivateData,
434 IWineD3DTextureImpl_GetPrivateData,
435 IWineD3DTextureImpl_FreePrivateData,
436 IWineD3DTextureImpl_SetPriority,
437 IWineD3DTextureImpl_GetPriority,
438 IWineD3DTextureImpl_PreLoad,
439 IWineD3DTextureImpl_UnLoad,
440 IWineD3DTextureImpl_GetType,
441 /* IWineD3DBaseTexture */
442 IWineD3DTextureImpl_SetLOD,
443 IWineD3DTextureImpl_GetLOD,
444 IWineD3DTextureImpl_GetLevelCount,
445 IWineD3DTextureImpl_SetAutoGenFilterType,
446 IWineD3DTextureImpl_GetAutoGenFilterType,
447 IWineD3DTextureImpl_GenerateMipSubLevels,
448 IWineD3DTextureImpl_BindTexture,
449 IWineD3DTextureImpl_IsCondNP2,
450 /* IWineD3DTexture */
451 IWineD3DTextureImpl_GetLevelDesc,
452 IWineD3DTextureImpl_GetSurfaceLevel,
453 IWineD3DTextureImpl_Map,
454 IWineD3DTextureImpl_Unmap,
455 IWineD3DTextureImpl_AddDirtyRect
458 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
459 IWineD3DDeviceImpl *device, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool,
460 void *parent, const struct wined3d_parent_ops *parent_ops)
462 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
463 const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
464 UINT pow2_width, pow2_height;
469 /* TODO: It should only be possible to create textures for formats
470 * that are reported as supported. */
471 if (WINED3DFMT_UNKNOWN >= format_id)
473 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
474 return WINED3DERR_INVALIDCALL;
477 /* Non-power2 support. */
478 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
481 pow2_height = height;
485 /* Find the nearest pow2 match. */
486 pow2_width = pow2_height = 1;
487 while (pow2_width < width) pow2_width <<= 1;
488 while (pow2_height < height) pow2_height <<= 1;
490 if (pow2_width != width || pow2_height != height)
494 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
495 return WINED3DERR_INVALIDCALL;
501 /* Calculate levels for mip mapping. */
502 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
504 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
506 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
507 return WINED3DERR_INVALIDCALL;
512 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
513 return WINED3DERR_INVALIDCALL;
520 levels = wined3d_log2i(max(width, height)) + 1;
521 TRACE("Calculated levels = %u.\n", levels);
524 texture->lpVtbl = &IWineD3DTexture_Vtbl;
526 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, 1, levels,
527 WINED3DRTYPE_TEXTURE, device, usage, format, pool, parent, parent_ops);
530 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
534 /* Precalculated scaling for 'faked' non power of two texture coords.
535 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
536 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
537 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
538 if (gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
540 texture->baseTexture.pow2Matrix[0] = 1.0f;
541 texture->baseTexture.pow2Matrix[5] = 1.0f;
542 texture->baseTexture.pow2Matrix[10] = 1.0f;
543 texture->baseTexture.pow2Matrix[15] = 1.0f;
544 texture->baseTexture.target = GL_TEXTURE_2D;
545 texture->cond_np2 = TRUE;
546 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
548 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
549 && !(format->id == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
550 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
552 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
554 texture->baseTexture.pow2Matrix[0] = (float)width;
555 texture->baseTexture.pow2Matrix[5] = (float)height;
556 texture->baseTexture.pow2Matrix[10] = 1.0f;
557 texture->baseTexture.pow2Matrix[15] = 1.0f;
558 texture->baseTexture.target = GL_TEXTURE_RECTANGLE_ARB;
559 texture->cond_np2 = TRUE;
561 if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
563 texture->baseTexture.minMipLookup = minMipLookup_noMip;
567 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
572 if ((width != pow2_width) || (height != pow2_height))
574 texture->baseTexture.pow2Matrix_identity = FALSE;
575 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
576 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
580 texture->baseTexture.pow2Matrix[0] = 1.0f;
581 texture->baseTexture.pow2Matrix[5] = 1.0f;
584 texture->baseTexture.pow2Matrix[10] = 1.0f;
585 texture->baseTexture.pow2Matrix[15] = 1.0f;
586 texture->baseTexture.target = GL_TEXTURE_2D;
587 texture->cond_np2 = FALSE;
589 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
591 /* Generate all the surfaces. */
594 for (i = 0; i < texture->baseTexture.level_count; ++i)
596 IWineD3DSurface *surface;
598 /* Use the callback to create the texture surface. */
599 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h,
600 format->id, usage, pool, i, 0, &surface);
603 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
604 texture_cleanup(texture);
608 surface_set_container((IWineD3DSurfaceImpl *)surface, WINED3D_CONTAINER_TEXTURE, (IWineD3DBase *)texture);
609 surface_set_texture_target((IWineD3DSurfaceImpl *)surface, texture->baseTexture.target);
610 texture->baseTexture.sub_resources[i] = (IWineD3DResourceImpl *)surface;
611 TRACE("Created surface level %u @ %p.\n", i, surface);
612 /* Calculate the next mipmap level. */
613 tmp_w = max(1, tmp_w >> 1);
614 tmp_h = max(1, tmp_h >> 1);
616 texture->baseTexture.internal_preload = texture_internal_preload;