2 * IWineD3DVolume implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wined3d_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
26 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->wineD3DDevice)->wineD3D))->gl_info
28 /* *******************************************
29 IWineD3DVolume IUnknown parts follow
30 ******************************************* */
31 HRESULT WINAPI IWineD3DVolumeImpl_QueryInterface(IWineD3DVolume *iface, REFIID riid, LPVOID *ppobj)
33 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
34 WARN("(%p)->(%s,%p) should not be called\n",This,debugstr_guid(riid),ppobj);
38 ULONG WINAPI IWineD3DVolumeImpl_AddRef(IWineD3DVolume *iface) {
39 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
40 TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
41 IUnknown_AddRef(This->parent);
42 return InterlockedIncrement(&This->ref);
45 ULONG WINAPI IWineD3DVolumeImpl_Release(IWineD3DVolume *iface) {
46 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
48 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
49 ref = InterlockedDecrement(&This->ref);
51 HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
52 IWineD3DDevice_Release((IWineD3DDevice *)This->wineD3DDevice);
53 HeapFree(GetProcessHeap(), 0, This);
55 IUnknown_Release(This->parent); /* Released the reference to the d3dx object */
60 /* *******************************************
61 IWineD3DVolume parts follow
62 ******************************************* */
63 HRESULT WINAPI IWineD3DVolumeImpl_GetParent(IWineD3DVolume *iface, IUnknown **pParent) {
64 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
65 IUnknown_AddRef(This->parent);
66 *pParent = This->parent;
70 HRESULT WINAPI IWineD3DVolumeImpl_GetDevice(IWineD3DVolume *iface, IWineD3DDevice** ppDevice) {
71 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
72 TRACE("(%p) : returning %p\n", This, This->wineD3DDevice);
74 *ppDevice = (IWineD3DDevice *) This->wineD3DDevice;
75 IWineD3DDevice_AddRef(*ppDevice);
80 HRESULT WINAPI IWineD3DVolumeImpl_SetPrivateData(IWineD3DVolume *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
81 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
82 FIXME("(%p) : stub\n", This);
86 HRESULT WINAPI IWineD3DVolumeImpl_GetPrivateData(IWineD3DVolume *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
87 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
88 FIXME("(%p) : stub\n", This);
92 HRESULT WINAPI IWineD3DVolumeImpl_FreePrivateData(IWineD3DVolume *iface, REFGUID refguid) {
93 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
94 FIXME("(%p) : stub\n", This);
98 HRESULT WINAPI IWineD3DVolumeImpl_GetContainer(IWineD3DVolume *iface, REFIID riid, void** ppContainer) {
99 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
100 TRACE("(%p) : returning %p\n", This, This->container);
101 *ppContainer = This->container;
102 IUnknown_AddRef(This->container);
106 HRESULT WINAPI IWineD3DVolumeImpl_GetDesc(IWineD3DVolume *iface, WINED3DVOLUME_DESC* pDesc) {
107 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
108 TRACE("(%p) : copying into %p\n", This, pDesc);
110 *(pDesc->Format) = This->currentDesc.Format;
111 *(pDesc->Type) = This->currentDesc.Type;
112 *(pDesc->Usage) = This->currentDesc.Usage;
113 *(pDesc->Pool) = This->currentDesc.Pool;
114 *(pDesc->Size) = This->currentDesc.Size; /* dx8 only */
115 *(pDesc->Width) = This->currentDesc.Width;
116 *(pDesc->Height) = This->currentDesc.Height;
117 *(pDesc->Depth) = This->currentDesc.Depth;
121 HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
122 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
123 FIXME("(%p) : pBox=%p stub\n", This, pBox);
125 /* fixme: should we really lock as such? */
126 TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->allocatedMemory);
128 pLockedVolume->RowPitch = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */
129 pLockedVolume->SlicePitch = This->bytesPerPixel * This->currentDesc.Width * This->currentDesc.Height; /* Bytes / slice */
131 TRACE("No box supplied - all is ok\n");
132 pLockedVolume->pBits = This->allocatedMemory;
133 This->lockedBox.Left = 0;
134 This->lockedBox.Top = 0;
135 This->lockedBox.Front = 0;
136 This->lockedBox.Right = This->currentDesc.Width;
137 This->lockedBox.Bottom = This->currentDesc.Height;
138 This->lockedBox.Back = This->currentDesc.Depth;
140 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);
141 pLockedVolume->pBits = This->allocatedMemory +
142 (pLockedVolume->SlicePitch * pBox->Front) + /* FIXME: is front < back or vica versa? */
143 (pLockedVolume->RowPitch * pBox->Top) +
144 (pBox->Left * This->bytesPerPixel);
145 This->lockedBox.Left = pBox->Left;
146 This->lockedBox.Top = pBox->Top;
147 This->lockedBox.Front = pBox->Front;
148 This->lockedBox.Right = pBox->Right;
149 This->lockedBox.Bottom = pBox->Bottom;
150 This->lockedBox.Back = pBox->Back;
153 if (Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY)) {
158 * as seen in msdn docs
160 IWineD3DVolume_AddDirtyBox(iface, &This->lockedBox);
162 /** Dirtify Container if needed */
163 if (NULL != This->container) {
165 IWineD3DVolumeTexture *cont = (IWineD3DVolumeTexture*) This->container;
166 D3DRESOURCETYPE containerType = IWineD3DBaseTexture_GetType((IWineD3DBaseTexture *) cont);
168 if (containerType == D3DRTYPE_VOLUMETEXTURE) {
169 IWineD3DBaseTextureImpl* pTexture = (IWineD3DBaseTextureImpl*) cont;
170 pTexture->baseTexture.dirty = TRUE;
172 FIXME("Set dirty on container type %d\n", containerType);
178 TRACE("returning memory@%p rpitch(%d) spitch(%d)\n", pLockedVolume->pBits, pLockedVolume->RowPitch, pLockedVolume->SlicePitch);
182 HRESULT WINAPI IWineD3DVolumeImpl_UnlockBox(IWineD3DVolume *iface) {
183 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
184 if (FALSE == This->locked) {
185 ERR("trying to lock unlocked volume@%p\n", This);
186 return D3DERR_INVALIDCALL;
188 TRACE("(%p) : unlocking volume\n", This);
189 This->locked = FALSE;
190 memset(&This->lockedBox, 0, sizeof(RECT));
194 /* Internal use functions follow : */
196 HRESULT WINAPI IWineD3DVolumeImpl_CleanDirtyBox(IWineD3DVolume *iface) {
197 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
199 This->lockedBox.Left = This->currentDesc.Width;
200 This->lockedBox.Top = This->currentDesc.Height;
201 This->lockedBox.Front = This->currentDesc.Depth;
202 This->lockedBox.Right = 0;
203 This->lockedBox.Bottom = 0;
204 This->lockedBox.Back = 0;
208 HRESULT WINAPI IWineD3DVolumeImpl_AddDirtyBox(IWineD3DVolume *iface, CONST D3DBOX* pDirtyBox) {
209 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
211 if (NULL != pDirtyBox) {
212 This->lockedBox.Left = min(This->lockedBox.Left, pDirtyBox->Left);
213 This->lockedBox.Top = min(This->lockedBox.Top, pDirtyBox->Top);
214 This->lockedBox.Front = min(This->lockedBox.Front, pDirtyBox->Front);
215 This->lockedBox.Right = max(This->lockedBox.Right, pDirtyBox->Right);
216 This->lockedBox.Bottom = max(This->lockedBox.Bottom, pDirtyBox->Bottom);
217 This->lockedBox.Back = max(This->lockedBox.Back, pDirtyBox->Back);
219 This->lockedBox.Left = 0;
220 This->lockedBox.Top = 0;
221 This->lockedBox.Front = 0;
222 This->lockedBox.Right = This->currentDesc.Width;
223 This->lockedBox.Bottom = This->currentDesc.Height;
224 This->lockedBox.Back = This->currentDesc.Depth;
229 IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
231 IWineD3DVolumeImpl_QueryInterface,
232 IWineD3DVolumeImpl_AddRef,
233 IWineD3DVolumeImpl_Release,
234 IWineD3DVolumeImpl_GetParent,
235 IWineD3DVolumeImpl_GetDevice,
236 IWineD3DVolumeImpl_SetPrivateData,
237 IWineD3DVolumeImpl_GetPrivateData,
238 IWineD3DVolumeImpl_FreePrivateData,
239 IWineD3DVolumeImpl_GetContainer,
240 IWineD3DVolumeImpl_GetDesc,
241 IWineD3DVolumeImpl_LockBox,
242 IWineD3DVolumeImpl_UnlockBox,
243 IWineD3DVolumeImpl_AddDirtyBox,
244 IWineD3DVolumeImpl_CleanDirtyBox