windowscodecs/tests: Make sure returns values are used (LLVM/Clang).
[wine] / dlls / wined3d / cubetexture.c
1 /*
2  * IWineD3DCubeTexture implementation
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26 #include "wined3d_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
29
30 /* Context activation is done by the caller. */
31 static HRESULT cubetexture_bind(IWineD3DBaseTextureImpl *texture, BOOL srgb)
32 {
33     BOOL set_gl_texture_desc;
34     HRESULT hr;
35
36     TRACE("texture %p, srgb %#x.\n", texture, srgb);
37
38     hr = basetexture_bind(texture, srgb, &set_gl_texture_desc);
39     if (set_gl_texture_desc && SUCCEEDED(hr))
40     {
41         UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
42         UINT i;
43
44         for (i = 0; i < sub_count; ++i)
45         {
46             IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[i];
47
48             if (texture->baseTexture.is_srgb)
49                 surface_set_texture_name(surface, texture->baseTexture.texture_srgb.name, TRUE);
50             else
51                 surface_set_texture_name(surface, texture->baseTexture.texture_rgb.name, FALSE);
52         }
53     }
54
55     return hr;
56 }
57
58 /* Do not call while under the GL lock. */
59 static void cubetexture_preload(IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb)
60 {
61     UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
62     IWineD3DDeviceImpl *device = texture->resource.device;
63     struct wined3d_context *context = NULL;
64     BOOL srgb_mode;
65     BOOL *dirty;
66     UINT i;
67
68     TRACE("texture %p, srgb %#x.\n", texture, srgb);
69
70     switch (srgb)
71     {
72         case SRGB_RGB:
73             srgb_mode = FALSE;
74             break;
75
76         case SRGB_BOTH:
77             cubetexture_preload(texture, SRGB_RGB);
78             /* Fallthrough */
79
80         case SRGB_SRGB:
81             srgb_mode = TRUE;
82             break;
83
84         default:
85             srgb_mode = texture->baseTexture.is_srgb;
86             break;
87     }
88     dirty = srgb_mode ? &texture->baseTexture.texture_srgb.dirty : &texture->baseTexture.texture_rgb.dirty;
89
90     /* We only have to activate a context for gl when we're not drawing.
91      * In most cases PreLoad will be called during draw and a context was
92      * activated at the beginning of drawPrimitive. */
93     if (!device->isInDraw)
94     {
95         /* No danger of recursive calls, context_acquire() sets isInDraw to true
96          * when loading offscreen render targets into their texture. */
97         context = context_acquire(device, NULL);
98     }
99
100     if (texture->resource.format->id == WINED3DFMT_P8_UINT
101             || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
102     {
103         for (i = 0; i < sub_count; ++i)
104         {
105             IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[i];
106
107             if (palette9_changed(surface))
108             {
109                 TRACE("Reloading surface %p because the d3d8/9 palette was changed.\n", surface);
110                 /* TODO: This is not necessarily needed with hw palettized texture support. */
111                 surface_load_location(surface, SFLAG_INSYSMEM, NULL);
112                 /* Make sure the texture is reloaded because of the palette change,
113                  * this kills performance though :( */
114                 surface_modify_location(surface, SFLAG_INTEXTURE, FALSE);
115             }
116         }
117     }
118
119     /* If the texture is marked dirty or the srgb sampler setting has changed
120      * since the last load then reload the surfaces. */
121     if (*dirty)
122     {
123         for (i = 0; i < sub_count; ++i)
124         {
125             surface_load((IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[i], srgb_mode);
126         }
127     }
128     else
129     {
130         TRACE("Texture %p not dirty, nothing to do.\n" , texture);
131     }
132
133     /* No longer dirty. */
134     *dirty = FALSE;
135
136     if (context) context_release(context);
137 }
138
139 static const struct wined3d_texture_ops cubetexture_ops =
140 {
141     cubetexture_bind,
142     cubetexture_preload,
143 };
144
145 static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This)
146 {
147     UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
148     UINT i;
149
150     TRACE("(%p) : Cleaning up.\n", This);
151
152     for (i = 0; i < sub_count; ++i)
153     {
154         IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
155
156         if (surface)
157         {
158             /* Clean out the texture name we gave to the surface so that the
159              * surface doesn't try and release it. */
160             surface_set_texture_name(surface, 0, TRUE);
161             surface_set_texture_name(surface, 0, FALSE);
162             surface_set_texture_target(surface, 0);
163             surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
164             IWineD3DSurface_Release((IWineD3DSurface *)surface);
165         }
166     }
167     basetexture_cleanup((IWineD3DBaseTextureImpl *)This);
168 }
169
170 /* *******************************************
171    IWineD3DCubeTexture IUnknown parts follow
172    ******************************************* */
173
174 static HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DCubeTexture *iface, REFIID riid, LPVOID *ppobj)
175 {
176     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
177     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
178     if (IsEqualGUID(riid, &IID_IUnknown)
179         || IsEqualGUID(riid, &IID_IWineD3DBase)
180         || IsEqualGUID(riid, &IID_IWineD3DResource)
181         || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
182         || IsEqualGUID(riid, &IID_IWineD3DCubeTexture)) {
183         IUnknown_AddRef(iface);
184         *ppobj = This;
185         return S_OK;
186     }
187     *ppobj = NULL;
188     return E_NOINTERFACE;
189 }
190
191 static ULONG WINAPI IWineD3DCubeTextureImpl_AddRef(IWineD3DCubeTexture *iface) {
192     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
193     TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
194     return InterlockedIncrement(&This->resource.ref);
195 }
196
197 /* Do not call while under the GL lock. */
198 static ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DCubeTexture *iface) {
199     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
200     ULONG ref;
201     TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
202     ref = InterlockedDecrement(&This->resource.ref);
203     if (!ref)
204     {
205         cubetexture_cleanup(This);
206         This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
207         HeapFree(GetProcessHeap(), 0, This);
208     }
209     return ref;
210 }
211
212 /* ****************************************************
213    IWineD3DCubeTexture IWineD3DResource parts follow
214    **************************************************** */
215 static HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface,
216         REFGUID riid, const void *data, DWORD data_size, DWORD flags)
217 {
218     return resource_set_private_data((IWineD3DResourceImpl *)iface, riid, data, data_size, flags);
219 }
220
221 static HRESULT WINAPI IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture *iface,
222         REFGUID guid, void *data, DWORD *data_size)
223 {
224     return resource_get_private_data((IWineD3DResourceImpl *)iface, guid, data, data_size);
225 }
226
227 static HRESULT WINAPI IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture *iface, REFGUID refguid)
228 {
229     return resource_free_private_data((IWineD3DResourceImpl *)iface, refguid);
230 }
231
232 static DWORD WINAPI IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture *iface, DWORD priority)
233 {
234     return resource_set_priority((IWineD3DResourceImpl *)iface, priority);
235 }
236
237 static DWORD WINAPI IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture *iface)
238 {
239     return resource_get_priority((IWineD3DResourceImpl *)iface);
240 }
241
242 /* Do not call while under the GL lock. */
243 static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface)
244 {
245     cubetexture_preload((IWineD3DBaseTextureImpl *)iface, SRGB_ANY);
246 }
247
248 /* Do not call while under the GL lock. */
249 static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface)
250 {
251     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
252     UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
253     UINT i;
254
255     TRACE("iface %p.\n", iface);
256
257     /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
258      * surface before, this one will be a NOP and vice versa. Unloading an unloaded
259      * surface is fine. */
260
261     for (i = 0; i < sub_count; ++i)
262     {
263         IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
264
265         IWineD3DSurface_UnLoad((IWineD3DSurface *)surface);
266         surface_set_texture_name(surface, 0, TRUE);
267         surface_set_texture_name(surface, 0, FALSE);
268     }
269
270     basetexture_unload((IWineD3DBaseTextureImpl *)This);
271 }
272
273 static WINED3DRESOURCETYPE WINAPI IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture *iface)
274 {
275     return resource_get_type((IWineD3DResourceImpl *)iface);
276 }
277
278 static void * WINAPI IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture *iface)
279 {
280     TRACE("iface %p.\n", iface);
281
282     return ((IWineD3DCubeTextureImpl *)iface)->resource.parent;
283 }
284
285 /* ******************************************************
286    IWineD3DCubeTexture IWineD3DBaseTexture parts follow
287    ****************************************************** */
288 static DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
289     return basetexture_set_lod((IWineD3DBaseTextureImpl *)iface, LODNew);
290 }
291
292 static DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
293     return basetexture_get_lod((IWineD3DBaseTextureImpl *)iface);
294 }
295
296 static DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface)
297 {
298     return basetexture_get_level_count((IWineD3DBaseTextureImpl *)iface);
299 }
300
301 static HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface,
302         WINED3DTEXTUREFILTERTYPE FilterType)
303 {
304   return basetexture_set_autogen_filter_type((IWineD3DBaseTextureImpl *)iface, FilterType);
305 }
306
307 static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface)
308 {
309   return basetexture_get_autogen_filter_type((IWineD3DBaseTextureImpl *)iface);
310 }
311
312 static void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface)
313 {
314     basetexture_generate_mipmaps((IWineD3DBaseTextureImpl *)iface);
315 }
316
317 static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
318 {
319     TRACE("iface %p.\n", iface);
320
321     return FALSE;
322 }
323
324 static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface,
325         UINT sub_resource_idx, WINED3DSURFACE_DESC *desc)
326 {
327     IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
328     IWineD3DSurface *surface;
329
330     TRACE("iface %p, sub_resource_idx %u, desc %p.\n", iface, sub_resource_idx, desc);
331
332     if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
333     {
334         WARN("Failed to get sub-resource.\n");
335         return WINED3DERR_INVALIDCALL;
336     }
337
338     IWineD3DSurface_GetDesc(surface, desc);
339
340     return WINED3D_OK;
341 }
342
343 static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface,
344         UINT sub_resource_idx, IWineD3DSurface **surface)
345 {
346     IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
347     IWineD3DSurface *s;
348
349     TRACE("iface %p, sub_resource_idx %u, surface %p.\n",
350             iface, sub_resource_idx, surface);
351
352     if (!(s = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
353     {
354         WARN("Failed to get sub-resource.\n");
355         return WINED3DERR_INVALIDCALL;
356     }
357
358     IWineD3DSurface_AddRef(s);
359     *surface = s;
360
361     TRACE("Returning surface %p.\n", *surface);
362
363     return WINED3D_OK;
364 }
365
366 static HRESULT WINAPI IWineD3DCubeTextureImpl_Map(IWineD3DCubeTexture *iface,
367         UINT sub_resource_idx, WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
368 {
369     IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
370     IWineD3DSurface *surface;
371
372     TRACE("iface %p, sub_resource_idx %u, locked_rect %p, rect %s, flags %#x.\n",
373             iface, sub_resource_idx, locked_rect, wine_dbgstr_rect(rect), flags);
374
375     if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
376     {
377         WARN("Failed to get sub-resource.\n");
378         return WINED3DERR_INVALIDCALL;
379     }
380
381     return IWineD3DSurface_Map(surface, locked_rect, rect, flags);
382 }
383
384 static HRESULT WINAPI IWineD3DCubeTextureImpl_Unmap(IWineD3DCubeTexture *iface,
385         UINT sub_resource_idx)
386 {
387     IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
388     IWineD3DSurface *surface;
389
390     TRACE("iface %p, sub_resource_idx %u.\n",
391             iface, sub_resource_idx);
392
393     if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx)))
394     {
395         WARN("Failed to get sub-resource.\n");
396         return WINED3DERR_INVALIDCALL;
397     }
398
399     return IWineD3DSurface_Unmap(surface);
400 }
401
402 static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface,
403         WINED3DCUBEMAP_FACES face, const RECT *dirty_rect)
404 {
405     IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
406     UINT sub_resource_idx = face * texture->baseTexture.level_count;
407     IWineD3DSurfaceImpl *surface;
408
409     TRACE("iface %p, face %u, dirty_rect %s.\n",
410             iface, face, wine_dbgstr_rect(dirty_rect));
411
412     if (!(surface = (IWineD3DSurfaceImpl *)basetexture_get_sub_resource(texture, sub_resource_idx)))
413     {
414         WARN("Failed to get sub-resource.\n");
415         return WINED3DERR_INVALIDCALL;
416     }
417
418     texture->baseTexture.texture_rgb.dirty = TRUE;
419     texture->baseTexture.texture_srgb.dirty = TRUE;
420     surface_add_dirty_rect(surface, dirty_rect);
421
422     return WINED3D_OK;
423 }
424
425 static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
426 {
427     /* IUnknown */
428     IWineD3DCubeTextureImpl_QueryInterface,
429     IWineD3DCubeTextureImpl_AddRef,
430     IWineD3DCubeTextureImpl_Release,
431     /* IWineD3DResource */
432     IWineD3DCubeTextureImpl_GetParent,
433     IWineD3DCubeTextureImpl_SetPrivateData,
434     IWineD3DCubeTextureImpl_GetPrivateData,
435     IWineD3DCubeTextureImpl_FreePrivateData,
436     IWineD3DCubeTextureImpl_SetPriority,
437     IWineD3DCubeTextureImpl_GetPriority,
438     IWineD3DCubeTextureImpl_PreLoad,
439     IWineD3DCubeTextureImpl_UnLoad,
440     IWineD3DCubeTextureImpl_GetType,
441     /* IWineD3DBaseTexture */
442     IWineD3DCubeTextureImpl_SetLOD,
443     IWineD3DCubeTextureImpl_GetLOD,
444     IWineD3DCubeTextureImpl_GetLevelCount,
445     IWineD3DCubeTextureImpl_SetAutoGenFilterType,
446     IWineD3DCubeTextureImpl_GetAutoGenFilterType,
447     IWineD3DCubeTextureImpl_GenerateMipSubLevels,
448     IWineD3DCubeTextureImpl_IsCondNP2,
449     /* IWineD3DCubeTexture */
450     IWineD3DCubeTextureImpl_GetLevelDesc,
451     IWineD3DCubeTextureImpl_GetCubeMapSurface,
452     IWineD3DCubeTextureImpl_Map,
453     IWineD3DCubeTextureImpl_Unmap,
454     IWineD3DCubeTextureImpl_AddDirtyRect
455 };
456
457 HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
458         IWineD3DDeviceImpl *device, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool,
459         void *parent, const struct wined3d_parent_ops *parent_ops)
460 {
461     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
462     const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
463     UINT pow2_edge_length;
464     unsigned int i, j;
465     UINT tmp_w;
466     HRESULT hr;
467
468     /* TODO: It should only be possible to create textures for formats
469      * that are reported as supported. */
470     if (WINED3DFMT_UNKNOWN >= format_id)
471     {
472         WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
473         return WINED3DERR_INVALIDCALL;
474     }
475
476     if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH)
477     {
478         WARN("(%p) : Tried to create not supported cube texture.\n", texture);
479         return WINED3DERR_INVALIDCALL;
480     }
481
482     /* Calculate levels for mip mapping */
483     if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
484     {
485         if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
486         {
487             WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
488             return WINED3DERR_INVALIDCALL;
489         }
490
491         if (levels > 1)
492         {
493             WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
494             return WINED3DERR_INVALIDCALL;
495         }
496
497         levels = 1;
498     }
499     else if (!levels)
500     {
501         levels = wined3d_log2i(edge_length) + 1;
502         TRACE("Calculated levels = %u.\n", levels);
503     }
504
505     texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
506
507     hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, &cubetexture_ops,
508             6, levels, WINED3DRTYPE_CUBETEXTURE, device, usage, format, pool,
509             parent, parent_ops);
510     if (FAILED(hr))
511     {
512         WARN("Failed to initialize basetexture, returning %#x\n", hr);
513         return hr;
514     }
515
516     /* Find the nearest pow2 match. */
517     pow2_edge_length = 1;
518     while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
519
520     if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || (edge_length == pow2_edge_length))
521     {
522         /* Precalculated scaling for 'faked' non power of two texture coords. */
523         texture->baseTexture.pow2Matrix[0] = 1.0f;
524         texture->baseTexture.pow2Matrix[5] = 1.0f;
525         texture->baseTexture.pow2Matrix[10] = 1.0f;
526         texture->baseTexture.pow2Matrix[15] = 1.0f;
527     }
528     else
529     {
530         /* Precalculated scaling for 'faked' non power of two texture coords. */
531         texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
532         texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
533         texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
534         texture->baseTexture.pow2Matrix[15] = 1.0f;
535         texture->baseTexture.pow2Matrix_identity = FALSE;
536     }
537     texture->baseTexture.target = GL_TEXTURE_CUBE_MAP_ARB;
538
539     /* Generate all the surfaces. */
540     tmp_w = edge_length;
541     for (i = 0; i < texture->baseTexture.level_count; ++i)
542     {
543         /* Create the 6 faces. */
544         for (j = 0; j < 6; ++j)
545         {
546             static const GLenum cube_targets[6] =
547             {
548                 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
549                 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
550                 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
551                 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
552                 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
553                 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
554             };
555             UINT idx = j * texture->baseTexture.level_count + i;
556             IWineD3DSurface *surface;
557
558             hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
559                     format_id, usage, pool, i /* Level */, j, &surface);
560             if (FAILED(hr))
561             {
562                 FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
563                 cubetexture_cleanup(texture);
564                 return hr;
565             }
566
567             surface_set_container((IWineD3DSurfaceImpl *)surface, WINED3D_CONTAINER_TEXTURE, (IWineD3DBase *)texture);
568             surface_set_texture_target((IWineD3DSurfaceImpl *)surface, cube_targets[j]);
569             texture->baseTexture.sub_resources[idx] = (IWineD3DResourceImpl *)surface;
570             TRACE("Created surface level %u @ %p.\n", i, surface);
571         }
572         tmp_w = max(1, tmp_w >> 1);
573     }
574
575     return WINED3D_OK;
576 }