2 * IDirect3DVertexBuffer8 implementation
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DVertexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
33 IUnknown_AddRef(iface);
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
44 static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
45 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
46 ULONG ref = InterlockedIncrement(&This->ref);
48 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
52 IDirect3DDevice8_AddRef(This->parentDevice);
54 IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
55 wined3d_mutex_unlock();
61 static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
62 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
63 ULONG ref = InterlockedDecrement(&This->ref);
65 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
68 IDirect3DDevice8_Release(This->parentDevice);
70 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
71 wined3d_mutex_unlock();
77 /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
78 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
79 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
80 IWineD3DDevice *wined3d_device;
82 TRACE("(%p) Relay\n", This);
85 hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
88 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
89 IWineD3DDevice_Release(wined3d_device);
91 wined3d_mutex_unlock();
96 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
97 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
99 TRACE("(%p) Relay\n", This);
101 wined3d_mutex_lock();
102 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
103 wined3d_mutex_unlock();
108 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
109 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
111 TRACE("(%p) Relay\n", This);
113 wined3d_mutex_lock();
114 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
115 wined3d_mutex_unlock();
120 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
121 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
123 TRACE("(%p) Relay\n", This);
125 wined3d_mutex_lock();
126 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
127 wined3d_mutex_unlock();
132 static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
133 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
135 TRACE("(%p) Relay\n", This);
137 wined3d_mutex_lock();
138 ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
139 wined3d_mutex_unlock();
144 static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
145 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
147 TRACE("(%p) Relay\n", This);
149 wined3d_mutex_lock();
150 ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
151 wined3d_mutex_unlock();
156 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
157 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
158 TRACE("(%p) Relay\n", This);
160 wined3d_mutex_lock();
161 IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
162 wined3d_mutex_unlock();
165 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
166 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
167 TRACE("(%p)\n", This);
169 return D3DRTYPE_VERTEXBUFFER;
172 /* IDirect3DVertexBuffer8 Interface follow: */
173 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
174 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
176 TRACE("(%p) Relay\n", This);
178 wined3d_mutex_lock();
179 hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
180 wined3d_mutex_unlock();
185 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
186 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
188 TRACE("(%p) Relay\n", This);
190 wined3d_mutex_lock();
191 hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
192 wined3d_mutex_unlock();
197 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
198 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
200 WINED3DBUFFER_DESC desc;
201 TRACE("(%p) Relay\n", This);
203 wined3d_mutex_lock();
204 hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
205 wined3d_mutex_unlock();
208 pDesc->Type = D3DRTYPE_VERTEXBUFFER;
209 pDesc->Usage = desc.Usage;
210 pDesc->Pool = desc.Pool;
211 pDesc->Size = desc.Size;
212 pDesc->FVF = This->fvf;
213 pDesc->Format = D3DFMT_VERTEXDATA;
219 static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
222 IDirect3DVertexBuffer8Impl_QueryInterface,
223 IDirect3DVertexBuffer8Impl_AddRef,
224 IDirect3DVertexBuffer8Impl_Release,
225 /* IDirect3DResource8 */
226 IDirect3DVertexBuffer8Impl_GetDevice,
227 IDirect3DVertexBuffer8Impl_SetPrivateData,
228 IDirect3DVertexBuffer8Impl_GetPrivateData,
229 IDirect3DVertexBuffer8Impl_FreePrivateData,
230 IDirect3DVertexBuffer8Impl_SetPriority,
231 IDirect3DVertexBuffer8Impl_GetPriority,
232 IDirect3DVertexBuffer8Impl_PreLoad,
233 IDirect3DVertexBuffer8Impl_GetType,
234 /* IDirect3DVertexBuffer8 */
235 IDirect3DVertexBuffer8Impl_Lock,
236 IDirect3DVertexBuffer8Impl_Unlock,
237 IDirect3DVertexBuffer8Impl_GetDesc
240 static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
242 HeapFree(GetProcessHeap(), 0, parent);
245 static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
247 d3d8_vertexbuffer_wined3d_object_destroyed,
250 HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
251 UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
255 buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
259 wined3d_mutex_lock();
260 hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
261 usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
262 (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
263 wined3d_mutex_unlock();
266 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
270 buffer->parentDevice = (IDirect3DDevice8 *)device;
271 IUnknown_AddRef(buffer->parentDevice);