2 * IDirect3DVertexBuffer9 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
28 /* IDirect3DVertexBuffer9 IUnknown parts follow: */
29 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface
, REFIID riid
, LPVOID
* ppobj
) {
30 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
32 if (IsEqualGUID(riid
, &IID_IUnknown
)
33 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
34 || IsEqualGUID(riid
, &IID_IDirect3DVertexBuffer9
)) {
35 IUnknown_AddRef(iface
);
40 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
45 static ULONG WINAPI
IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface
) {
46 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
47 ULONG ref
= InterlockedIncrement(&This
->ref
);
49 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
54 static ULONG WINAPI
IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface
) {
55 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
56 ULONG ref
= InterlockedDecrement(&This
->ref
);
58 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
61 EnterCriticalSection(&d3d9_cs
);
62 IWineD3DVertexBuffer_Release(This
->wineD3DVertexBuffer
);
63 LeaveCriticalSection(&d3d9_cs
);
64 IUnknown_Release(This
->parentDevice
);
65 HeapFree(GetProcessHeap(), 0, This
);
70 /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
71 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface
, IDirect3DDevice9
** ppDevice
) {
72 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
74 TRACE("(%p) Relay\n", This
);
76 EnterCriticalSection(&d3d9_cs
);
77 hr
= IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9
) This
, ppDevice
);
78 LeaveCriticalSection(&d3d9_cs
);
82 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
83 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
84 TRACE("(%p) Relay\n", This
);
85 return IWineD3DVertexBuffer_SetPrivateData(This
->wineD3DVertexBuffer
, refguid
, pData
, SizeOfData
, Flags
);
88 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
89 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
91 TRACE("(%p) Relay\n", This
);
93 EnterCriticalSection(&d3d9_cs
);
94 hr
= IWineD3DVertexBuffer_GetPrivateData(This
->wineD3DVertexBuffer
, refguid
, pData
, pSizeOfData
);
95 LeaveCriticalSection(&d3d9_cs
);
99 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface
, REFGUID refguid
) {
100 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
102 TRACE("(%p) Relay\n", This
);
104 EnterCriticalSection(&d3d9_cs
);
105 hr
= IWineD3DVertexBuffer_FreePrivateData(This
->wineD3DVertexBuffer
, refguid
);
106 LeaveCriticalSection(&d3d9_cs
);
110 static DWORD WINAPI
IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface
, DWORD PriorityNew
) {
111 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
113 TRACE("(%p) Relay\n", This
);
115 EnterCriticalSection(&d3d9_cs
);
116 hr
= IWineD3DVertexBuffer_SetPriority(This
->wineD3DVertexBuffer
, PriorityNew
);
117 LeaveCriticalSection(&d3d9_cs
);
121 static DWORD WINAPI
IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface
) {
122 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
124 TRACE("(%p) Relay\n", This
);
126 EnterCriticalSection(&d3d9_cs
);
127 hr
= IWineD3DVertexBuffer_GetPriority(This
->wineD3DVertexBuffer
);
128 LeaveCriticalSection(&d3d9_cs
);
132 static void WINAPI
IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface
) {
133 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
134 TRACE("(%p) Relay\n", This
);
136 EnterCriticalSection(&d3d9_cs
);
137 IWineD3DVertexBuffer_PreLoad(This
->wineD3DVertexBuffer
);
138 LeaveCriticalSection(&d3d9_cs
);
142 static D3DRESOURCETYPE WINAPI
IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface
) {
143 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
145 TRACE("(%p) Relay\n", This
);
147 EnterCriticalSection(&d3d9_cs
);
148 ret
= IWineD3DVertexBuffer_GetType(This
->wineD3DVertexBuffer
);
149 LeaveCriticalSection(&d3d9_cs
);
153 /* IDirect3DVertexBuffer9 Interface follow: */
154 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface
, UINT OffsetToLock
, UINT SizeToLock
, void** ppbData
, DWORD Flags
) {
155 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
157 TRACE("(%p) Relay\n", This
);
159 EnterCriticalSection(&d3d9_cs
);
160 hr
= IWineD3DVertexBuffer_Lock(This
->wineD3DVertexBuffer
, OffsetToLock
, SizeToLock
, (BYTE
**)ppbData
, Flags
);
161 LeaveCriticalSection(&d3d9_cs
);
165 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface
) {
166 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
168 TRACE("(%p) Relay\n", This
);
170 EnterCriticalSection(&d3d9_cs
);
171 hr
= IWineD3DVertexBuffer_Unlock(This
->wineD3DVertexBuffer
);
172 LeaveCriticalSection(&d3d9_cs
);
176 static HRESULT WINAPI
IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface
, D3DVERTEXBUFFER_DESC
* pDesc
) {
177 IDirect3DVertexBuffer9Impl
*This
= (IDirect3DVertexBuffer9Impl
*)iface
;
179 TRACE("(%p) Relay\n", This
);
181 EnterCriticalSection(&d3d9_cs
);
182 hr
= IWineD3DVertexBuffer_GetDesc(This
->wineD3DVertexBuffer
, (WINED3DVERTEXBUFFER_DESC
*) pDesc
);
183 LeaveCriticalSection(&d3d9_cs
);
187 static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl
=
190 IDirect3DVertexBuffer9Impl_QueryInterface
,
191 IDirect3DVertexBuffer9Impl_AddRef
,
192 IDirect3DVertexBuffer9Impl_Release
,
193 /* IDirect3DResource9 */
194 IDirect3DVertexBuffer9Impl_GetDevice
,
195 IDirect3DVertexBuffer9Impl_SetPrivateData
,
196 IDirect3DVertexBuffer9Impl_GetPrivateData
,
197 IDirect3DVertexBuffer9Impl_FreePrivateData
,
198 IDirect3DVertexBuffer9Impl_SetPriority
,
199 IDirect3DVertexBuffer9Impl_GetPriority
,
200 IDirect3DVertexBuffer9Impl_PreLoad
,
201 IDirect3DVertexBuffer9Impl_GetType
,
202 /* IDirect3DVertexBuffer9 */
203 IDirect3DVertexBuffer9Impl_Lock
,
204 IDirect3DVertexBuffer9Impl_Unlock
,
205 IDirect3DVertexBuffer9Impl_GetDesc
209 /* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
210 HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface
,
211 UINT Size
, DWORD Usage
, DWORD FVF
, D3DPOOL Pool
,
212 IDirect3DVertexBuffer9
** ppVertexBuffer
, HANDLE
* pSharedHandle
) {
214 IDirect3DVertexBuffer9Impl
*object
;
215 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
216 HRESULT hrc
= D3D_OK
;
218 /* Allocate the storage for the device */
219 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DVertexBuffer9Impl
));
220 if (NULL
== object
) {
221 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
222 return D3DERR_OUTOFVIDEOMEMORY
;
225 object
->lpVtbl
= &Direct3DVertexBuffer9_Vtbl
;
227 EnterCriticalSection(&d3d9_cs
);
228 hrc
= IWineD3DDevice_CreateVertexBuffer(This
->WineD3DDevice
, Size
, Usage
& WINED3DUSAGE_MASK
, FVF
, (WINED3DPOOL
) Pool
, &(object
->wineD3DVertexBuffer
), pSharedHandle
, (IUnknown
*)object
);
229 LeaveCriticalSection(&d3d9_cs
);
234 WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This
);
235 HeapFree(GetProcessHeap(), 0, object
);
237 IUnknown_AddRef(iface
);
238 object
->parentDevice
= iface
;
239 TRACE("(%p) : Created vertex buffer %p\n", This
, object
);
240 *ppVertexBuffer
= (LPDIRECT3DVERTEXBUFFER9
) object
;