d3d8: Properly retrieve an interface pointer in IDirect3DDevice8Impl_GetRenderTarget().
[wine] / dlls / d3d8 / texture.c
1 /*
2  * Copyright 2005 Oliver Stieber
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20 #include "d3d8_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
23
24 static inline struct d3d8_texture *impl_from_IDirect3DTexture8(IDirect3DTexture8 *iface)
25 {
26     return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
27 }
28
29 static inline struct d3d8_texture *impl_from_IDirect3DCubeTexture8(IDirect3DCubeTexture8 *iface)
30 {
31     return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
32 }
33
34 static inline struct d3d8_texture *impl_from_IDirect3DVolumeTexture8(IDirect3DVolumeTexture8 *iface)
35 {
36     return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
37 }
38
39 static HRESULT WINAPI d3d8_texture_2d_QueryInterface(IDirect3DTexture8 *iface, REFIID riid, void **out)
40 {
41     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
42
43     if (IsEqualGUID(riid, &IID_IDirect3DTexture8)
44             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
45             || IsEqualGUID(riid, &IID_IDirect3DResource8)
46             || IsEqualGUID(riid, &IID_IUnknown))
47     {
48         IUnknown_AddRef(iface);
49         *out = iface;
50         return S_OK;
51     }
52
53     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
54
55     *out = NULL;
56     return E_NOINTERFACE;
57 }
58
59 static ULONG WINAPI d3d8_texture_2d_AddRef(IDirect3DTexture8 *iface)
60 {
61     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
62     ULONG ref = InterlockedIncrement(&texture->refcount);
63
64     TRACE("%p increasing refcount to %u.\n", iface, ref);
65
66     if (ref == 1)
67     {
68         IDirect3DDevice8_AddRef(texture->parent_device);
69         wined3d_mutex_lock();
70         wined3d_texture_incref(texture->wined3d_texture);
71         wined3d_mutex_unlock();
72     }
73
74     return ref;
75 }
76
77 static ULONG WINAPI d3d8_texture_2d_Release(IDirect3DTexture8 *iface)
78 {
79     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
80     ULONG ref = InterlockedDecrement(&texture->refcount);
81
82     TRACE("%p decreasing refcount to %u.\n", iface, ref);
83
84     if (!ref)
85     {
86         IDirect3DDevice8 *parent_device = texture->parent_device;
87
88         wined3d_mutex_lock();
89         wined3d_texture_decref(texture->wined3d_texture);
90         wined3d_mutex_unlock();
91
92         /* Release the device last, as it may cause the device to be destroyed. */
93         IDirect3DDevice8_Release(parent_device);
94     }
95     return ref;
96 }
97
98 static HRESULT WINAPI d3d8_texture_2d_GetDevice(IDirect3DTexture8 *iface, IDirect3DDevice8 **device)
99 {
100     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
101
102     TRACE("iface %p, device %p.\n", iface, device);
103
104     *device = texture->parent_device;
105     IDirect3DDevice8_AddRef(*device);
106
107     TRACE("Returning device %p.\n", *device);
108
109     return D3D_OK;
110 }
111
112 static HRESULT WINAPI d3d8_texture_2d_SetPrivateData(IDirect3DTexture8 *iface,
113         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
114 {
115     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
116     struct wined3d_resource *resource;
117     HRESULT hr;
118
119     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
120             iface, debugstr_guid(guid), data, data_size, flags);
121
122     wined3d_mutex_lock();
123     resource = wined3d_texture_get_resource(texture->wined3d_texture);
124     hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
125     wined3d_mutex_unlock();
126
127     return hr;
128 }
129
130 static HRESULT WINAPI d3d8_texture_2d_GetPrivateData(IDirect3DTexture8 *iface,
131         REFGUID guid, void *data, DWORD *data_size)
132 {
133     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
134     struct wined3d_resource *resource;
135     HRESULT hr;
136
137     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
138             iface, debugstr_guid(guid), data, data_size);
139
140     wined3d_mutex_lock();
141     resource = wined3d_texture_get_resource(texture->wined3d_texture);
142     hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
143     wined3d_mutex_unlock();
144
145     return hr;
146 }
147
148 static HRESULT WINAPI d3d8_texture_2d_FreePrivateData(IDirect3DTexture8 *iface, REFGUID guid)
149 {
150     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
151     struct wined3d_resource *resource;
152     HRESULT hr;
153
154     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
155
156     wined3d_mutex_lock();
157     resource = wined3d_texture_get_resource(texture->wined3d_texture);
158     hr = wined3d_resource_free_private_data(resource, guid);
159     wined3d_mutex_unlock();
160
161     return hr;
162 }
163
164 static DWORD WINAPI d3d8_texture_2d_SetPriority(IDirect3DTexture8 *iface, DWORD priority)
165 {
166     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
167     DWORD ret;
168
169     TRACE("iface %p, priority %u.\n", iface, priority);
170
171     wined3d_mutex_lock();
172     ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
173     wined3d_mutex_unlock();
174
175     return ret;
176 }
177
178 static DWORD WINAPI d3d8_texture_2d_GetPriority(IDirect3DTexture8 *iface)
179 {
180     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
181     DWORD ret;
182
183     TRACE("iface %p.\n", iface);
184
185     wined3d_mutex_lock();
186     ret = wined3d_texture_get_priority(texture->wined3d_texture);
187     wined3d_mutex_unlock();
188
189     return ret;
190 }
191
192 static void WINAPI d3d8_texture_2d_PreLoad(IDirect3DTexture8 *iface)
193 {
194     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
195
196     TRACE("iface %p.\n", iface);
197
198     wined3d_mutex_lock();
199     wined3d_texture_preload(texture->wined3d_texture);
200     wined3d_mutex_unlock();
201 }
202
203 static D3DRESOURCETYPE WINAPI d3d8_texture_2d_GetType(IDirect3DTexture8 *iface)
204 {
205     TRACE("iface %p.\n", iface);
206
207     return D3DRTYPE_TEXTURE;
208 }
209
210 static DWORD WINAPI d3d8_texture_2d_SetLOD(IDirect3DTexture8 *iface, DWORD lod)
211 {
212     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
213     DWORD ret;
214
215     TRACE("iface %p, lod %u.\n", iface, lod);
216
217     wined3d_mutex_lock();
218     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
219     wined3d_mutex_unlock();
220
221     return ret;
222 }
223
224 static DWORD WINAPI d3d8_texture_2d_GetLOD(IDirect3DTexture8 *iface)
225 {
226     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
227     DWORD ret;
228
229     TRACE("iface %p.\n", iface);
230
231     wined3d_mutex_lock();
232     ret = wined3d_texture_get_lod(texture->wined3d_texture);
233     wined3d_mutex_unlock();
234
235     return ret;
236 }
237
238 static DWORD WINAPI d3d8_texture_2d_GetLevelCount(IDirect3DTexture8 *iface)
239 {
240     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
241     DWORD ret;
242
243     TRACE("iface %p.\n", iface);
244
245     wined3d_mutex_lock();
246     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
247     wined3d_mutex_unlock();
248
249     return ret;
250 }
251
252 static HRESULT WINAPI d3d8_texture_2d_GetLevelDesc(IDirect3DTexture8 *iface, UINT level, D3DSURFACE_DESC *desc)
253 {
254     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
255     struct wined3d_resource *sub_resource;
256     HRESULT hr = D3D_OK;
257
258     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
259
260     wined3d_mutex_lock();
261     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
262         hr = D3DERR_INVALIDCALL;
263     else
264     {
265         struct wined3d_resource_desc wined3d_desc;
266
267         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
268         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
269         desc->Type = wined3d_desc.resource_type;
270         desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
271         desc->Pool = wined3d_desc.pool;
272         desc->Size = wined3d_desc.size;
273         desc->MultiSampleType = wined3d_desc.multisample_type;
274         desc->Width = wined3d_desc.width;
275         desc->Height = wined3d_desc.height;
276     }
277     wined3d_mutex_unlock();
278
279     return hr;
280 }
281
282 static HRESULT WINAPI d3d8_texture_2d_GetSurfaceLevel(IDirect3DTexture8 *iface,
283         UINT level, IDirect3DSurface8 **surface)
284 {
285     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
286     struct wined3d_resource *sub_resource;
287     IDirect3DSurface8Impl *surface_impl;
288
289     TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
290
291     wined3d_mutex_lock();
292     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
293     {
294         wined3d_mutex_unlock();
295         return D3DERR_INVALIDCALL;
296     }
297
298     surface_impl = wined3d_resource_get_parent(sub_resource);
299     *surface = &surface_impl->IDirect3DSurface8_iface;
300     IDirect3DSurface8_AddRef(*surface);
301     wined3d_mutex_unlock();
302
303     return D3D_OK;
304 }
305
306 static HRESULT WINAPI d3d8_texture_2d_LockRect(IDirect3DTexture8 *iface, UINT level,
307         D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
308 {
309     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
310     struct wined3d_resource *sub_resource;
311     IDirect3DSurface8Impl *surface_impl;
312     HRESULT hr;
313
314     TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
315             iface, level, locked_rect, rect, flags);
316
317     wined3d_mutex_lock();
318     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
319         hr = D3DERR_INVALIDCALL;
320     else
321     {
322         surface_impl = wined3d_resource_get_parent(sub_resource);
323         hr = IDirect3DSurface8_LockRect(&surface_impl->IDirect3DSurface8_iface, locked_rect, rect, flags);
324     }
325     wined3d_mutex_unlock();
326
327     return hr;
328 }
329
330 static HRESULT WINAPI d3d8_texture_2d_UnlockRect(IDirect3DTexture8 *iface, UINT level)
331 {
332     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
333     struct wined3d_resource *sub_resource;
334     IDirect3DSurface8Impl *surface_impl;
335     HRESULT hr;
336
337     TRACE("iface %p, level %u.\n", iface, level);
338
339     wined3d_mutex_lock();
340     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
341         hr = D3DERR_INVALIDCALL;
342     else
343     {
344         surface_impl = wined3d_resource_get_parent(sub_resource);
345         hr = IDirect3DSurface8_UnlockRect(&surface_impl->IDirect3DSurface8_iface);
346     }
347     wined3d_mutex_unlock();
348
349     return hr;
350 }
351
352 static HRESULT WINAPI d3d8_texture_2d_AddDirtyRect(IDirect3DTexture8 *iface, const RECT *dirty_rect)
353 {
354     struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
355     HRESULT hr;
356
357     TRACE("iface %p, dirty_rect %s.\n",
358             iface, wine_dbgstr_rect(dirty_rect));
359
360     wined3d_mutex_lock();
361     if (!dirty_rect)
362         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
363     else
364     {
365         struct wined3d_box dirty_region;
366
367         dirty_region.left = dirty_rect->left;
368         dirty_region.top = dirty_rect->top;
369         dirty_region.right = dirty_rect->right;
370         dirty_region.bottom = dirty_rect->bottom;
371         dirty_region.front = 0;
372         dirty_region.back = 1;
373         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
374     }
375     wined3d_mutex_unlock();
376
377     return hr;
378 }
379
380 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
381 {
382     /* IUnknown */
383     d3d8_texture_2d_QueryInterface,
384     d3d8_texture_2d_AddRef,
385     d3d8_texture_2d_Release,
386     /* IDirect3DResource8 */
387     d3d8_texture_2d_GetDevice,
388     d3d8_texture_2d_SetPrivateData,
389     d3d8_texture_2d_GetPrivateData,
390     d3d8_texture_2d_FreePrivateData,
391     d3d8_texture_2d_SetPriority,
392     d3d8_texture_2d_GetPriority,
393     d3d8_texture_2d_PreLoad,
394     d3d8_texture_2d_GetType,
395     /* IDirect3dBaseTexture8 */
396     d3d8_texture_2d_SetLOD,
397     d3d8_texture_2d_GetLOD,
398     d3d8_texture_2d_GetLevelCount,
399     /* IDirect3DTexture8 */
400     d3d8_texture_2d_GetLevelDesc,
401     d3d8_texture_2d_GetSurfaceLevel,
402     d3d8_texture_2d_LockRect,
403     d3d8_texture_2d_UnlockRect,
404     d3d8_texture_2d_AddDirtyRect,
405 };
406
407 static HRESULT WINAPI d3d8_texture_cube_QueryInterface(IDirect3DCubeTexture8 *iface, REFIID riid, void **out)
408 {
409     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
410
411     if (IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)
412             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
413             || IsEqualGUID(riid, &IID_IDirect3DResource8)
414             || IsEqualGUID(riid, &IID_IUnknown))
415     {
416         IUnknown_AddRef(iface);
417         *out = iface;
418         return S_OK;
419     }
420
421     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
422
423     *out = NULL;
424     return E_NOINTERFACE;
425 }
426
427 static ULONG WINAPI d3d8_texture_cube_AddRef(IDirect3DCubeTexture8 *iface)
428 {
429     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
430     ULONG ref = InterlockedIncrement(&texture->refcount);
431
432     TRACE("%p increasing refcount to %u.\n", iface, ref);
433
434     if (ref == 1)
435     {
436         IUnknown_AddRef(texture->parent_device);
437         wined3d_mutex_lock();
438         wined3d_texture_incref(texture->wined3d_texture);
439         wined3d_mutex_unlock();
440     }
441
442     return ref;
443 }
444
445 static ULONG WINAPI d3d8_texture_cube_Release(IDirect3DCubeTexture8 *iface)
446 {
447     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
448     ULONG ref = InterlockedDecrement(&texture->refcount);
449
450     TRACE("%p decreasing refcount to %u.\n", iface, ref);
451
452     if (!ref)
453     {
454         IDirect3DDevice8 *parent_device = texture->parent_device;
455
456         TRACE("Releasing child %p.\n", texture->wined3d_texture);
457
458         wined3d_mutex_lock();
459         wined3d_texture_decref(texture->wined3d_texture);
460         wined3d_mutex_unlock();
461
462         /* Release the device last, as it may cause the device to be destroyed. */
463         IDirect3DDevice8_Release(parent_device);
464     }
465     return ref;
466 }
467
468 static HRESULT WINAPI d3d8_texture_cube_GetDevice(IDirect3DCubeTexture8 *iface, IDirect3DDevice8 **device)
469 {
470     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
471
472     TRACE("iface %p, device %p.\n", iface, device);
473
474     *device = texture->parent_device;
475     IDirect3DDevice8_AddRef(*device);
476
477     TRACE("Returning device %p.\n", *device);
478
479     return D3D_OK;
480 }
481
482 static HRESULT WINAPI d3d8_texture_cube_SetPrivateData(IDirect3DCubeTexture8 *iface,
483         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
484 {
485     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
486     struct wined3d_resource *resource;
487     HRESULT hr;
488
489     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
490             iface, debugstr_guid(guid), data, data_size, flags);
491
492     wined3d_mutex_lock();
493     resource = wined3d_texture_get_resource(texture->wined3d_texture);
494     hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
495     wined3d_mutex_unlock();
496
497     return hr;
498 }
499
500 static HRESULT WINAPI d3d8_texture_cube_GetPrivateData(IDirect3DCubeTexture8 *iface,
501         REFGUID guid, void *data, DWORD *data_size)
502 {
503     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
504     struct wined3d_resource *resource;
505     HRESULT hr;
506
507     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
508             iface, debugstr_guid(guid), data, data_size);
509
510     wined3d_mutex_lock();
511     resource = wined3d_texture_get_resource(texture->wined3d_texture);
512     hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
513     wined3d_mutex_unlock();
514
515     return hr;
516 }
517
518 static HRESULT WINAPI d3d8_texture_cube_FreePrivateData(IDirect3DCubeTexture8 *iface, REFGUID guid)
519 {
520     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
521     struct wined3d_resource *resource;
522     HRESULT hr;
523
524     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
525
526     wined3d_mutex_lock();
527     resource = wined3d_texture_get_resource(texture->wined3d_texture);
528     hr = wined3d_resource_free_private_data(resource, guid);
529     wined3d_mutex_unlock();
530
531     return hr;
532 }
533
534 static DWORD WINAPI d3d8_texture_cube_SetPriority(IDirect3DCubeTexture8 *iface, DWORD priority)
535 {
536     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
537     DWORD ret;
538
539     TRACE("iface %p, priority %u.\n", iface, priority);
540
541     wined3d_mutex_lock();
542     ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
543     wined3d_mutex_unlock();
544
545     return ret;
546 }
547
548 static DWORD WINAPI d3d8_texture_cube_GetPriority(IDirect3DCubeTexture8 *iface)
549 {
550     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
551     DWORD ret;
552
553     TRACE("iface %p.\n", iface);
554
555     wined3d_mutex_lock();
556     ret =  wined3d_texture_get_priority(texture->wined3d_texture);
557     wined3d_mutex_unlock();
558
559     return ret;
560 }
561
562 static void WINAPI d3d8_texture_cube_PreLoad(IDirect3DCubeTexture8 *iface)
563 {
564     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
565
566     TRACE("iface %p.\n", iface);
567
568     wined3d_mutex_lock();
569     wined3d_texture_preload(texture->wined3d_texture);
570     wined3d_mutex_unlock();
571 }
572
573 static D3DRESOURCETYPE WINAPI d3d8_texture_cube_GetType(IDirect3DCubeTexture8 *iface)
574 {
575     TRACE("iface %p.\n", iface);
576
577     return D3DRTYPE_CUBETEXTURE;
578 }
579
580 static DWORD WINAPI d3d8_texture_cube_SetLOD(IDirect3DCubeTexture8 *iface, DWORD lod)
581 {
582     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
583     DWORD ret;
584
585     TRACE("iface %p, lod %u.\n", iface, lod);
586
587     wined3d_mutex_lock();
588     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
589     wined3d_mutex_unlock();
590
591     return ret;
592 }
593
594 static DWORD WINAPI d3d8_texture_cube_GetLOD(IDirect3DCubeTexture8 *iface)
595 {
596     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
597     DWORD ret;
598
599     TRACE("iface %p.\n", iface);
600
601     wined3d_mutex_lock();
602     ret = wined3d_texture_get_lod(texture->wined3d_texture);
603     wined3d_mutex_unlock();
604
605     return ret;
606 }
607
608 static DWORD WINAPI d3d8_texture_cube_GetLevelCount(IDirect3DCubeTexture8 *iface)
609 {
610     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
611     DWORD ret;
612
613     TRACE("iface %p.\n", iface);
614
615     wined3d_mutex_lock();
616     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
617     wined3d_mutex_unlock();
618
619     return ret;
620 }
621
622 static HRESULT WINAPI d3d8_texture_cube_GetLevelDesc(IDirect3DCubeTexture8 *iface, UINT level, D3DSURFACE_DESC *desc)
623 {
624     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
625     struct wined3d_resource *sub_resource;
626     HRESULT hr = D3D_OK;
627
628     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
629
630     wined3d_mutex_lock();
631     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
632         hr = D3DERR_INVALIDCALL;
633     else
634     {
635         struct wined3d_resource_desc wined3d_desc;
636
637         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
638         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
639         desc->Type = wined3d_desc.resource_type;
640         desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
641         desc->Pool = wined3d_desc.pool;
642         desc->Size = wined3d_desc.size;
643         desc->MultiSampleType = wined3d_desc.multisample_type;
644         desc->Width = wined3d_desc.width;
645         desc->Height = wined3d_desc.height;
646     }
647     wined3d_mutex_unlock();
648
649     return hr;
650 }
651
652 static HRESULT WINAPI d3d8_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture8 *iface,
653         D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface8 **surface)
654 {
655     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
656     struct wined3d_resource *sub_resource;
657     IDirect3DSurface8Impl *surface_impl;
658     UINT sub_resource_idx;
659
660     TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
661
662     wined3d_mutex_lock();
663     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
664     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
665     {
666         wined3d_mutex_unlock();
667         return D3DERR_INVALIDCALL;
668     }
669
670     surface_impl = wined3d_resource_get_parent(sub_resource);
671     *surface = &surface_impl->IDirect3DSurface8_iface;
672     IDirect3DSurface8_AddRef(*surface);
673     wined3d_mutex_unlock();
674
675     return D3D_OK;
676 }
677
678 static HRESULT WINAPI d3d8_texture_cube_LockRect(IDirect3DCubeTexture8 *iface,
679         D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
680         DWORD flags)
681 {
682     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
683     struct wined3d_resource *sub_resource;
684     IDirect3DSurface8Impl *surface_impl;
685     UINT sub_resource_idx;
686     HRESULT hr;
687
688     TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
689             iface, face, level, locked_rect, rect, flags);
690
691     wined3d_mutex_lock();
692     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
693     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
694         hr = D3DERR_INVALIDCALL;
695     else
696     {
697         surface_impl = wined3d_resource_get_parent(sub_resource);
698         hr = IDirect3DSurface8_LockRect(&surface_impl->IDirect3DSurface8_iface, locked_rect, rect, flags);
699     }
700     wined3d_mutex_unlock();
701
702     return hr;
703 }
704
705 static HRESULT WINAPI d3d8_texture_cube_UnlockRect(IDirect3DCubeTexture8 *iface,
706         D3DCUBEMAP_FACES face, UINT level)
707 {
708     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
709     struct wined3d_resource *sub_resource;
710     IDirect3DSurface8Impl *surface_impl;
711     UINT sub_resource_idx;
712     HRESULT hr;
713
714     TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
715
716     wined3d_mutex_lock();
717     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
718     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
719         hr = D3DERR_INVALIDCALL;
720     else
721     {
722         surface_impl = wined3d_resource_get_parent(sub_resource);
723         hr = IDirect3DSurface8_UnlockRect(&surface_impl->IDirect3DSurface8_iface);
724     }
725     wined3d_mutex_unlock();
726
727     return hr;
728 }
729
730 static HRESULT WINAPI d3d8_texture_cube_AddDirtyRect(IDirect3DCubeTexture8 *iface,
731         D3DCUBEMAP_FACES face, const RECT *dirty_rect)
732 {
733     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
734     HRESULT hr;
735
736     TRACE("iface %p, face %#x, dirty_rect %s.\n",
737             iface, face, wine_dbgstr_rect(dirty_rect));
738
739     wined3d_mutex_lock();
740     if (!dirty_rect)
741         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
742     else
743     {
744         struct wined3d_box dirty_region;
745
746         dirty_region.left = dirty_rect->left;
747         dirty_region.top = dirty_rect->top;
748         dirty_region.right = dirty_rect->right;
749         dirty_region.bottom = dirty_rect->bottom;
750         dirty_region.front = 0;
751         dirty_region.back = 1;
752         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
753     }
754     wined3d_mutex_unlock();
755
756     return hr;
757 }
758
759 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
760 {
761     /* IUnknown */
762     d3d8_texture_cube_QueryInterface,
763     d3d8_texture_cube_AddRef,
764     d3d8_texture_cube_Release,
765     /* IDirect3DResource8 */
766     d3d8_texture_cube_GetDevice,
767     d3d8_texture_cube_SetPrivateData,
768     d3d8_texture_cube_GetPrivateData,
769     d3d8_texture_cube_FreePrivateData,
770     d3d8_texture_cube_SetPriority,
771     d3d8_texture_cube_GetPriority,
772     d3d8_texture_cube_PreLoad,
773     d3d8_texture_cube_GetType,
774     /* IDirect3DBaseTexture8 */
775     d3d8_texture_cube_SetLOD,
776     d3d8_texture_cube_GetLOD,
777     d3d8_texture_cube_GetLevelCount,
778     /* IDirect3DCubeTexture8 */
779     d3d8_texture_cube_GetLevelDesc,
780     d3d8_texture_cube_GetCubeMapSurface,
781     d3d8_texture_cube_LockRect,
782     d3d8_texture_cube_UnlockRect,
783     d3d8_texture_cube_AddDirtyRect,
784 };
785
786 static HRESULT WINAPI d3d8_texture_3d_QueryInterface(IDirect3DVolumeTexture8 *iface, REFIID riid, void **out)
787 {
788     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
789
790     if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)
791             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
792             || IsEqualGUID(riid, &IID_IDirect3DResource8)
793             || IsEqualGUID(riid, &IID_IUnknown))
794     {
795         IUnknown_AddRef(iface);
796         *out = iface;
797         return S_OK;
798     }
799
800     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
801
802     *out = NULL;
803     return E_NOINTERFACE;
804 }
805
806 static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface)
807 {
808     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
809     ULONG ref = InterlockedIncrement(&texture->refcount);
810
811     TRACE("%p increasing refcount to %u.\n", iface, ref);
812
813     if (ref == 1)
814     {
815         IDirect3DDevice8_AddRef(texture->parent_device);
816         wined3d_mutex_lock();
817         wined3d_texture_incref(texture->wined3d_texture);
818         wined3d_mutex_unlock();
819     }
820
821     return ref;
822 }
823
824 static ULONG WINAPI d3d8_texture_3d_Release(IDirect3DVolumeTexture8 *iface)
825 {
826     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
827     ULONG ref = InterlockedDecrement(&texture->refcount);
828
829     TRACE("%p decreasing refcount to %u.\n", iface, ref);
830
831     if (!ref)
832     {
833         IDirect3DDevice8 *parent_device = texture->parent_device;
834
835         wined3d_mutex_lock();
836         wined3d_texture_decref(texture->wined3d_texture);
837         wined3d_mutex_unlock();
838
839         /* Release the device last, as it may cause the device to be destroyed. */
840         IDirect3DDevice8_Release(parent_device);
841     }
842     return ref;
843 }
844
845 static HRESULT WINAPI d3d8_texture_3d_GetDevice(IDirect3DVolumeTexture8 *iface, IDirect3DDevice8 **device)
846 {
847     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
848
849     TRACE("iface %p, device %p.\n", iface, device);
850
851     *device = texture->parent_device;
852     IDirect3DDevice8_AddRef(*device);
853
854     TRACE("Returning device %p.\n", *device);
855
856     return D3D_OK;
857 }
858
859 static HRESULT WINAPI d3d8_texture_3d_SetPrivateData(IDirect3DVolumeTexture8 *iface,
860         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
861 {
862     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
863     struct wined3d_resource *resource;
864     HRESULT hr;
865
866     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
867             iface, debugstr_guid(guid), data, data_size, flags);
868
869     wined3d_mutex_lock();
870     resource = wined3d_texture_get_resource(texture->wined3d_texture);
871     hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
872     wined3d_mutex_unlock();
873
874     return hr;
875 }
876
877 static HRESULT WINAPI d3d8_texture_3d_GetPrivateData(IDirect3DVolumeTexture8 *iface,
878         REFGUID guid, void *data, DWORD *data_size)
879 {
880     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
881     struct wined3d_resource *resource;
882     HRESULT hr;
883
884     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
885             iface, debugstr_guid(guid), data, data_size);
886
887     wined3d_mutex_lock();
888     resource = wined3d_texture_get_resource(texture->wined3d_texture);
889     hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
890     wined3d_mutex_unlock();
891
892     return hr;
893 }
894
895 static HRESULT WINAPI d3d8_texture_3d_FreePrivateData(IDirect3DVolumeTexture8 *iface, REFGUID guid)
896 {
897     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
898     struct wined3d_resource *resource;
899     HRESULT hr;
900
901     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
902
903     wined3d_mutex_lock();
904     resource = wined3d_texture_get_resource(texture->wined3d_texture);
905     hr = wined3d_resource_free_private_data(resource, guid);
906     wined3d_mutex_unlock();
907
908     return hr;
909 }
910
911 static DWORD WINAPI d3d8_texture_3d_SetPriority(IDirect3DVolumeTexture8 *iface, DWORD priority)
912 {
913     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
914     DWORD ret;
915
916     TRACE("iface %p, priority %u.\n", iface, priority);
917
918     wined3d_mutex_lock();
919     ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
920     wined3d_mutex_unlock();
921
922     return ret;
923 }
924
925 static DWORD WINAPI d3d8_texture_3d_GetPriority(IDirect3DVolumeTexture8 *iface)
926 {
927     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
928     DWORD ret;
929
930     TRACE("iface %p.\n", iface);
931
932     wined3d_mutex_lock();
933     ret = wined3d_texture_get_priority(texture->wined3d_texture);
934     wined3d_mutex_unlock();
935
936     return ret;
937 }
938
939 static void WINAPI d3d8_texture_3d_PreLoad(IDirect3DVolumeTexture8 *iface)
940 {
941     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
942
943     TRACE("iface %p.\n", iface);
944
945     wined3d_mutex_lock();
946     wined3d_texture_preload(texture->wined3d_texture);
947     wined3d_mutex_unlock();
948 }
949
950 static D3DRESOURCETYPE WINAPI d3d8_texture_3d_GetType(IDirect3DVolumeTexture8 *iface)
951 {
952     TRACE("iface %p.\n", iface);
953
954     return D3DRTYPE_VOLUMETEXTURE;
955 }
956
957 static DWORD WINAPI d3d8_texture_3d_SetLOD(IDirect3DVolumeTexture8 *iface, DWORD lod)
958 {
959     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
960     DWORD ret;
961
962     TRACE("iface %p, lod %u.\n", iface, lod);
963
964     wined3d_mutex_lock();
965     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
966     wined3d_mutex_unlock();
967
968     return ret;
969 }
970
971 static DWORD WINAPI d3d8_texture_3d_GetLOD(IDirect3DVolumeTexture8 *iface)
972 {
973     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
974     DWORD ret;
975
976     TRACE("iface %p.\n", iface);
977
978     wined3d_mutex_lock();
979     ret = wined3d_texture_get_lod(texture->wined3d_texture);
980     wined3d_mutex_unlock();
981
982     return ret;
983 }
984
985 static DWORD WINAPI d3d8_texture_3d_GetLevelCount(IDirect3DVolumeTexture8 *iface)
986 {
987     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
988     DWORD ret;
989
990     TRACE("iface %p.\n", iface);
991
992     wined3d_mutex_lock();
993     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
994     wined3d_mutex_unlock();
995
996     return ret;
997 }
998
999 static HRESULT WINAPI d3d8_texture_3d_GetLevelDesc(IDirect3DVolumeTexture8 *iface, UINT level, D3DVOLUME_DESC *desc)
1000 {
1001     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1002     struct wined3d_resource *sub_resource;
1003     HRESULT hr = D3D_OK;
1004
1005     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
1006
1007     wined3d_mutex_lock();
1008     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1009         hr = D3DERR_INVALIDCALL;
1010     else
1011     {
1012         struct wined3d_resource_desc wined3d_desc;
1013
1014         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
1015         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
1016         desc->Type = wined3d_desc.resource_type;
1017         desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
1018         desc->Pool = wined3d_desc.pool;
1019         desc->Size = wined3d_desc.size;
1020         desc->Width = wined3d_desc.width;
1021         desc->Height = wined3d_desc.height;
1022         desc->Depth = wined3d_desc.depth;
1023     }
1024     wined3d_mutex_unlock();
1025
1026     return hr;
1027 }
1028
1029 static HRESULT WINAPI d3d8_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture8 *iface,
1030         UINT level, IDirect3DVolume8 **volume)
1031 {
1032     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1033     struct wined3d_resource *sub_resource;
1034     IDirect3DVolume8Impl *volume_impl;
1035
1036     TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
1037
1038     wined3d_mutex_lock();
1039     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1040     {
1041         wined3d_mutex_unlock();
1042         return D3DERR_INVALIDCALL;
1043     }
1044
1045     volume_impl = wined3d_resource_get_parent(sub_resource);
1046     *volume = &volume_impl->IDirect3DVolume8_iface;
1047     IDirect3DVolume8_AddRef(*volume);
1048     wined3d_mutex_unlock();
1049
1050     return D3D_OK;
1051 }
1052
1053 static HRESULT WINAPI d3d8_texture_3d_LockBox(IDirect3DVolumeTexture8 *iface,
1054         UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
1055 {
1056     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1057     struct wined3d_resource *sub_resource;
1058     IDirect3DVolume8Impl *volume_impl;
1059     HRESULT hr;
1060
1061     TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1062             iface, level, locked_box, box, flags);
1063
1064     wined3d_mutex_lock();
1065     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1066         hr = D3DERR_INVALIDCALL;
1067     else
1068     {
1069         volume_impl = wined3d_resource_get_parent(sub_resource);
1070         hr = IDirect3DVolume8_LockBox(&volume_impl->IDirect3DVolume8_iface, locked_box, box, flags);
1071     }
1072     wined3d_mutex_unlock();
1073
1074     return hr;
1075 }
1076
1077 static HRESULT WINAPI d3d8_texture_3d_UnlockBox(IDirect3DVolumeTexture8 *iface, UINT level)
1078 {
1079     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1080     struct wined3d_resource *sub_resource;
1081     IDirect3DVolume8Impl *volume_impl;
1082     HRESULT hr;
1083
1084     TRACE("iface %p, level %u.\n", iface, level);
1085
1086     wined3d_mutex_lock();
1087     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1088         hr = D3DERR_INVALIDCALL;
1089     else
1090     {
1091         volume_impl = wined3d_resource_get_parent(sub_resource);
1092         hr = IDirect3DVolume8_UnlockBox(&volume_impl->IDirect3DVolume8_iface);
1093     }
1094     wined3d_mutex_unlock();
1095
1096     return hr;
1097 }
1098
1099 static HRESULT WINAPI d3d8_texture_3d_AddDirtyBox(IDirect3DVolumeTexture8 *iface, const D3DBOX *dirty_box)
1100 {
1101     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1102     HRESULT hr;
1103
1104     TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
1105
1106     wined3d_mutex_lock();
1107     hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
1108     wined3d_mutex_unlock();
1109
1110     return hr;
1111 }
1112
1113 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
1114 {
1115     /* IUnknown */
1116     d3d8_texture_3d_QueryInterface,
1117     d3d8_texture_3d_AddRef,
1118     d3d8_texture_3d_Release,
1119     /* IDirect3DResource8 */
1120     d3d8_texture_3d_GetDevice,
1121     d3d8_texture_3d_SetPrivateData,
1122     d3d8_texture_3d_GetPrivateData,
1123     d3d8_texture_3d_FreePrivateData,
1124     d3d8_texture_3d_SetPriority,
1125     d3d8_texture_3d_GetPriority,
1126     d3d8_texture_3d_PreLoad,
1127     d3d8_texture_3d_GetType,
1128     /* IDirect3DBaseTexture8 */
1129     d3d8_texture_3d_SetLOD,
1130     d3d8_texture_3d_GetLOD,
1131     d3d8_texture_3d_GetLevelCount,
1132     /* IDirect3DVolumeTexture8 */
1133     d3d8_texture_3d_GetLevelDesc,
1134     d3d8_texture_3d_GetVolumeLevel,
1135     d3d8_texture_3d_LockBox,
1136     d3d8_texture_3d_UnlockBox,
1137     d3d8_texture_3d_AddDirtyBox
1138 };
1139
1140 struct d3d8_texture *unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture8 *iface)
1141 {
1142     if (!iface)
1143         return NULL;
1144     assert(iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl
1145             || iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl
1146             || iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl);
1147     return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
1148 }
1149
1150 static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
1151 {
1152     HeapFree(GetProcessHeap(), 0, parent);
1153 }
1154
1155 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
1156 {
1157     d3d8_texture_wined3d_object_destroyed,
1158 };
1159
1160 HRESULT texture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
1161         UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1162 {
1163     HRESULT hr;
1164
1165     texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl;
1166     texture->refcount = 1;
1167
1168     wined3d_mutex_lock();
1169     hr = wined3d_texture_create_2d(device->wined3d_device, width, height, levels,
1170             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
1171             texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1172     wined3d_mutex_unlock();
1173     if (FAILED(hr))
1174     {
1175         WARN("Failed to create wined3d texture, hr %#x.\n", hr);
1176         return hr;
1177     }
1178
1179     texture->parent_device = &device->IDirect3DDevice8_iface;
1180     IDirect3DDevice8_AddRef(texture->parent_device);
1181
1182     return D3D_OK;
1183 }
1184
1185 HRESULT cubetexture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
1186         UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1187 {
1188     HRESULT hr;
1189
1190     texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl;
1191     texture->refcount = 1;
1192
1193     wined3d_mutex_lock();
1194     hr = wined3d_texture_create_cube(device->wined3d_device, edge_length, levels,
1195             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
1196             &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1197     wined3d_mutex_unlock();
1198     if (FAILED(hr))
1199     {
1200         WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
1201         return hr;
1202     }
1203
1204     texture->parent_device = &device->IDirect3DDevice8_iface;
1205     IDirect3DDevice8_AddRef(texture->parent_device);
1206
1207     return D3D_OK;
1208 }
1209
1210 HRESULT volumetexture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
1211         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1212 {
1213     HRESULT hr;
1214
1215     texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl;
1216     texture->refcount = 1;
1217
1218     wined3d_mutex_lock();
1219     hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels,
1220             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
1221             &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1222     wined3d_mutex_unlock();
1223     if (FAILED(hr))
1224     {
1225         WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
1226         return hr;
1227     }
1228
1229     texture->parent_device = &device->IDirect3DDevice8_iface;
1230     IDirect3DDevice8_AddRef(texture->parent_device);
1231
1232     return D3D_OK;
1233 }