comctl32/tests: Add NULL terminator to unicode string constant.
[wine/hramrach.git] / dlls / d3d9 / indexbuffer.c
blob1b7e8e43276d922484f5c0e952354b62f2010a4d
1 /*
2 * IDirect3DIndexBuffer9 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Raphael Junqueira
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.
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.
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
22 #include "config.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DIndexBuffer9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
31 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DResource9)
35 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
36 IDirect3DIndexBuffer9_AddRef(iface);
37 *ppobj = This;
38 return S_OK;
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
46 static ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
47 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("%p increasing refcount to %u.\n", iface, ref);
52 if (ref == 1)
54 IDirect3DDevice9Ex_AddRef(This->parentDevice);
55 wined3d_mutex_lock();
56 IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
57 wined3d_mutex_unlock();
60 return ref;
63 static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
64 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
69 if (ref == 0) {
70 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
72 wined3d_mutex_lock();
73 IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice9Ex_Release(parentDevice);
79 return ref;
82 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
83 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(IDirect3DIndexBuffer9 *iface, IDirect3DDevice9 **device)
85 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
87 TRACE("iface %p, device %p.\n", iface, device);
89 *device = (IDirect3DDevice9 *)This->parentDevice;
90 IDirect3DDevice9_AddRef(*device);
92 TRACE("Returning device %p.\n", *device);
94 return D3D_OK;
97 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
98 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
99 HRESULT hr;
101 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
102 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
104 wined3d_mutex_lock();
105 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
106 wined3d_mutex_unlock();
108 return hr;
111 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
112 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
113 HRESULT hr;
115 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
116 iface, debugstr_guid(refguid), pData, pSizeOfData);
118 wined3d_mutex_lock();
119 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
120 wined3d_mutex_unlock();
122 return hr;
125 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
126 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
127 HRESULT hr;
129 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
131 wined3d_mutex_lock();
132 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
133 wined3d_mutex_unlock();
135 return hr;
138 static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
139 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
140 DWORD ret;
142 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
144 wined3d_mutex_lock();
145 ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
146 wined3d_mutex_unlock();
148 return ret;
151 static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
152 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
153 DWORD ret;
155 TRACE("iface %p.\n", iface);
157 wined3d_mutex_lock();
158 ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
159 wined3d_mutex_unlock();
161 return ret;
164 static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
165 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
167 TRACE("iface %p.\n", iface);
169 wined3d_mutex_lock();
170 IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
171 wined3d_mutex_unlock();
174 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(IDirect3DIndexBuffer9 *iface)
176 TRACE("iface %p.\n", iface);
178 return D3DRTYPE_INDEXBUFFER;
181 /* IDirect3DIndexBuffer9 Interface follow: */
182 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
183 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
184 HRESULT hr;
186 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
187 iface, OffsetToLock, SizeToLock, ppbData, Flags);
189 wined3d_mutex_lock();
190 hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
191 wined3d_mutex_unlock();
193 return hr;
196 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
197 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
198 HRESULT hr;
200 TRACE("iface %p.\n", iface);
202 wined3d_mutex_lock();
203 hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
204 wined3d_mutex_unlock();
206 return hr;
209 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
210 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
211 HRESULT hr;
212 WINED3DBUFFER_DESC desc;
214 TRACE("iface %p, desc %p.\n", iface, pDesc);
216 wined3d_mutex_lock();
217 hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
218 wined3d_mutex_unlock();
220 if (SUCCEEDED(hr)) {
221 pDesc->Format = d3dformat_from_wined3dformat(This->format);
222 pDesc->Usage = desc.Usage;
223 pDesc->Pool = desc.Pool;
224 pDesc->Size = desc.Size;
225 pDesc->Type = D3DRTYPE_INDEXBUFFER;
228 return hr;
232 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
234 /* IUnknown */
235 IDirect3DIndexBuffer9Impl_QueryInterface,
236 IDirect3DIndexBuffer9Impl_AddRef,
237 IDirect3DIndexBuffer9Impl_Release,
238 /* IDirect3DResource9 */
239 IDirect3DIndexBuffer9Impl_GetDevice,
240 IDirect3DIndexBuffer9Impl_SetPrivateData,
241 IDirect3DIndexBuffer9Impl_GetPrivateData,
242 IDirect3DIndexBuffer9Impl_FreePrivateData,
243 IDirect3DIndexBuffer9Impl_SetPriority,
244 IDirect3DIndexBuffer9Impl_GetPriority,
245 IDirect3DIndexBuffer9Impl_PreLoad,
246 IDirect3DIndexBuffer9Impl_GetType,
247 /* IDirect3DIndexBuffer9 */
248 IDirect3DIndexBuffer9Impl_Lock,
249 IDirect3DIndexBuffer9Impl_Unlock,
250 IDirect3DIndexBuffer9Impl_GetDesc
253 static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
255 HeapFree(GetProcessHeap(), 0, parent);
258 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
260 d3d9_indexbuffer_wined3d_object_destroyed,
263 HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
264 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
266 HRESULT hr;
268 buffer->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
269 buffer->ref = 1;
270 buffer->format = wined3dformat_from_d3dformat(format);
272 wined3d_mutex_lock();
273 hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
274 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
275 (IUnknown *)buffer, &d3d9_indexbuffer_wined3d_parent_ops);
276 wined3d_mutex_unlock();
277 if (FAILED(hr))
279 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
280 return hr;
283 buffer->parentDevice = (IDirect3DDevice9Ex *)device;
284 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
286 return D3D_OK;