kernel32/tests: Init pointers in common way, add some win_skip() while skipping.
[wine/hramrach.git] / dlls / wined3d / texture.c
blob1e272144a8ad545c155decc56d9f97c8fc0d5fa0
1 /*
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
25 #include "config.h"
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;
36 unsigned int i;
37 BOOL srgb_mode;
38 BOOL *dirty;
40 TRACE("(%p) : About to load texture.\n", This);
42 switch (srgb)
44 case SRGB_RGB:
45 srgb_mode = FALSE;
46 break;
48 case SRGB_BOTH:
49 texture_internal_preload(iface, SRGB_RGB);
50 /* Fallthrough */
52 case SRGB_SRGB:
53 srgb_mode = TRUE;
54 break;
56 default:
57 srgb_mode = This->baseTexture.is_srgb;
58 break;
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. */
87 if (*dirty)
89 for (i = 0; i < This->baseTexture.levels; ++i)
91 IWineD3DSurface_LoadTexture(This->surfaces[i], srgb_mode);
94 else
96 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
99 if (context) context_release(context);
101 /* No longer dirty. */
102 *dirty = FALSE;
105 static void texture_cleanup(IWineD3DTextureImpl *This)
107 unsigned int i;
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);
143 *ppobj = This;
144 return WINED3D_OK;
146 *ppobj = NULL;
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;
158 ULONG ref;
159 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
160 ref = InterlockedDecrement(&This->resource.ref);
161 if (!ref)
163 texture_cleanup(This);
164 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
165 HeapFree(GetProcessHeap(), 0, This);
167 return ref;
171 /* ****************************************************
172 IWineD3DTexture IWineD3DResource parts follow
173 **************************************************** */
174 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
175 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
178 static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
179 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
182 static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
183 return resource_free_private_data((IWineD3DResource *)iface, refguid);
186 static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
187 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
190 static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
191 return resource_get_priority((IWineD3DResource *)iface);
194 static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
195 texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
198 static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
199 unsigned int i;
200 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
201 TRACE("(%p)\n", This);
203 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
204 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
205 * surface is fine
207 for (i = 0; i < This->baseTexture.levels; i++) {
208 IWineD3DSurface_UnLoad(This->surfaces[i]);
209 surface_set_texture_name(This->surfaces[i], 0, FALSE); /* Delete rgb name */
210 surface_set_texture_name(This->surfaces[i], 0, TRUE); /* delete srgb name */
213 basetexture_unload((IWineD3DBaseTexture *)iface);
216 static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
217 return resource_get_type((IWineD3DResource *)iface);
220 static HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
221 return resource_get_parent((IWineD3DResource *)iface, pParent);
224 /* ******************************************************
225 IWineD3DTexture IWineD3DBaseTexture parts follow
226 ****************************************************** */
227 static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
228 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
231 static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
232 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
235 static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
236 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
239 static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
240 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
243 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
244 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
247 static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
248 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
251 /* Internal function, No d3d mapping */
252 static BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
253 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
256 static BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
257 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
260 /* Context activation is done by the caller. */
261 static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
262 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
263 BOOL set_gl_texture_desc;
264 HRESULT hr;
266 TRACE("(%p) : relay to BaseTexture\n", This);
268 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
269 if (set_gl_texture_desc && SUCCEEDED(hr)) {
270 UINT i;
271 struct gl_texture *gl_tex;
273 if(This->baseTexture.is_srgb) {
274 gl_tex = &This->baseTexture.texture_srgb;
275 } else {
276 gl_tex = &This->baseTexture.texture_rgb;
279 for (i = 0; i < This->baseTexture.levels; ++i) {
280 surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb);
282 /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
283 * partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something
284 * that prevents us from hitting the accelerated codepath. Thus manually set the GL state. The same applies to filtering.
285 * Even if the texture has only one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW fallback on macos.
287 if(IWineD3DBaseTexture_IsCondNP2(iface)) {
288 ENTER_GL();
289 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
290 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
291 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
292 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
293 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
294 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
295 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
296 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
297 LEAVE_GL();
298 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
299 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
300 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
301 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
302 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
306 return hr;
309 static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
310 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
311 TRACE("(%p)\n", This);
313 return This->target;
316 static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
317 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
318 TRACE("(%p)\n", This);
320 return This->cond_np2;
323 /* *******************************************
324 IWineD3DTexture IWineD3DTexture parts follow
325 ******************************************* */
326 static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
327 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
329 if (Level < This->baseTexture.levels) {
330 TRACE("(%p) Level (%d)\n", This, Level);
331 return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc);
333 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
334 return WINED3DERR_INVALIDCALL;
337 static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
338 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
339 HRESULT hr = WINED3DERR_INVALIDCALL;
341 if (Level < This->baseTexture.levels) {
342 *ppSurfaceLevel = This->surfaces[Level];
343 IWineD3DSurface_AddRef(This->surfaces[Level]);
344 hr = WINED3D_OK;
345 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
347 if (WINED3D_OK != hr) {
348 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
349 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
351 return hr;
354 static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
355 CONST RECT *pRect, DWORD Flags) {
356 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
357 HRESULT hr = WINED3DERR_INVALIDCALL;
359 if (Level < This->baseTexture.levels) {
360 hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags);
362 if (WINED3D_OK == hr) {
363 TRACE("(%p) Level (%d) success\n", This, Level);
364 } else {
365 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
368 return hr;
371 static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
372 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
373 HRESULT hr = WINED3DERR_INVALIDCALL;
375 if (Level < This->baseTexture.levels) {
376 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
378 if ( WINED3D_OK == hr) {
379 TRACE("(%p) Level (%d) success\n", This, Level);
380 } else {
381 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
383 return hr;
386 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
387 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
388 This->baseTexture.texture_rgb.dirty = TRUE;
389 This->baseTexture.texture_srgb.dirty = TRUE;
390 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
391 surface_add_dirty_rect(This->surfaces[0], pDirtyRect);
393 return WINED3D_OK;
396 static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
398 /* IUnknown */
399 IWineD3DTextureImpl_QueryInterface,
400 IWineD3DTextureImpl_AddRef,
401 IWineD3DTextureImpl_Release,
402 /* IWineD3DResource */
403 IWineD3DTextureImpl_GetParent,
404 IWineD3DTextureImpl_SetPrivateData,
405 IWineD3DTextureImpl_GetPrivateData,
406 IWineD3DTextureImpl_FreePrivateData,
407 IWineD3DTextureImpl_SetPriority,
408 IWineD3DTextureImpl_GetPriority,
409 IWineD3DTextureImpl_PreLoad,
410 IWineD3DTextureImpl_UnLoad,
411 IWineD3DTextureImpl_GetType,
412 /* IWineD3DBaseTexture */
413 IWineD3DTextureImpl_SetLOD,
414 IWineD3DTextureImpl_GetLOD,
415 IWineD3DTextureImpl_GetLevelCount,
416 IWineD3DTextureImpl_SetAutoGenFilterType,
417 IWineD3DTextureImpl_GetAutoGenFilterType,
418 IWineD3DTextureImpl_GenerateMipSubLevels,
419 IWineD3DTextureImpl_SetDirty,
420 IWineD3DTextureImpl_GetDirty,
421 IWineD3DTextureImpl_BindTexture,
422 IWineD3DTextureImpl_GetTextureDimensions,
423 IWineD3DTextureImpl_IsCondNP2,
424 /* IWineD3DTexture */
425 IWineD3DTextureImpl_GetLevelDesc,
426 IWineD3DTextureImpl_GetSurfaceLevel,
427 IWineD3DTextureImpl_LockRect,
428 IWineD3DTextureImpl_UnlockRect,
429 IWineD3DTextureImpl_AddDirtyRect
432 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
433 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
434 IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
436 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
437 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
438 UINT pow2_width, pow2_height;
439 UINT tmp_w, tmp_h;
440 unsigned int i;
441 HRESULT hr;
443 /* TODO: It should only be possible to create textures for formats
444 * that are reported as supported. */
445 if (WINED3DFMT_UNKNOWN >= format)
447 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
448 return WINED3DERR_INVALIDCALL;
451 /* Non-power2 support. */
452 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
454 pow2_width = width;
455 pow2_height = height;
457 else
459 /* Find the nearest pow2 match. */
460 pow2_width = pow2_height = 1;
461 while (pow2_width < width) pow2_width <<= 1;
462 while (pow2_height < height) pow2_height <<= 1;
464 if (pow2_width != width || pow2_height != height)
466 if (levels > 1)
468 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
469 return WINED3DERR_INVALIDCALL;
471 levels = 1;
475 /* Calculate levels for mip mapping. */
476 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
478 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
480 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
481 return WINED3DERR_INVALIDCALL;
484 if (levels > 1)
486 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
487 return WINED3DERR_INVALIDCALL;
490 levels = 1;
492 else if (!levels)
494 levels = wined3d_log2i(max(width, height)) + 1;
495 TRACE("Calculated levels = %u.\n", levels);
498 texture->lpVtbl = &IWineD3DTexture_Vtbl;
500 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
501 device, 0, usage, format_desc, pool, parent, parent_ops);
502 if (FAILED(hr))
504 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
505 return hr;
508 /* Precalculated scaling for 'faked' non power of two texture coords.
509 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
510 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
511 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
512 if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
514 texture->baseTexture.pow2Matrix[0] = 1.0f;
515 texture->baseTexture.pow2Matrix[5] = 1.0f;
516 texture->baseTexture.pow2Matrix[10] = 1.0f;
517 texture->baseTexture.pow2Matrix[15] = 1.0f;
518 texture->target = GL_TEXTURE_2D;
519 texture->cond_np2 = TRUE;
520 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
522 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
523 && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
524 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
526 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
528 texture->baseTexture.pow2Matrix[0] = (float)width;
529 texture->baseTexture.pow2Matrix[5] = (float)height;
530 texture->baseTexture.pow2Matrix[10] = 1.0f;
531 texture->baseTexture.pow2Matrix[15] = 1.0f;
532 texture->target = GL_TEXTURE_RECTANGLE_ARB;
533 texture->cond_np2 = TRUE;
535 if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
537 texture->baseTexture.minMipLookup = minMipLookup_noMip;
539 else
541 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
544 else
546 if ((width != pow2_width) || (height != pow2_height))
548 texture->baseTexture.pow2Matrix_identity = FALSE;
549 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
550 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
552 else
554 texture->baseTexture.pow2Matrix[0] = 1.0f;
555 texture->baseTexture.pow2Matrix[5] = 1.0f;
558 texture->baseTexture.pow2Matrix[10] = 1.0f;
559 texture->baseTexture.pow2Matrix[15] = 1.0f;
560 texture->target = GL_TEXTURE_2D;
561 texture->cond_np2 = FALSE;
563 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
565 /* Generate all the surfaces. */
566 tmp_w = width;
567 tmp_h = height;
568 for (i = 0; i < texture->baseTexture.levels; ++i)
570 /* Use the callback to create the texture surface. */
571 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
572 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
573 if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
575 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
576 texture->surfaces[i] = NULL;
577 texture_cleanup(texture);
578 return hr;
581 IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
582 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
583 surface_set_texture_target(texture->surfaces[i], texture->target);
584 /* Calculate the next mipmap level. */
585 tmp_w = max(1, tmp_w >> 1);
586 tmp_h = max(1, tmp_h >> 1);
588 texture->baseTexture.internal_preload = texture_internal_preload;
590 return WINED3D_OK;