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 | IWineD3DVertexBuffer_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 | HRESULT hr;
|
---|
83 | TRACE("(%p) Relay\n", This);
|
---|
84 |
|
---|
85 | EnterCriticalSection(&d3d9_cs);
|
---|
86 | hr = IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
|
---|
87 | LeaveCriticalSection(&d3d9_cs);
|
---|
88 | return hr;
|
---|
89 | }
|
---|
90 |
|
---|
91 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
92 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
93 | TRACE("(%p) Relay\n", This);
|
---|
94 | return IWineD3DVertexBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
|
---|
95 | }
|
---|
96 |
|
---|
97 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
98 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
99 | HRESULT hr;
|
---|
100 | TRACE("(%p) Relay\n", This);
|
---|
101 |
|
---|
102 | EnterCriticalSection(&d3d9_cs);
|
---|
103 | hr = IWineD3DVertexBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
|
---|
104 | LeaveCriticalSection(&d3d9_cs);
|
---|
105 | return hr;
|
---|
106 | }
|
---|
107 |
|
---|
108 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
|
---|
109 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
110 | HRESULT hr;
|
---|
111 | TRACE("(%p) Relay\n", This);
|
---|
112 |
|
---|
113 | EnterCriticalSection(&d3d9_cs);
|
---|
114 | hr = IWineD3DVertexBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
|
---|
115 | LeaveCriticalSection(&d3d9_cs);
|
---|
116 | return hr;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
|
---|
120 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
121 | HRESULT hr;
|
---|
122 | TRACE("(%p) Relay\n", This);
|
---|
123 |
|
---|
124 | EnterCriticalSection(&d3d9_cs);
|
---|
125 | hr = IWineD3DVertexBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
|
---|
126 | LeaveCriticalSection(&d3d9_cs);
|
---|
127 | return hr;
|
---|
128 | }
|
---|
129 |
|
---|
130 | static DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
131 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
132 | HRESULT hr;
|
---|
133 | TRACE("(%p) Relay\n", This);
|
---|
134 |
|
---|
135 | EnterCriticalSection(&d3d9_cs);
|
---|
136 | hr = IWineD3DVertexBuffer_GetPriority(This->wineD3DVertexBuffer);
|
---|
137 | LeaveCriticalSection(&d3d9_cs);
|
---|
138 | return hr;
|
---|
139 | }
|
---|
140 |
|
---|
141 | static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
142 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
143 | TRACE("(%p) Relay\n", This);
|
---|
144 |
|
---|
145 | EnterCriticalSection(&d3d9_cs);
|
---|
146 | IWineD3DVertexBuffer_PreLoad(This->wineD3DVertexBuffer);
|
---|
147 | LeaveCriticalSection(&d3d9_cs);
|
---|
148 | return ;
|
---|
149 | }
|
---|
150 |
|
---|
151 | static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
152 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
153 | D3DRESOURCETYPE ret;
|
---|
154 | TRACE("(%p) Relay\n", This);
|
---|
155 |
|
---|
156 | EnterCriticalSection(&d3d9_cs);
|
---|
157 | ret = IWineD3DVertexBuffer_GetType(This->wineD3DVertexBuffer);
|
---|
158 | LeaveCriticalSection(&d3d9_cs);
|
---|
159 | return ret;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /* IDirect3DVertexBuffer9 Interface follow: */
|
---|
163 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
|
---|
164 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
165 | HRESULT hr;
|
---|
166 | TRACE("(%p) Relay\n", This);
|
---|
167 |
|
---|
168 | EnterCriticalSection(&d3d9_cs);
|
---|
169 | hr = IWineD3DVertexBuffer_Lock(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
|
---|
170 | LeaveCriticalSection(&d3d9_cs);
|
---|
171 | return hr;
|
---|
172 | }
|
---|
173 |
|
---|
174 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
|
---|
175 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
176 | HRESULT hr;
|
---|
177 | TRACE("(%p) Relay\n", This);
|
---|
178 |
|
---|
179 | EnterCriticalSection(&d3d9_cs);
|
---|
180 | hr = IWineD3DVertexBuffer_Unlock(This->wineD3DVertexBuffer);
|
---|
181 | LeaveCriticalSection(&d3d9_cs);
|
---|
182 | return hr;
|
---|
183 | }
|
---|
184 |
|
---|
185 | static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
|
---|
186 | IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
|
---|
187 | HRESULT hr;
|
---|
188 | TRACE("(%p) Relay\n", This);
|
---|
189 |
|
---|
190 | EnterCriticalSection(&d3d9_cs);
|
---|
191 | hr = IWineD3DVertexBuffer_GetDesc(This->wineD3DVertexBuffer, (WINED3DVERTEXBUFFER_DESC *) pDesc);
|
---|
192 | LeaveCriticalSection(&d3d9_cs);
|
---|
193 | return hr;
|
---|
194 | }
|
---|
195 |
|
---|
196 | static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
|
---|
197 | {
|
---|
198 | /* IUnknown */
|
---|
199 | IDirect3DVertexBuffer9Impl_QueryInterface,
|
---|
200 | IDirect3DVertexBuffer9Impl_AddRef,
|
---|
201 | IDirect3DVertexBuffer9Impl_Release,
|
---|
202 | /* IDirect3DResource9 */
|
---|
203 | IDirect3DVertexBuffer9Impl_GetDevice,
|
---|
204 | IDirect3DVertexBuffer9Impl_SetPrivateData,
|
---|
205 | IDirect3DVertexBuffer9Impl_GetPrivateData,
|
---|
206 | IDirect3DVertexBuffer9Impl_FreePrivateData,
|
---|
207 | IDirect3DVertexBuffer9Impl_SetPriority,
|
---|
208 | IDirect3DVertexBuffer9Impl_GetPriority,
|
---|
209 | IDirect3DVertexBuffer9Impl_PreLoad,
|
---|
210 | IDirect3DVertexBuffer9Impl_GetType,
|
---|
211 | /* IDirect3DVertexBuffer9 */
|
---|
212 | IDirect3DVertexBuffer9Impl_Lock,
|
---|
213 | IDirect3DVertexBuffer9Impl_Unlock,
|
---|
214 | IDirect3DVertexBuffer9Impl_GetDesc
|
---|
215 | };
|
---|
216 |
|
---|
217 |
|
---|
218 | /* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
|
---|
219 | HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface,
|
---|
220 | UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool,
|
---|
221 | IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
|
---|
222 |
|
---|
223 | IDirect3DVertexBuffer9Impl *object;
|
---|
224 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
225 | HRESULT hrc = D3D_OK;
|
---|
226 |
|
---|
227 | /* Allocate the storage for the device */
|
---|
228 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
|
---|
229 | if (NULL == object) {
|
---|
230 | FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
|
---|
231 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
232 | }
|
---|
233 |
|
---|
234 | object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
|
---|
235 | object->ref = 1;
|
---|
236 | EnterCriticalSection(&d3d9_cs);
|
---|
237 | hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), pSharedHandle, (IUnknown *)object);
|
---|
238 | LeaveCriticalSection(&d3d9_cs);
|
---|
239 |
|
---|
240 | if (hrc != D3D_OK) {
|
---|
241 |
|
---|
242 | /* free up object */
|
---|
243 | WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
|
---|
244 | HeapFree(GetProcessHeap(), 0, object);
|
---|
245 | } else {
|
---|
246 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
247 | object->parentDevice = iface;
|
---|
248 | TRACE("(%p) : Created vertex buffer %p\n", This, object);
|
---|
249 | *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
|
---|
250 | }
|
---|
251 | return hrc;
|
---|
252 | }
|
---|