1 | /*
|
---|
2 | * IDirect3DVertexBuffer9 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2004 Jason Edmeades
|
---|
5 | * Copyright 2002-2004 Raphael Junqueira
|
---|
6 | * Copyright 2005 Oliver Stieber
|
---|
7 | *
|
---|
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.
|
---|
12 | *
|
---|
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.
|
---|
17 | *
|
---|
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
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
25 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
26 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
27 | * a choice of LGPL license versions is made available with the language indicating
|
---|
28 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
29 | * of the LGPL is applied is otherwise unspecified.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "config.h"
|
---|
33 | #include "d3d9_private.h"
|
---|
34 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
36 |
|
---|
37 | /* IDirect3DVertexBuffer9 IUnknown parts follow: */
|
---|
38 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
|
---|
39 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
40 |
|
---|
41 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
42 | || IsEqualGUID(riid, &IID_IDirect3DResource9)
|
---|
43 | || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
|
---|
44 | IDirect3DVertexBuffer9_AddRef(iface);
|
---|
45 | *ppobj = This;
|
---|
46 | return S_OK;
|
---|
47 | }
|
---|
48 |
|
---|
49 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
50 | *ppobj = NULL;
|
---|
51 | return E_NOINTERFACE;
|
---|
52 | }
|
---|
53 |
|
---|
54 | static ULONG WINAPI IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
55 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
56 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
57 |
|
---|
58 | TRACE("(%p) : AddRef from %d\n", This, ref - 1);
|
---|
59 |
|
---|
60 | return ref;
|
---|
61 | }
|
---|
62 |
|
---|
63 | static ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
64 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
65 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
66 |
|
---|
67 | TRACE("(%p) : ReleaseRef to %d\n", This, ref);
|
---|
68 |
|
---|
69 | if (ref == 0) {
|
---|
70 | EnterCriticalSection(&d3d9_cs);
|
---|
71 | IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
|
---|
72 | LeaveCriticalSection(&d3d9_cs);
|
---|
73 | IDirect3DDevice9Ex_Release(This->parentDevice);
|
---|
74 | HeapFree(GetProcessHeap(), 0, This);
|
---|
75 | }
|
---|
76 | return ref;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
|
---|
80 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
|
---|
81 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
82 | IWineD3DDevice *wined3d_device;
|
---|
83 | HRESULT hr;
|
---|
84 | TRACE("(%p) Relay\n", This);
|
---|
85 |
|
---|
86 | EnterCriticalSection(&d3d9_cs);
|
---|
87 | hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
|
---|
88 | if (SUCCEEDED(hr))
|
---|
89 | {
|
---|
90 | IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
|
---|
91 | IWineD3DDevice_Release(wined3d_device);
|
---|
92 | }
|
---|
93 | LeaveCriticalSection(&d3d9_cs);
|
---|
94 | return hr;
|
---|
95 | }
|
---|
96 |
|
---|
97 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
98 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
99 | HRESULT hr;
|
---|
100 |
|
---|
101 | TRACE("(%p) Relay\n", This);
|
---|
102 |
|
---|
103 | EnterCriticalSection(&d3d9_cs);
|
---|
104 | hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
|
---|
105 | LeaveCriticalSection(&d3d9_cs);
|
---|
106 |
|
---|
107 | return hr;
|
---|
108 | }
|
---|
109 |
|
---|
110 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
111 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
112 | HRESULT hr;
|
---|
113 | TRACE("(%p) Relay\n", This);
|
---|
114 |
|
---|
115 | EnterCriticalSection(&d3d9_cs);
|
---|
116 | hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
|
---|
117 | LeaveCriticalSection(&d3d9_cs);
|
---|
118 | return hr;
|
---|
119 | }
|
---|
120 |
|
---|
121 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
|
---|
122 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
123 | HRESULT hr;
|
---|
124 | TRACE("(%p) Relay\n", This);
|
---|
125 |
|
---|
126 | EnterCriticalSection(&d3d9_cs);
|
---|
127 | hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
|
---|
128 | LeaveCriticalSection(&d3d9_cs);
|
---|
129 | return hr;
|
---|
130 | }
|
---|
131 |
|
---|
132 | static DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
|
---|
133 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
134 | HRESULT hr;
|
---|
135 | TRACE("(%p) Relay\n", This);
|
---|
136 |
|
---|
137 | EnterCriticalSection(&d3d9_cs);
|
---|
138 | hr = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
|
---|
139 | LeaveCriticalSection(&d3d9_cs);
|
---|
140 | return hr;
|
---|
141 | }
|
---|
142 |
|
---|
143 | static DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
144 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
145 | HRESULT hr;
|
---|
146 | TRACE("(%p) Relay\n", This);
|
---|
147 |
|
---|
148 | EnterCriticalSection(&d3d9_cs);
|
---|
149 | hr = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
|
---|
150 | LeaveCriticalSection(&d3d9_cs);
|
---|
151 | return hr;
|
---|
152 | }
|
---|
153 |
|
---|
154 | static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
155 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
156 | TRACE("(%p) Relay\n", This);
|
---|
157 |
|
---|
158 | EnterCriticalSection(&d3d9_cs);
|
---|
159 | IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
|
---|
160 | LeaveCriticalSection(&d3d9_cs);
|
---|
161 | return ;
|
---|
162 | }
|
---|
163 |
|
---|
164 | static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
165 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
166 | TRACE("(%p)\n", This);
|
---|
167 |
|
---|
168 | return D3DRTYPE_VERTEXBUFFER;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /* IDirect3DVertexBuffer9 Interface follow: */
|
---|
172 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
|
---|
173 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
174 | HRESULT hr;
|
---|
175 | TRACE("(%p) Relay\n", This);
|
---|
176 |
|
---|
177 | EnterCriticalSection(&d3d9_cs);
|
---|
178 | hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
|
---|
179 | LeaveCriticalSection(&d3d9_cs);
|
---|
180 | return hr;
|
---|
181 | }
|
---|
182 |
|
---|
183 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
184 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
185 | HRESULT hr;
|
---|
186 | TRACE("(%p) Relay\n", This);
|
---|
187 |
|
---|
188 | EnterCriticalSection(&d3d9_cs);
|
---|
189 | hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
|
---|
190 | LeaveCriticalSection(&d3d9_cs);
|
---|
191 | return hr;
|
---|
192 | }
|
---|
193 |
|
---|
194 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
|
---|
195 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
196 | HRESULT hr;
|
---|
197 | WINED3DBUFFER_DESC desc;
|
---|
198 | TRACE("(%p) Relay\n", This);
|
---|
199 |
|
---|
200 | EnterCriticalSection(&d3d9_cs);
|
---|
201 | hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
|
---|
202 | LeaveCriticalSection(&d3d9_cs);
|
---|
203 |
|
---|
204 | if (SUCCEEDED(hr)) {
|
---|
205 | pDesc->Format = D3DFMT_VERTEXDATA;
|
---|
206 | pDesc->Usage = desc.Usage;
|
---|
207 | pDesc->Pool = desc.Pool;
|
---|
208 | pDesc->Size = desc.Size;
|
---|
209 | pDesc->Type = D3DRTYPE_VERTEXBUFFER;
|
---|
210 | pDesc->FVF = This->fvf;
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | return hr;
|
---|
215 | }
|
---|
216 |
|
---|
217 | static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
|
---|
218 | {
|
---|
219 | /* IUnknown */
|
---|
220 | IDirect3DVertexBuffer9Impl_QueryInterface,
|
---|
221 | IDirect3DVertexBuffer9Impl_AddRef,
|
---|
222 | IDirect3DVertexBuffer9Impl_Release,
|
---|
223 | /* IDirect3DResource9 */
|
---|
224 | IDirect3DVertexBuffer9Impl_GetDevice,
|
---|
225 | IDirect3DVertexBuffer9Impl_SetPrivateData,
|
---|
226 | IDirect3DVertexBuffer9Impl_GetPrivateData,
|
---|
227 | IDirect3DVertexBuffer9Impl_FreePrivateData,
|
---|
228 | IDirect3DVertexBuffer9Impl_SetPriority,
|
---|
229 | IDirect3DVertexBuffer9Impl_GetPriority,
|
---|
230 | IDirect3DVertexBuffer9Impl_PreLoad,
|
---|
231 | IDirect3DVertexBuffer9Impl_GetType,
|
---|
232 | /* IDirect3DVertexBuffer9 */
|
---|
233 | IDirect3DVertexBuffer9Impl_Lock,
|
---|
234 | IDirect3DVertexBuffer9Impl_Unlock,
|
---|
235 | IDirect3DVertexBuffer9Impl_GetDesc
|
---|
236 | };
|
---|
237 |
|
---|
238 |
|
---|
239 | /* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
|
---|
240 | HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface,
|
---|
241 | UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool,
|
---|
242 | IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
|
---|
243 |
|
---|
244 | IDirect3DVertexBuffer9Impl *object;
|
---|
245 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
246 | HRESULT hrc = D3D_OK;
|
---|
247 |
|
---|
248 | /* Allocate the storage for the device */
|
---|
249 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
|
---|
250 | if (NULL == object) {
|
---|
251 | FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
|
---|
252 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
253 | }
|
---|
254 |
|
---|
255 | object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
|
---|
256 | object->ref = 1;
|
---|
257 | object->fvf = FVF;
|
---|
258 | EnterCriticalSection(&d3d9_cs);
|
---|
259 | hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
|
---|
260 | 0 /* fvf for ddraw only */, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), (IUnknown *)object);
|
---|
261 | LeaveCriticalSection(&d3d9_cs);
|
---|
262 |
|
---|
263 | if (hrc != D3D_OK) {
|
---|
264 |
|
---|
265 | /* free up object */
|
---|
266 | WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
|
---|
267 | HeapFree(GetProcessHeap(), 0, object);
|
---|
268 | } else {
|
---|
269 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
270 | object->parentDevice = iface;
|
---|
271 | TRACE("(%p) : Created vertex buffer %p\n", This, object);
|
---|
272 | *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
|
---|
273 | }
|
---|
274 | return hrc;
|
---|
275 | }
|
---|