2 * IDirect3DIndexBuffer9 implementation
4 * Copyright 2002-2004 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 /* IDirect3DIndexBuffer9 IUnknown parts follow: */
28 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface
, REFIID riid
, LPVOID
* ppobj
) {
29 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
31 if (IsEqualGUID(riid
, &IID_IUnknown
)
32 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
33 || IsEqualGUID(riid
, &IID_IDirect3DIndexBuffer9
)) {
34 IDirect3DIndexBuffer9_AddRef(iface
);
39 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
44 static ULONG WINAPI
IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface
) {
45 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
46 ULONG ref
= InterlockedIncrement(&This
->ref
);
48 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
53 static ULONG WINAPI
IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface
) {
54 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
55 ULONG ref
= InterlockedDecrement(&This
->ref
);
57 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
60 EnterCriticalSection(&d3d9_cs
);
61 IWineD3DBuffer_Release(This
->wineD3DIndexBuffer
);
62 LeaveCriticalSection(&d3d9_cs
);
63 IDirect3DDevice9Ex_Release(This
->parentDevice
);
64 HeapFree(GetProcessHeap(), 0, This
);
69 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
70 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface
, IDirect3DDevice9
** ppDevice
) {
71 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
72 IWineD3DDevice
*wined3d_device
;
74 TRACE("(%p) Relay\n", This
);
76 EnterCriticalSection(&d3d9_cs
);
77 hr
= IWineD3DBuffer_GetDevice(This
->wineD3DIndexBuffer
, &wined3d_device
);
80 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
81 IWineD3DDevice_Release(wined3d_device
);
83 LeaveCriticalSection(&d3d9_cs
);
87 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
88 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
90 TRACE("(%p) Relay\n", This
);
92 EnterCriticalSection(&d3d9_cs
);
93 hr
= IWineD3DBuffer_SetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, SizeOfData
, Flags
);
94 LeaveCriticalSection(&d3d9_cs
);
98 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
99 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
101 TRACE("(%p) Relay\n", This
);
103 EnterCriticalSection(&d3d9_cs
);
104 hr
= IWineD3DBuffer_GetPrivateData(This
->wineD3DIndexBuffer
, refguid
, pData
, pSizeOfData
);
105 LeaveCriticalSection(&d3d9_cs
);
109 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface
, REFGUID refguid
) {
110 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
112 TRACE("(%p) Relay\n", This
);
114 EnterCriticalSection(&d3d9_cs
);
115 hr
= IWineD3DBuffer_FreePrivateData(This
->wineD3DIndexBuffer
, refguid
);
116 LeaveCriticalSection(&d3d9_cs
);
120 static DWORD WINAPI
IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface
, DWORD PriorityNew
) {
121 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
123 TRACE("(%p) Relay\n", This
);
125 EnterCriticalSection(&d3d9_cs
);
126 ret
= IWineD3DBuffer_SetPriority(This
->wineD3DIndexBuffer
, PriorityNew
);
127 LeaveCriticalSection(&d3d9_cs
);
131 static DWORD WINAPI
IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface
) {
132 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
134 TRACE("(%p) Relay\n", This
);
136 EnterCriticalSection(&d3d9_cs
);
137 ret
= IWineD3DBuffer_GetPriority(This
->wineD3DIndexBuffer
);
138 LeaveCriticalSection(&d3d9_cs
);
142 static void WINAPI
IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface
) {
143 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
144 TRACE("(%p) Relay\n", This
);
146 EnterCriticalSection(&d3d9_cs
);
147 IWineD3DBuffer_PreLoad(This
->wineD3DIndexBuffer
);
148 LeaveCriticalSection(&d3d9_cs
);
151 static D3DRESOURCETYPE WINAPI
IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface
) {
152 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
153 TRACE("(%p)\n", This
);
155 return D3DRTYPE_INDEXBUFFER
;
158 /* IDirect3DIndexBuffer9 Interface follow: */
159 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface
, UINT OffsetToLock
, UINT SizeToLock
, void** ppbData
, DWORD Flags
) {
160 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
162 TRACE("(%p) Relay\n", This
);
164 EnterCriticalSection(&d3d9_cs
);
165 hr
= IWineD3DBuffer_Map(This
->wineD3DIndexBuffer
, OffsetToLock
, SizeToLock
, (BYTE
**)ppbData
, Flags
);
166 LeaveCriticalSection(&d3d9_cs
);
170 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface
) {
171 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
173 TRACE("(%p) Relay\n", This
);
175 EnterCriticalSection(&d3d9_cs
);
176 hr
= IWineD3DBuffer_Unmap(This
->wineD3DIndexBuffer
);
177 LeaveCriticalSection(&d3d9_cs
);
181 static HRESULT WINAPI
IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface
, D3DINDEXBUFFER_DESC
*pDesc
) {
182 IDirect3DIndexBuffer9Impl
*This
= (IDirect3DIndexBuffer9Impl
*)iface
;
184 WINED3DBUFFER_DESC desc
;
185 TRACE("(%p) Relay\n", This
);
187 EnterCriticalSection(&d3d9_cs
);
188 hr
= IWineD3DBuffer_GetDesc(This
->wineD3DIndexBuffer
, &desc
);
189 LeaveCriticalSection(&d3d9_cs
);
192 pDesc
->Format
= d3dformat_from_wined3dformat(This
->format
);
193 pDesc
->Usage
= desc
.Usage
;
194 pDesc
->Pool
= desc
.Pool
;
195 pDesc
->Size
= desc
.Size
;
196 pDesc
->Type
= D3DRTYPE_INDEXBUFFER
;
203 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl
=
206 IDirect3DIndexBuffer9Impl_QueryInterface
,
207 IDirect3DIndexBuffer9Impl_AddRef
,
208 IDirect3DIndexBuffer9Impl_Release
,
209 /* IDirect3DResource9 */
210 IDirect3DIndexBuffer9Impl_GetDevice
,
211 IDirect3DIndexBuffer9Impl_SetPrivateData
,
212 IDirect3DIndexBuffer9Impl_GetPrivateData
,
213 IDirect3DIndexBuffer9Impl_FreePrivateData
,
214 IDirect3DIndexBuffer9Impl_SetPriority
,
215 IDirect3DIndexBuffer9Impl_GetPriority
,
216 IDirect3DIndexBuffer9Impl_PreLoad
,
217 IDirect3DIndexBuffer9Impl_GetType
,
218 /* IDirect3DIndexBuffer9 */
219 IDirect3DIndexBuffer9Impl_Lock
,
220 IDirect3DIndexBuffer9Impl_Unlock
,
221 IDirect3DIndexBuffer9Impl_GetDesc
225 /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
226 HRESULT WINAPI
IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface
,
227 UINT Length
, DWORD Usage
, D3DFORMAT Format
, D3DPOOL Pool
,
228 IDirect3DIndexBuffer9
** ppIndexBuffer
, HANDLE
* pSharedHandle
) {
230 IDirect3DIndexBuffer9Impl
*object
;
231 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
232 HRESULT hrc
= D3D_OK
;
234 TRACE("(%p) Relay\n", This
);
235 /* Allocate the storage for the device */
236 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
237 if (NULL
== object
) {
238 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
239 return D3DERR_OUTOFVIDEOMEMORY
;
242 object
->lpVtbl
= &Direct3DIndexBuffer9_Vtbl
;
244 object
->format
= wined3dformat_from_d3dformat(Format
);
245 TRACE("Calling wined3d create index buffer\n");
246 EnterCriticalSection(&d3d9_cs
);
247 hrc
= IWineD3DDevice_CreateIndexBuffer(This
->WineD3DDevice
, Length
, Usage
& WINED3DUSAGE_MASK
,
248 (WINED3DPOOL
)Pool
, &object
->wineD3DIndexBuffer
, (IUnknown
*)object
);
249 LeaveCriticalSection(&d3d9_cs
);
253 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This
);
254 HeapFree(GetProcessHeap(), 0, object
);
256 IDirect3DDevice9Ex_AddRef(iface
);
257 object
->parentDevice
= iface
;
258 *ppIndexBuffer
= (LPDIRECT3DINDEXBUFFER9
) object
;
259 TRACE("(%p) : Created index buffer %p\n", This
, object
);