wined3d: Remove an obsolete comment.
[wine] / dlls / d3d8 / volumetexture.c
1 /*
2  * IDirect3DVolumeTexture8 implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 static inline IDirect3DVolumeTexture8Impl *impl_from_IDirect3DVolumeTexture8(IDirect3DVolumeTexture8 *iface)
27 {
28     return CONTAINING_RECORD(iface, IDirect3DVolumeTexture8Impl, IDirect3DVolumeTexture8_iface);
29 }
30
31 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_QueryInterface(IDirect3DVolumeTexture8 *iface,
32         REFIID riid, void **ppobj)
33 {
34     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
35
36     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
37
38     if (IsEqualGUID(riid, &IID_IUnknown)
39     || IsEqualGUID(riid, &IID_IDirect3DResource8)
40     || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
41     || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)) {
42         IUnknown_AddRef(iface);
43         *ppobj = This;
44         return S_OK;
45     }
46
47     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
48     *ppobj = NULL;
49     return E_NOINTERFACE;
50 }
51
52 static ULONG WINAPI IDirect3DVolumeTexture8Impl_AddRef(IDirect3DVolumeTexture8 *iface)
53 {
54     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
55     ULONG ref = InterlockedIncrement(&This->ref);
56
57     TRACE("%p increasing refcount to %u.\n", iface, ref);
58
59     if (ref == 1)
60     {
61         IDirect3DDevice8_AddRef(This->parentDevice);
62         wined3d_mutex_lock();
63         wined3d_texture_incref(This->wined3d_texture);
64         wined3d_mutex_unlock();
65     }
66
67     return ref;
68 }
69
70 static ULONG WINAPI IDirect3DVolumeTexture8Impl_Release(IDirect3DVolumeTexture8 *iface)
71 {
72     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
73     ULONG ref = InterlockedDecrement(&This->ref);
74
75     TRACE("%p decreasing refcount to %u.\n", iface, ref);
76
77     if (ref == 0) {
78         IDirect3DDevice8 *parentDevice = This->parentDevice;
79
80         wined3d_mutex_lock();
81         wined3d_texture_decref(This->wined3d_texture);
82         wined3d_mutex_unlock();
83
84         /* Release the device last, as it may cause the device to be destroyed. */
85         IDirect3DDevice8_Release(parentDevice);
86     }
87     return ref;
88 }
89
90 /* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */
91 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTexture8 *iface,
92         IDirect3DDevice8 **device)
93 {
94     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
95
96     TRACE("iface %p, device %p.\n", iface, device);
97
98     *device = This->parentDevice;
99     IDirect3DDevice8_AddRef(*device);
100
101     TRACE("Returning device %p.\n", *device);
102
103     return D3D_OK;
104 }
105
106 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_SetPrivateData(IDirect3DVolumeTexture8 *iface,
107         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
108 {
109     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
110     struct wined3d_resource *resource;
111     HRESULT hr;
112
113     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
114             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
115
116     wined3d_mutex_lock();
117     resource = wined3d_texture_get_resource(This->wined3d_texture);
118     hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
119     wined3d_mutex_unlock();
120
121     return hr;
122 }
123
124 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetPrivateData(IDirect3DVolumeTexture8 *iface,
125         REFGUID refguid, void *pData, DWORD *pSizeOfData)
126 {
127     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
128     struct wined3d_resource *resource;
129     HRESULT hr;
130
131     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
132             iface, debugstr_guid(refguid), pData, pSizeOfData);
133
134     wined3d_mutex_lock();
135     resource = wined3d_texture_get_resource(This->wined3d_texture);
136     hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
137     wined3d_mutex_unlock();
138
139     return hr;
140 }
141
142 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_FreePrivateData(IDirect3DVolumeTexture8 *iface,
143         REFGUID refguid)
144 {
145     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
146     struct wined3d_resource *resource;
147     HRESULT hr;
148
149     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
150
151     wined3d_mutex_lock();
152     resource = wined3d_texture_get_resource(This->wined3d_texture);
153     hr = wined3d_resource_free_private_data(resource, refguid);
154     wined3d_mutex_unlock();
155
156     return hr;
157 }
158
159 static DWORD WINAPI IDirect3DVolumeTexture8Impl_SetPriority(IDirect3DVolumeTexture8 *iface,
160         DWORD PriorityNew)
161 {
162     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
163     DWORD ret;
164
165     TRACE("iface %p, priority %u.\n", iface, PriorityNew);
166
167     wined3d_mutex_lock();
168     ret = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
169     wined3d_mutex_unlock();
170
171     return ret;
172 }
173
174 static DWORD WINAPI IDirect3DVolumeTexture8Impl_GetPriority(IDirect3DVolumeTexture8 *iface)
175 {
176     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
177     DWORD ret;
178
179     TRACE("iface %p.\n", iface);
180
181     wined3d_mutex_lock();
182     ret = wined3d_texture_get_priority(This->wined3d_texture);
183     wined3d_mutex_unlock();
184
185     return ret;
186 }
187
188 static void WINAPI IDirect3DVolumeTexture8Impl_PreLoad(IDirect3DVolumeTexture8 *iface)
189 {
190     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
191
192     TRACE("iface %p.\n", iface);
193
194     wined3d_mutex_lock();
195     wined3d_texture_preload(This->wined3d_texture);
196     wined3d_mutex_unlock();
197 }
198
199 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture8Impl_GetType(IDirect3DVolumeTexture8 *iface)
200 {
201     TRACE("iface %p.\n", iface);
202
203     return D3DRTYPE_VOLUMETEXTURE;
204 }
205
206 /* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */
207 static DWORD WINAPI IDirect3DVolumeTexture8Impl_SetLOD(IDirect3DVolumeTexture8 *iface, DWORD LODNew)
208 {
209     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
210     DWORD ret;
211
212     TRACE("iface %p, lod %u.\n", iface, LODNew);
213
214     wined3d_mutex_lock();
215     ret = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
216     wined3d_mutex_unlock();
217
218     return ret;
219 }
220
221 static DWORD WINAPI IDirect3DVolumeTexture8Impl_GetLOD(IDirect3DVolumeTexture8 *iface)
222 {
223     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
224     DWORD ret;
225
226     TRACE("iface %p.\n", iface);
227
228     wined3d_mutex_lock();
229     ret = wined3d_texture_get_lod(This->wined3d_texture);
230     wined3d_mutex_unlock();
231
232     return ret;
233 }
234
235 static DWORD WINAPI IDirect3DVolumeTexture8Impl_GetLevelCount(IDirect3DVolumeTexture8 *iface)
236 {
237     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
238     DWORD ret;
239
240     TRACE("iface %p.\n", iface);
241
242     wined3d_mutex_lock();
243     ret = wined3d_texture_get_level_count(This->wined3d_texture);
244     wined3d_mutex_unlock();
245
246     return ret;
247 }
248
249 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetLevelDesc(IDirect3DVolumeTexture8 *iface,
250         UINT level, D3DVOLUME_DESC *desc)
251 {
252     IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface);
253     struct wined3d_resource *sub_resource;
254     HRESULT hr = D3D_OK;
255
256     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
257
258     wined3d_mutex_lock();
259     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
260         hr = D3DERR_INVALIDCALL;
261     else
262     {
263         struct wined3d_resource_desc wined3d_desc;
264
265         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
266         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
267         desc->Type = wined3d_desc.resource_type;
268         desc->Usage = wined3d_desc.usage;
269         desc->Pool = wined3d_desc.pool;
270         desc->Size = wined3d_desc.size;
271         desc->Width = wined3d_desc.width;
272         desc->Height = wined3d_desc.height;
273         desc->Depth = wined3d_desc.depth;
274     }
275     wined3d_mutex_unlock();
276
277     return hr;
278 }
279
280 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetVolumeLevel(IDirect3DVolumeTexture8 *iface,
281         UINT level, IDirect3DVolume8 **volume)
282 {
283     IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface);
284     struct wined3d_resource *sub_resource;
285
286     TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
287
288     wined3d_mutex_lock();
289     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
290     {
291         wined3d_mutex_unlock();
292         return D3DERR_INVALIDCALL;
293     }
294
295     *volume = wined3d_resource_get_parent(sub_resource);
296     IDirect3DVolume8_AddRef(*volume);
297     wined3d_mutex_unlock();
298
299     return D3D_OK;
300 }
301
302 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_LockBox(IDirect3DVolumeTexture8 *iface,
303         UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
304 {
305     IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface);
306     struct wined3d_resource *sub_resource;
307     HRESULT hr;
308
309     TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
310             iface, level, locked_box, box, flags);
311
312     wined3d_mutex_lock();
313     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
314         hr = D3DERR_INVALIDCALL;
315     else
316         hr = IDirect3DVolume8_LockBox((IDirect3DVolume8 *)wined3d_resource_get_parent(sub_resource),
317                 locked_box, box, flags);
318     wined3d_mutex_unlock();
319
320     return hr;
321 }
322
323 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_UnlockBox(IDirect3DVolumeTexture8 *iface,
324         UINT level)
325 {
326     IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface);
327     struct wined3d_resource *sub_resource;
328     HRESULT hr;
329
330     TRACE("iface %p, level %u.\n", iface, level);
331
332     wined3d_mutex_lock();
333     if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
334         hr = D3DERR_INVALIDCALL;
335     else
336         hr = IDirect3DVolume8_UnlockBox((IDirect3DVolume8 *)wined3d_resource_get_parent(sub_resource));
337     wined3d_mutex_unlock();
338
339     return hr;
340 }
341
342 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_AddDirtyBox(IDirect3DVolumeTexture8 *iface,
343         const D3DBOX *dirty_box)
344 {
345     IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface);
346     HRESULT hr;
347
348     TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
349
350     wined3d_mutex_lock();
351     hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const WINED3DBOX *)dirty_box);
352     wined3d_mutex_unlock();
353
354     return hr;
355 }
356
357 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
358 {
359     /* IUnknown */
360     IDirect3DVolumeTexture8Impl_QueryInterface,
361     IDirect3DVolumeTexture8Impl_AddRef,
362     IDirect3DVolumeTexture8Impl_Release,
363     /* IDirect3DResource8 */
364     IDirect3DVolumeTexture8Impl_GetDevice,
365     IDirect3DVolumeTexture8Impl_SetPrivateData,
366     IDirect3DVolumeTexture8Impl_GetPrivateData,
367     IDirect3DVolumeTexture8Impl_FreePrivateData,
368     IDirect3DVolumeTexture8Impl_SetPriority,
369     IDirect3DVolumeTexture8Impl_GetPriority,
370     IDirect3DVolumeTexture8Impl_PreLoad,
371     IDirect3DVolumeTexture8Impl_GetType,
372     /* IDirect3DBaseTexture8 */
373     IDirect3DVolumeTexture8Impl_SetLOD,
374     IDirect3DVolumeTexture8Impl_GetLOD,
375     IDirect3DVolumeTexture8Impl_GetLevelCount,
376     /* IDirect3DVolumeTexture8 */
377     IDirect3DVolumeTexture8Impl_GetLevelDesc,
378     IDirect3DVolumeTexture8Impl_GetVolumeLevel,
379     IDirect3DVolumeTexture8Impl_LockBox,
380     IDirect3DVolumeTexture8Impl_UnlockBox,
381     IDirect3DVolumeTexture8Impl_AddDirtyBox
382 };
383
384 static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
385 {
386     HeapFree(GetProcessHeap(), 0, parent);
387 }
388
389 static const struct wined3d_parent_ops d3d8_volumetexture_wined3d_parent_ops =
390 {
391     volumetexture_wined3d_object_destroyed,
392 };
393
394 HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
395         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
396 {
397     HRESULT hr;
398
399     texture->IDirect3DVolumeTexture8_iface.lpVtbl = &Direct3DVolumeTexture8_Vtbl;
400     texture->ref = 1;
401
402     wined3d_mutex_lock();
403     hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels,
404             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
405             &d3d8_volumetexture_wined3d_parent_ops, &texture->wined3d_texture);
406     wined3d_mutex_unlock();
407     if (FAILED(hr))
408     {
409         WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
410         return hr;
411     }
412
413     texture->parentDevice = &device->IDirect3DDevice8_iface;
414     IDirect3DDevice8_AddRef(texture->parentDevice);
415
416     return D3D_OK;
417 }