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 | /*
|
---|
22 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #include "config.h"
|
---|
31 | #include "d3d8_private.h"
|
---|
32 |
|
---|
33 | WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
---|
34 |
|
---|
35 | /* IDirect3DVertexBuffer8 IUnknown parts follow: */
|
---|
36 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
|
---|
37 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
38 |
|
---|
39 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
40 | || IsEqualGUID(riid, &IID_IDirect3DResource8)
|
---|
41 | || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
|
---|
42 | IUnknown_AddRef(iface);
|
---|
43 | *ppobj = This;
|
---|
44 | return S_OK;
|
---|
45 | }
|
---|
46 |
|
---|
47 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
48 |
|
---|
49 | *ppobj = NULL;
|
---|
50 | return E_NOINTERFACE;
|
---|
51 | }
|
---|
52 |
|
---|
53 | static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
54 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
55 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
56 |
|
---|
57 | TRACE("(%p) : AddRef from %d\n", This, ref - 1);
|
---|
58 |
|
---|
59 | if (ref == 1)
|
---|
60 | {
|
---|
61 | IDirect3DDevice8_AddRef(This->parentDevice);
|
---|
62 | wined3d_mutex_lock();
|
---|
63 | IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
|
---|
64 | wined3d_mutex_unlock();
|
---|
65 | }
|
---|
66 |
|
---|
67 | return ref;
|
---|
68 | }
|
---|
69 |
|
---|
70 | static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
71 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
72 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
73 |
|
---|
74 | TRACE("(%p) : ReleaseRef to %d\n", This, ref);
|
---|
75 |
|
---|
76 | if (ref == 0) {
|
---|
77 | IDirect3DDevice8_Release(This->parentDevice);
|
---|
78 | wined3d_mutex_lock();
|
---|
79 | IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
|
---|
80 | wined3d_mutex_unlock();
|
---|
81 | }
|
---|
82 |
|
---|
83 | return ref;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
|
---|
87 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
|
---|
88 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
89 | IWineD3DDevice *wined3d_device;
|
---|
90 | HRESULT hr;
|
---|
91 | TRACE("(%p) Relay\n", This);
|
---|
92 |
|
---|
93 | wined3d_mutex_lock();
|
---|
94 | hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
|
---|
95 | if (SUCCEEDED(hr))
|
---|
96 | {
|
---|
97 | IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
|
---|
98 | IWineD3DDevice_Release(wined3d_device);
|
---|
99 | }
|
---|
100 | wined3d_mutex_unlock();
|
---|
101 |
|
---|
102 | return hr;
|
---|
103 | }
|
---|
104 |
|
---|
105 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
|
---|
106 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
107 | HRESULT hr;
|
---|
108 | TRACE("(%p) Relay\n", This);
|
---|
109 |
|
---|
110 | wined3d_mutex_lock();
|
---|
111 | hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
|
---|
112 | wined3d_mutex_unlock();
|
---|
113 |
|
---|
114 | return hr;
|
---|
115 | }
|
---|
116 |
|
---|
117 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
|
---|
118 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
119 | HRESULT hr;
|
---|
120 | TRACE("(%p) Relay\n", This);
|
---|
121 |
|
---|
122 | wined3d_mutex_lock();
|
---|
123 | hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
|
---|
124 | wined3d_mutex_unlock();
|
---|
125 |
|
---|
126 | return hr;
|
---|
127 | }
|
---|
128 |
|
---|
129 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
|
---|
130 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
131 | HRESULT hr;
|
---|
132 | TRACE("(%p) Relay\n", This);
|
---|
133 |
|
---|
134 | wined3d_mutex_lock();
|
---|
135 | hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
|
---|
136 | wined3d_mutex_unlock();
|
---|
137 |
|
---|
138 | return hr;
|
---|
139 | }
|
---|
140 |
|
---|
141 | static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
|
---|
142 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
143 | DWORD ret;
|
---|
144 | TRACE("(%p) Relay\n", This);
|
---|
145 |
|
---|
146 | wined3d_mutex_lock();
|
---|
147 | ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
|
---|
148 | wined3d_mutex_unlock();
|
---|
149 |
|
---|
150 | return ret;
|
---|
151 | }
|
---|
152 |
|
---|
153 | static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
154 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
155 | DWORD ret;
|
---|
156 | TRACE("(%p) Relay\n", This);
|
---|
157 |
|
---|
158 | wined3d_mutex_lock();
|
---|
159 | ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
|
---|
160 | wined3d_mutex_unlock();
|
---|
161 |
|
---|
162 | return ret;
|
---|
163 | }
|
---|
164 |
|
---|
165 | static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
166 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
167 | TRACE("(%p) Relay\n", This);
|
---|
168 |
|
---|
169 | wined3d_mutex_lock();
|
---|
170 | IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
|
---|
171 | wined3d_mutex_unlock();
|
---|
172 | }
|
---|
173 |
|
---|
174 | static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
175 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
176 | TRACE("(%p)\n", This);
|
---|
177 |
|
---|
178 | return D3DRTYPE_VERTEXBUFFER;
|
---|
179 | }
|
---|
180 |
|
---|
181 | /* IDirect3DVertexBuffer8 Interface follow: */
|
---|
182 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
|
---|
183 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
184 | HRESULT hr;
|
---|
185 | TRACE("(%p) Relay\n", This);
|
---|
186 |
|
---|
187 | wined3d_mutex_lock();
|
---|
188 | hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
|
---|
189 | wined3d_mutex_unlock();
|
---|
190 |
|
---|
191 | return hr;
|
---|
192 | }
|
---|
193 |
|
---|
194 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
195 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
196 | HRESULT hr;
|
---|
197 | TRACE("(%p) Relay\n", This);
|
---|
198 |
|
---|
199 | wined3d_mutex_lock();
|
---|
200 | hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
|
---|
201 | wined3d_mutex_unlock();
|
---|
202 |
|
---|
203 | return hr;
|
---|
204 | }
|
---|
205 |
|
---|
206 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
|
---|
207 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
208 | HRESULT hr;
|
---|
209 | WINED3DBUFFER_DESC desc;
|
---|
210 | TRACE("(%p) Relay\n", This);
|
---|
211 |
|
---|
212 | wined3d_mutex_lock();
|
---|
213 | hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
|
---|
214 | wined3d_mutex_unlock();
|
---|
215 |
|
---|
216 | if (SUCCEEDED(hr)) {
|
---|
217 | pDesc->Type = D3DRTYPE_VERTEXBUFFER;
|
---|
218 | pDesc->Usage = desc.Usage;
|
---|
219 | pDesc->Pool = desc.Pool;
|
---|
220 | pDesc->Size = desc.Size;
|
---|
221 | pDesc->FVF = This->fvf;
|
---|
222 | pDesc->Format = D3DFMT_VERTEXDATA;
|
---|
223 | }
|
---|
224 |
|
---|
225 | return hr;
|
---|
226 | }
|
---|
227 |
|
---|
228 | static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
|
---|
229 | {
|
---|
230 | /* IUnknown */
|
---|
231 | IDirect3DVertexBuffer8Impl_QueryInterface,
|
---|
232 | IDirect3DVertexBuffer8Impl_AddRef,
|
---|
233 | IDirect3DVertexBuffer8Impl_Release,
|
---|
234 | /* IDirect3DResource8 */
|
---|
235 | IDirect3DVertexBuffer8Impl_GetDevice,
|
---|
236 | IDirect3DVertexBuffer8Impl_SetPrivateData,
|
---|
237 | IDirect3DVertexBuffer8Impl_GetPrivateData,
|
---|
238 | IDirect3DVertexBuffer8Impl_FreePrivateData,
|
---|
239 | IDirect3DVertexBuffer8Impl_SetPriority,
|
---|
240 | IDirect3DVertexBuffer8Impl_GetPriority,
|
---|
241 | IDirect3DVertexBuffer8Impl_PreLoad,
|
---|
242 | IDirect3DVertexBuffer8Impl_GetType,
|
---|
243 | /* IDirect3DVertexBuffer8 */
|
---|
244 | IDirect3DVertexBuffer8Impl_Lock,
|
---|
245 | IDirect3DVertexBuffer8Impl_Unlock,
|
---|
246 | IDirect3DVertexBuffer8Impl_GetDesc
|
---|
247 | };
|
---|
248 |
|
---|
249 | static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
|
---|
250 | {
|
---|
251 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
252 | }
|
---|
253 |
|
---|
254 | static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
|
---|
255 | {
|
---|
256 | d3d8_vertexbuffer_wined3d_object_destroyed,
|
---|
257 | };
|
---|
258 |
|
---|
259 | HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
|
---|
260 | UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
|
---|
261 | {
|
---|
262 | HRESULT hr;
|
---|
263 |
|
---|
264 | buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
|
---|
265 | buffer->ref = 1;
|
---|
266 | buffer->fvf = fvf;
|
---|
267 |
|
---|
268 | wined3d_mutex_lock();
|
---|
269 | hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
|
---|
270 | usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
|
---|
271 | (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
|
---|
272 | wined3d_mutex_unlock();
|
---|
273 | if (FAILED(hr))
|
---|
274 | {
|
---|
275 | WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
|
---|
276 | return hr;
|
---|
277 | }
|
---|
278 |
|
---|
279 | buffer->parentDevice = (IDirect3DDevice8 *)device;
|
---|
280 | IUnknown_AddRef(buffer->parentDevice);
|
---|
281 |
|
---|
282 | return D3D_OK;
|
---|
283 | }
|
---|