2 * IDirect3DVolume8 implementation
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
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
26 static inline struct d3d8_volume
*impl_from_IDirect3DVolume8(IDirect3DVolume8
*iface
)
28 return CONTAINING_RECORD(iface
, struct d3d8_volume
, IDirect3DVolume8_iface
);
31 static HRESULT WINAPI
d3d8_volume_QueryInterface(IDirect3DVolume8
*iface
, REFIID riid
, void **out
)
33 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
35 if (IsEqualGUID(riid
, &IID_IDirect3DVolume8
)
36 || IsEqualGUID(riid
, &IID_IUnknown
))
38 IDirect3DVolume8_AddRef(iface
);
43 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
49 static ULONG WINAPI
d3d8_volume_AddRef(IDirect3DVolume8
*iface
)
51 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
53 TRACE("iface %p.\n", iface
);
54 TRACE("Forwarding to %p.\n", volume
->texture
);
56 return IDirect3DBaseTexture8_AddRef(&volume
->texture
->IDirect3DBaseTexture8_iface
);
59 static ULONG WINAPI
d3d8_volume_Release(IDirect3DVolume8
*iface
)
61 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
63 TRACE("iface %p.\n", iface
);
64 TRACE("Forwarding to %p.\n", volume
->texture
);
66 return IDirect3DBaseTexture8_Release(&volume
->texture
->IDirect3DBaseTexture8_iface
);
69 static HRESULT WINAPI
d3d8_volume_GetDevice(IDirect3DVolume8
*iface
, IDirect3DDevice8
**device
)
71 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
73 TRACE("iface %p, device %p.\n", iface
, device
);
75 return IDirect3DBaseTexture8_GetDevice(&volume
->texture
->IDirect3DBaseTexture8_iface
, device
);
78 static HRESULT WINAPI
d3d8_volume_SetPrivateData(IDirect3DVolume8
*iface
, REFGUID guid
,
79 const void *data
, DWORD data_size
, DWORD flags
)
81 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
82 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
83 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
85 return d3d8_resource_set_private_data(&volume
->resource
, guid
, data
, data_size
, flags
);
88 static HRESULT WINAPI
d3d8_volume_GetPrivateData(IDirect3DVolume8
*iface
, REFGUID guid
,
89 void *data
, DWORD
*data_size
)
91 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
92 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
93 iface
, debugstr_guid(guid
), data
, data_size
);
95 return d3d8_resource_get_private_data(&volume
->resource
, guid
, data
, data_size
);
98 static HRESULT WINAPI
d3d8_volume_FreePrivateData(IDirect3DVolume8
*iface
, REFGUID guid
)
100 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
101 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
103 return d3d8_resource_free_private_data(&volume
->resource
, guid
);
106 static HRESULT WINAPI
d3d8_volume_GetContainer(IDirect3DVolume8
*iface
, REFIID riid
, void **container
)
108 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
110 TRACE("iface %p, riid %s, container %p.\n", iface
, debugstr_guid(riid
), container
);
112 return IDirect3DBaseTexture8_QueryInterface(&volume
->texture
->IDirect3DBaseTexture8_iface
, riid
, container
);
115 static HRESULT WINAPI
d3d8_volume_GetDesc(IDirect3DVolume8
*iface
, D3DVOLUME_DESC
*desc
)
117 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
118 struct wined3d_sub_resource_desc wined3d_desc
;
120 TRACE("iface %p, desc %p.\n", iface
, desc
);
122 wined3d_mutex_lock();
123 wined3d_texture_get_sub_resource_desc(volume
->wined3d_texture
, volume
->sub_resource_idx
, &wined3d_desc
);
124 wined3d_mutex_unlock();
126 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
127 desc
->Type
= D3DRTYPE_VOLUME
;
128 desc
->Usage
= wined3d_desc
.usage
& WINED3DUSAGE_MASK
;
129 desc
->Pool
= wined3d_desc
.pool
;
130 desc
->Size
= wined3d_desc
.size
;
131 desc
->Width
= wined3d_desc
.width
;
132 desc
->Height
= wined3d_desc
.height
;
133 desc
->Depth
= wined3d_desc
.depth
;
138 static HRESULT WINAPI
d3d8_volume_LockBox(IDirect3DVolume8
*iface
,
139 D3DLOCKED_BOX
*locked_box
, const D3DBOX
*box
, DWORD flags
)
141 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
142 struct wined3d_map_desc map_desc
;
145 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
146 iface
, locked_box
, box
, flags
);
148 wined3d_mutex_lock();
149 if (FAILED(hr
= wined3d_resource_map(wined3d_texture_get_resource(volume
->wined3d_texture
),
150 volume
->sub_resource_idx
, &map_desc
, (const struct wined3d_box
*)box
, flags
)))
151 map_desc
.data
= NULL
;
152 wined3d_mutex_unlock();
154 locked_box
->RowPitch
= map_desc
.row_pitch
;
155 locked_box
->SlicePitch
= map_desc
.slice_pitch
;
156 locked_box
->pBits
= map_desc
.data
;
161 static HRESULT WINAPI
d3d8_volume_UnlockBox(IDirect3DVolume8
*iface
)
163 struct d3d8_volume
*volume
= impl_from_IDirect3DVolume8(iface
);
166 TRACE("iface %p.\n", iface
);
168 wined3d_mutex_lock();
169 hr
= wined3d_resource_unmap(wined3d_texture_get_resource(volume
->wined3d_texture
), volume
->sub_resource_idx
);
170 wined3d_mutex_unlock();
172 if (hr
== WINEDDERR_NOTLOCKED
)
173 return D3DERR_INVALIDCALL
;
177 static const IDirect3DVolume8Vtbl d3d8_volume_vtbl
=
180 d3d8_volume_QueryInterface
,
183 /* IDirect3DVolume8 */
184 d3d8_volume_GetDevice
,
185 d3d8_volume_SetPrivateData
,
186 d3d8_volume_GetPrivateData
,
187 d3d8_volume_FreePrivateData
,
188 d3d8_volume_GetContainer
,
191 d3d8_volume_UnlockBox
,
194 static void STDMETHODCALLTYPE
volume_wined3d_object_destroyed(void *parent
)
196 struct d3d8_volume
*volume
= parent
;
197 d3d8_resource_cleanup(&volume
->resource
);
198 HeapFree(GetProcessHeap(), 0, volume
);
201 static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops
=
203 volume_wined3d_object_destroyed
,
206 void volume_init(struct d3d8_volume
*volume
, struct wined3d_texture
*wined3d_texture
,
207 unsigned int sub_resource_idx
, const struct wined3d_parent_ops
**parent_ops
)
209 volume
->IDirect3DVolume8_iface
.lpVtbl
= &d3d8_volume_vtbl
;
210 d3d8_resource_init(&volume
->resource
);
211 volume
->resource
.refcount
= 0;
212 volume
->texture
= wined3d_texture_get_parent(wined3d_texture
);
213 volume
->wined3d_texture
= wined3d_texture
;
214 volume
->sub_resource_idx
= sub_resource_idx
;
216 *parent_ops
= &d3d8_volume_wined3d_parent_ops
;