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 #define GLINFO_LOCATION (*gl_info)
32 static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
34 /* Override the IWineD3DResource PreLoad method. */
35 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
36 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
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 /* ActivateContext sets isInDraw to TRUE when loading a pbuffer into a texture,
66 * thus no danger of recursive calls. */
67 ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
70 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
71 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
73 for (i = 0; i < This->baseTexture.levels; ++i)
75 if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[i]))
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(This->surfaces[i], SFLAG_INSYSMEM, NULL);
80 /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
81 IWineD3DSurface_ModifyLocation(This->surfaces[i], 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.levels; ++i)
92 IWineD3DSurface_LoadTexture(This->surfaces[i], srgb_mode);
97 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
100 /* No longer dirty. */
104 static void texture_cleanup(IWineD3DTextureImpl *This)
108 TRACE("(%p) : Cleaning up\n", This);
110 for (i = 0; i < This->baseTexture.levels; ++i)
112 if (This->surfaces[i])
114 /* Clean out the texture name we gave to the surface so that the
115 * surface doesn't try and release it */
116 surface_set_texture_name(This->surfaces[i], 0, TRUE);
117 surface_set_texture_name(This->surfaces[i], 0, FALSE);
118 surface_set_texture_target(This->surfaces[i], 0);
119 IWineD3DSurface_SetContainer(This->surfaces[i], 0);
120 IWineD3DSurface_Release(This->surfaces[i]);
124 TRACE("(%p) : Cleaning up base texture\n", This);
125 basetexture_cleanup((IWineD3DBaseTexture *)This);
128 #undef GLINFO_LOCATION
130 /* *******************************************
131 IWineD3DTexture IUnknown parts follow
132 ******************************************* */
134 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
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 static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
160 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
162 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
163 ref = InterlockedDecrement(&This->resource.ref);
166 texture_cleanup(This);
167 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
168 HeapFree(GetProcessHeap(), 0, This);
174 /* ****************************************************
175 IWineD3DTexture IWineD3DResource parts follow
176 **************************************************** */
177 static HRESULT WINAPI IWineD3DTextureImpl_GetDevice(IWineD3DTexture *iface, IWineD3DDevice** ppDevice) {
178 return resource_get_device((IWineD3DResource *)iface, ppDevice);
181 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
182 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
185 static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
186 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
189 static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
190 return resource_free_private_data((IWineD3DResource *)iface, refguid);
193 static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
194 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
197 static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
198 return resource_get_priority((IWineD3DResource *)iface);
201 static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
202 texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
205 static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
207 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
208 TRACE("(%p)\n", This);
210 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
211 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
214 for (i = 0; i < This->baseTexture.levels; i++) {
215 IWineD3DSurface_UnLoad(This->surfaces[i]);
216 surface_set_texture_name(This->surfaces[i], 0, FALSE); /* Delete rgb name */
217 surface_set_texture_name(This->surfaces[i], 0, TRUE); /* delete srgb name */
220 basetexture_unload((IWineD3DBaseTexture *)iface);
223 static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
224 return resource_get_type((IWineD3DResource *)iface);
227 static HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
228 return resource_get_parent((IWineD3DResource *)iface, pParent);
231 /* ******************************************************
232 IWineD3DTexture IWineD3DBaseTexture parts follow
233 ****************************************************** */
234 static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
235 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
238 static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
239 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
242 static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
243 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
246 static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
247 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
250 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
251 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
254 static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
255 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
258 /* Internal function, No d3d mapping */
259 static BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
260 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
263 static BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
264 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
267 /* Context activation is done by the caller. */
268 static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
269 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
270 BOOL set_gl_texture_desc;
273 TRACE("(%p) : relay to BaseTexture\n", This);
275 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
276 if (set_gl_texture_desc && SUCCEEDED(hr)) {
278 struct gl_texture *gl_tex;
280 if(This->baseTexture.is_srgb) {
281 gl_tex = &This->baseTexture.texture_srgb;
283 gl_tex = &This->baseTexture.texture_rgb;
286 for (i = 0; i < This->baseTexture.levels; ++i) {
287 surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb);
289 /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
290 * partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something
291 * that prevents us from hitting the accelerated codepath. Thus manually set the GL state. The same applies to filtering.
292 * Even if the texture has only one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW fallback on macos.
294 if(IWineD3DBaseTexture_IsCondNP2(iface)) {
296 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
297 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
298 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
299 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
300 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
301 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
302 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
303 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
305 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
306 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
307 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
308 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
309 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
316 static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
317 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
318 TRACE("(%p)\n", This);
323 static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
324 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
325 TRACE("(%p)\n", This);
327 return This->cond_np2;
330 /* *******************************************
331 IWineD3DTexture IWineD3DTexture parts follow
332 ******************************************* */
333 static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
334 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
336 if (Level < This->baseTexture.levels) {
337 TRACE("(%p) Level (%d)\n", This, Level);
338 return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc);
340 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
341 return WINED3DERR_INVALIDCALL;
344 static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
345 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
346 HRESULT hr = WINED3DERR_INVALIDCALL;
348 if (Level < This->baseTexture.levels) {
349 *ppSurfaceLevel = This->surfaces[Level];
350 IWineD3DSurface_AddRef(This->surfaces[Level]);
352 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
354 if (WINED3D_OK != hr) {
355 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
356 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
361 static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
362 CONST RECT *pRect, DWORD Flags) {
363 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
364 HRESULT hr = WINED3DERR_INVALIDCALL;
366 if (Level < This->baseTexture.levels) {
367 hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags);
369 if (WINED3D_OK == hr) {
370 TRACE("(%p) Level (%d) success\n", This, Level);
372 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
378 static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
379 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
380 HRESULT hr = WINED3DERR_INVALIDCALL;
382 if (Level < This->baseTexture.levels) {
383 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
385 if ( WINED3D_OK == hr) {
386 TRACE("(%p) Level (%d) success\n", This, Level);
388 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
393 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
394 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
395 This->baseTexture.texture_rgb.dirty = TRUE;
396 This->baseTexture.texture_srgb.dirty = TRUE;
397 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
398 surface_add_dirty_rect(This->surfaces[0], pDirtyRect);
403 static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
406 IWineD3DTextureImpl_QueryInterface,
407 IWineD3DTextureImpl_AddRef,
408 IWineD3DTextureImpl_Release,
409 /* IWineD3DResource */
410 IWineD3DTextureImpl_GetParent,
411 IWineD3DTextureImpl_GetDevice,
412 IWineD3DTextureImpl_SetPrivateData,
413 IWineD3DTextureImpl_GetPrivateData,
414 IWineD3DTextureImpl_FreePrivateData,
415 IWineD3DTextureImpl_SetPriority,
416 IWineD3DTextureImpl_GetPriority,
417 IWineD3DTextureImpl_PreLoad,
418 IWineD3DTextureImpl_UnLoad,
419 IWineD3DTextureImpl_GetType,
420 /* IWineD3DBaseTexture */
421 IWineD3DTextureImpl_SetLOD,
422 IWineD3DTextureImpl_GetLOD,
423 IWineD3DTextureImpl_GetLevelCount,
424 IWineD3DTextureImpl_SetAutoGenFilterType,
425 IWineD3DTextureImpl_GetAutoGenFilterType,
426 IWineD3DTextureImpl_GenerateMipSubLevels,
427 IWineD3DTextureImpl_SetDirty,
428 IWineD3DTextureImpl_GetDirty,
429 IWineD3DTextureImpl_BindTexture,
430 IWineD3DTextureImpl_GetTextureDimensions,
431 IWineD3DTextureImpl_IsCondNP2,
432 /* IWineD3DTexture */
433 IWineD3DTextureImpl_GetLevelDesc,
434 IWineD3DTextureImpl_GetSurfaceLevel,
435 IWineD3DTextureImpl_LockRect,
436 IWineD3DTextureImpl_UnlockRect,
437 IWineD3DTextureImpl_AddDirtyRect
440 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
441 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
442 IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
444 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
445 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
446 UINT pow2_width, pow2_height;
451 /* TODO: It should only be possible to create textures for formats
452 * that are reported as supported. */
453 if (WINED3DFMT_UNKNOWN >= format)
455 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
456 return WINED3DERR_INVALIDCALL;
459 /* Non-power2 support. */
460 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
463 pow2_height = height;
467 /* Find the nearest pow2 match. */
468 pow2_width = pow2_height = 1;
469 while (pow2_width < width) pow2_width <<= 1;
470 while (pow2_height < height) pow2_height <<= 1;
472 if (pow2_width != width || pow2_height != height)
476 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
477 return WINED3DERR_INVALIDCALL;
483 /* Calculate levels for mip mapping. */
484 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
486 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
488 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
489 return WINED3DERR_INVALIDCALL;
494 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
495 return WINED3DERR_INVALIDCALL;
502 levels = wined3d_log2i(max(width, height)) + 1;
503 TRACE("Calculated levels = %u.\n", levels);
506 texture->lpVtbl = &IWineD3DTexture_Vtbl;
508 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
509 device, 0, usage, format_desc, pool, parent, parent_ops);
512 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
516 /* Precalculated scaling for 'faked' non power of two texture coords.
517 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
518 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
519 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
520 if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
522 texture->baseTexture.pow2Matrix[0] = 1.0f;
523 texture->baseTexture.pow2Matrix[5] = 1.0f;
524 texture->baseTexture.pow2Matrix[10] = 1.0f;
525 texture->baseTexture.pow2Matrix[15] = 1.0f;
526 texture->target = GL_TEXTURE_2D;
527 texture->cond_np2 = TRUE;
528 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
530 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
531 && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
532 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
534 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
536 texture->baseTexture.pow2Matrix[0] = (float)width;
537 texture->baseTexture.pow2Matrix[5] = (float)height;
538 texture->baseTexture.pow2Matrix[10] = 1.0f;
539 texture->baseTexture.pow2Matrix[15] = 1.0f;
540 texture->target = GL_TEXTURE_RECTANGLE_ARB;
541 texture->cond_np2 = TRUE;
543 if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
545 texture->baseTexture.minMipLookup = minMipLookup_noMip;
549 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
554 if ((width != pow2_width) || (height != pow2_height))
556 texture->baseTexture.pow2Matrix_identity = FALSE;
557 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
558 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
562 texture->baseTexture.pow2Matrix[0] = 1.0f;
563 texture->baseTexture.pow2Matrix[5] = 1.0f;
566 texture->baseTexture.pow2Matrix[10] = 1.0f;
567 texture->baseTexture.pow2Matrix[15] = 1.0f;
568 texture->target = GL_TEXTURE_2D;
569 texture->cond_np2 = FALSE;
571 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
573 /* Generate all the surfaces. */
576 for (i = 0; i < texture->baseTexture.levels; ++i)
578 /* Use the callback to create the texture surface. */
579 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
580 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
581 if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
583 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
584 texture->surfaces[i] = NULL;
585 texture_cleanup(texture);
589 IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
590 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
591 surface_set_texture_target(texture->surfaces[i], texture->target);
592 /* Calculate the next mipmap level. */
593 tmp_w = max(1, tmp_w >> 1);
594 tmp_h = max(1, tmp_h >> 1);
596 texture->baseTexture.internal_preload = texture_internal_preload;