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