2 * IDirect3DVolume8 implementation
4 * Copyright 2002-2003 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
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 #include "d3d8_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
40 /* IDirect3DVolume IUnknown parts follow: */
41 HRESULT WINAPI
IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface
, REFIID riid
, LPVOID
* ppobj
) {
42 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
44 if (IsEqualGUID(riid
, &IID_IUnknown
)
45 || IsEqualGUID(riid
, &IID_IDirect3DVolume8
)) {
46 IDirect3DVolume8Impl_AddRef(iface
);
51 WARN("(%p)->(%s,%p) not found\n", This
, debugstr_guid(riid
), ppobj
);
55 ULONG WINAPI
IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface
) {
56 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
57 ULONG ref
= InterlockedIncrement(&This
->ref
);
59 TRACE("(%p) : AddRef from %ld\n", This
, ref
- 1);
64 ULONG WINAPI
IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface
) {
65 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
66 ULONG ref
= InterlockedDecrement(&This
->ref
);
68 TRACE("(%p) : ReleaseRef to %ld\n", This
, ref
);
71 HeapFree(GetProcessHeap(), 0, This
->allocatedMemory
);
72 HeapFree(GetProcessHeap(), 0, This
);
77 /* IDirect3DVolume8: */
78 HRESULT WINAPI
IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface
, IDirect3DDevice8
** ppDevice
) {
79 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
80 TRACE("(%p) : returning %p\n", This
, This
->Device
);
81 *ppDevice
= (LPDIRECT3DDEVICE8
) This
->Device
;
83 /* Note Calling this method will increase the internal reference count
84 on the IDirect3DDevice8 interface. */
85 IDirect3DDevice8Impl_AddRef(*ppDevice
);
90 HRESULT WINAPI
IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
91 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
92 FIXME("(%p) : stub\n", This
);
96 HRESULT WINAPI
IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
97 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
98 FIXME("(%p) : stub\n", This
);
102 HRESULT WINAPI
IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface
, REFGUID refguid
) {
103 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
104 FIXME("(%p) : stub\n", This
);
108 HRESULT WINAPI
IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface
, REFIID riid
, void** ppContainer
) {
109 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
110 TRACE("(%p) : returning %p\n", This
, This
->Container
);
111 *ppContainer
= This
->Container
;
112 IUnknown_AddRef(This
->Container
);
116 HRESULT WINAPI
IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface
, D3DVOLUME_DESC
* pDesc
) {
117 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
118 TRACE("(%p) : copying into %p\n", This
, pDesc
);
119 memcpy(pDesc
, &This
->myDesc
, sizeof(D3DVOLUME_DESC
));
123 HRESULT WINAPI
IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface
, D3DLOCKED_BOX
* pLockedVolume
, CONST D3DBOX
* pBox
, DWORD Flags
) {
124 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
125 FIXME("(%p) : pBox=%p stub\n", This
, pBox
);
127 /* fixme: should we really lock as such? */
128 TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This
, pBox
, pLockedVolume
, This
->allocatedMemory
);
130 pLockedVolume
->RowPitch
= This
->bytesPerPixel
* This
->myDesc
.Width
; /* Bytes / row */
131 pLockedVolume
->SlicePitch
= This
->bytesPerPixel
* This
->myDesc
.Width
* This
->myDesc
.Height
; /* Bytes / slice */
133 TRACE("No box supplied - all is ok\n");
134 pLockedVolume
->pBits
= This
->allocatedMemory
;
135 This
->lockedBox
.Left
= 0;
136 This
->lockedBox
.Top
= 0;
137 This
->lockedBox
.Front
= 0;
138 This
->lockedBox
.Right
= This
->myDesc
.Width
;
139 This
->lockedBox
.Bottom
= This
->myDesc
.Height
;
140 This
->lockedBox
.Back
= This
->myDesc
.Depth
;
142 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
);
143 pLockedVolume
->pBits
= This
->allocatedMemory
+
144 (pLockedVolume
->SlicePitch
* pBox
->Front
) + /* FIXME: is front < back or vica versa? */
145 (pLockedVolume
->RowPitch
* pBox
->Top
) +
146 (pBox
->Left
* This
->bytesPerPixel
);
147 This
->lockedBox
.Left
= pBox
->Left
;
148 This
->lockedBox
.Top
= pBox
->Top
;
149 This
->lockedBox
.Front
= pBox
->Front
;
150 This
->lockedBox
.Right
= pBox
->Right
;
151 This
->lockedBox
.Bottom
= pBox
->Bottom
;
152 This
->lockedBox
.Back
= pBox
->Back
;
155 if (Flags
& (D3DLOCK_NO_DIRTY_UPDATE
| D3DLOCK_READONLY
)) {
160 * as seen in msdn docs
162 IDirect3DVolume8Impl_AddDirtyBox(iface
, &This
->lockedBox
);
164 /** Dirtify Container if needed */
165 if (NULL
!= This
->Container
) {
166 IDirect3DVolumeTexture8
* cont
= (IDirect3DVolumeTexture8
*) This
->Container
;
167 D3DRESOURCETYPE containerType
= IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8
) cont
);
168 if (containerType
== D3DRTYPE_VOLUMETEXTURE
) {
169 IDirect3DBaseTexture8Impl
* pTexture
= (IDirect3DBaseTexture8Impl
*) cont
;
170 pTexture
->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
IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface
) {
183 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)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
));
195 IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl
=
197 IDirect3DVolume8Impl_QueryInterface
,
198 IDirect3DVolume8Impl_AddRef
,
199 IDirect3DVolume8Impl_Release
,
200 IDirect3DVolume8Impl_GetDevice
,
201 IDirect3DVolume8Impl_SetPrivateData
,
202 IDirect3DVolume8Impl_GetPrivateData
,
203 IDirect3DVolume8Impl_FreePrivateData
,
204 IDirect3DVolume8Impl_GetContainer
,
205 IDirect3DVolume8Impl_GetDesc
,
206 IDirect3DVolume8Impl_LockBox
,
207 IDirect3DVolume8Impl_UnlockBox
211 HRESULT WINAPI
IDirect3DVolume8Impl_CleanDirtyBox(LPDIRECT3DVOLUME8 iface
) {
212 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
214 This
->lockedBox
.Left
= This
->myDesc
.Width
;
215 This
->lockedBox
.Top
= This
->myDesc
.Height
;
216 This
->lockedBox
.Front
= This
->myDesc
.Depth
;
217 This
->lockedBox
.Right
= 0;
218 This
->lockedBox
.Bottom
= 0;
219 This
->lockedBox
.Back
= 0;
225 * very stupid way to handle multiple dirty box but it works :)
227 HRESULT WINAPI
IDirect3DVolume8Impl_AddDirtyBox(LPDIRECT3DVOLUME8 iface
, CONST D3DBOX
* pDirtyBox
) {
228 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
230 if (NULL
!= pDirtyBox
) {
231 This
->lockedBox
.Left
= min(This
->lockedBox
.Left
, pDirtyBox
->Left
);
232 This
->lockedBox
.Top
= min(This
->lockedBox
.Top
, pDirtyBox
->Top
);
233 This
->lockedBox
.Front
= min(This
->lockedBox
.Front
, pDirtyBox
->Front
);
234 This
->lockedBox
.Right
= max(This
->lockedBox
.Right
, pDirtyBox
->Right
);
235 This
->lockedBox
.Bottom
= max(This
->lockedBox
.Bottom
, pDirtyBox
->Bottom
);
236 This
->lockedBox
.Back
= max(This
->lockedBox
.Back
, pDirtyBox
->Back
);
238 This
->lockedBox
.Left
= 0;
239 This
->lockedBox
.Top
= 0;
240 This
->lockedBox
.Front
= 0;
241 This
->lockedBox
.Right
= This
->myDesc
.Width
;
242 This
->lockedBox
.Bottom
= This
->myDesc
.Height
;
243 This
->lockedBox
.Back
= This
->myDesc
.Depth
;