VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c@ 33252

Last change on this file since 33252 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.7 KB
Line 
1/*
2 * IDirect3DIndexBuffer9 implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Raphael Junqueira
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22/*
23 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30
31#include "config.h"
32#include "d3d9_private.h"
33
34WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
35
36/* IDirect3DIndexBuffer9 IUnknown parts follow: */
37static HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
38 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
39
40 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
41
42 if (IsEqualGUID(riid, &IID_IUnknown)
43 || IsEqualGUID(riid, &IID_IDirect3DResource9)
44 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
45 IDirect3DIndexBuffer9_AddRef(iface);
46 *ppobj = This;
47 return S_OK;
48 }
49
50 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
51 *ppobj = NULL;
52 return E_NOINTERFACE;
53}
54
55static ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
56 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)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 IDirect3DDevice9Ex_AddRef(This->parentDevice);
64 wined3d_mutex_lock();
65 IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
66 wined3d_mutex_unlock();
67 }
68
69 return ref;
70}
71
72static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
73 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
74 ULONG ref = InterlockedDecrement(&This->ref);
75
76 TRACE("%p decreasing refcount to %u.\n", iface, ref);
77
78 if (ref == 0) {
79 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
80
81 wined3d_mutex_lock();
82 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
83 wined3d_mutex_unlock();
84
85 /* Release the device last, as it may cause the device to be destroyed. */
86 IDirect3DDevice9Ex_Release(parentDevice);
87 }
88 return ref;
89}
90
91/* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
92static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(IDirect3DIndexBuffer9 *iface, IDirect3DDevice9 **device)
93{
94 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
95
96 TRACE("iface %p, device %p.\n", iface, device);
97
98 *device = (IDirect3DDevice9 *)This->parentDevice;
99 IDirect3DDevice9_AddRef(*device);
100
101 TRACE("Returning device %p.\n", *device);
102
103 return D3D_OK;
104}
105
106static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
107 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
108 HRESULT hr;
109
110 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
111 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
112
113 wined3d_mutex_lock();
114 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
115 wined3d_mutex_unlock();
116
117 return hr;
118}
119
120static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
121 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
122 HRESULT hr;
123
124 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
125 iface, debugstr_guid(refguid), pData, pSizeOfData);
126
127 wined3d_mutex_lock();
128 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
129 wined3d_mutex_unlock();
130
131 return hr;
132}
133
134static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
135 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
136 HRESULT hr;
137
138 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
139
140 wined3d_mutex_lock();
141 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
142 wined3d_mutex_unlock();
143
144 return hr;
145}
146
147static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
148 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
149 DWORD ret;
150
151 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
152
153 wined3d_mutex_lock();
154 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
155 wined3d_mutex_unlock();
156
157 return ret;
158}
159
160static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
161 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
162 DWORD ret;
163
164 TRACE("iface %p.\n", iface);
165
166 wined3d_mutex_lock();
167 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
168 wined3d_mutex_unlock();
169
170 return ret;
171}
172
173static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
174 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
175
176 TRACE("iface %p.\n", iface);
177
178 wined3d_mutex_lock();
179 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
180 wined3d_mutex_unlock();
181}
182
183static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(IDirect3DIndexBuffer9 *iface)
184{
185 TRACE("iface %p.\n", iface);
186
187 return D3DRTYPE_INDEXBUFFER;
188}
189
190/* IDirect3DIndexBuffer9 Interface follow: */
191static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
192 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
193 HRESULT hr;
194
195 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
196 iface, OffsetToLock, SizeToLock, ppbData, Flags);
197
198 wined3d_mutex_lock();
199 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
200 wined3d_mutex_unlock();
201
202 return hr;
203}
204
205static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
206 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
207 HRESULT hr;
208
209 TRACE("iface %p.\n", iface);
210
211 wined3d_mutex_lock();
212 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
213 wined3d_mutex_unlock();
214
215 return hr;
216}
217
218static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
219 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
220 HRESULT hr;
221 WINED3DBUFFER_DESC desc;
222
223 TRACE("iface %p, desc %p.\n", iface, pDesc);
224
225 wined3d_mutex_lock();
226 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
227 wined3d_mutex_unlock();
228
229 if (SUCCEEDED(hr)) {
230 pDesc->Format = d3dformat_from_wined3dformat(This->format);
231 pDesc->Usage = desc.Usage;
232 pDesc->Pool = desc.Pool;
233 pDesc->Size = desc.Size;
234 pDesc->Type = D3DRTYPE_INDEXBUFFER;
235 }
236
237 return hr;
238}
239
240
241static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
242{
243 /* IUnknown */
244 IDirect3DIndexBuffer9Impl_QueryInterface,
245 IDirect3DIndexBuffer9Impl_AddRef,
246 IDirect3DIndexBuffer9Impl_Release,
247 /* IDirect3DResource9 */
248 IDirect3DIndexBuffer9Impl_GetDevice,
249 IDirect3DIndexBuffer9Impl_SetPrivateData,
250 IDirect3DIndexBuffer9Impl_GetPrivateData,
251 IDirect3DIndexBuffer9Impl_FreePrivateData,
252 IDirect3DIndexBuffer9Impl_SetPriority,
253 IDirect3DIndexBuffer9Impl_GetPriority,
254 IDirect3DIndexBuffer9Impl_PreLoad,
255 IDirect3DIndexBuffer9Impl_GetType,
256 /* IDirect3DIndexBuffer9 */
257 IDirect3DIndexBuffer9Impl_Lock,
258 IDirect3DIndexBuffer9Impl_Unlock,
259 IDirect3DIndexBuffer9Impl_GetDesc
260};
261
262static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
263{
264 HeapFree(GetProcessHeap(), 0, parent);
265}
266
267static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
268{
269 d3d9_indexbuffer_wined3d_object_destroyed,
270};
271
272HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
273 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
274{
275 HRESULT hr;
276
277 buffer->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
278 buffer->ref = 1;
279 buffer->format = wined3dformat_from_d3dformat(format);
280
281 wined3d_mutex_lock();
282 hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
283 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
284 (IUnknown *)buffer, &d3d9_indexbuffer_wined3d_parent_ops);
285 wined3d_mutex_unlock();
286 if (FAILED(hr))
287 {
288 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
289 return hr;
290 }
291
292 buffer->parentDevice = (IDirect3DDevice9Ex *)device;
293 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
294
295 return D3D_OK;
296}
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