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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
34 #include "d3d8_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
38 /* IDirect3DVolume IUnknown parts follow: */
39 HRESULT WINAPI
IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface
, REFIID riid
, LPVOID
* ppobj
) {
40 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
42 if (IsEqualGUID(riid
, &IID_IUnknown
)
43 || IsEqualGUID(riid
, &IID_IDirect3DVolume8
)) {
44 IDirect3DVolume8Impl_AddRef(iface
);
49 WARN("(%p)->(%s,%p) not found\n", This
, debugstr_guid(riid
), ppobj
);
53 ULONG WINAPI
IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface
) {
54 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
55 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
59 ULONG WINAPI
IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface
) {
60 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
61 ULONG ref
= --This
->ref
;
62 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
64 HeapFree(GetProcessHeap(), 0, This
->allocatedMemory
);
65 HeapFree(GetProcessHeap(), 0, This
);
70 /* IDirect3DVolume8: */
71 HRESULT WINAPI
IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface
, IDirect3DDevice8
** ppDevice
) {
72 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
73 TRACE("(%p) : returning %p\n", This
, This
->Device
);
74 *ppDevice
= (LPDIRECT3DDEVICE8
) This
->Device
;
76 /* Note Calling this method will increase the internal reference count
77 on the IDirect3DDevice8 interface. */
78 IDirect3DDevice8Impl_AddRef(*ppDevice
);
83 HRESULT WINAPI
IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
84 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
85 FIXME("(%p) : stub\n", This
);
89 HRESULT WINAPI
IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
90 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
91 FIXME("(%p) : stub\n", This
);
95 HRESULT WINAPI
IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface
, REFGUID refguid
) {
96 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
97 FIXME("(%p) : stub\n", This
);
101 HRESULT WINAPI
IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface
, REFIID riid
, void** ppContainer
) {
102 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
103 TRACE("(%p) : returning %p\n", This
, This
->Container
);
104 *ppContainer
= This
->Container
;
105 IUnknown_AddRef(This
->Container
);
109 HRESULT WINAPI
IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface
, D3DVOLUME_DESC
* pDesc
) {
110 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
111 TRACE("(%p) : copying into %p\n", This
, pDesc
);
112 memcpy(pDesc
, &This
->myDesc
, sizeof(D3DVOLUME_DESC
));
116 HRESULT WINAPI
IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface
, D3DLOCKED_BOX
* pLockedVolume
, CONST D3DBOX
* pBox
, DWORD Flags
) {
117 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
118 FIXME("(%p) : pBox=%p stub\n", This
, pBox
);
120 /* fixme: should we really lock as such? */
121 TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This
, pBox
, pLockedVolume
, This
->allocatedMemory
);
123 pLockedVolume
->RowPitch
= This
->bytesPerPixel
* This
->myDesc
.Width
; /* Bytes / row */
124 pLockedVolume
->SlicePitch
= This
->bytesPerPixel
* This
->myDesc
.Width
* This
->myDesc
.Height
; /* Bytes / slice */
126 TRACE("No box supplied - all is ok\n");
127 pLockedVolume
->pBits
= This
->allocatedMemory
;
128 This
->lockedBox
.Left
= 0;
129 This
->lockedBox
.Top
= 0;
130 This
->lockedBox
.Front
= 0;
131 This
->lockedBox
.Right
= This
->myDesc
.Width
;
132 This
->lockedBox
.Bottom
= This
->myDesc
.Height
;
133 This
->lockedBox
.Back
= This
->myDesc
.Depth
;
135 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
);
136 pLockedVolume
->pBits
= This
->allocatedMemory
+
137 (pLockedVolume
->SlicePitch
* pBox
->Front
) + /* FIXME: is front < back or vica versa? */
138 (pLockedVolume
->RowPitch
* pBox
->Top
) +
139 (pBox
->Left
* This
->bytesPerPixel
);
140 This
->lockedBox
.Left
= pBox
->Left
;
141 This
->lockedBox
.Top
= pBox
->Top
;
142 This
->lockedBox
.Front
= pBox
->Front
;
143 This
->lockedBox
.Right
= pBox
->Right
;
144 This
->lockedBox
.Bottom
= pBox
->Bottom
;
145 This
->lockedBox
.Back
= pBox
->Back
;
148 if (Flags
& (D3DLOCK_NO_DIRTY_UPDATE
| D3DLOCK_READONLY
)) {
153 * as seen in msdn docs
155 IDirect3DVolume8Impl_AddDirtyBox(iface
, &This
->lockedBox
);
157 /** Dirtify Container if needed */
158 if (NULL
!= This
->Container
) {
159 IDirect3DVolumeTexture8
* cont
= (IDirect3DVolumeTexture8
*) This
->Container
;
160 D3DRESOURCETYPE containerType
= IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8
) cont
);
161 if (containerType
== D3DRTYPE_VOLUMETEXTURE
) {
162 IDirect3DBaseTexture8Impl
* pTexture
= (IDirect3DBaseTexture8Impl
*) cont
;
163 pTexture
->Dirty
= TRUE
;
165 FIXME("Set dirty on container type %d\n", containerType
);
171 TRACE("returning memory@%p rpitch(%d) spitch(%d)\n", pLockedVolume
->pBits
, pLockedVolume
->RowPitch
, pLockedVolume
->SlicePitch
);
175 HRESULT WINAPI
IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface
) {
176 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
177 if (FALSE
== This
->locked
) {
178 ERR("trying to lock unlocked volume@%p\n", This
);
179 return D3DERR_INVALIDCALL
;
181 TRACE("(%p) : unlocking volume\n", This
);
182 This
->locked
= FALSE
;
183 memset(&This
->lockedBox
, 0, sizeof(RECT
));
188 IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl
=
190 IDirect3DVolume8Impl_QueryInterface
,
191 IDirect3DVolume8Impl_AddRef
,
192 IDirect3DVolume8Impl_Release
,
193 IDirect3DVolume8Impl_GetDevice
,
194 IDirect3DVolume8Impl_SetPrivateData
,
195 IDirect3DVolume8Impl_GetPrivateData
,
196 IDirect3DVolume8Impl_FreePrivateData
,
197 IDirect3DVolume8Impl_GetContainer
,
198 IDirect3DVolume8Impl_GetDesc
,
199 IDirect3DVolume8Impl_LockBox
,
200 IDirect3DVolume8Impl_UnlockBox
204 HRESULT WINAPI
IDirect3DVolume8Impl_CleanDirtyBox(LPDIRECT3DVOLUME8 iface
) {
205 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
207 This
->lockedBox
.Left
= This
->myDesc
.Width
;
208 This
->lockedBox
.Top
= This
->myDesc
.Height
;
209 This
->lockedBox
.Front
= This
->myDesc
.Depth
;
210 This
->lockedBox
.Right
= 0;
211 This
->lockedBox
.Bottom
= 0;
212 This
->lockedBox
.Back
= 0;
218 * very stupid way to handle multiple dirty box but it works :)
220 HRESULT WINAPI
IDirect3DVolume8Impl_AddDirtyBox(LPDIRECT3DVOLUME8 iface
, CONST D3DBOX
* pDirtyBox
) {
221 IDirect3DVolume8Impl
*This
= (IDirect3DVolume8Impl
*)iface
;
223 if (NULL
!= pDirtyBox
) {
224 This
->lockedBox
.Left
= min(This
->lockedBox
.Left
, pDirtyBox
->Left
);
225 This
->lockedBox
.Top
= min(This
->lockedBox
.Top
, pDirtyBox
->Top
);
226 This
->lockedBox
.Front
= min(This
->lockedBox
.Front
, pDirtyBox
->Front
);
227 This
->lockedBox
.Right
= max(This
->lockedBox
.Right
, pDirtyBox
->Right
);
228 This
->lockedBox
.Bottom
= max(This
->lockedBox
.Bottom
, pDirtyBox
->Bottom
);
229 This
->lockedBox
.Back
= max(This
->lockedBox
.Back
, pDirtyBox
->Back
);
231 This
->lockedBox
.Left
= 0;
232 This
->lockedBox
.Top
= 0;
233 This
->lockedBox
.Front
= 0;
234 This
->lockedBox
.Right
= This
->myDesc
.Width
;
235 This
->lockedBox
.Bottom
= This
->myDesc
.Height
;
236 This
->lockedBox
.Back
= This
->myDesc
.Depth
;