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.device;
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.level_count; ++i)
74 IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
75 if (palette9_changed(surface))
77 TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
78 /* TODO: This is not necessarily needed with hw palettized texture support. */
79 IWineD3DSurface_LoadLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, NULL);
80 /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
81 IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INTEXTURE, FALSE);
86 /* If the texture is marked dirty or the srgb sampler setting has changed
87 * since the last load then reload the surfaces. */
90 for (i = 0; i < This->baseTexture.level_count; ++i)
92 IWineD3DSurface_LoadTexture((IWineD3DSurface *)This->baseTexture.sub_resources[i], srgb_mode);
97 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
100 if (context) context_release(context);
102 /* No longer dirty. */
106 static void texture_cleanup(IWineD3DTextureImpl *This)
110 TRACE("(%p) : Cleaning up\n", This);
112 for (i = 0; i < This->baseTexture.level_count; ++i)
114 IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
117 /* Clean out the texture name we gave to the surface so that the
118 * surface doesn't try and release it */
119 surface_set_texture_name(surface, 0, TRUE);
120 surface_set_texture_name(surface, 0, FALSE);
121 surface_set_texture_target(surface, 0);
122 IWineD3DSurface_SetContainer(surface, NULL);
123 IWineD3DSurface_Release(surface);
127 TRACE("(%p) : Cleaning up base texture\n", This);
128 basetexture_cleanup((IWineD3DBaseTexture *)This);
131 /* *******************************************
132 IWineD3DTexture IUnknown parts follow
133 ******************************************* */
135 static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
137 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
138 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
139 if (IsEqualGUID(riid, &IID_IUnknown)
140 || IsEqualGUID(riid, &IID_IWineD3DBase)
141 || IsEqualGUID(riid, &IID_IWineD3DResource)
142 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
143 || IsEqualGUID(riid, &IID_IWineD3DTexture)){
144 IUnknown_AddRef(iface);
149 return E_NOINTERFACE;
152 static ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
153 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
154 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
155 return InterlockedIncrement(&This->resource.ref);
158 static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
159 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
161 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
162 ref = InterlockedDecrement(&This->resource.ref);
165 texture_cleanup(This);
166 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
167 HeapFree(GetProcessHeap(), 0, This);
173 /* ****************************************************
174 IWineD3DTexture IWineD3DResource parts follow
175 **************************************************** */
176 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
177 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
180 static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
181 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
184 static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
185 return resource_free_private_data((IWineD3DResource *)iface, refguid);
188 static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
189 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
192 static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
193 return resource_get_priority((IWineD3DResource *)iface);
196 static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
197 texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
200 static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
202 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
203 TRACE("(%p)\n", This);
205 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
206 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
209 for (i = 0; i < This->baseTexture.level_count; ++i)
211 IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
212 IWineD3DSurface_UnLoad(surface);
213 surface_set_texture_name(surface, 0, FALSE); /* Delete rgb name */
214 surface_set_texture_name(surface, 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.level_count; ++i)
285 IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
286 surface_set_texture_name(surface, gl_tex->name, This->baseTexture.is_srgb);
289 /* Conditinal non power of two textures use a different clamping
290 * default. If we're using the GL_WINE_normalized_texrect partial
291 * driver emulation, we're dealing with a GL_TEXTURE_2D texture which
292 * has the address mode set to repeat - something that prevents us
293 * from hitting the accelerated codepath. Thus manually set the GL
294 * state. The same applies to filtering. Even if the texture has only
295 * one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
296 * fallback on macos. */
297 if(IWineD3DBaseTexture_IsCondNP2(iface)) {
299 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
300 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
301 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
302 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
303 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
304 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
305 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
306 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
308 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
309 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
310 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
311 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
312 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
319 static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
320 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
321 TRACE("(%p)\n", This);
326 static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
327 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
328 TRACE("(%p)\n", This);
330 return This->cond_np2;
333 /* *******************************************
334 IWineD3DTexture IWineD3DTexture parts follow
335 ******************************************* */
336 static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
337 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
339 if (Level < This->baseTexture.level_count)
341 TRACE("(%p) Level (%d)\n", This, Level);
342 return IWineD3DSurface_GetDesc((IWineD3DSurface *)This->baseTexture.sub_resources[Level], pDesc);
344 WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
345 return WINED3DERR_INVALIDCALL;
348 static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
349 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
350 HRESULT hr = WINED3DERR_INVALIDCALL;
352 if (Level < This->baseTexture.level_count)
354 *ppSurfaceLevel = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
355 IWineD3DSurface_AddRef(*ppSurfaceLevel);
357 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
359 if (WINED3D_OK != hr) {
360 WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
361 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
366 static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
367 CONST RECT *pRect, DWORD Flags) {
368 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
369 HRESULT hr = WINED3DERR_INVALIDCALL;
371 if (Level < This->baseTexture.level_count)
373 IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
374 hr = IWineD3DSurface_LockRect(surface, pLockedRect, pRect, Flags);
376 if (WINED3D_OK == hr) {
377 TRACE("(%p) Level (%d) success\n", This, Level);
379 WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
385 static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
386 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
387 HRESULT hr = WINED3DERR_INVALIDCALL;
389 if (Level < This->baseTexture.level_count)
391 IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
392 hr = IWineD3DSurface_UnlockRect(surface);
394 if ( WINED3D_OK == hr) {
395 TRACE("(%p) Level (%d) success\n", This, Level);
397 WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
402 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
403 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
404 This->baseTexture.texture_rgb.dirty = TRUE;
405 This->baseTexture.texture_srgb.dirty = TRUE;
406 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
407 surface_add_dirty_rect((IWineD3DSurface *)This->baseTexture.sub_resources[0], pDirtyRect);
412 static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
415 IWineD3DTextureImpl_QueryInterface,
416 IWineD3DTextureImpl_AddRef,
417 IWineD3DTextureImpl_Release,
418 /* IWineD3DResource */
419 IWineD3DTextureImpl_GetParent,
420 IWineD3DTextureImpl_SetPrivateData,
421 IWineD3DTextureImpl_GetPrivateData,
422 IWineD3DTextureImpl_FreePrivateData,
423 IWineD3DTextureImpl_SetPriority,
424 IWineD3DTextureImpl_GetPriority,
425 IWineD3DTextureImpl_PreLoad,
426 IWineD3DTextureImpl_UnLoad,
427 IWineD3DTextureImpl_GetType,
428 /* IWineD3DBaseTexture */
429 IWineD3DTextureImpl_SetLOD,
430 IWineD3DTextureImpl_GetLOD,
431 IWineD3DTextureImpl_GetLevelCount,
432 IWineD3DTextureImpl_SetAutoGenFilterType,
433 IWineD3DTextureImpl_GetAutoGenFilterType,
434 IWineD3DTextureImpl_GenerateMipSubLevels,
435 IWineD3DTextureImpl_SetDirty,
436 IWineD3DTextureImpl_GetDirty,
437 IWineD3DTextureImpl_BindTexture,
438 IWineD3DTextureImpl_GetTextureDimensions,
439 IWineD3DTextureImpl_IsCondNP2,
440 /* IWineD3DTexture */
441 IWineD3DTextureImpl_GetLevelDesc,
442 IWineD3DTextureImpl_GetSurfaceLevel,
443 IWineD3DTextureImpl_LockRect,
444 IWineD3DTextureImpl_UnlockRect,
445 IWineD3DTextureImpl_AddDirtyRect
448 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
449 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
450 IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
452 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
453 const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
454 UINT pow2_width, pow2_height;
459 /* TODO: It should only be possible to create textures for formats
460 * that are reported as supported. */
461 if (WINED3DFMT_UNKNOWN >= format)
463 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
464 return WINED3DERR_INVALIDCALL;
467 /* Non-power2 support. */
468 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
471 pow2_height = height;
475 /* Find the nearest pow2 match. */
476 pow2_width = pow2_height = 1;
477 while (pow2_width < width) pow2_width <<= 1;
478 while (pow2_height < height) pow2_height <<= 1;
480 if (pow2_width != width || pow2_height != height)
484 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
485 return WINED3DERR_INVALIDCALL;
491 /* Calculate levels for mip mapping. */
492 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
494 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
496 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
497 return WINED3DERR_INVALIDCALL;
502 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
503 return WINED3DERR_INVALIDCALL;
510 levels = wined3d_log2i(max(width, height)) + 1;
511 TRACE("Calculated levels = %u.\n", levels);
514 texture->lpVtbl = &IWineD3DTexture_Vtbl;
516 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, 1, levels,
517 WINED3DRTYPE_TEXTURE, device, 0, usage, format_desc, pool, parent, parent_ops);
520 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
524 /* Precalculated scaling for 'faked' non power of two texture coords.
525 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
526 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
527 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
528 if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
530 texture->baseTexture.pow2Matrix[0] = 1.0f;
531 texture->baseTexture.pow2Matrix[5] = 1.0f;
532 texture->baseTexture.pow2Matrix[10] = 1.0f;
533 texture->baseTexture.pow2Matrix[15] = 1.0f;
534 texture->target = GL_TEXTURE_2D;
535 texture->cond_np2 = TRUE;
536 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
538 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
539 && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
540 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
542 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
544 texture->baseTexture.pow2Matrix[0] = (float)width;
545 texture->baseTexture.pow2Matrix[5] = (float)height;
546 texture->baseTexture.pow2Matrix[10] = 1.0f;
547 texture->baseTexture.pow2Matrix[15] = 1.0f;
548 texture->target = GL_TEXTURE_RECTANGLE_ARB;
549 texture->cond_np2 = TRUE;
551 if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
553 texture->baseTexture.minMipLookup = minMipLookup_noMip;
557 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
562 if ((width != pow2_width) || (height != pow2_height))
564 texture->baseTexture.pow2Matrix_identity = FALSE;
565 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
566 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
570 texture->baseTexture.pow2Matrix[0] = 1.0f;
571 texture->baseTexture.pow2Matrix[5] = 1.0f;
574 texture->baseTexture.pow2Matrix[10] = 1.0f;
575 texture->baseTexture.pow2Matrix[15] = 1.0f;
576 texture->target = GL_TEXTURE_2D;
577 texture->cond_np2 = FALSE;
579 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
581 /* Generate all the surfaces. */
584 for (i = 0; i < texture->baseTexture.level_count; ++i)
586 IWineD3DSurface *surface;
588 /* Use the callback to create the texture surface. */
589 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
590 usage, pool, i, 0, &surface);
593 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
594 texture_cleanup(texture);
598 IWineD3DSurface_SetContainer(surface, (IWineD3DBase *)texture);
599 surface_set_texture_target(surface, texture->target);
600 texture->baseTexture.sub_resources[i] = (IWineD3DResourceImpl *)surface;
601 TRACE("Created surface level %u @ %p.\n", i, surface);
602 /* Calculate the next mipmap level. */
603 tmp_w = max(1, tmp_w >> 1);
604 tmp_h = max(1, tmp_h >> 1);
606 texture->baseTexture.internal_preload = texture_internal_preload;