wordpad: Find dialogs intialize find field with selection.
[wine/hramrach.git] / dlls / d3d8 / vertexbuffer.c
blob476fcc492c2e24d1d80014b03a3c8e63ed98b01f
1 /*
2 * IDirect3DVertexBuffer8 implementation
4 * Copyright 2005 Oliver Stieber
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.
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.
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
21 #include "config.h"
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DVertexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource8)
34 || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
35 IUnknown_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
46 static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
47 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("%p increasing refcount to %u.\n", iface, ref);
52 if (ref == 1)
54 IDirect3DDevice8_AddRef(This->parentDevice);
55 wined3d_mutex_lock();
56 IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
57 wined3d_mutex_unlock();
60 return ref;
63 static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
64 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
69 if (ref == 0) {
70 IDirect3DDevice8 *parentDevice = This->parentDevice;
72 wined3d_mutex_lock();
73 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice8_Release(parentDevice);
80 return ref;
83 /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
84 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device)
86 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
88 TRACE("iface %p, device %p.\n", iface, device);
90 *device = (IDirect3DDevice8 *)This->parentDevice;
91 IDirect3DDevice8_AddRef(*device);
93 TRACE("Returning device %p.\n", *device);
95 return D3D_OK;
98 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
99 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)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 IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
113 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)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 IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
127 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)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 IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
140 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
141 DWORD ret;
143 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
145 wined3d_mutex_lock();
146 ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
147 wined3d_mutex_unlock();
149 return ret;
152 static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
153 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
154 DWORD ret;
156 TRACE("iface %p.\n", iface);
158 wined3d_mutex_lock();
159 ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
160 wined3d_mutex_unlock();
162 return ret;
165 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
166 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
168 TRACE("iface %p.\n", iface);
170 wined3d_mutex_lock();
171 IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
172 wined3d_mutex_unlock();
175 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(IDirect3DVertexBuffer8 *iface)
177 TRACE("iface %p.\n", iface);
179 return D3DRTYPE_VERTEXBUFFER;
182 /* IDirect3DVertexBuffer8 Interface follow: */
183 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
184 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)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, ppbData, Flags);
192 wined3d_mutex_unlock();
194 return hr;
197 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
198 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)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 IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
211 IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)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->Type = D3DRTYPE_VERTEXBUFFER;
223 pDesc->Usage = desc.Usage;
224 pDesc->Pool = desc.Pool;
225 pDesc->Size = desc.Size;
226 pDesc->FVF = This->fvf;
227 pDesc->Format = D3DFMT_VERTEXDATA;
230 return hr;
233 static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
235 /* IUnknown */
236 IDirect3DVertexBuffer8Impl_QueryInterface,
237 IDirect3DVertexBuffer8Impl_AddRef,
238 IDirect3DVertexBuffer8Impl_Release,
239 /* IDirect3DResource8 */
240 IDirect3DVertexBuffer8Impl_GetDevice,
241 IDirect3DVertexBuffer8Impl_SetPrivateData,
242 IDirect3DVertexBuffer8Impl_GetPrivateData,
243 IDirect3DVertexBuffer8Impl_FreePrivateData,
244 IDirect3DVertexBuffer8Impl_SetPriority,
245 IDirect3DVertexBuffer8Impl_GetPriority,
246 IDirect3DVertexBuffer8Impl_PreLoad,
247 IDirect3DVertexBuffer8Impl_GetType,
248 /* IDirect3DVertexBuffer8 */
249 IDirect3DVertexBuffer8Impl_Lock,
250 IDirect3DVertexBuffer8Impl_Unlock,
251 IDirect3DVertexBuffer8Impl_GetDesc
254 static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
256 HeapFree(GetProcessHeap(), 0, parent);
259 static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
261 d3d8_vertexbuffer_wined3d_object_destroyed,
264 HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
265 UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
267 HRESULT hr;
269 buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
270 buffer->ref = 1;
271 buffer->fvf = fvf;
273 wined3d_mutex_lock();
274 hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
275 usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
276 (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
277 wined3d_mutex_unlock();
278 if (FAILED(hr))
280 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
281 return hr;
284 buffer->parentDevice = (IDirect3DDevice8 *)device;
285 IUnknown_AddRef(buffer->parentDevice);
287 return D3D_OK;