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 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
|
---|
40 |
|
---|
41 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
42 | || IsEqualGUID(riid, &IID_IDirect3DResource8)
|
---|
43 | || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
|
---|
44 | IUnknown_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 |
|
---|
51 | *ppobj = NULL;
|
---|
52 | return E_NOINTERFACE;
|
---|
53 | }
|
---|
54 |
|
---|
55 | static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
56 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
57 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
58 |
|
---|
59 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
60 |
|
---|
61 | if (ref == 1)
|
---|
62 | {
|
---|
63 | IDirect3DDevice8_AddRef(This->parentDevice);
|
---|
64 | wined3d_mutex_lock();
|
---|
65 | IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
|
---|
66 | wined3d_mutex_unlock();
|
---|
67 | }
|
---|
68 |
|
---|
69 | return ref;
|
---|
70 | }
|
---|
71 |
|
---|
72 | static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
73 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
74 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
75 |
|
---|
76 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
77 |
|
---|
78 | if (ref == 0) {
|
---|
79 | IDirect3DDevice8 *parentDevice = This->parentDevice;
|
---|
80 |
|
---|
81 | wined3d_mutex_lock();
|
---|
82 | IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
|
---|
83 | wined3d_mutex_unlock();
|
---|
84 |
|
---|
85 | /* Release the device last, as it may cause the device to be destroyed. */
|
---|
86 | IDirect3DDevice8_Release(parentDevice);
|
---|
87 | }
|
---|
88 |
|
---|
89 | return ref;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
|
---|
93 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device)
|
---|
94 | {
|
---|
95 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
96 |
|
---|
97 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
98 |
|
---|
99 | *device = (IDirect3DDevice8 *)This->parentDevice;
|
---|
100 | IDirect3DDevice8_AddRef(*device);
|
---|
101 |
|
---|
102 | TRACE("Returning device %p.\n", *device);
|
---|
103 |
|
---|
104 | return D3D_OK;
|
---|
105 | }
|
---|
106 |
|
---|
107 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
|
---|
108 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
109 | HRESULT hr;
|
---|
110 |
|
---|
111 | TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
|
---|
112 | iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
|
---|
113 |
|
---|
114 | wined3d_mutex_lock();
|
---|
115 | hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
|
---|
116 | wined3d_mutex_unlock();
|
---|
117 |
|
---|
118 | return hr;
|
---|
119 | }
|
---|
120 |
|
---|
121 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
|
---|
122 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
123 | HRESULT hr;
|
---|
124 |
|
---|
125 | TRACE("iface %p, guid %s, data %p, data_size %p.\n",
|
---|
126 | iface, debugstr_guid(refguid), pData, pSizeOfData);
|
---|
127 |
|
---|
128 | wined3d_mutex_lock();
|
---|
129 | hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
|
---|
130 | wined3d_mutex_unlock();
|
---|
131 |
|
---|
132 | return hr;
|
---|
133 | }
|
---|
134 |
|
---|
135 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
|
---|
136 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
137 | HRESULT hr;
|
---|
138 |
|
---|
139 | TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
|
---|
140 |
|
---|
141 | wined3d_mutex_lock();
|
---|
142 | hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
|
---|
143 | wined3d_mutex_unlock();
|
---|
144 |
|
---|
145 | return hr;
|
---|
146 | }
|
---|
147 |
|
---|
148 | static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
|
---|
149 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
150 | DWORD ret;
|
---|
151 |
|
---|
152 | TRACE("iface %p, priority %u.\n", iface, PriorityNew);
|
---|
153 |
|
---|
154 | wined3d_mutex_lock();
|
---|
155 | ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
|
---|
156 | wined3d_mutex_unlock();
|
---|
157 |
|
---|
158 | return ret;
|
---|
159 | }
|
---|
160 |
|
---|
161 | static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
162 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
163 | DWORD ret;
|
---|
164 |
|
---|
165 | TRACE("iface %p.\n", iface);
|
---|
166 |
|
---|
167 | wined3d_mutex_lock();
|
---|
168 | ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
|
---|
169 | wined3d_mutex_unlock();
|
---|
170 |
|
---|
171 | return ret;
|
---|
172 | }
|
---|
173 |
|
---|
174 | static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
175 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
176 |
|
---|
177 | TRACE("iface %p.\n", iface);
|
---|
178 |
|
---|
179 | wined3d_mutex_lock();
|
---|
180 | IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
|
---|
181 | wined3d_mutex_unlock();
|
---|
182 | }
|
---|
183 |
|
---|
184 | static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(IDirect3DVertexBuffer8 *iface)
|
---|
185 | {
|
---|
186 | TRACE("iface %p.\n", iface);
|
---|
187 |
|
---|
188 | return D3DRTYPE_VERTEXBUFFER;
|
---|
189 | }
|
---|
190 |
|
---|
191 | /* IDirect3DVertexBuffer8 Interface follow: */
|
---|
192 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
|
---|
193 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
194 | HRESULT hr;
|
---|
195 |
|
---|
196 | TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
|
---|
197 | iface, OffsetToLock, SizeToLock, ppbData, Flags);
|
---|
198 |
|
---|
199 | wined3d_mutex_lock();
|
---|
200 | hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
|
---|
201 | wined3d_mutex_unlock();
|
---|
202 |
|
---|
203 | return hr;
|
---|
204 | }
|
---|
205 |
|
---|
206 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
|
---|
207 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
208 | HRESULT hr;
|
---|
209 |
|
---|
210 | TRACE("iface %p.\n", iface);
|
---|
211 |
|
---|
212 | wined3d_mutex_lock();
|
---|
213 | hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
|
---|
214 | wined3d_mutex_unlock();
|
---|
215 |
|
---|
216 | return hr;
|
---|
217 | }
|
---|
218 |
|
---|
219 | static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
|
---|
220 | IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
|
---|
221 | HRESULT hr;
|
---|
222 | WINED3DBUFFER_DESC desc;
|
---|
223 |
|
---|
224 | TRACE("iface %p, desc %p.\n", iface, pDesc);
|
---|
225 |
|
---|
226 | wined3d_mutex_lock();
|
---|
227 | hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
|
---|
228 | wined3d_mutex_unlock();
|
---|
229 |
|
---|
230 | if (SUCCEEDED(hr)) {
|
---|
231 | pDesc->Type = D3DRTYPE_VERTEXBUFFER;
|
---|
232 | pDesc->Usage = desc.Usage;
|
---|
233 | pDesc->Pool = desc.Pool;
|
---|
234 | pDesc->Size = desc.Size;
|
---|
235 | pDesc->FVF = This->fvf;
|
---|
236 | pDesc->Format = D3DFMT_VERTEXDATA;
|
---|
237 | }
|
---|
238 |
|
---|
239 | return hr;
|
---|
240 | }
|
---|
241 |
|
---|
242 | static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
|
---|
243 | {
|
---|
244 | /* IUnknown */
|
---|
245 | IDirect3DVertexBuffer8Impl_QueryInterface,
|
---|
246 | IDirect3DVertexBuffer8Impl_AddRef,
|
---|
247 | IDirect3DVertexBuffer8Impl_Release,
|
---|
248 | /* IDirect3DResource8 */
|
---|
249 | IDirect3DVertexBuffer8Impl_GetDevice,
|
---|
250 | IDirect3DVertexBuffer8Impl_SetPrivateData,
|
---|
251 | IDirect3DVertexBuffer8Impl_GetPrivateData,
|
---|
252 | IDirect3DVertexBuffer8Impl_FreePrivateData,
|
---|
253 | IDirect3DVertexBuffer8Impl_SetPriority,
|
---|
254 | IDirect3DVertexBuffer8Impl_GetPriority,
|
---|
255 | IDirect3DVertexBuffer8Impl_PreLoad,
|
---|
256 | IDirect3DVertexBuffer8Impl_GetType,
|
---|
257 | /* IDirect3DVertexBuffer8 */
|
---|
258 | IDirect3DVertexBuffer8Impl_Lock,
|
---|
259 | IDirect3DVertexBuffer8Impl_Unlock,
|
---|
260 | IDirect3DVertexBuffer8Impl_GetDesc
|
---|
261 | };
|
---|
262 |
|
---|
263 | static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
|
---|
264 | {
|
---|
265 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
266 | }
|
---|
267 |
|
---|
268 | static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
|
---|
269 | {
|
---|
270 | d3d8_vertexbuffer_wined3d_object_destroyed,
|
---|
271 | };
|
---|
272 |
|
---|
273 | HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
|
---|
274 | UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
|
---|
275 | {
|
---|
276 | HRESULT hr;
|
---|
277 |
|
---|
278 | buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
|
---|
279 | buffer->ref = 1;
|
---|
280 | buffer->fvf = fvf;
|
---|
281 |
|
---|
282 | wined3d_mutex_lock();
|
---|
283 | hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
|
---|
284 | usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
|
---|
285 | (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
|
---|
286 | wined3d_mutex_unlock();
|
---|
287 | if (FAILED(hr))
|
---|
288 | {
|
---|
289 | WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
|
---|
290 | return hr;
|
---|
291 | }
|
---|
292 |
|
---|
293 | buffer->parentDevice = (IDirect3DDevice8 *)device;
|
---|
294 | IUnknown_AddRef(buffer->parentDevice);
|
---|
295 |
|
---|
296 | return D3D_OK;
|
---|
297 | }
|
---|