xcopy: Remove spaces before '\n's in the Korean translation.
[wine/hramrach.git] / dlls / ddraw / vertexbuffer.c
blob48e9ae7b8e72e197cf170883f9dbf2c2925445e5
1 /* Direct3D Vertex Buffer
2 * Copyright (c) 2002 Lionel ULMER
3 * Copyright (c) 2006 Stefan DÖSINGER
5 * This file contains the implementation of Direct3DVertexBuffer COM object
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 "wine/port.h"
25 #include "ddraw_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
29 /*****************************************************************************
30 * IUnknown Methods
31 *****************************************************************************/
33 /*****************************************************************************
34 * IDirect3DVertexBuffer7::QueryInterface
36 * The QueryInterface Method for Vertex Buffers
37 * For a link to QueryInterface rules, see IDirectDraw7::QueryInterface
39 * Params
40 * riid: Queryied Interface id
41 * obj: Address to return the interface pointer
43 * Returns:
44 * S_OK on success
45 * E_NOINTERFACE if the interface wasn't found
47 *****************************************************************************/
48 static HRESULT WINAPI
49 IDirect3DVertexBufferImpl_QueryInterface(IDirect3DVertexBuffer7 *iface,
50 REFIID riid,
51 void **obj)
53 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
55 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
57 /* By default, set the object pointer to NULL */
58 *obj = NULL;
60 if ( IsEqualGUID( &IID_IUnknown, riid ) )
62 IUnknown_AddRef(iface);
63 *obj = iface;
64 TRACE(" Creating IUnknown interface at %p.\n", *obj);
65 return S_OK;
67 if ( IsEqualGUID( &IID_IDirect3DVertexBuffer, riid ) )
69 IUnknown_AddRef(iface);
70 *obj = &This->IDirect3DVertexBuffer_vtbl;
71 TRACE(" Creating IDirect3DVertexBuffer interface %p\n", *obj);
72 return S_OK;
74 if ( IsEqualGUID( &IID_IDirect3DVertexBuffer7, riid ) )
76 IUnknown_AddRef(iface);
77 *obj = iface;
78 TRACE(" Creating IDirect3DVertexBuffer7 interface %p\n", *obj);
79 return S_OK;
81 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
82 return E_NOINTERFACE;
85 static HRESULT WINAPI
86 Thunk_IDirect3DVertexBufferImpl_1_QueryInterface(IDirect3DVertexBuffer *iface,
87 REFIID riid,
88 void **obj)
90 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
92 return IDirect3DVertexBuffer7_QueryInterface((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), riid, obj);
95 /*****************************************************************************
96 * IDirect3DVertexBuffer7::AddRef
98 * AddRef for Vertex Buffers
100 * Returns:
101 * The new refcount
103 *****************************************************************************/
104 static ULONG WINAPI
105 IDirect3DVertexBufferImpl_AddRef(IDirect3DVertexBuffer7 *iface)
107 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
108 ULONG ref = InterlockedIncrement(&This->ref);
110 TRACE("%p increasing refcount to %u.\n", This, ref);
112 return ref;
115 static ULONG WINAPI
116 Thunk_IDirect3DVertexBufferImpl_1_AddRef(IDirect3DVertexBuffer *iface)
118 TRACE("iface %p.\n", iface);
120 return IDirect3DVertexBuffer7_AddRef((IDirect3DVertexBuffer7 *)vb_from_vb1(iface));
124 /*****************************************************************************
125 * IDirect3DVertexBuffer7::Release
127 * Release for Vertex Buffers
129 * Returns:
130 * The new refcount
132 *****************************************************************************/
133 static ULONG WINAPI
134 IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface)
136 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
137 ULONG ref = InterlockedDecrement(&This->ref);
139 TRACE("%p decreasing refcount to %u.\n", This, ref);
141 if (ref == 0)
143 IWineD3DBuffer *curVB = NULL;
144 UINT offset, stride;
146 EnterCriticalSection(&ddraw_cs);
147 /* D3D7 Vertex buffers don't stay bound in the device, they are passed as a parameter
148 * to drawPrimitiveVB. DrawPrimitiveVB sets them as the stream source in wined3d,
149 * and they should get unset there before they are destroyed
151 IWineD3DDevice_GetStreamSource(This->ddraw->wineD3DDevice,
152 0 /* Stream number */,
153 &curVB,
154 &offset,
155 &stride);
156 if(curVB == This->wineD3DVertexBuffer)
158 IWineD3DDevice_SetStreamSource(This->ddraw->wineD3DDevice,
159 0 /* Steam number */,
160 NULL /* stream data */,
161 0 /* Offset */,
162 0 /* stride */);
164 if(curVB)
166 IWineD3DBuffer_Release(curVB); /* For the GetStreamSource */
169 IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration);
170 IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
171 LeaveCriticalSection(&ddraw_cs);
172 HeapFree(GetProcessHeap(), 0, This);
174 return 0;
176 return ref;
179 static ULONG WINAPI
180 Thunk_IDirect3DVertexBufferImpl_1_Release(IDirect3DVertexBuffer *iface)
182 TRACE("iface %p.\n", iface);
184 return IDirect3DVertexBuffer7_Release((IDirect3DVertexBuffer7 *)vb_from_vb1(iface));
187 /*****************************************************************************
188 * IDirect3DVertexBuffer Methods
189 *****************************************************************************/
191 /*****************************************************************************
192 * IDirect3DVertexBuffer7::Lock
194 * Locks the vertex buffer and returns a pointer to the vertex data
195 * Locking vertex buffers is similar to locking surfaces, because Windows
196 * uses surfaces to store vertex data internally (According to the DX sdk)
198 * Params:
199 * Flags: Locking flags. Relevant here are DDLOCK_READONLY, DDLOCK_WRITEONLY,
200 * DDLOCK_DISCARDCONTENTS and DDLOCK_NOOVERWRITE.
201 * Data: Returns a pointer to the vertex data
202 * Size: Returns the size of the buffer if not NULL
204 * Returns:
205 * D3D_OK on success
206 * DDERR_INVALIDPARAMS if Data is NULL
207 * D3DERR_VERTEXBUFFEROPTIMIZED if called on an optimized buffer(WineD3D)
209 *****************************************************************************/
210 static HRESULT WINAPI
211 IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface,
212 DWORD Flags,
213 void **Data,
214 DWORD *Size)
216 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
217 WINED3DBUFFER_DESC Desc;
218 HRESULT hr;
219 DWORD wined3d_flags = 0;
221 TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, Flags, Data, Size);
223 /* Writeonly: Pointless. Event: Unsupported by native according to the sdk
224 * nosyslock: Not applicable
226 if(!(Flags & DDLOCK_WAIT)) wined3d_flags |= WINED3DLOCK_DONOTWAIT;
227 if(Flags & DDLOCK_READONLY) wined3d_flags |= WINED3DLOCK_READONLY;
228 if(Flags & DDLOCK_NOOVERWRITE) wined3d_flags |= WINED3DLOCK_NOOVERWRITE;
229 if(Flags & DDLOCK_DISCARDCONTENTS) wined3d_flags |= WINED3DLOCK_DISCARD;
231 EnterCriticalSection(&ddraw_cs);
232 if(Size)
234 /* Get the size, for returning it, and for locking */
235 hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &Desc);
236 if(hr != D3D_OK)
238 ERR("(%p) IWineD3DBuffer::GetDesc failed with hr=%08x\n", This, hr);
239 LeaveCriticalSection(&ddraw_cs);
240 return hr;
242 *Size = Desc.Size;
245 hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, 0 /* OffsetToLock */,
246 0 /* SizeToLock, 0 == Full lock */, (BYTE **)Data, wined3d_flags);
247 LeaveCriticalSection(&ddraw_cs);
248 return hr;
251 static HRESULT WINAPI
252 Thunk_IDirect3DVertexBufferImpl_1_Lock(IDirect3DVertexBuffer *iface,
253 DWORD Flags,
254 void **Data,
255 DWORD *Size)
257 TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, Flags, Data, Size);
259 return IDirect3DVertexBuffer7_Lock((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), Flags, Data, Size);
262 /*****************************************************************************
263 * IDirect3DVertexBuffer7::Unlock
265 * Unlocks a vertex Buffer
267 * Returns:
268 * D3D_OK on success
270 *****************************************************************************/
271 static HRESULT WINAPI
272 IDirect3DVertexBufferImpl_Unlock(IDirect3DVertexBuffer7 *iface)
274 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
275 HRESULT hr;
277 TRACE("iface %p.\n", iface);
279 EnterCriticalSection(&ddraw_cs);
280 hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
281 LeaveCriticalSection(&ddraw_cs);
283 return hr;
286 static HRESULT WINAPI
287 Thunk_IDirect3DVertexBufferImpl_1_Unlock(IDirect3DVertexBuffer *iface)
289 TRACE("iface %p.\n", iface);
291 return IDirect3DVertexBuffer7_Unlock((IDirect3DVertexBuffer7 *)vb_from_vb1(iface));
295 /*****************************************************************************
296 * IDirect3DVertexBuffer7::ProcessVertices
298 * Processes untransformed Vertices into a transformed or optimized vertex
299 * buffer. It can also perform other operations, such as lighting or clipping
301 * Params
302 * VertexOp: Operation(s) to perform: D3DVOP_CLIP, _EXTENTS, _LIGHT, _TRANSFORM
303 * DestIndex: Index in the destination buffer(This), where the vertices are
304 * placed
305 * Count: Number of Vertices in the Source buffer to process
306 * SrcBuffer: Source vertex buffer
307 * SrcIndex: Index of the first vertex in the src buffer to process
308 * D3DDevice: Device to use for transformation
309 * Flags: 0 for default, D3DPV_DONOTCOPYDATA to prevent copying
310 * unchaned vertices
312 * Returns:
313 * D3D_OK on success
314 * DDERR_INVALIDPARAMS If D3DVOP_TRANSFORM wasn't passed
316 *****************************************************************************/
317 static HRESULT WINAPI
318 IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexBuffer7 *iface,
319 DWORD VertexOp,
320 DWORD DestIndex,
321 DWORD Count,
322 IDirect3DVertexBuffer7 *SrcBuffer,
323 DWORD SrcIndex,
324 IDirect3DDevice7 *D3DDevice,
325 DWORD Flags)
327 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
328 IDirect3DVertexBufferImpl *Src = (IDirect3DVertexBufferImpl *)SrcBuffer;
329 IDirect3DDeviceImpl *D3D = (IDirect3DDeviceImpl *)D3DDevice;
330 BOOL oldClip, doClip;
331 HRESULT hr;
333 TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n",
334 iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, D3DDevice, Flags);
336 /* Vertex operations:
337 * D3DVOP_CLIP: Clips vertices outside the viewing frustrum. Needs clipping information
338 * in the vertex buffer (Buffer may not be created with D3DVBCAPS_DONOTCLIP)
339 * D3DVOP_EXTENTS: Causes the screen extents to be updated when rendering the vertices
340 * D3DVOP_LIGHT: Lights the vertices
341 * D3DVOP_TRANSFORM: Transform the vertices. This flag is necessary
343 * WineD3D only transforms and clips the vertices by now, so EXTENTS and LIGHT
344 * are not implemented. Clipping is disabled ATM, because of unsure conditions.
346 if( !(VertexOp & D3DVOP_TRANSFORM) ) return DDERR_INVALIDPARAMS;
348 EnterCriticalSection(&ddraw_cs);
349 /* WineD3D doesn't know d3d7 vertex operation, it uses
350 * render states instead. Set the render states according to
351 * the vertex ops
353 doClip = VertexOp & D3DVOP_CLIP ? TRUE : FALSE;
354 IWineD3DDevice_GetRenderState(D3D->wineD3DDevice,
355 WINED3DRS_CLIPPING,
356 (DWORD *) &oldClip);
357 if(doClip != oldClip)
359 IWineD3DDevice_SetRenderState(D3D->wineD3DDevice,
360 WINED3DRS_CLIPPING,
361 doClip);
364 IWineD3DDevice_SetStreamSource(D3D->wineD3DDevice,
365 0, /* Stream No */
366 Src->wineD3DVertexBuffer,
367 0, /* Offset */
368 get_flexible_vertex_size(Src->fvf));
369 IWineD3DDevice_SetVertexDeclaration(D3D->wineD3DDevice,
370 Src->wineD3DVertexDeclaration);
371 hr = IWineD3DDevice_ProcessVertices(D3D->wineD3DDevice,
372 SrcIndex,
373 DestIndex,
374 Count,
375 This->wineD3DVertexBuffer,
376 NULL /* Output vdecl */,
377 Flags,
378 This->fvf);
380 /* Restore the states if needed */
381 if(doClip != oldClip)
382 IWineD3DDevice_SetRenderState(D3D->wineD3DDevice,
383 WINED3DRS_CLIPPING,
384 oldClip);
385 LeaveCriticalSection(&ddraw_cs);
386 return hr;
389 static HRESULT WINAPI
390 Thunk_IDirect3DVertexBufferImpl_1_ProcessVertices(IDirect3DVertexBuffer *iface,
391 DWORD VertexOp,
392 DWORD DestIndex,
393 DWORD Count,
394 IDirect3DVertexBuffer *SrcBuffer,
395 DWORD SrcIndex,
396 IDirect3DDevice3 *D3DDevice,
397 DWORD Flags)
399 IDirect3DVertexBufferImpl *Src = SrcBuffer ? vb_from_vb1(SrcBuffer) : NULL;
400 IDirect3DDeviceImpl *D3D = D3DDevice ? device_from_device3(D3DDevice) : NULL;
402 TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n",
403 iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, D3DDevice, Flags);
405 return IDirect3DVertexBuffer7_ProcessVertices((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), VertexOp,
406 DestIndex, Count, (IDirect3DVertexBuffer7 *)Src, SrcIndex, (IDirect3DDevice7 *)D3D, Flags);
409 /*****************************************************************************
410 * IDirect3DVertexBuffer7::GetVertexBufferDesc
412 * Returns the description of a vertex buffer
414 * Params:
415 * Desc: Address to write the description to
417 * Returns
418 * DDERR_INVALIDPARAMS if Desc is NULL
419 * D3D_OK on success
421 *****************************************************************************/
422 static HRESULT WINAPI
423 IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface,
424 D3DVERTEXBUFFERDESC *Desc)
426 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
427 WINED3DBUFFER_DESC WDesc;
428 HRESULT hr;
430 TRACE("iface %p, desc %p.\n", iface, Desc);
432 if(!Desc) return DDERR_INVALIDPARAMS;
434 EnterCriticalSection(&ddraw_cs);
435 hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &WDesc);
436 if(hr != D3D_OK)
438 ERR("(%p) IWineD3DBuffer::GetDesc failed with hr=%08x\n", This, hr);
439 LeaveCriticalSection(&ddraw_cs);
440 return hr;
443 /* Now fill the Desc structure */
444 Desc->dwCaps = This->Caps;
445 Desc->dwFVF = This->fvf;
446 Desc->dwNumVertices = WDesc.Size / get_flexible_vertex_size(This->fvf);
447 LeaveCriticalSection(&ddraw_cs);
449 return D3D_OK;
452 static HRESULT WINAPI
453 Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(IDirect3DVertexBuffer *iface,
454 D3DVERTEXBUFFERDESC *Desc)
456 TRACE("iface %p, desc %p.\n", iface, Desc);
458 return IDirect3DVertexBuffer7_GetVertexBufferDesc((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), Desc);
462 /*****************************************************************************
463 * IDirect3DVertexBuffer7::Optimize
465 * Converts an unoptimized vertex buffer into an optimized buffer
467 * Params:
468 * D3DDevice: Device for which this buffer is optimized
469 * Flags: Not used, should be set to 0
471 * Returns
472 * D3D_OK, because it's a stub
474 *****************************************************************************/
475 static HRESULT WINAPI
476 IDirect3DVertexBufferImpl_Optimize(IDirect3DVertexBuffer7 *iface,
477 IDirect3DDevice7 *D3DDevice,
478 DWORD Flags)
480 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
481 static BOOL hide = FALSE;
483 TRACE("iface %p, device %p, flags %#x.\n", iface, D3DDevice, Flags);
485 if (!hide)
487 FIXME("iface %p, device %p, flags %#x stub!\n", iface, D3DDevice, Flags);
488 hide = TRUE;
491 /* We could forward this call to WineD3D and take advantage
492 * of it once we use OpenGL vertex buffers
494 EnterCriticalSection(&ddraw_cs);
495 This->Caps |= D3DVBCAPS_OPTIMIZED;
496 LeaveCriticalSection(&ddraw_cs);
498 return DD_OK;
501 static HRESULT WINAPI
502 Thunk_IDirect3DVertexBufferImpl_1_Optimize(IDirect3DVertexBuffer *iface,
503 IDirect3DDevice3 *D3DDevice,
504 DWORD Flags)
506 IDirect3DDeviceImpl *D3D = D3DDevice ? device_from_device3(D3DDevice) : NULL;
508 TRACE("iface %p, device %p, flags %#x.\n", iface, D3DDevice, Flags);
510 return IDirect3DVertexBuffer7_Optimize((IDirect3DVertexBuffer7 *)vb_from_vb1(iface),
511 (IDirect3DDevice7 *)D3D, Flags);
514 /*****************************************************************************
515 * IDirect3DVertexBuffer7::ProcessVerticesStrided
517 * This method processes untransformed strided vertices into a processed
518 * or optimized vertex buffer.
520 * For more details on the parameters, see
521 * IDirect3DVertexBuffer7::ProcessVertices
523 * Params:
524 * VertexOp: Operations to perform
525 * DestIndex: Destination index to write the vertices to
526 * Count: Number of input vertices
527 * StrideData: Array containing the input vertices
528 * VertexTypeDesc: Vertex Description or source index?????????
529 * D3DDevice: IDirect3DDevice7 to use for processing
530 * Flags: Can be D3DPV_DONOTCOPYDATA to avoid copying unmodified vertices
532 * Returns
533 * D3D_OK on success, or DDERR_*
535 *****************************************************************************/
536 static HRESULT WINAPI
537 IDirect3DVertexBufferImpl_ProcessVerticesStrided(IDirect3DVertexBuffer7 *iface,
538 DWORD VertexOp,
539 DWORD DestIndex,
540 DWORD Count,
541 D3DDRAWPRIMITIVESTRIDEDDATA *StrideData,
542 DWORD VertexTypeDesc,
543 IDirect3DDevice7 *D3DDevice,
544 DWORD Flags)
546 FIXME("iface %p, vertex_op %#x, dst_idx %u, count %u, data %p, vertex_type %#x, device %p, flags %#x stub!\n",
547 iface, VertexOp, DestIndex, Count, StrideData, VertexTypeDesc, D3DDevice, Flags);
549 return DD_OK;
552 /*****************************************************************************
553 * The VTables
554 *****************************************************************************/
556 static const struct IDirect3DVertexBuffer7Vtbl d3d_vertex_buffer7_vtbl =
558 /*** IUnknown Methods ***/
559 IDirect3DVertexBufferImpl_QueryInterface,
560 IDirect3DVertexBufferImpl_AddRef,
561 IDirect3DVertexBufferImpl_Release,
562 /*** IDirect3DVertexBuffer Methods ***/
563 IDirect3DVertexBufferImpl_Lock,
564 IDirect3DVertexBufferImpl_Unlock,
565 IDirect3DVertexBufferImpl_ProcessVertices,
566 IDirect3DVertexBufferImpl_GetVertexBufferDesc,
567 IDirect3DVertexBufferImpl_Optimize,
568 /*** IDirect3DVertexBuffer7 Methods ***/
569 IDirect3DVertexBufferImpl_ProcessVerticesStrided
572 static const struct IDirect3DVertexBufferVtbl d3d_vertex_buffer1_vtbl =
574 /*** IUnknown Methods ***/
575 Thunk_IDirect3DVertexBufferImpl_1_QueryInterface,
576 Thunk_IDirect3DVertexBufferImpl_1_AddRef,
577 Thunk_IDirect3DVertexBufferImpl_1_Release,
578 /*** IDirect3DVertexBuffer Methods ***/
579 Thunk_IDirect3DVertexBufferImpl_1_Lock,
580 Thunk_IDirect3DVertexBufferImpl_1_Unlock,
581 Thunk_IDirect3DVertexBufferImpl_1_ProcessVertices,
582 Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc,
583 Thunk_IDirect3DVertexBufferImpl_1_Optimize
586 HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
587 IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc)
589 DWORD usage;
590 HRESULT hr;
592 buffer->lpVtbl = &d3d_vertex_buffer7_vtbl;
593 buffer->IDirect3DVertexBuffer_vtbl = &d3d_vertex_buffer1_vtbl;
594 buffer->ref = 1;
596 buffer->ddraw = ddraw;
597 buffer->Caps = desc->dwCaps;
598 buffer->fvf = desc->dwFVF;
600 usage = desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0;
601 usage |= WINED3DUSAGE_STATICDECL;
603 EnterCriticalSection(&ddraw_cs);
605 hr = IWineD3DDevice_CreateVertexBuffer(ddraw->wineD3DDevice,
606 get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices,
607 usage, desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
608 &buffer->wineD3DVertexBuffer, (IUnknown *)buffer, &ddraw_null_wined3d_parent_ops);
609 if (FAILED(hr))
611 WARN("Failed to create wined3d vertex buffer, hr %#x.\n", hr);
612 LeaveCriticalSection(&ddraw_cs);
614 if (hr == WINED3DERR_INVALIDCALL)
615 return DDERR_INVALIDPARAMS;
616 else
617 return hr;
620 buffer->wineD3DVertexDeclaration = ddraw_find_decl(ddraw, desc->dwFVF);
621 if (!buffer->wineD3DVertexDeclaration)
623 ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF);
624 IWineD3DBuffer_Release(buffer->wineD3DVertexBuffer);
625 LeaveCriticalSection(&ddraw_cs);
627 return DDERR_INVALIDPARAMS;
629 IWineD3DVertexDeclaration_AddRef(buffer->wineD3DVertexDeclaration);
631 LeaveCriticalSection(&ddraw_cs);
633 return D3D_OK;