VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c@ 32580

Last change on this file since 32580 was 25949, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.36 and disable unnecessary fbo state poll

  • Property svn:eol-style set to native
File size: 9.8 KB
Line 
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
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37/* IDirect3DVertexBuffer9 IUnknown parts follow: */
38static HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
39 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
40
41 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
42
43 if (IsEqualGUID(riid, &IID_IUnknown)
44 || IsEqualGUID(riid, &IID_IDirect3DResource9)
45 || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
46 IDirect3DVertexBuffer9_AddRef(iface);
47 *ppobj = This;
48 return S_OK;
49 }
50
51 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
52 *ppobj = NULL;
53 return E_NOINTERFACE;
54}
55
56static ULONG WINAPI IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface) {
57 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
58 ULONG ref = InterlockedIncrement(&This->ref);
59
60 TRACE("%p increasing refcount to %u.\n", iface, ref);
61
62 if (ref == 1)
63 {
64 IDirect3DDevice9Ex_AddRef(This->parentDevice);
65 wined3d_mutex_lock();
66 IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
67 wined3d_mutex_unlock();
68 }
69
70 return ref;
71}
72
73static ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
74 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
75 ULONG ref = InterlockedDecrement(&This->ref);
76
77 TRACE("%p decreasing refcount to %u.\n", iface, ref);
78
79 if (ref == 0) {
80 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
81
82 wined3d_mutex_lock();
83 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
84 wined3d_mutex_unlock();
85
86 /* Release the device last, as it may cause the device to be destroyed. */
87 IDirect3DDevice9Ex_Release(parentDevice);
88 }
89 return ref;
90}
91
92/* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
93static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device)
94{
95 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
96
97 TRACE("iface %p, device %p.\n", iface, device);
98
99 *device = (IDirect3DDevice9 *)This->parentDevice;
100 IDirect3DDevice9_AddRef(*device);
101
102 TRACE("Returning device %p.\n", *device);
103
104 return D3D_OK;
105}
106
107static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
108 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)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
121static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
122 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)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
135static HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
136 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)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
148static DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
149 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
150 HRESULT hr;
151
152 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
153
154 wined3d_mutex_lock();
155 hr = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
156 wined3d_mutex_unlock();
157
158 return hr;
159}
160
161static DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
162 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
163 HRESULT hr;
164
165 TRACE("iface %p.\n", iface);
166
167 wined3d_mutex_lock();
168 hr = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
169 wined3d_mutex_unlock();
170
171 return hr;
172}
173
174static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
175 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
176
177 TRACE("iface %p.\n", iface);
178
179 wined3d_mutex_lock();
180 IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
181 wined3d_mutex_unlock();
182}
183
184static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(IDirect3DVertexBuffer9 *iface)
185{
186 TRACE("iface %p.\n", iface);
187
188 return D3DRTYPE_VERTEXBUFFER;
189}
190
191/* IDirect3DVertexBuffer9 Interface follow: */
192static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
193 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)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, (BYTE **)ppbData, Flags);
201 wined3d_mutex_unlock();
202
203 return hr;
204}
205
206static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
207 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)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
219static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
220 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)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->Format = D3DFMT_VERTEXDATA;
232 pDesc->Usage = desc.Usage;
233 pDesc->Pool = desc.Pool;
234 pDesc->Size = desc.Size;
235 pDesc->Type = D3DRTYPE_VERTEXBUFFER;
236 pDesc->FVF = This->fvf;
237 }
238
239
240 return hr;
241}
242
243static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
244{
245 /* IUnknown */
246 IDirect3DVertexBuffer9Impl_QueryInterface,
247 IDirect3DVertexBuffer9Impl_AddRef,
248 IDirect3DVertexBuffer9Impl_Release,
249 /* IDirect3DResource9 */
250 IDirect3DVertexBuffer9Impl_GetDevice,
251 IDirect3DVertexBuffer9Impl_SetPrivateData,
252 IDirect3DVertexBuffer9Impl_GetPrivateData,
253 IDirect3DVertexBuffer9Impl_FreePrivateData,
254 IDirect3DVertexBuffer9Impl_SetPriority,
255 IDirect3DVertexBuffer9Impl_GetPriority,
256 IDirect3DVertexBuffer9Impl_PreLoad,
257 IDirect3DVertexBuffer9Impl_GetType,
258 /* IDirect3DVertexBuffer9 */
259 IDirect3DVertexBuffer9Impl_Lock,
260 IDirect3DVertexBuffer9Impl_Unlock,
261 IDirect3DVertexBuffer9Impl_GetDesc
262};
263
264static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
265{
266 HeapFree(GetProcessHeap(), 0, parent);
267}
268
269static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
270{
271 d3d9_vertexbuffer_wined3d_object_destroyed,
272};
273
274HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
275 UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
276{
277 HRESULT hr;
278
279 buffer->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
280 buffer->ref = 1;
281 buffer->fvf = fvf;
282
283 wined3d_mutex_lock();
284 hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
285 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
286 (IUnknown *)buffer, &d3d9_vertexbuffer_wined3d_parent_ops);
287 wined3d_mutex_unlock();
288 if (FAILED(hr))
289 {
290 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
291 return hr;
292 }
293
294 buffer->parentDevice = (IDirect3DDevice9Ex *)device;
295 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
296
297 return D3D_OK;
298}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette