d3d8: Avoid '\n' in middle of TRACE() messages.
[wine.git] / dlls / d3d9 / texture.c
blob07bd83ed0421d350b07e9493e8837eaba643e408
1 /*
2 * Copyright 2002-2005 Jason Edmeades
3 * Copyright 2002-2005 Raphael Junqueira
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26 static inline struct d3d9_texture *impl_from_IDirect3DTexture9(IDirect3DTexture9 *iface)
28 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
31 static inline struct d3d9_texture *impl_from_IDirect3DCubeTexture9(IDirect3DCubeTexture9 *iface)
33 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
36 static inline struct d3d9_texture *impl_from_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 *iface)
38 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
41 static HRESULT WINAPI d3d9_texture_2d_QueryInterface(IDirect3DTexture9 *iface, REFIID riid, void **out)
43 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
45 if (IsEqualGUID(riid, &IID_IDirect3DTexture9)
46 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
47 || IsEqualGUID(riid, &IID_IDirect3DResource9)
48 || IsEqualGUID(riid, &IID_IUnknown))
50 IDirect3DTexture9_AddRef(iface);
51 *out = iface;
52 return S_OK;
55 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
57 *out = NULL;
58 return E_NOINTERFACE;
61 static ULONG WINAPI d3d9_texture_2d_AddRef(IDirect3DTexture9 *iface)
63 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
64 ULONG ref = InterlockedIncrement(&texture->resource.refcount);
66 TRACE("%p increasing refcount to %u.\n", iface, ref);
68 if (ref == 1)
70 struct d3d9_surface *surface;
72 IDirect3DDevice9Ex_AddRef(texture->parent_device);
73 wined3d_mutex_lock();
74 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
76 wined3d_rendertarget_view_incref(surface->wined3d_rtv);
78 wined3d_texture_incref(texture->wined3d_texture);
79 wined3d_mutex_unlock();
82 return ref;
85 static ULONG WINAPI d3d9_texture_2d_Release(IDirect3DTexture9 *iface)
87 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
88 ULONG ref = InterlockedDecrement(&texture->resource.refcount);
90 TRACE("%p decreasing refcount to %u.\n", iface, ref);
92 if (!ref)
94 IDirect3DDevice9Ex *parent_device = texture->parent_device;
95 struct d3d9_surface *surface;
97 wined3d_mutex_lock();
98 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
100 wined3d_rendertarget_view_decref(surface->wined3d_rtv);
102 wined3d_texture_decref(texture->wined3d_texture);
103 wined3d_mutex_unlock();
105 /* Release the device last, as it may cause the device to be destroyed. */
106 IDirect3DDevice9Ex_Release(parent_device);
108 return ref;
111 static HRESULT WINAPI d3d9_texture_2d_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device)
113 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
115 TRACE("iface %p, device %p.\n", iface, device);
117 *device = (IDirect3DDevice9 *)texture->parent_device;
118 IDirect3DDevice9_AddRef(*device);
120 TRACE("Returning device %p.\n", *device);
122 return D3D_OK;
125 static HRESULT WINAPI d3d9_texture_2d_SetPrivateData(IDirect3DTexture9 *iface,
126 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
128 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
129 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
130 iface, debugstr_guid(guid), data, data_size, flags);
132 return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
135 static HRESULT WINAPI d3d9_texture_2d_GetPrivateData(IDirect3DTexture9 *iface,
136 REFGUID guid, void *data, DWORD *data_size)
138 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
139 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
140 iface, debugstr_guid(guid), data, data_size);
142 return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
145 static HRESULT WINAPI d3d9_texture_2d_FreePrivateData(IDirect3DTexture9 *iface, REFGUID guid)
147 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
148 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
150 return d3d9_resource_free_private_data(&texture->resource, guid);
153 static DWORD WINAPI d3d9_texture_2d_SetPriority(IDirect3DTexture9 *iface, DWORD priority)
155 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
156 struct wined3d_resource *resource;
157 DWORD ret;
159 TRACE("iface %p, priority %u.\n", iface, priority);
161 wined3d_mutex_lock();
162 resource = wined3d_texture_get_resource(texture->wined3d_texture);
163 ret = wined3d_resource_set_priority(resource, priority);
164 wined3d_mutex_unlock();
166 return ret;
169 static DWORD WINAPI d3d9_texture_2d_GetPriority(IDirect3DTexture9 *iface)
171 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
172 const struct wined3d_resource *resource;
173 DWORD ret;
175 TRACE("iface %p.\n", iface);
177 wined3d_mutex_lock();
178 resource = wined3d_texture_get_resource(texture->wined3d_texture);
179 ret = wined3d_resource_get_priority(resource);
180 wined3d_mutex_unlock();
182 return ret;
185 static void WINAPI d3d9_texture_2d_PreLoad(IDirect3DTexture9 *iface)
187 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
189 TRACE("iface %p.\n", iface);
191 wined3d_mutex_lock();
192 wined3d_texture_preload(texture->wined3d_texture);
193 wined3d_mutex_unlock();
196 static D3DRESOURCETYPE WINAPI d3d9_texture_2d_GetType(IDirect3DTexture9 *iface)
198 TRACE("iface %p.\n", iface);
200 return D3DRTYPE_TEXTURE;
203 static DWORD WINAPI d3d9_texture_2d_SetLOD(IDirect3DTexture9 *iface, DWORD lod)
205 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
206 DWORD ret;
208 TRACE("iface %p, lod %u.\n", iface, lod);
210 wined3d_mutex_lock();
211 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
212 wined3d_mutex_unlock();
214 return ret;
217 static DWORD WINAPI d3d9_texture_2d_GetLOD(IDirect3DTexture9 *iface)
219 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
220 DWORD ret;
222 TRACE("iface %p.\n", iface);
224 wined3d_mutex_lock();
225 ret = wined3d_texture_get_lod(texture->wined3d_texture);
226 wined3d_mutex_unlock();
228 return ret;
231 static DWORD WINAPI d3d9_texture_2d_GetLevelCount(IDirect3DTexture9 *iface)
233 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
234 DWORD ret;
236 TRACE("iface %p.\n", iface);
238 wined3d_mutex_lock();
239 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
240 wined3d_mutex_unlock();
242 return ret;
245 static HRESULT WINAPI d3d9_texture_2d_SetAutoGenFilterType(IDirect3DTexture9 *iface, D3DTEXTUREFILTERTYPE filter_type)
247 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
248 HRESULT hr;
250 TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
252 wined3d_mutex_lock();
253 hr = wined3d_texture_set_autogen_filter_type(texture->wined3d_texture,
254 (enum wined3d_texture_filter_type)filter_type);
255 wined3d_mutex_unlock();
257 return hr;
260 static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_2d_GetAutoGenFilterType(IDirect3DTexture9 *iface)
262 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
263 D3DTEXTUREFILTERTYPE ret;
265 TRACE("iface %p.\n", iface);
267 wined3d_mutex_lock();
268 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(texture->wined3d_texture);
269 wined3d_mutex_unlock();
271 return ret;
274 static void WINAPI d3d9_texture_2d_GenerateMipSubLevels(IDirect3DTexture9 *iface)
276 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
278 TRACE("iface %p.\n", iface);
280 wined3d_mutex_lock();
281 wined3d_texture_generate_mipmaps(texture->wined3d_texture);
282 wined3d_mutex_unlock();
285 static HRESULT WINAPI d3d9_texture_2d_GetLevelDesc(IDirect3DTexture9 *iface, UINT level, D3DSURFACE_DESC *desc)
287 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
288 struct wined3d_sub_resource_desc wined3d_desc;
289 HRESULT hr;
291 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
293 wined3d_mutex_lock();
294 if (SUCCEEDED(hr = wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, level, &wined3d_desc)))
296 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
297 desc->Type = D3DRTYPE_SURFACE;
298 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
299 desc->Pool = wined3d_desc.pool;
300 desc->MultiSampleType = wined3d_desc.multisample_type;
301 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
302 desc->Width = wined3d_desc.width;
303 desc->Height = wined3d_desc.height;
305 wined3d_mutex_unlock();
307 return hr;
310 static HRESULT WINAPI d3d9_texture_2d_GetSurfaceLevel(IDirect3DTexture9 *iface,
311 UINT level, IDirect3DSurface9 **surface)
313 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
314 struct d3d9_surface *surface_impl;
316 TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
318 wined3d_mutex_lock();
319 if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
321 wined3d_mutex_unlock();
322 return D3DERR_INVALIDCALL;
325 *surface = &surface_impl->IDirect3DSurface9_iface;
326 IDirect3DSurface9_AddRef(*surface);
327 wined3d_mutex_unlock();
329 return D3D_OK;
332 static HRESULT WINAPI d3d9_texture_2d_LockRect(IDirect3DTexture9 *iface,
333 UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
335 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
336 struct d3d9_surface *surface_impl;
337 HRESULT hr;
339 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
340 iface, level, locked_rect, rect, flags);
342 wined3d_mutex_lock();
343 if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
344 hr = D3DERR_INVALIDCALL;
345 else
346 hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags);
347 wined3d_mutex_unlock();
349 return hr;
352 static HRESULT WINAPI d3d9_texture_2d_UnlockRect(IDirect3DTexture9 *iface, UINT level)
354 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
355 struct d3d9_surface *surface_impl;
356 HRESULT hr;
358 TRACE("iface %p, level %u.\n", iface, level);
360 wined3d_mutex_lock();
361 if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
362 hr = D3DERR_INVALIDCALL;
363 else
364 hr = IDirect3DSurface9_UnlockRect(&surface_impl->IDirect3DSurface9_iface);
365 wined3d_mutex_unlock();
367 return hr;
370 static HRESULT WINAPI d3d9_texture_2d_AddDirtyRect(IDirect3DTexture9 *iface, const RECT *dirty_rect)
372 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
373 HRESULT hr;
375 TRACE("iface %p, dirty_rect %s.\n",
376 iface, wine_dbgstr_rect(dirty_rect));
378 wined3d_mutex_lock();
379 if (!dirty_rect)
380 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
381 else
383 struct wined3d_box dirty_region;
385 dirty_region.left = dirty_rect->left;
386 dirty_region.top = dirty_rect->top;
387 dirty_region.right = dirty_rect->right;
388 dirty_region.bottom = dirty_rect->bottom;
389 dirty_region.front = 0;
390 dirty_region.back = 1;
391 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
393 wined3d_mutex_unlock();
395 return hr;
398 static const IDirect3DTexture9Vtbl d3d9_texture_2d_vtbl =
400 /* IUnknown */
401 d3d9_texture_2d_QueryInterface,
402 d3d9_texture_2d_AddRef,
403 d3d9_texture_2d_Release,
404 /* IDirect3DResource9 */
405 d3d9_texture_2d_GetDevice,
406 d3d9_texture_2d_SetPrivateData,
407 d3d9_texture_2d_GetPrivateData,
408 d3d9_texture_2d_FreePrivateData,
409 d3d9_texture_2d_SetPriority,
410 d3d9_texture_2d_GetPriority,
411 d3d9_texture_2d_PreLoad,
412 d3d9_texture_2d_GetType,
413 /* IDirect3dBaseTexture9 */
414 d3d9_texture_2d_SetLOD,
415 d3d9_texture_2d_GetLOD,
416 d3d9_texture_2d_GetLevelCount,
417 d3d9_texture_2d_SetAutoGenFilterType,
418 d3d9_texture_2d_GetAutoGenFilterType,
419 d3d9_texture_2d_GenerateMipSubLevels,
420 /* IDirect3DTexture9 */
421 d3d9_texture_2d_GetLevelDesc,
422 d3d9_texture_2d_GetSurfaceLevel,
423 d3d9_texture_2d_LockRect,
424 d3d9_texture_2d_UnlockRect,
425 d3d9_texture_2d_AddDirtyRect,
428 static HRESULT WINAPI d3d9_texture_cube_QueryInterface(IDirect3DCubeTexture9 *iface, REFIID riid, void **out)
430 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
432 if (IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)
433 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
434 || IsEqualGUID(riid, &IID_IDirect3DResource9)
435 || IsEqualGUID(riid, &IID_IUnknown))
437 IDirect3DCubeTexture9_AddRef(iface);
438 *out = iface;
439 return S_OK;
442 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
444 *out = NULL;
445 return E_NOINTERFACE;
448 static ULONG WINAPI d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 *iface)
450 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
451 ULONG ref = InterlockedIncrement(&texture->resource.refcount);
453 TRACE("%p increasing refcount to %u.\n", iface, ref);
455 if (ref == 1)
457 struct d3d9_surface *surface;
459 IDirect3DDevice9Ex_AddRef(texture->parent_device);
460 wined3d_mutex_lock();
461 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
463 wined3d_rendertarget_view_decref(surface->wined3d_rtv);
465 wined3d_texture_incref(texture->wined3d_texture);
466 wined3d_mutex_unlock();
469 return ref;
472 static ULONG WINAPI d3d9_texture_cube_Release(IDirect3DCubeTexture9 *iface)
474 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
475 ULONG ref = InterlockedDecrement(&texture->resource.refcount);
477 TRACE("%p decreasing refcount to %u.\n", iface, ref);
479 if (!ref)
481 IDirect3DDevice9Ex *parent_device = texture->parent_device;
482 struct d3d9_surface *surface;
484 TRACE("Releasing child %p.\n", texture->wined3d_texture);
486 wined3d_mutex_lock();
487 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
489 wined3d_rendertarget_view_decref(surface->wined3d_rtv);
491 wined3d_texture_decref(texture->wined3d_texture);
492 wined3d_mutex_unlock();
494 /* Release the device last, as it may cause the device to be destroyed. */
495 IDirect3DDevice9Ex_Release(parent_device);
497 return ref;
500 static HRESULT WINAPI d3d9_texture_cube_GetDevice(IDirect3DCubeTexture9 *iface, IDirect3DDevice9 **device)
502 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
504 TRACE("iface %p, device %p.\n", iface, device);
506 *device = (IDirect3DDevice9 *)texture->parent_device;
507 IDirect3DDevice9_AddRef(*device);
509 TRACE("Returning device %p.\n", *device);
511 return D3D_OK;
514 static HRESULT WINAPI d3d9_texture_cube_SetPrivateData(IDirect3DCubeTexture9 *iface,
515 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
517 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
518 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
519 iface, debugstr_guid(guid), data, data_size, flags);
521 return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
524 static HRESULT WINAPI d3d9_texture_cube_GetPrivateData(IDirect3DCubeTexture9 *iface,
525 REFGUID guid, void *data, DWORD *data_size)
527 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
528 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
529 iface, debugstr_guid(guid), data, data_size);
531 return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
534 static HRESULT WINAPI d3d9_texture_cube_FreePrivateData(IDirect3DCubeTexture9 *iface, REFGUID guid)
536 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
537 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
539 return d3d9_resource_free_private_data(&texture->resource, guid);
542 static DWORD WINAPI d3d9_texture_cube_SetPriority(IDirect3DCubeTexture9 *iface, DWORD priority)
544 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
545 struct wined3d_resource *resource;
546 DWORD ret;
548 TRACE("iface %p, priority %u.\n", iface, priority);
550 wined3d_mutex_lock();
551 resource = wined3d_texture_get_resource(texture->wined3d_texture);
552 ret = wined3d_resource_set_priority(resource, priority);
553 wined3d_mutex_unlock();
555 return ret;
558 static DWORD WINAPI d3d9_texture_cube_GetPriority(IDirect3DCubeTexture9 *iface)
560 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
561 const struct wined3d_resource *resource;
562 DWORD ret;
564 TRACE("iface %p.\n", iface);
566 wined3d_mutex_lock();
567 resource = wined3d_texture_get_resource(texture->wined3d_texture);
568 ret = wined3d_resource_get_priority(resource);
569 wined3d_mutex_unlock();
571 return ret;
574 static void WINAPI d3d9_texture_cube_PreLoad(IDirect3DCubeTexture9 *iface)
576 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
578 TRACE("iface %p.\n", iface);
580 wined3d_mutex_lock();
581 wined3d_texture_preload(texture->wined3d_texture);
582 wined3d_mutex_unlock();
585 static D3DRESOURCETYPE WINAPI d3d9_texture_cube_GetType(IDirect3DCubeTexture9 *iface)
587 TRACE("iface %p.\n", iface);
589 return D3DRTYPE_CUBETEXTURE;
592 static DWORD WINAPI d3d9_texture_cube_SetLOD(IDirect3DCubeTexture9 *iface, DWORD lod)
594 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
595 DWORD ret;
597 TRACE("iface %p, lod %u.\n", iface, lod);
599 wined3d_mutex_lock();
600 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
601 wined3d_mutex_unlock();
603 return ret;
606 static DWORD WINAPI d3d9_texture_cube_GetLOD(IDirect3DCubeTexture9 *iface)
608 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
609 DWORD ret;
611 TRACE("iface %p.\n", iface);
613 wined3d_mutex_lock();
614 ret = wined3d_texture_get_lod(texture->wined3d_texture);
615 wined3d_mutex_unlock();
617 return ret;
620 static DWORD WINAPI d3d9_texture_cube_GetLevelCount(IDirect3DCubeTexture9 *iface)
622 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
623 DWORD ret;
625 TRACE("iface %p.\n", iface);
627 wined3d_mutex_lock();
628 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
629 wined3d_mutex_unlock();
631 return ret;
634 static HRESULT WINAPI d3d9_texture_cube_SetAutoGenFilterType(IDirect3DCubeTexture9 *iface,
635 D3DTEXTUREFILTERTYPE filter_type)
637 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
638 HRESULT hr;
640 TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
642 wined3d_mutex_lock();
643 hr = wined3d_texture_set_autogen_filter_type(texture->wined3d_texture,
644 (enum wined3d_texture_filter_type)filter_type);
645 wined3d_mutex_unlock();
647 return hr;
650 static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_cube_GetAutoGenFilterType(IDirect3DCubeTexture9 *iface)
652 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
653 D3DTEXTUREFILTERTYPE ret;
655 TRACE("iface %p.\n", iface);
657 wined3d_mutex_lock();
658 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(texture->wined3d_texture);
659 wined3d_mutex_unlock();
661 return ret;
664 static void WINAPI d3d9_texture_cube_GenerateMipSubLevels(IDirect3DCubeTexture9 *iface)
666 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
668 TRACE("iface %p.\n", iface);
670 wined3d_mutex_lock();
671 wined3d_texture_generate_mipmaps(texture->wined3d_texture);
672 wined3d_mutex_unlock();
675 static HRESULT WINAPI d3d9_texture_cube_GetLevelDesc(IDirect3DCubeTexture9 *iface, UINT level, D3DSURFACE_DESC *desc)
677 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
678 struct wined3d_sub_resource_desc wined3d_desc;
679 DWORD level_count;
680 HRESULT hr;
682 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
684 wined3d_mutex_lock();
685 level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
686 if (level >= level_count)
688 wined3d_mutex_unlock();
689 return D3DERR_INVALIDCALL;
692 if (SUCCEEDED(hr = wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, level, &wined3d_desc)))
694 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
695 desc->Type = D3DRTYPE_SURFACE;
696 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
697 desc->Pool = wined3d_desc.pool;
698 desc->MultiSampleType = wined3d_desc.multisample_type;
699 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
700 desc->Width = wined3d_desc.width;
701 desc->Height = wined3d_desc.height;
703 wined3d_mutex_unlock();
705 return hr;
708 static HRESULT WINAPI d3d9_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture9 *iface,
709 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface)
711 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
712 struct d3d9_surface *surface_impl;
713 UINT sub_resource_idx;
714 DWORD level_count;
716 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
718 wined3d_mutex_lock();
719 level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
720 if (level >= level_count)
722 wined3d_mutex_unlock();
723 return D3DERR_INVALIDCALL;
726 sub_resource_idx = level_count * face + level;
727 if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, sub_resource_idx)))
729 wined3d_mutex_unlock();
730 return D3DERR_INVALIDCALL;
733 *surface = &surface_impl->IDirect3DSurface9_iface;
734 IDirect3DSurface9_AddRef(*surface);
735 wined3d_mutex_unlock();
737 return D3D_OK;
740 static HRESULT WINAPI d3d9_texture_cube_LockRect(IDirect3DCubeTexture9 *iface,
741 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
742 DWORD flags)
744 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
745 struct d3d9_surface *surface_impl;
746 UINT sub_resource_idx;
747 HRESULT hr;
749 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
750 iface, face, level, locked_rect, rect, flags);
752 wined3d_mutex_lock();
753 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
754 if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, sub_resource_idx)))
755 hr = D3DERR_INVALIDCALL;
756 else
757 hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags);
758 wined3d_mutex_unlock();
760 return hr;
763 static HRESULT WINAPI d3d9_texture_cube_UnlockRect(IDirect3DCubeTexture9 *iface,
764 D3DCUBEMAP_FACES face, UINT level)
766 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
767 struct d3d9_surface *surface_impl;
768 UINT sub_resource_idx;
769 HRESULT hr;
771 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
773 wined3d_mutex_lock();
774 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
775 if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, sub_resource_idx)))
776 hr = D3DERR_INVALIDCALL;
777 else
778 hr = IDirect3DSurface9_UnlockRect(&surface_impl->IDirect3DSurface9_iface);
779 wined3d_mutex_unlock();
781 return hr;
784 static HRESULT WINAPI d3d9_texture_cube_AddDirtyRect(IDirect3DCubeTexture9 *iface,
785 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
787 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
788 HRESULT hr;
790 TRACE("iface %p, face %#x, dirty_rect %s.\n",
791 iface, face, wine_dbgstr_rect(dirty_rect));
793 wined3d_mutex_lock();
794 if (!dirty_rect)
795 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
796 else
798 struct wined3d_box dirty_region;
800 dirty_region.left = dirty_rect->left;
801 dirty_region.top = dirty_rect->top;
802 dirty_region.right = dirty_rect->right;
803 dirty_region.bottom = dirty_rect->bottom;
804 dirty_region.front = 0;
805 dirty_region.back = 1;
806 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
808 wined3d_mutex_unlock();
810 return hr;
813 static const IDirect3DCubeTexture9Vtbl d3d9_texture_cube_vtbl =
815 /* IUnknown */
816 d3d9_texture_cube_QueryInterface,
817 d3d9_texture_cube_AddRef,
818 d3d9_texture_cube_Release,
819 /* IDirect3DResource9 */
820 d3d9_texture_cube_GetDevice,
821 d3d9_texture_cube_SetPrivateData,
822 d3d9_texture_cube_GetPrivateData,
823 d3d9_texture_cube_FreePrivateData,
824 d3d9_texture_cube_SetPriority,
825 d3d9_texture_cube_GetPriority,
826 d3d9_texture_cube_PreLoad,
827 d3d9_texture_cube_GetType,
828 /* IDirect3DBaseTexture9 */
829 d3d9_texture_cube_SetLOD,
830 d3d9_texture_cube_GetLOD,
831 d3d9_texture_cube_GetLevelCount,
832 d3d9_texture_cube_SetAutoGenFilterType,
833 d3d9_texture_cube_GetAutoGenFilterType,
834 d3d9_texture_cube_GenerateMipSubLevels,
835 /* IDirect3DCubeTexture9 */
836 d3d9_texture_cube_GetLevelDesc,
837 d3d9_texture_cube_GetCubeMapSurface,
838 d3d9_texture_cube_LockRect,
839 d3d9_texture_cube_UnlockRect,
840 d3d9_texture_cube_AddDirtyRect,
843 static HRESULT WINAPI d3d9_texture_3d_QueryInterface(IDirect3DVolumeTexture9 *iface, REFIID riid, void **out)
845 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
847 if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)
848 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
849 || IsEqualGUID(riid, &IID_IDirect3DResource9)
850 || IsEqualGUID(riid, &IID_IUnknown))
852 IDirect3DVolumeTexture9_AddRef(iface);
853 *out = iface;
854 return S_OK;
857 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
859 *out = NULL;
860 return E_NOINTERFACE;
863 static ULONG WINAPI d3d9_texture_3d_AddRef(IDirect3DVolumeTexture9 *iface)
865 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
866 ULONG ref = InterlockedIncrement(&texture->resource.refcount);
868 TRACE("%p increasing refcount to %u.\n", iface, ref);
870 if (ref == 1)
872 IDirect3DDevice9Ex_AddRef(texture->parent_device);
873 wined3d_mutex_lock();
874 wined3d_texture_incref(texture->wined3d_texture);
875 wined3d_mutex_unlock();
878 return ref;
881 static ULONG WINAPI d3d9_texture_3d_Release(IDirect3DVolumeTexture9 *iface)
883 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
884 ULONG ref = InterlockedDecrement(&texture->resource.refcount);
886 TRACE("%p decreasing refcount to %u.\n", iface, ref);
888 if (!ref)
890 IDirect3DDevice9Ex *parent_device = texture->parent_device;
892 wined3d_mutex_lock();
893 wined3d_texture_decref(texture->wined3d_texture);
894 wined3d_mutex_unlock();
896 /* Release the device last, as it may cause the device to be destroyed. */
897 IDirect3DDevice9Ex_Release(parent_device);
899 return ref;
902 static HRESULT WINAPI d3d9_texture_3d_GetDevice(IDirect3DVolumeTexture9 *iface, IDirect3DDevice9 **device)
904 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
906 TRACE("iface %p, device %p.\n", iface, device);
908 *device = (IDirect3DDevice9 *)texture->parent_device;
909 IDirect3DDevice9_AddRef(*device);
911 TRACE("Returning device %p.\n", *device);
913 return D3D_OK;
916 static HRESULT WINAPI d3d9_texture_3d_SetPrivateData(IDirect3DVolumeTexture9 *iface,
917 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
919 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
920 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
921 iface, debugstr_guid(guid), data, data_size, flags);
923 return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
926 static HRESULT WINAPI d3d9_texture_3d_GetPrivateData(IDirect3DVolumeTexture9 *iface,
927 REFGUID guid, void *data, DWORD *data_size)
929 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
930 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
931 iface, debugstr_guid(guid), data, data_size);
933 return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
936 static HRESULT WINAPI d3d9_texture_3d_FreePrivateData(IDirect3DVolumeTexture9 *iface, REFGUID guid)
938 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
939 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
941 return d3d9_resource_free_private_data(&texture->resource, guid);
944 static DWORD WINAPI d3d9_texture_3d_SetPriority(IDirect3DVolumeTexture9 *iface, DWORD priority)
946 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
947 struct wined3d_resource *resource;
948 DWORD ret;
950 TRACE("iface %p, priority %u.\n", iface, priority);
952 wined3d_mutex_lock();
953 resource = wined3d_texture_get_resource(texture->wined3d_texture);
954 ret = wined3d_resource_set_priority(resource, priority);
955 wined3d_mutex_unlock();
957 return ret;
960 static DWORD WINAPI d3d9_texture_3d_GetPriority(IDirect3DVolumeTexture9 *iface)
962 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
963 const struct wined3d_resource *resource;
964 DWORD ret;
966 TRACE("iface %p.\n", iface);
968 wined3d_mutex_lock();
969 resource = wined3d_texture_get_resource(texture->wined3d_texture);
970 ret = wined3d_resource_get_priority(resource);
971 wined3d_mutex_unlock();
973 return ret;
976 static void WINAPI d3d9_texture_3d_PreLoad(IDirect3DVolumeTexture9 *iface)
978 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
980 TRACE("iface %p.\n", iface);
982 wined3d_mutex_lock();
983 wined3d_texture_preload(texture->wined3d_texture);
984 wined3d_mutex_unlock();
987 static D3DRESOURCETYPE WINAPI d3d9_texture_3d_GetType(IDirect3DVolumeTexture9 *iface)
989 TRACE("iface %p.\n", iface);
991 return D3DRTYPE_VOLUMETEXTURE;
994 static DWORD WINAPI d3d9_texture_3d_SetLOD(IDirect3DVolumeTexture9 *iface, DWORD lod)
996 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
997 DWORD ret;
999 TRACE("iface %p, lod %u.\n", iface, lod);
1001 wined3d_mutex_lock();
1002 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
1003 wined3d_mutex_unlock();
1005 return ret;
1008 static DWORD WINAPI d3d9_texture_3d_GetLOD(IDirect3DVolumeTexture9 *iface)
1010 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1011 DWORD ret;
1013 TRACE("iface %p.\n", iface);
1015 wined3d_mutex_lock();
1016 ret = wined3d_texture_get_lod(texture->wined3d_texture);
1017 wined3d_mutex_unlock();
1019 return ret;
1022 static DWORD WINAPI d3d9_texture_3d_GetLevelCount(IDirect3DVolumeTexture9 *iface)
1024 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1025 DWORD ret;
1027 TRACE("iface %p.\n", iface);
1029 wined3d_mutex_lock();
1030 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
1031 wined3d_mutex_unlock();
1033 return ret;
1036 static HRESULT WINAPI d3d9_texture_3d_SetAutoGenFilterType(IDirect3DVolumeTexture9 *iface,
1037 D3DTEXTUREFILTERTYPE filter_type)
1039 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1040 HRESULT hr;
1042 TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
1044 wined3d_mutex_lock();
1045 hr = wined3d_texture_set_autogen_filter_type(texture->wined3d_texture,
1046 (enum wined3d_texture_filter_type)filter_type);
1047 wined3d_mutex_unlock();
1049 return hr;
1052 static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_3d_GetAutoGenFilterType(IDirect3DVolumeTexture9 *iface)
1054 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1055 D3DTEXTUREFILTERTYPE filter_type;
1057 TRACE("iface %p.\n", iface);
1059 wined3d_mutex_lock();
1060 filter_type = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(texture->wined3d_texture);
1061 wined3d_mutex_unlock();
1063 return filter_type;
1066 static void WINAPI d3d9_texture_3d_GenerateMipSubLevels(IDirect3DVolumeTexture9 *iface)
1068 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1070 TRACE("iface %p.\n", iface);
1072 wined3d_mutex_lock();
1073 wined3d_texture_generate_mipmaps(texture->wined3d_texture);
1074 wined3d_mutex_unlock();
1077 static HRESULT WINAPI d3d9_texture_3d_GetLevelDesc(IDirect3DVolumeTexture9 *iface, UINT level, D3DVOLUME_DESC *desc)
1079 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1080 struct wined3d_sub_resource_desc wined3d_desc;
1081 HRESULT hr;
1083 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
1085 wined3d_mutex_lock();
1086 if (SUCCEEDED(hr = wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, level, &wined3d_desc)))
1088 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
1089 desc->Type = D3DRTYPE_VOLUME;
1090 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
1091 desc->Pool = wined3d_desc.pool;
1092 desc->Width = wined3d_desc.width;
1093 desc->Height = wined3d_desc.height;
1094 desc->Depth = wined3d_desc.depth;
1096 wined3d_mutex_unlock();
1098 return hr;
1101 static HRESULT WINAPI d3d9_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture9 *iface,
1102 UINT level, IDirect3DVolume9 **volume)
1104 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1105 struct d3d9_volume *volume_impl;
1107 TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
1109 wined3d_mutex_lock();
1110 if (!(volume_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
1112 wined3d_mutex_unlock();
1113 return D3DERR_INVALIDCALL;
1116 *volume = &volume_impl->IDirect3DVolume9_iface;
1117 IDirect3DVolume9_AddRef(*volume);
1118 wined3d_mutex_unlock();
1120 return D3D_OK;
1123 static HRESULT WINAPI d3d9_texture_3d_LockBox(IDirect3DVolumeTexture9 *iface,
1124 UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
1126 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1127 struct d3d9_volume *volume_impl;
1128 HRESULT hr;
1130 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1131 iface, level, locked_box, box, flags);
1133 wined3d_mutex_lock();
1134 if (!(volume_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
1135 hr = D3DERR_INVALIDCALL;
1136 else
1137 hr = IDirect3DVolume9_LockBox(&volume_impl->IDirect3DVolume9_iface, locked_box, box, flags);
1138 wined3d_mutex_unlock();
1140 return hr;
1143 static HRESULT WINAPI d3d9_texture_3d_UnlockBox(IDirect3DVolumeTexture9 *iface, UINT level)
1145 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1146 struct d3d9_volume *volume_impl;
1147 HRESULT hr;
1149 TRACE("iface %p, level %u.\n", iface, level);
1151 wined3d_mutex_lock();
1152 if (!(volume_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
1153 hr = D3DERR_INVALIDCALL;
1154 else
1155 hr = IDirect3DVolume9_UnlockBox(&volume_impl->IDirect3DVolume9_iface);
1156 wined3d_mutex_unlock();
1158 return hr;
1161 static HRESULT WINAPI d3d9_texture_3d_AddDirtyBox(IDirect3DVolumeTexture9 *iface, const D3DBOX *dirty_box)
1163 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1164 HRESULT hr;
1166 TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
1168 wined3d_mutex_lock();
1169 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
1170 wined3d_mutex_unlock();
1172 return hr;
1176 static const IDirect3DVolumeTexture9Vtbl d3d9_texture_3d_vtbl =
1178 /* IUnknown */
1179 d3d9_texture_3d_QueryInterface,
1180 d3d9_texture_3d_AddRef,
1181 d3d9_texture_3d_Release,
1182 /* IDirect3DResource9 */
1183 d3d9_texture_3d_GetDevice,
1184 d3d9_texture_3d_SetPrivateData,
1185 d3d9_texture_3d_GetPrivateData,
1186 d3d9_texture_3d_FreePrivateData,
1187 d3d9_texture_3d_SetPriority,
1188 d3d9_texture_3d_GetPriority,
1189 d3d9_texture_3d_PreLoad,
1190 d3d9_texture_3d_GetType,
1191 /* IDirect3DBaseTexture9 */
1192 d3d9_texture_3d_SetLOD,
1193 d3d9_texture_3d_GetLOD,
1194 d3d9_texture_3d_GetLevelCount,
1195 d3d9_texture_3d_SetAutoGenFilterType,
1196 d3d9_texture_3d_GetAutoGenFilterType,
1197 d3d9_texture_3d_GenerateMipSubLevels,
1198 /* IDirect3DVolumeTexture9 */
1199 d3d9_texture_3d_GetLevelDesc,
1200 d3d9_texture_3d_GetVolumeLevel,
1201 d3d9_texture_3d_LockBox,
1202 d3d9_texture_3d_UnlockBox,
1203 d3d9_texture_3d_AddDirtyBox,
1206 struct d3d9_texture *unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture9 *iface)
1208 if (!iface)
1209 return NULL;
1211 if (iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl
1212 && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl
1213 && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl)
1215 WARN("%p is not a valid IDirect3DBaseTexture9 interface.\n", iface);
1216 return NULL;
1219 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
1222 static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
1224 struct d3d9_texture *texture = parent;
1225 d3d9_resource_cleanup(&texture->resource);
1226 HeapFree(GetProcessHeap(), 0, texture);
1229 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
1231 d3d9_texture_wined3d_object_destroyed,
1234 HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1235 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1237 struct wined3d_resource_desc desc;
1238 DWORD flags = 0;
1239 HRESULT hr;
1241 texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl;
1242 d3d9_resource_init(&texture->resource);
1243 list_init(&texture->rtv_list);
1245 desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
1246 desc.format = wined3dformat_from_d3dformat(format);
1247 desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1248 desc.multisample_quality = 0;
1249 desc.usage = usage & WINED3DUSAGE_MASK;
1250 desc.usage |= WINED3DUSAGE_TEXTURE;
1251 desc.pool = pool;
1252 desc.width = width;
1253 desc.height = height;
1254 desc.depth = 1;
1255 desc.size = 0;
1257 if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC))
1258 flags |= WINED3D_TEXTURE_CREATE_MAPPABLE;
1260 if (!levels)
1262 if (usage & D3DUSAGE_AUTOGENMIPMAP)
1263 levels = 1;
1264 else
1265 levels = wined3d_log2i(max(width, height)) + 1;
1268 wined3d_mutex_lock();
1269 hr = wined3d_texture_create(device->wined3d_device, &desc, levels, flags,
1270 NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1271 wined3d_mutex_unlock();
1272 if (FAILED(hr))
1274 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
1275 return hr;
1278 texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1279 IDirect3DDevice9Ex_AddRef(texture->parent_device);
1281 return D3D_OK;
1284 HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1285 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1287 struct wined3d_resource_desc desc;
1288 DWORD flags = 0;
1289 HRESULT hr;
1291 texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl;
1292 d3d9_resource_init(&texture->resource);
1293 list_init(&texture->rtv_list);
1295 desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
1296 desc.format = wined3dformat_from_d3dformat(format);
1297 desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1298 desc.multisample_quality = 0;
1299 desc.usage = usage & WINED3DUSAGE_MASK;
1300 desc.usage |= WINED3DUSAGE_LEGACY_CUBEMAP | WINED3DUSAGE_TEXTURE;
1301 desc.pool = pool;
1302 desc.width = edge_length;
1303 desc.height = edge_length;
1304 desc.depth = 1;
1305 desc.size = 0;
1307 if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC))
1308 flags |= WINED3D_TEXTURE_CREATE_MAPPABLE;
1310 if (!levels)
1312 if (usage & D3DUSAGE_AUTOGENMIPMAP)
1313 levels = 1;
1314 else
1315 levels = wined3d_log2i(edge_length) + 1;
1318 wined3d_mutex_lock();
1319 hr = wined3d_texture_create(device->wined3d_device, &desc, levels, flags,
1320 NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1321 wined3d_mutex_unlock();
1322 if (FAILED(hr))
1324 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
1325 return hr;
1328 texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1329 IDirect3DDevice9Ex_AddRef(texture->parent_device);
1331 return D3D_OK;
1334 HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1335 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1337 struct wined3d_resource_desc desc;
1338 HRESULT hr;
1340 texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl;
1341 d3d9_resource_init(&texture->resource);
1342 list_init(&texture->rtv_list);
1344 desc.resource_type = WINED3D_RTYPE_TEXTURE_3D;
1345 desc.format = wined3dformat_from_d3dformat(format);
1346 desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1347 desc.multisample_quality = 0;
1348 desc.usage = usage & WINED3DUSAGE_MASK;
1349 desc.usage |= WINED3DUSAGE_TEXTURE;
1350 desc.pool = pool;
1351 desc.width = width;
1352 desc.height = height;
1353 desc.depth = depth;
1354 desc.size = 0;
1356 if (!levels)
1358 if (usage & D3DUSAGE_AUTOGENMIPMAP)
1359 levels = 1;
1360 else
1361 levels = wined3d_log2i(max(max(width, height), depth)) + 1;
1364 wined3d_mutex_lock();
1365 hr = wined3d_texture_create(device->wined3d_device, &desc, levels, 0,
1366 NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1367 wined3d_mutex_unlock();
1368 if (FAILED(hr))
1370 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
1371 return hr;
1374 texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1375 IDirect3DDevice9Ex_AddRef(texture->parent_device);
1377 return D3D_OK;