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