Sync ddraw, d3d8 and d3d9 + wined3d to wine 1.1.28
[reactos.git] / reactos / dll / directx / wine / d3d8 / indexbuffer.c
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 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DIndexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_QueryInterface(LPDIRECT3DINDEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
29
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)) {
33 IUnknown_AddRef(iface);
34 *ppobj = This;
35 return S_OK;
36 }
37
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39 *ppobj = NULL;
40 return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRef(LPDIRECT3DINDEXBUFFER8 iface) {
44 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
45 ULONG ref = InterlockedIncrement(&This->ref);
46
47 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
48
49 return ref;
50 }
51
52 static ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface) {
53 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
54 ULONG ref = InterlockedDecrement(&This->ref);
55
56 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
57
58 if (ref == 0) {
59 wined3d_mutex_lock();
60 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
61 wined3d_mutex_unlock();
62
63 IUnknown_Release(This->parentDevice);
64 HeapFree(GetProcessHeap(), 0, This);
65 }
66 return ref;
67 }
68
69 /* IDirect3DIndexBuffer8 IDirect3DResource8 Interface follow: */
70 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
71 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
72 IWineD3DDevice *wined3d_device;
73 HRESULT hr;
74 TRACE("(%p) Relay\n", This);
75
76 wined3d_mutex_lock();
77 hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
78 if (SUCCEEDED(hr))
79 {
80 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
81 IWineD3DDevice_Release(wined3d_device);
82 }
83 wined3d_mutex_unlock();
84
85 return hr;
86 }
87
88 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
89 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
90 HRESULT hr;
91 TRACE("(%p) Relay\n", This);
92
93 wined3d_mutex_lock();
94 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
95 wined3d_mutex_unlock();
96
97 return hr;
98 }
99
100 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
101 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
102 HRESULT hr;
103 TRACE("(%p) Relay\n", This);
104
105 wined3d_mutex_lock();
106 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
107 wined3d_mutex_unlock();
108
109 return hr;
110 }
111
112 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid) {
113 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
114 HRESULT hr;
115 TRACE("(%p) Relay\n", This);
116
117 wined3d_mutex_lock();
118 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
119 wined3d_mutex_unlock();
120
121 return hr;
122 }
123
124 static DWORD WINAPI IDirect3DIndexBuffer8Impl_SetPriority(LPDIRECT3DINDEXBUFFER8 iface, DWORD PriorityNew) {
125 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
126 DWORD ret;
127 TRACE("(%p) Relay\n", This);
128
129 wined3d_mutex_lock();
130 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
131 wined3d_mutex_unlock();
132
133 return ret;
134 }
135
136 static DWORD WINAPI IDirect3DIndexBuffer8Impl_GetPriority(LPDIRECT3DINDEXBUFFER8 iface) {
137 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
138 DWORD ret;
139 TRACE("(%p) Relay\n", This);
140
141 wined3d_mutex_lock();
142 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
143 wined3d_mutex_unlock();
144
145 return ret;
146 }
147
148 static void WINAPI IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface) {
149 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
150 TRACE("(%p) Relay\n", This);
151
152 wined3d_mutex_lock();
153 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
154 wined3d_mutex_unlock();
155 }
156
157 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(LPDIRECT3DINDEXBUFFER8 iface) {
158 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
159 TRACE("(%p)\n", This);
160
161 return D3DRTYPE_INDEXBUFFER;
162 }
163
164 /* IDirect3DIndexBuffer8 Interface follow: */
165 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Lock(LPDIRECT3DINDEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
166 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
167 HRESULT hr;
168 TRACE("(%p) Relay\n", This);
169
170 wined3d_mutex_lock();
171 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
172 wined3d_mutex_unlock();
173
174 return hr;
175 }
176
177 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface) {
178 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
179 HRESULT hr;
180 TRACE("(%p) Relay\n", This);
181
182 wined3d_mutex_lock();
183 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
184 wined3d_mutex_unlock();
185
186 return hr;
187 }
188
189 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface, D3DINDEXBUFFER_DESC *pDesc) {
190 IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
191 HRESULT hr;
192 WINED3DBUFFER_DESC desc;
193 TRACE("(%p) Relay\n", This);
194
195 wined3d_mutex_lock();
196 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
197 wined3d_mutex_unlock();
198
199 if (SUCCEEDED(hr)) {
200 pDesc->Format = d3dformat_from_wined3dformat(This->format);
201 pDesc->Type = D3DRTYPE_INDEXBUFFER;
202 pDesc->Usage = desc.Usage;
203 pDesc->Pool = desc.Pool;
204 pDesc->Size = desc.Size;
205 }
206
207 return hr;
208 }
209
210
211 const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
212 {
213 /* IUnknown */
214 IDirect3DIndexBuffer8Impl_QueryInterface,
215 IDirect3DIndexBuffer8Impl_AddRef,
216 IDirect3DIndexBuffer8Impl_Release,
217 /* IDirect3DResource8 */
218 IDirect3DIndexBuffer8Impl_GetDevice,
219 IDirect3DIndexBuffer8Impl_SetPrivateData,
220 IDirect3DIndexBuffer8Impl_GetPrivateData,
221 IDirect3DIndexBuffer8Impl_FreePrivateData,
222 IDirect3DIndexBuffer8Impl_SetPriority,
223 IDirect3DIndexBuffer8Impl_GetPriority,
224 IDirect3DIndexBuffer8Impl_PreLoad,
225 IDirect3DIndexBuffer8Impl_GetType,
226 /* IDirect3DIndexBuffer8 */
227 IDirect3DIndexBuffer8Impl_Lock,
228 IDirect3DIndexBuffer8Impl_Unlock,
229 IDirect3DIndexBuffer8Impl_GetDesc
230 };