VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c@ 33282

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