Added version information.
[wine] / dlls / d3d8 / volume.c
1 /*
2  * IDirect3DVolume8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27 #include "wine/debug.h"
28
29 #include "d3d8_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32
33 /* IDirect3DVolume IUnknown parts follow: */
34 HRESULT WINAPI IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface,REFIID riid,LPVOID *ppobj)
35 {
36     ICOM_THIS(IDirect3DVolume8Impl,iface);
37
38     if (IsEqualGUID(riid, &IID_IUnknown)
39         || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
40         IDirect3DVolume8Impl_AddRef(iface);
41         *ppobj = This;
42         return D3D_OK;
43     }
44
45     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
46     return E_NOINTERFACE;
47 }
48
49 ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
50     ICOM_THIS(IDirect3DVolume8Impl,iface);
51     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52     return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
56     ICOM_THIS(IDirect3DVolume8Impl,iface);
57     ULONG ref = --This->ref;
58     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
59     if (ref == 0) {
60         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DVolume8: */
67 HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8** ppDevice) {
68     ICOM_THIS(IDirect3DVolume8Impl,iface);
69     TRACE("(%p) : returning %p\n", This, This->Device);
70     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
71
72     /* Note  Calling this method will increase the internal reference count 
73        on the IDirect3DDevice8 interface. */
74     IDirect3DDevice8Impl_AddRef(*ppDevice);
75
76     return D3D_OK;
77 }
78 HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
79     ICOM_THIS(IDirect3DVolume8Impl,iface);
80     FIXME("(%p) : stub\n", This);    
81     return D3D_OK;
82 }
83 HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID  refguid, void* pData, DWORD* pSizeOfData) {
84     ICOM_THIS(IDirect3DVolume8Impl,iface);
85     FIXME("(%p) : stub\n", This);    
86     return D3D_OK;
87 }
88 HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
89     ICOM_THIS(IDirect3DVolume8Impl,iface);
90     FIXME("(%p) : stub\n", This);    
91     return D3D_OK;
92 }
93
94 HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void** ppContainer) {
95     ICOM_THIS(IDirect3DVolume8Impl,iface);
96     TRACE("(%p) : returning %p\n", This, This->Container);
97     *ppContainer = This->Container;
98     IUnknown_AddRef(This->Container);
99     return D3D_OK;
100 }
101 HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC* pDesc) {
102     ICOM_THIS(IDirect3DVolume8Impl,iface);
103     TRACE("(%p) : copying into %p\n", This, pDesc);
104     memcpy(pDesc, &This->myDesc, sizeof(D3DVOLUME_DESC));
105     return D3D_OK;
106 }
107 HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
108     ICOM_THIS(IDirect3DVolume8Impl,iface);
109     FIXME("(%p) : pBox=%p stub\n", This, pBox);    
110
111     /* fixme: should we really lock as such? */
112     TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->allocatedMemory);
113
114     pLockedVolume->RowPitch   = This->bytesPerPixel * This->myDesc.Width;                        /* Bytes / row   */
115     pLockedVolume->SlicePitch = This->bytesPerPixel * This->myDesc.Width * This->myDesc.Height;  /* Bytes / slice */
116     if (!pBox) {
117         TRACE("No box supplied - all is ok\n");
118         pLockedVolume->pBits = This->allocatedMemory;
119     } else {
120         TRACE("Lock Box (%p) = l %d, t %d, r %d, b %d, fr %d, ba %d\n", pBox, pBox->Left, pBox->Top, pBox->Right, pBox->Bottom, pBox->Front, pBox->Back);
121         pLockedVolume->pBits = This->allocatedMemory + 
122             (pLockedVolume->SlicePitch * pBox->Front) + /* FIXME: is front < back or vica versa? */
123             (pLockedVolume->RowPitch * pBox->Top) + 
124             (pBox->Left * This->bytesPerPixel);
125     }
126     
127     if (Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY)) {
128       /* Dont dirtify */
129     } else {
130       /**
131        * Dirtify on lock
132        * as seen in msdn docs
133        */
134       /**  Dirtify Container if needed */
135       if (NULL != This->Container) {
136         IDirect3DVolumeTexture8* cont = (IDirect3DVolumeTexture8*) This->Container;     
137         D3DRESOURCETYPE containerType = IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) cont);
138         if (containerType == D3DRTYPE_VOLUMETEXTURE) {
139           IDirect3DBaseTexture8Impl* pTexture = (IDirect3DBaseTexture8Impl*) cont;
140           pTexture->Dirty = TRUE;
141         } else {
142           FIXME("Set dirty on container type %d\n", containerType);
143         }
144       }
145     }
146
147     TRACE("returning memory@%p rpitch(%d) spitch(%d)\n", pLockedVolume->pBits, pLockedVolume->RowPitch, pLockedVolume->SlicePitch);
148     return D3D_OK;
149 }
150 HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
151     ICOM_THIS(IDirect3DVolume8Impl,iface);
152     TRACE("(%p) : stub\n", This);
153 #if 0
154     if (This->Container) {
155         IDirect3DVolumeTexture8* cont = (IDirect3DVolumeTexture8*) This->Container;
156         D3DRESOURCETYPE containerType = IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) cont);
157         if (containerType == D3DRTYPE_VOLUMETEXTURE) {
158             IDirect3DTexture8Impl* pTexture = (IDirect3DTexture8Impl*) cont;
159             pTexture->Dirty = TRUE;
160         } else {
161             FIXME("Set dirty on container type %d\n", containerType);
162         }
163     }
164 #endif
165     return D3D_OK;
166 }
167
168
169 ICOM_VTABLE(IDirect3DVolume8) Direct3DVolume8_Vtbl =
170 {
171     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
172     IDirect3DVolume8Impl_QueryInterface,
173     IDirect3DVolume8Impl_AddRef,
174     IDirect3DVolume8Impl_Release,
175     IDirect3DVolume8Impl_GetDevice,
176     IDirect3DVolume8Impl_SetPrivateData,
177     IDirect3DVolume8Impl_GetPrivateData,
178     IDirect3DVolume8Impl_FreePrivateData,
179     IDirect3DVolume8Impl_GetContainer,
180     IDirect3DVolume8Impl_GetDesc,
181     IDirect3DVolume8Impl_LockBox,
182     IDirect3DVolume8Impl_UnlockBox
183 };