winemac: Don't bring a window onto the screen in SetFocus().
[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         IDirect3DTexture8_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     struct d3d8_surface *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     struct d3d8_surface *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     struct d3d8_surface *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         IDirect3DCubeTexture8_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         IDirect3DDevice8_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 (level >= wined3d_texture_get_level_count(texture->wined3d_texture))
632     {
633         wined3d_mutex_unlock();
634         return D3DERR_INVALIDCALL;
635     }
636
637     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
638         hr = D3DERR_INVALIDCALL;
639     else
640     {
641         struct wined3d_resource_desc wined3d_desc;
642
643         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
644         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
645         desc->Type = wined3d_desc.resource_type;
646         desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
647         desc->Pool = wined3d_desc.pool;
648         desc->Size = wined3d_desc.size;
649         desc->MultiSampleType = wined3d_desc.multisample_type;
650         desc->Width = wined3d_desc.width;
651         desc->Height = wined3d_desc.height;
652     }
653     wined3d_mutex_unlock();
654
655     return hr;
656 }
657
658 static HRESULT WINAPI d3d8_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture8 *iface,
659         D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface8 **surface)
660 {
661     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
662     struct wined3d_resource *sub_resource;
663     struct d3d8_surface *surface_impl;
664     UINT sub_resource_idx;
665     DWORD level_count;
666
667     TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
668
669     wined3d_mutex_lock();
670     level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
671     if (level >= level_count)
672     {
673         wined3d_mutex_unlock();
674         return D3DERR_INVALIDCALL;
675     }
676
677     sub_resource_idx = level_count * face + level;
678     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
679     {
680         wined3d_mutex_unlock();
681         return D3DERR_INVALIDCALL;
682     }
683
684     surface_impl = wined3d_resource_get_parent(sub_resource);
685     *surface = &surface_impl->IDirect3DSurface8_iface;
686     IDirect3DSurface8_AddRef(*surface);
687     wined3d_mutex_unlock();
688
689     return D3D_OK;
690 }
691
692 static HRESULT WINAPI d3d8_texture_cube_LockRect(IDirect3DCubeTexture8 *iface,
693         D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
694         DWORD flags)
695 {
696     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
697     struct wined3d_resource *sub_resource;
698     struct d3d8_surface *surface_impl;
699     UINT sub_resource_idx;
700     HRESULT hr;
701
702     TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
703             iface, face, level, locked_rect, rect, flags);
704
705     wined3d_mutex_lock();
706     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
707     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
708         hr = D3DERR_INVALIDCALL;
709     else
710     {
711         surface_impl = wined3d_resource_get_parent(sub_resource);
712         hr = IDirect3DSurface8_LockRect(&surface_impl->IDirect3DSurface8_iface, locked_rect, rect, flags);
713     }
714     wined3d_mutex_unlock();
715
716     return hr;
717 }
718
719 static HRESULT WINAPI d3d8_texture_cube_UnlockRect(IDirect3DCubeTexture8 *iface,
720         D3DCUBEMAP_FACES face, UINT level)
721 {
722     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
723     struct wined3d_resource *sub_resource;
724     struct d3d8_surface *surface_impl;
725     UINT sub_resource_idx;
726     HRESULT hr;
727
728     TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
729
730     wined3d_mutex_lock();
731     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
732     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
733         hr = D3DERR_INVALIDCALL;
734     else
735     {
736         surface_impl = wined3d_resource_get_parent(sub_resource);
737         hr = IDirect3DSurface8_UnlockRect(&surface_impl->IDirect3DSurface8_iface);
738     }
739     wined3d_mutex_unlock();
740
741     return hr;
742 }
743
744 static HRESULT WINAPI d3d8_texture_cube_AddDirtyRect(IDirect3DCubeTexture8 *iface,
745         D3DCUBEMAP_FACES face, const RECT *dirty_rect)
746 {
747     struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
748     HRESULT hr;
749
750     TRACE("iface %p, face %#x, dirty_rect %s.\n",
751             iface, face, wine_dbgstr_rect(dirty_rect));
752
753     wined3d_mutex_lock();
754     if (!dirty_rect)
755         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
756     else
757     {
758         struct wined3d_box dirty_region;
759
760         dirty_region.left = dirty_rect->left;
761         dirty_region.top = dirty_rect->top;
762         dirty_region.right = dirty_rect->right;
763         dirty_region.bottom = dirty_rect->bottom;
764         dirty_region.front = 0;
765         dirty_region.back = 1;
766         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
767     }
768     wined3d_mutex_unlock();
769
770     return hr;
771 }
772
773 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
774 {
775     /* IUnknown */
776     d3d8_texture_cube_QueryInterface,
777     d3d8_texture_cube_AddRef,
778     d3d8_texture_cube_Release,
779     /* IDirect3DResource8 */
780     d3d8_texture_cube_GetDevice,
781     d3d8_texture_cube_SetPrivateData,
782     d3d8_texture_cube_GetPrivateData,
783     d3d8_texture_cube_FreePrivateData,
784     d3d8_texture_cube_SetPriority,
785     d3d8_texture_cube_GetPriority,
786     d3d8_texture_cube_PreLoad,
787     d3d8_texture_cube_GetType,
788     /* IDirect3DBaseTexture8 */
789     d3d8_texture_cube_SetLOD,
790     d3d8_texture_cube_GetLOD,
791     d3d8_texture_cube_GetLevelCount,
792     /* IDirect3DCubeTexture8 */
793     d3d8_texture_cube_GetLevelDesc,
794     d3d8_texture_cube_GetCubeMapSurface,
795     d3d8_texture_cube_LockRect,
796     d3d8_texture_cube_UnlockRect,
797     d3d8_texture_cube_AddDirtyRect,
798 };
799
800 static HRESULT WINAPI d3d8_texture_3d_QueryInterface(IDirect3DVolumeTexture8 *iface, REFIID riid, void **out)
801 {
802     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
803
804     if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)
805             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
806             || IsEqualGUID(riid, &IID_IDirect3DResource8)
807             || IsEqualGUID(riid, &IID_IUnknown))
808     {
809         IDirect3DVolumeTexture8_AddRef(iface);
810         *out = iface;
811         return S_OK;
812     }
813
814     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
815
816     *out = NULL;
817     return E_NOINTERFACE;
818 }
819
820 static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface)
821 {
822     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
823     ULONG ref = InterlockedIncrement(&texture->refcount);
824
825     TRACE("%p increasing refcount to %u.\n", iface, ref);
826
827     if (ref == 1)
828     {
829         IDirect3DDevice8_AddRef(texture->parent_device);
830         wined3d_mutex_lock();
831         wined3d_texture_incref(texture->wined3d_texture);
832         wined3d_mutex_unlock();
833     }
834
835     return ref;
836 }
837
838 static ULONG WINAPI d3d8_texture_3d_Release(IDirect3DVolumeTexture8 *iface)
839 {
840     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
841     ULONG ref = InterlockedDecrement(&texture->refcount);
842
843     TRACE("%p decreasing refcount to %u.\n", iface, ref);
844
845     if (!ref)
846     {
847         IDirect3DDevice8 *parent_device = texture->parent_device;
848
849         wined3d_mutex_lock();
850         wined3d_texture_decref(texture->wined3d_texture);
851         wined3d_mutex_unlock();
852
853         /* Release the device last, as it may cause the device to be destroyed. */
854         IDirect3DDevice8_Release(parent_device);
855     }
856     return ref;
857 }
858
859 static HRESULT WINAPI d3d8_texture_3d_GetDevice(IDirect3DVolumeTexture8 *iface, IDirect3DDevice8 **device)
860 {
861     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
862
863     TRACE("iface %p, device %p.\n", iface, device);
864
865     *device = texture->parent_device;
866     IDirect3DDevice8_AddRef(*device);
867
868     TRACE("Returning device %p.\n", *device);
869
870     return D3D_OK;
871 }
872
873 static HRESULT WINAPI d3d8_texture_3d_SetPrivateData(IDirect3DVolumeTexture8 *iface,
874         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
875 {
876     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
877     struct wined3d_resource *resource;
878     HRESULT hr;
879
880     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
881             iface, debugstr_guid(guid), data, data_size, flags);
882
883     wined3d_mutex_lock();
884     resource = wined3d_texture_get_resource(texture->wined3d_texture);
885     hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
886     wined3d_mutex_unlock();
887
888     return hr;
889 }
890
891 static HRESULT WINAPI d3d8_texture_3d_GetPrivateData(IDirect3DVolumeTexture8 *iface,
892         REFGUID guid, void *data, DWORD *data_size)
893 {
894     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
895     struct wined3d_resource *resource;
896     HRESULT hr;
897
898     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
899             iface, debugstr_guid(guid), data, data_size);
900
901     wined3d_mutex_lock();
902     resource = wined3d_texture_get_resource(texture->wined3d_texture);
903     hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
904     wined3d_mutex_unlock();
905
906     return hr;
907 }
908
909 static HRESULT WINAPI d3d8_texture_3d_FreePrivateData(IDirect3DVolumeTexture8 *iface, REFGUID guid)
910 {
911     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
912     struct wined3d_resource *resource;
913     HRESULT hr;
914
915     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
916
917     wined3d_mutex_lock();
918     resource = wined3d_texture_get_resource(texture->wined3d_texture);
919     hr = wined3d_resource_free_private_data(resource, guid);
920     wined3d_mutex_unlock();
921
922     return hr;
923 }
924
925 static DWORD WINAPI d3d8_texture_3d_SetPriority(IDirect3DVolumeTexture8 *iface, DWORD priority)
926 {
927     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
928     DWORD ret;
929
930     TRACE("iface %p, priority %u.\n", iface, priority);
931
932     wined3d_mutex_lock();
933     ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
934     wined3d_mutex_unlock();
935
936     return ret;
937 }
938
939 static DWORD WINAPI d3d8_texture_3d_GetPriority(IDirect3DVolumeTexture8 *iface)
940 {
941     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
942     DWORD ret;
943
944     TRACE("iface %p.\n", iface);
945
946     wined3d_mutex_lock();
947     ret = wined3d_texture_get_priority(texture->wined3d_texture);
948     wined3d_mutex_unlock();
949
950     return ret;
951 }
952
953 static void WINAPI d3d8_texture_3d_PreLoad(IDirect3DVolumeTexture8 *iface)
954 {
955     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
956
957     TRACE("iface %p.\n", iface);
958
959     wined3d_mutex_lock();
960     wined3d_texture_preload(texture->wined3d_texture);
961     wined3d_mutex_unlock();
962 }
963
964 static D3DRESOURCETYPE WINAPI d3d8_texture_3d_GetType(IDirect3DVolumeTexture8 *iface)
965 {
966     TRACE("iface %p.\n", iface);
967
968     return D3DRTYPE_VOLUMETEXTURE;
969 }
970
971 static DWORD WINAPI d3d8_texture_3d_SetLOD(IDirect3DVolumeTexture8 *iface, DWORD lod)
972 {
973     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
974     DWORD ret;
975
976     TRACE("iface %p, lod %u.\n", iface, lod);
977
978     wined3d_mutex_lock();
979     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
980     wined3d_mutex_unlock();
981
982     return ret;
983 }
984
985 static DWORD WINAPI d3d8_texture_3d_GetLOD(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_lod(texture->wined3d_texture);
994     wined3d_mutex_unlock();
995
996     return ret;
997 }
998
999 static DWORD WINAPI d3d8_texture_3d_GetLevelCount(IDirect3DVolumeTexture8 *iface)
1000 {
1001     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1002     DWORD ret;
1003
1004     TRACE("iface %p.\n", iface);
1005
1006     wined3d_mutex_lock();
1007     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
1008     wined3d_mutex_unlock();
1009
1010     return ret;
1011 }
1012
1013 static HRESULT WINAPI d3d8_texture_3d_GetLevelDesc(IDirect3DVolumeTexture8 *iface, UINT level, D3DVOLUME_DESC *desc)
1014 {
1015     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1016     struct wined3d_resource *sub_resource;
1017     HRESULT hr = D3D_OK;
1018
1019     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
1020
1021     wined3d_mutex_lock();
1022     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1023         hr = D3DERR_INVALIDCALL;
1024     else
1025     {
1026         struct wined3d_resource_desc wined3d_desc;
1027
1028         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
1029         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
1030         desc->Type = wined3d_desc.resource_type;
1031         desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
1032         desc->Pool = wined3d_desc.pool;
1033         desc->Size = wined3d_desc.size;
1034         desc->Width = wined3d_desc.width;
1035         desc->Height = wined3d_desc.height;
1036         desc->Depth = wined3d_desc.depth;
1037     }
1038     wined3d_mutex_unlock();
1039
1040     return hr;
1041 }
1042
1043 static HRESULT WINAPI d3d8_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture8 *iface,
1044         UINT level, IDirect3DVolume8 **volume)
1045 {
1046     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1047     struct wined3d_resource *sub_resource;
1048     struct d3d8_volume *volume_impl;
1049
1050     TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
1051
1052     wined3d_mutex_lock();
1053     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1054     {
1055         wined3d_mutex_unlock();
1056         return D3DERR_INVALIDCALL;
1057     }
1058
1059     volume_impl = wined3d_resource_get_parent(sub_resource);
1060     *volume = &volume_impl->IDirect3DVolume8_iface;
1061     IDirect3DVolume8_AddRef(*volume);
1062     wined3d_mutex_unlock();
1063
1064     return D3D_OK;
1065 }
1066
1067 static HRESULT WINAPI d3d8_texture_3d_LockBox(IDirect3DVolumeTexture8 *iface,
1068         UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
1069 {
1070     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1071     struct wined3d_resource *sub_resource;
1072     struct d3d8_volume *volume_impl;
1073     HRESULT hr;
1074
1075     TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1076             iface, level, locked_box, box, flags);
1077
1078     wined3d_mutex_lock();
1079     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1080         hr = D3DERR_INVALIDCALL;
1081     else
1082     {
1083         volume_impl = wined3d_resource_get_parent(sub_resource);
1084         hr = IDirect3DVolume8_LockBox(&volume_impl->IDirect3DVolume8_iface, locked_box, box, flags);
1085     }
1086     wined3d_mutex_unlock();
1087
1088     return hr;
1089 }
1090
1091 static HRESULT WINAPI d3d8_texture_3d_UnlockBox(IDirect3DVolumeTexture8 *iface, UINT level)
1092 {
1093     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1094     struct wined3d_resource *sub_resource;
1095     struct d3d8_volume *volume_impl;
1096     HRESULT hr;
1097
1098     TRACE("iface %p, level %u.\n", iface, level);
1099
1100     wined3d_mutex_lock();
1101     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1102         hr = D3DERR_INVALIDCALL;
1103     else
1104     {
1105         volume_impl = wined3d_resource_get_parent(sub_resource);
1106         hr = IDirect3DVolume8_UnlockBox(&volume_impl->IDirect3DVolume8_iface);
1107     }
1108     wined3d_mutex_unlock();
1109
1110     return hr;
1111 }
1112
1113 static HRESULT WINAPI d3d8_texture_3d_AddDirtyBox(IDirect3DVolumeTexture8 *iface, const D3DBOX *dirty_box)
1114 {
1115     struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1116     HRESULT hr;
1117
1118     TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
1119
1120     wined3d_mutex_lock();
1121     hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
1122     wined3d_mutex_unlock();
1123
1124     return hr;
1125 }
1126
1127 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
1128 {
1129     /* IUnknown */
1130     d3d8_texture_3d_QueryInterface,
1131     d3d8_texture_3d_AddRef,
1132     d3d8_texture_3d_Release,
1133     /* IDirect3DResource8 */
1134     d3d8_texture_3d_GetDevice,
1135     d3d8_texture_3d_SetPrivateData,
1136     d3d8_texture_3d_GetPrivateData,
1137     d3d8_texture_3d_FreePrivateData,
1138     d3d8_texture_3d_SetPriority,
1139     d3d8_texture_3d_GetPriority,
1140     d3d8_texture_3d_PreLoad,
1141     d3d8_texture_3d_GetType,
1142     /* IDirect3DBaseTexture8 */
1143     d3d8_texture_3d_SetLOD,
1144     d3d8_texture_3d_GetLOD,
1145     d3d8_texture_3d_GetLevelCount,
1146     /* IDirect3DVolumeTexture8 */
1147     d3d8_texture_3d_GetLevelDesc,
1148     d3d8_texture_3d_GetVolumeLevel,
1149     d3d8_texture_3d_LockBox,
1150     d3d8_texture_3d_UnlockBox,
1151     d3d8_texture_3d_AddDirtyBox
1152 };
1153
1154 struct d3d8_texture *unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture8 *iface)
1155 {
1156     if (!iface)
1157         return NULL;
1158     assert(iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl
1159             || iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl
1160             || iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl);
1161     return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
1162 }
1163
1164 static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
1165 {
1166     HeapFree(GetProcessHeap(), 0, parent);
1167 }
1168
1169 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
1170 {
1171     d3d8_texture_wined3d_object_destroyed,
1172 };
1173
1174 HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device,
1175         UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1176 {
1177     HRESULT hr;
1178
1179     texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl;
1180     texture->refcount = 1;
1181
1182     wined3d_mutex_lock();
1183     hr = wined3d_texture_create_2d(device->wined3d_device, width, height, levels,
1184             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
1185             texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1186     wined3d_mutex_unlock();
1187     if (FAILED(hr))
1188     {
1189         WARN("Failed to create wined3d texture, hr %#x.\n", hr);
1190         return hr;
1191     }
1192
1193     texture->parent_device = &device->IDirect3DDevice8_iface;
1194     IDirect3DDevice8_AddRef(texture->parent_device);
1195
1196     return D3D_OK;
1197 }
1198
1199 HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *device,
1200         UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1201 {
1202     HRESULT hr;
1203
1204     texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl;
1205     texture->refcount = 1;
1206
1207     wined3d_mutex_lock();
1208     hr = wined3d_texture_create_cube(device->wined3d_device, edge_length, levels,
1209             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
1210             &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1211     wined3d_mutex_unlock();
1212     if (FAILED(hr))
1213     {
1214         WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
1215         return hr;
1216     }
1217
1218     texture->parent_device = &device->IDirect3DDevice8_iface;
1219     IDirect3DDevice8_AddRef(texture->parent_device);
1220
1221     return D3D_OK;
1222 }
1223
1224 HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *device,
1225         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1226 {
1227     HRESULT hr;
1228
1229     texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl;
1230     texture->refcount = 1;
1231
1232     wined3d_mutex_lock();
1233     hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels,
1234             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
1235             &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1236     wined3d_mutex_unlock();
1237     if (FAILED(hr))
1238     {
1239         WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
1240         return hr;
1241     }
1242
1243     texture->parent_device = &device->IDirect3DDevice8_iface;
1244     IDirect3DDevice8_AddRef(texture->parent_device);
1245
1246     return D3D_OK;
1247 }