xinput1_3: Better match native export order.
[wine] / dlls / 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         EnterCriticalSection(&d3d8_cs);
61         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
62         LeaveCriticalSection(&d3d8_cs);
63         IUnknown_Release(This->parentDevice);
64         HeapFree(GetProcessHeap(), 0, This);
65     }
66
67     return ref;
68 }
69
70 /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
71 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
72     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
73     IWineD3DDevice *wined3d_device;
74     HRESULT hr;
75     TRACE("(%p) Relay\n", This);
76
77     EnterCriticalSection(&d3d8_cs);
78     hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
79     if (SUCCEEDED(hr))
80     {
81         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
82         IWineD3DDevice_Release(wined3d_device);
83     }
84     LeaveCriticalSection(&d3d8_cs);
85     return hr;
86 }
87
88 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
89     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
90     HRESULT hr;
91     TRACE("(%p) Relay\n", This);
92
93     EnterCriticalSection(&d3d8_cs);
94     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
95     LeaveCriticalSection(&d3d8_cs);
96     return hr;
97 }
98
99 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
100     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
101     HRESULT hr;
102     TRACE("(%p) Relay\n", This);
103
104     EnterCriticalSection(&d3d8_cs);
105     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
106     LeaveCriticalSection(&d3d8_cs);
107     return hr;
108 }
109
110 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
111     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
112     HRESULT hr;
113     TRACE("(%p) Relay\n", This);
114
115     EnterCriticalSection(&d3d8_cs);
116     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
117     LeaveCriticalSection(&d3d8_cs);
118     return hr;
119 }
120
121 static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
122     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
123     DWORD ret;
124     TRACE("(%p) Relay\n", This);
125
126     EnterCriticalSection(&d3d8_cs);
127     ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
128     LeaveCriticalSection(&d3d8_cs);
129     return ret;
130 }
131
132 static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
133     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
134     DWORD ret;
135     TRACE("(%p) Relay\n", This);
136
137     EnterCriticalSection(&d3d8_cs);
138     ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
139     LeaveCriticalSection(&d3d8_cs);
140     return ret;
141 }
142
143 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
144     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
145     TRACE("(%p) Relay\n", This);
146
147     EnterCriticalSection(&d3d8_cs);
148     IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
149     LeaveCriticalSection(&d3d8_cs);
150 }
151
152 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
153     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
154     TRACE("(%p)\n", This);
155
156     return D3DRTYPE_VERTEXBUFFER;
157 }
158
159 /* IDirect3DVertexBuffer8 Interface follow: */
160 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
161     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
162     HRESULT hr;
163     TRACE("(%p) Relay\n", This);
164
165     EnterCriticalSection(&d3d8_cs);
166     hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
167     LeaveCriticalSection(&d3d8_cs);
168     return hr;
169 }
170
171 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
172     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
173     HRESULT hr;
174     TRACE("(%p) Relay\n", This);
175
176     EnterCriticalSection(&d3d8_cs);
177     hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
178     LeaveCriticalSection(&d3d8_cs);
179     return hr;
180 }
181
182 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
183     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
184     HRESULT hr;
185     WINED3DBUFFER_DESC desc;
186     TRACE("(%p) Relay\n", This);
187
188     EnterCriticalSection(&d3d8_cs);
189     hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
190     LeaveCriticalSection(&d3d8_cs);
191
192     if (SUCCEEDED(hr)) {
193         pDesc->Type = D3DRTYPE_VERTEXBUFFER;
194         pDesc->Usage = desc.Usage;
195         pDesc->Pool = desc.Pool;
196         pDesc->Size = desc.Size;
197         pDesc->FVF = This->fvf;
198         pDesc->Format = D3DFMT_VERTEXDATA;
199     }
200
201     return hr;
202 }
203
204 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
205 {
206     /* IUnknown */
207     IDirect3DVertexBuffer8Impl_QueryInterface,
208     IDirect3DVertexBuffer8Impl_AddRef,
209     IDirect3DVertexBuffer8Impl_Release,
210     /* IDirect3DResource8 */
211     IDirect3DVertexBuffer8Impl_GetDevice,
212     IDirect3DVertexBuffer8Impl_SetPrivateData,
213     IDirect3DVertexBuffer8Impl_GetPrivateData,
214     IDirect3DVertexBuffer8Impl_FreePrivateData,
215     IDirect3DVertexBuffer8Impl_SetPriority,
216     IDirect3DVertexBuffer8Impl_GetPriority,
217     IDirect3DVertexBuffer8Impl_PreLoad,
218     IDirect3DVertexBuffer8Impl_GetType,
219     /* IDirect3DVertexBuffer8 */
220     IDirect3DVertexBuffer8Impl_Lock,
221     IDirect3DVertexBuffer8Impl_Unlock,
222     IDirect3DVertexBuffer8Impl_GetDesc
223 };