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 IDirect3DVertexBuffer9_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);
53 IDirect3DDevice9Ex_AddRef(This->parentDevice);
55 IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
56 wined3d_mutex_unlock();
62 static ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
63 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
66 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
69 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
72 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
73 wined3d_mutex_unlock();
75 /* Release the device last, as it may cause the device to be destroyed. */
76 IDirect3DDevice9Ex_Release(parentDevice);
81 /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
82 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
83 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
84 IWineD3DDevice *wined3d_device;
86 TRACE("(%p) Relay\n", This);
89 hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
92 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
93 IWineD3DDevice_Release(wined3d_device);
95 wined3d_mutex_unlock();
100 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
101 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
104 TRACE("(%p) Relay\n", This);
106 wined3d_mutex_lock();
107 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
108 wined3d_mutex_unlock();
113 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
114 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
116 TRACE("(%p) Relay\n", This);
118 wined3d_mutex_lock();
119 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
120 wined3d_mutex_unlock();
125 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
126 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
128 TRACE("(%p) Relay\n", This);
130 wined3d_mutex_lock();
131 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
132 wined3d_mutex_unlock();
137 static DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
138 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
140 TRACE("(%p) Relay\n", This);
142 wined3d_mutex_lock();
143 hr = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
144 wined3d_mutex_unlock();
149 static DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
150 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
152 TRACE("(%p) Relay\n", This);
154 wined3d_mutex_lock();
155 hr = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
156 wined3d_mutex_unlock();
161 static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
162 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
163 TRACE("(%p) Relay\n", This);
165 wined3d_mutex_lock();
166 IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
167 wined3d_mutex_unlock();
170 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
171 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
172 TRACE("(%p)\n", This);
174 return D3DRTYPE_VERTEXBUFFER;
177 /* IDirect3DVertexBuffer9 Interface follow: */
178 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
179 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
181 TRACE("(%p) Relay\n", This);
183 wined3d_mutex_lock();
184 hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
185 wined3d_mutex_unlock();
190 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
191 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
193 TRACE("(%p) Relay\n", This);
195 wined3d_mutex_lock();
196 hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
197 wined3d_mutex_unlock();
202 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
203 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
205 WINED3DBUFFER_DESC desc;
206 TRACE("(%p) Relay\n", This);
208 wined3d_mutex_lock();
209 hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
210 wined3d_mutex_unlock();
213 pDesc->Format = D3DFMT_VERTEXDATA;
214 pDesc->Usage = desc.Usage;
215 pDesc->Pool = desc.Pool;
216 pDesc->Size = desc.Size;
217 pDesc->Type = D3DRTYPE_VERTEXBUFFER;
218 pDesc->FVF = This->fvf;
225 static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
228 IDirect3DVertexBuffer9Impl_QueryInterface,
229 IDirect3DVertexBuffer9Impl_AddRef,
230 IDirect3DVertexBuffer9Impl_Release,
231 /* IDirect3DResource9 */
232 IDirect3DVertexBuffer9Impl_GetDevice,
233 IDirect3DVertexBuffer9Impl_SetPrivateData,
234 IDirect3DVertexBuffer9Impl_GetPrivateData,
235 IDirect3DVertexBuffer9Impl_FreePrivateData,
236 IDirect3DVertexBuffer9Impl_SetPriority,
237 IDirect3DVertexBuffer9Impl_GetPriority,
238 IDirect3DVertexBuffer9Impl_PreLoad,
239 IDirect3DVertexBuffer9Impl_GetType,
240 /* IDirect3DVertexBuffer9 */
241 IDirect3DVertexBuffer9Impl_Lock,
242 IDirect3DVertexBuffer9Impl_Unlock,
243 IDirect3DVertexBuffer9Impl_GetDesc
246 static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
248 HeapFree(GetProcessHeap(), 0, parent);
251 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
253 d3d9_vertexbuffer_wined3d_object_destroyed,
256 HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
257 UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
261 buffer->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
265 wined3d_mutex_lock();
266 hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
267 usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
268 (IUnknown *)buffer, &d3d9_vertexbuffer_wined3d_parent_ops);
269 wined3d_mutex_unlock();
272 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
276 buffer->parentDevice = (IDirect3DDevice9Ex *)device;
277 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);