Sync ddraw, d3d8 and d3d9 + wined3d to wine 1.1.28
[reactos.git] / reactos / dll / directx / wine / d3d8 / vertexbuffer.c
1 /*
2 * IDirect3DVertexBuffer8 implementation
3 *
4 * Copyright 2005 Oliver Stieber
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DVertexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
29
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
33 IUnknown_AddRef(iface);
34 *ppobj = This;
35 return S_OK;
36 }
37
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39
40 *ppobj = NULL;
41 return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
45 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
46 ULONG ref = InterlockedIncrement(&This->ref);
47
48 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
49
50 return ref;
51 }
52
53 static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
54 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
55 ULONG ref = InterlockedDecrement(&This->ref);
56
57 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58
59 if (ref == 0) {
60 wined3d_mutex_lock();
61 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
62 wined3d_mutex_unlock();
63
64 IUnknown_Release(This->parentDevice);
65 HeapFree(GetProcessHeap(), 0, This);
66 }
67
68 return ref;
69 }
70
71 /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
72 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
73 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
74 IWineD3DDevice *wined3d_device;
75 HRESULT hr;
76 TRACE("(%p) Relay\n", This);
77
78 wined3d_mutex_lock();
79 hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
80 if (SUCCEEDED(hr))
81 {
82 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
83 IWineD3DDevice_Release(wined3d_device);
84 }
85 wined3d_mutex_unlock();
86
87 return hr;
88 }
89
90 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
91 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
92 HRESULT hr;
93 TRACE("(%p) Relay\n", This);
94
95 wined3d_mutex_lock();
96 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
97 wined3d_mutex_unlock();
98
99 return hr;
100 }
101
102 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
103 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
104 HRESULT hr;
105 TRACE("(%p) Relay\n", This);
106
107 wined3d_mutex_lock();
108 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
109 wined3d_mutex_unlock();
110
111 return hr;
112 }
113
114 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
115 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
116 HRESULT hr;
117 TRACE("(%p) Relay\n", This);
118
119 wined3d_mutex_lock();
120 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
121 wined3d_mutex_unlock();
122
123 return hr;
124 }
125
126 static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
127 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
128 DWORD ret;
129 TRACE("(%p) Relay\n", This);
130
131 wined3d_mutex_lock();
132 ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
133 wined3d_mutex_unlock();
134
135 return ret;
136 }
137
138 static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
139 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
140 DWORD ret;
141 TRACE("(%p) Relay\n", This);
142
143 wined3d_mutex_lock();
144 ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
145 wined3d_mutex_unlock();
146
147 return ret;
148 }
149
150 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
151 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
152 TRACE("(%p) Relay\n", This);
153
154 wined3d_mutex_lock();
155 IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
156 wined3d_mutex_unlock();
157 }
158
159 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
160 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
161 TRACE("(%p)\n", This);
162
163 return D3DRTYPE_VERTEXBUFFER;
164 }
165
166 /* IDirect3DVertexBuffer8 Interface follow: */
167 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
168 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
169 HRESULT hr;
170 TRACE("(%p) Relay\n", This);
171
172 wined3d_mutex_lock();
173 hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
174 wined3d_mutex_unlock();
175
176 return hr;
177 }
178
179 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
180 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
181 HRESULT hr;
182 TRACE("(%p) Relay\n", This);
183
184 wined3d_mutex_lock();
185 hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
186 wined3d_mutex_unlock();
187
188 return hr;
189 }
190
191 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
192 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
193 HRESULT hr;
194 WINED3DBUFFER_DESC desc;
195 TRACE("(%p) Relay\n", This);
196
197 wined3d_mutex_lock();
198 hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
199 wined3d_mutex_unlock();
200
201 if (SUCCEEDED(hr)) {
202 pDesc->Type = D3DRTYPE_VERTEXBUFFER;
203 pDesc->Usage = desc.Usage;
204 pDesc->Pool = desc.Pool;
205 pDesc->Size = desc.Size;
206 pDesc->FVF = This->fvf;
207 pDesc->Format = D3DFMT_VERTEXDATA;
208 }
209
210 return hr;
211 }
212
213 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
214 {
215 /* IUnknown */
216 IDirect3DVertexBuffer8Impl_QueryInterface,
217 IDirect3DVertexBuffer8Impl_AddRef,
218 IDirect3DVertexBuffer8Impl_Release,
219 /* IDirect3DResource8 */
220 IDirect3DVertexBuffer8Impl_GetDevice,
221 IDirect3DVertexBuffer8Impl_SetPrivateData,
222 IDirect3DVertexBuffer8Impl_GetPrivateData,
223 IDirect3DVertexBuffer8Impl_FreePrivateData,
224 IDirect3DVertexBuffer8Impl_SetPriority,
225 IDirect3DVertexBuffer8Impl_GetPriority,
226 IDirect3DVertexBuffer8Impl_PreLoad,
227 IDirect3DVertexBuffer8Impl_GetType,
228 /* IDirect3DVertexBuffer8 */
229 IDirect3DVertexBuffer8Impl_Lock,
230 IDirect3DVertexBuffer8Impl_Unlock,
231 IDirect3DVertexBuffer8Impl_GetDesc
232 };