comctl32/tests: Add NULL terminator to unicode string constant.
[wine/hramrach.git] / dlls / d3d9 / vertexbuffer.c
blob1841bec19c04e4e6bc5960b4c2899bb78fc6d8d5
1 /*
2 * IDirect3DVertexBuffer9 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
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.
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.
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
23 #include "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 /* IDirect3DVertexBuffer9 IUnknown parts follow: */
29 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
30 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
32 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
34 if (IsEqualGUID(riid, &IID_IUnknown)
35 || IsEqualGUID(riid, &IID_IDirect3DResource9)
36 || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
37 IDirect3DVertexBuffer9_AddRef(iface);
38 *ppobj = This;
39 return S_OK;
42 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43 *ppobj = NULL;
44 return E_NOINTERFACE;
47 static ULONG WINAPI IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface) {
48 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
49 ULONG ref = InterlockedIncrement(&This->ref);
51 TRACE("%p increasing refcount to %u.\n", iface, ref);
53 if (ref == 1)
55 IDirect3DDevice9Ex_AddRef(This->parentDevice);
56 wined3d_mutex_lock();
57 IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
58 wined3d_mutex_unlock();
61 return ref;
64 static ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
65 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
66 ULONG ref = InterlockedDecrement(&This->ref);
68 TRACE("%p decreasing refcount to %u.\n", iface, ref);
70 if (ref == 0) {
71 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
73 wined3d_mutex_lock();
74 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
75 wined3d_mutex_unlock();
77 /* Release the device last, as it may cause the device to be destroyed. */
78 IDirect3DDevice9Ex_Release(parentDevice);
80 return ref;
83 /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
84 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device)
86 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
88 TRACE("iface %p, device %p.\n", iface, device);
90 *device = (IDirect3DDevice9 *)This->parentDevice;
91 IDirect3DDevice9_AddRef(*device);
93 TRACE("Returning device %p.\n", *device);
95 return D3D_OK;
98 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
99 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
100 HRESULT hr;
102 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
103 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
105 wined3d_mutex_lock();
106 hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
107 wined3d_mutex_unlock();
109 return hr;
112 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
113 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
114 HRESULT hr;
116 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
117 iface, debugstr_guid(refguid), pData, pSizeOfData);
119 wined3d_mutex_lock();
120 hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
121 wined3d_mutex_unlock();
123 return hr;
126 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
127 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
128 HRESULT hr;
130 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
132 wined3d_mutex_lock();
133 hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
134 wined3d_mutex_unlock();
136 return hr;
139 static DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
140 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
141 HRESULT hr;
143 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
145 wined3d_mutex_lock();
146 hr = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
147 wined3d_mutex_unlock();
149 return hr;
152 static DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
153 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
154 HRESULT hr;
156 TRACE("iface %p.\n", iface);
158 wined3d_mutex_lock();
159 hr = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
160 wined3d_mutex_unlock();
162 return hr;
165 static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
166 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
168 TRACE("iface %p.\n", iface);
170 wined3d_mutex_lock();
171 IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
172 wined3d_mutex_unlock();
175 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(IDirect3DVertexBuffer9 *iface)
177 TRACE("iface %p.\n", iface);
179 return D3DRTYPE_VERTEXBUFFER;
182 /* IDirect3DVertexBuffer9 Interface follow: */
183 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
184 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
185 HRESULT hr;
187 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
188 iface, OffsetToLock, SizeToLock, ppbData, Flags);
190 wined3d_mutex_lock();
191 hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
192 wined3d_mutex_unlock();
194 return hr;
197 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
198 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
199 HRESULT hr;
201 TRACE("iface %p.\n", iface);
203 wined3d_mutex_lock();
204 hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
205 wined3d_mutex_unlock();
207 return hr;
210 static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
211 IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
212 HRESULT hr;
213 WINED3DBUFFER_DESC desc;
215 TRACE("iface %p, desc %p.\n", iface, pDesc);
217 wined3d_mutex_lock();
218 hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
219 wined3d_mutex_unlock();
221 if (SUCCEEDED(hr)) {
222 pDesc->Format = D3DFMT_VERTEXDATA;
223 pDesc->Usage = desc.Usage;
224 pDesc->Pool = desc.Pool;
225 pDesc->Size = desc.Size;
226 pDesc->Type = D3DRTYPE_VERTEXBUFFER;
227 pDesc->FVF = This->fvf;
231 return hr;
234 static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
236 /* IUnknown */
237 IDirect3DVertexBuffer9Impl_QueryInterface,
238 IDirect3DVertexBuffer9Impl_AddRef,
239 IDirect3DVertexBuffer9Impl_Release,
240 /* IDirect3DResource9 */
241 IDirect3DVertexBuffer9Impl_GetDevice,
242 IDirect3DVertexBuffer9Impl_SetPrivateData,
243 IDirect3DVertexBuffer9Impl_GetPrivateData,
244 IDirect3DVertexBuffer9Impl_FreePrivateData,
245 IDirect3DVertexBuffer9Impl_SetPriority,
246 IDirect3DVertexBuffer9Impl_GetPriority,
247 IDirect3DVertexBuffer9Impl_PreLoad,
248 IDirect3DVertexBuffer9Impl_GetType,
249 /* IDirect3DVertexBuffer9 */
250 IDirect3DVertexBuffer9Impl_Lock,
251 IDirect3DVertexBuffer9Impl_Unlock,
252 IDirect3DVertexBuffer9Impl_GetDesc
255 static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
257 HeapFree(GetProcessHeap(), 0, parent);
260 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
262 d3d9_vertexbuffer_wined3d_object_destroyed,
265 HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
266 UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
268 HRESULT hr;
270 buffer->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
271 buffer->ref = 1;
272 buffer->fvf = fvf;
274 wined3d_mutex_lock();
275 hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
276 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
277 (IUnknown *)buffer, &d3d9_vertexbuffer_wined3d_parent_ops);
278 wined3d_mutex_unlock();
279 if (FAILED(hr))
281 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
282 return hr;
285 buffer->parentDevice = (IDirect3DDevice9Ex *)device;
286 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
288 return D3D_OK;