wined3d: Merge IWineD3DVertexBuffer with IWineD3DBuffer.
[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     HRESULT hr;
74     TRACE("(%p) Relay\n", This);
75
76     EnterCriticalSection(&d3d8_cs);
77     hr = IDirect3DResource8Impl_GetDevice((LPDIRECT3DRESOURCE8) This, ppDevice);
78     LeaveCriticalSection(&d3d8_cs);
79     return hr;
80 }
81
82 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
83     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
84     HRESULT hr;
85     TRACE("(%p) Relay\n", This);
86
87     EnterCriticalSection(&d3d8_cs);
88     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
89     LeaveCriticalSection(&d3d8_cs);
90     return hr;
91 }
92
93 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
94     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
95     HRESULT hr;
96     TRACE("(%p) Relay\n", This);
97
98     EnterCriticalSection(&d3d8_cs);
99     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
100     LeaveCriticalSection(&d3d8_cs);
101     return hr;
102 }
103
104 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
105     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
106     HRESULT hr;
107     TRACE("(%p) Relay\n", This);
108
109     EnterCriticalSection(&d3d8_cs);
110     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
111     LeaveCriticalSection(&d3d8_cs);
112     return hr;
113 }
114
115 static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
116     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
117     DWORD ret;
118     TRACE("(%p) Relay\n", This);
119
120     EnterCriticalSection(&d3d8_cs);
121     ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
122     LeaveCriticalSection(&d3d8_cs);
123     return ret;
124 }
125
126 static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
127     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
128     DWORD ret;
129     TRACE("(%p) Relay\n", This);
130
131     EnterCriticalSection(&d3d8_cs);
132     ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
133     LeaveCriticalSection(&d3d8_cs);
134     return ret;
135 }
136
137 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
138     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
139     TRACE("(%p) Relay\n", This);
140
141     EnterCriticalSection(&d3d8_cs);
142     IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
143     LeaveCriticalSection(&d3d8_cs);
144 }
145
146 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
147     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
148     D3DRESOURCETYPE type;
149     TRACE("(%p) Relay\n", This);
150
151     EnterCriticalSection(&d3d8_cs);
152     type = IWineD3DBuffer_GetType(This->wineD3DVertexBuffer);
153     LeaveCriticalSection(&d3d8_cs);
154     return type;
155 }
156
157 /* IDirect3DVertexBuffer8 Interface follow: */
158 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
159     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
160     HRESULT hr;
161     TRACE("(%p) Relay\n", This);
162
163     EnterCriticalSection(&d3d8_cs);
164     hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
165     LeaveCriticalSection(&d3d8_cs);
166     return hr;
167 }
168
169 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
170     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
171     HRESULT hr;
172     TRACE("(%p) Relay\n", This);
173
174     EnterCriticalSection(&d3d8_cs);
175     hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
176     LeaveCriticalSection(&d3d8_cs);
177     return hr;
178 }
179
180 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
181     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
182     HRESULT hr;
183     TRACE("(%p) Relay\n", This);
184
185     EnterCriticalSection(&d3d8_cs);
186     hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, (WINED3DVERTEXBUFFER_DESC *)pDesc);
187     LeaveCriticalSection(&d3d8_cs);
188
189     if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
190
191     return hr;
192 }
193
194 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
195 {
196     /* IUnknown */
197     IDirect3DVertexBuffer8Impl_QueryInterface,
198     IDirect3DVertexBuffer8Impl_AddRef,
199     IDirect3DVertexBuffer8Impl_Release,
200     /* IDirect3DResource8 */
201     IDirect3DVertexBuffer8Impl_GetDevice,
202     IDirect3DVertexBuffer8Impl_SetPrivateData,
203     IDirect3DVertexBuffer8Impl_GetPrivateData,
204     IDirect3DVertexBuffer8Impl_FreePrivateData,
205     IDirect3DVertexBuffer8Impl_SetPriority,
206     IDirect3DVertexBuffer8Impl_GetPriority,
207     IDirect3DVertexBuffer8Impl_PreLoad,
208     IDirect3DVertexBuffer8Impl_GetType,
209     /* IDirect3DVertexBuffer8 */
210     IDirect3DVertexBuffer8Impl_Lock,
211     IDirect3DVertexBuffer8Impl_Unlock,
212     IDirect3DVertexBuffer8Impl_GetDesc
213 };