mmsystem.dll16: Fix the pointer arithmetic and memory leak issues when unmapping.
[wine.git] / dlls / ddraw / vertexbuffer.c
blobdae15662d723c3fd1bc4fd372e37eb0f29d66ebb
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 IDirect3DVertexBufferImpl_1_QueryInterface(IDirect3DVertexBuffer *iface,
86 REFIID riid, void **obj)
88 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
90 return IDirect3DVertexBuffer7_QueryInterface((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), riid, obj);
93 /*****************************************************************************
94 * IDirect3DVertexBuffer7::AddRef
96 * AddRef for Vertex Buffers
98 * Returns:
99 * The new refcount
101 *****************************************************************************/
102 static ULONG WINAPI
103 IDirect3DVertexBufferImpl_AddRef(IDirect3DVertexBuffer7 *iface)
105 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
106 ULONG ref = InterlockedIncrement(&This->ref);
108 TRACE("%p increasing refcount to %u.\n", This, ref);
110 return ref;
113 static ULONG WINAPI IDirect3DVertexBufferImpl_1_AddRef(IDirect3DVertexBuffer *iface)
115 TRACE("iface %p.\n", iface);
117 return IDirect3DVertexBuffer7_AddRef((IDirect3DVertexBuffer7 *)vb_from_vb1(iface));
121 /*****************************************************************************
122 * IDirect3DVertexBuffer7::Release
124 * Release for Vertex Buffers
126 * Returns:
127 * The new refcount
129 *****************************************************************************/
130 static ULONG WINAPI
131 IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface)
133 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
134 ULONG ref = InterlockedDecrement(&This->ref);
136 TRACE("%p decreasing refcount to %u.\n", This, ref);
138 if (ref == 0)
140 struct wined3d_buffer *curVB = NULL;
141 UINT offset, stride;
143 EnterCriticalSection(&ddraw_cs);
144 /* D3D7 Vertex buffers don't stay bound in the device, they are passed as a parameter
145 * to drawPrimitiveVB. DrawPrimitiveVB sets them as the stream source in wined3d,
146 * and they should get unset there before they are destroyed
148 IWineD3DDevice_GetStreamSource(This->ddraw->wineD3DDevice,
149 0 /* Stream number */,
150 &curVB,
151 &offset,
152 &stride);
153 if(curVB == This->wineD3DVertexBuffer)
155 IWineD3DDevice_SetStreamSource(This->ddraw->wineD3DDevice,
156 0 /* Steam number */,
157 NULL /* stream data */,
158 0 /* Offset */,
159 0 /* stride */);
161 if (curVB)
162 wined3d_buffer_decref(curVB); /* For the GetStreamSource */
164 wined3d_vertex_declaration_decref(This->wineD3DVertexDeclaration);
165 wined3d_buffer_decref(This->wineD3DVertexBuffer);
166 LeaveCriticalSection(&ddraw_cs);
167 HeapFree(GetProcessHeap(), 0, This);
169 return 0;
171 return ref;
174 static ULONG WINAPI IDirect3DVertexBufferImpl_1_Release(IDirect3DVertexBuffer *iface)
176 TRACE("iface %p.\n", iface);
178 return IDirect3DVertexBuffer7_Release((IDirect3DVertexBuffer7 *)vb_from_vb1(iface));
181 /*****************************************************************************
182 * IDirect3DVertexBuffer Methods
183 *****************************************************************************/
185 /*****************************************************************************
186 * IDirect3DVertexBuffer7::Lock
188 * Locks the vertex buffer and returns a pointer to the vertex data
189 * Locking vertex buffers is similar to locking surfaces, because Windows
190 * uses surfaces to store vertex data internally (According to the DX sdk)
192 * Params:
193 * Flags: Locking flags. Relevant here are DDLOCK_READONLY, DDLOCK_WRITEONLY,
194 * DDLOCK_DISCARDCONTENTS and DDLOCK_NOOVERWRITE.
195 * Data: Returns a pointer to the vertex data
196 * Size: Returns the size of the buffer if not NULL
198 * Returns:
199 * D3D_OK on success
200 * DDERR_INVALIDPARAMS if Data is NULL
201 * D3DERR_VERTEXBUFFEROPTIMIZED if called on an optimized buffer(WineD3D)
203 *****************************************************************************/
204 static HRESULT WINAPI
205 IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface,
206 DWORD Flags,
207 void **Data,
208 DWORD *Size)
210 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
211 struct wined3d_resource_desc wined3d_desc;
212 struct wined3d_resource *wined3d_resource;
213 HRESULT hr;
214 DWORD wined3d_flags = 0;
216 TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, Flags, Data, Size);
218 /* Writeonly: Pointless. Event: Unsupported by native according to the sdk
219 * nosyslock: Not applicable
221 if(!(Flags & DDLOCK_WAIT)) wined3d_flags |= WINED3DLOCK_DONOTWAIT;
222 if(Flags & DDLOCK_READONLY) wined3d_flags |= WINED3DLOCK_READONLY;
223 if(Flags & DDLOCK_NOOVERWRITE) wined3d_flags |= WINED3DLOCK_NOOVERWRITE;
224 if(Flags & DDLOCK_DISCARDCONTENTS) wined3d_flags |= WINED3DLOCK_DISCARD;
226 EnterCriticalSection(&ddraw_cs);
227 if(Size)
229 /* Get the size, for returning it, and for locking */
230 wined3d_resource = wined3d_buffer_get_resource(This->wineD3DVertexBuffer);
231 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
232 *Size = wined3d_desc.size;
235 hr = wined3d_buffer_map(This->wineD3DVertexBuffer, 0, 0, (BYTE **)Data, wined3d_flags);
236 LeaveCriticalSection(&ddraw_cs);
237 return hr;
240 static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Lock(IDirect3DVertexBuffer *iface, DWORD Flags,
241 void **Data, DWORD *Size)
243 TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, Flags, Data, Size);
245 return IDirect3DVertexBuffer7_Lock((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), Flags, Data, Size);
248 /*****************************************************************************
249 * IDirect3DVertexBuffer7::Unlock
251 * Unlocks a vertex Buffer
253 * Returns:
254 * D3D_OK on success
256 *****************************************************************************/
257 static HRESULT WINAPI
258 IDirect3DVertexBufferImpl_Unlock(IDirect3DVertexBuffer7 *iface)
260 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
262 TRACE("iface %p.\n", iface);
264 EnterCriticalSection(&ddraw_cs);
265 wined3d_buffer_unmap(This->wineD3DVertexBuffer);
266 LeaveCriticalSection(&ddraw_cs);
268 return D3D_OK;
271 static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Unlock(IDirect3DVertexBuffer *iface)
273 TRACE("iface %p.\n", iface);
275 return IDirect3DVertexBuffer7_Unlock((IDirect3DVertexBuffer7 *)vb_from_vb1(iface));
279 /*****************************************************************************
280 * IDirect3DVertexBuffer7::ProcessVertices
282 * Processes untransformed Vertices into a transformed or optimized vertex
283 * buffer. It can also perform other operations, such as lighting or clipping
285 * Params
286 * VertexOp: Operation(s) to perform: D3DVOP_CLIP, _EXTENTS, _LIGHT, _TRANSFORM
287 * DestIndex: Index in the destination buffer(This), where the vertices are
288 * placed
289 * Count: Number of Vertices in the Source buffer to process
290 * SrcBuffer: Source vertex buffer
291 * SrcIndex: Index of the first vertex in the src buffer to process
292 * D3DDevice: Device to use for transformation
293 * Flags: 0 for default, D3DPV_DONOTCOPYDATA to prevent copying
294 * unchaned vertices
296 * Returns:
297 * D3D_OK on success
298 * DDERR_INVALIDPARAMS If D3DVOP_TRANSFORM wasn't passed
300 *****************************************************************************/
301 static HRESULT WINAPI
302 IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexBuffer7 *iface,
303 DWORD VertexOp,
304 DWORD DestIndex,
305 DWORD Count,
306 IDirect3DVertexBuffer7 *SrcBuffer,
307 DWORD SrcIndex,
308 IDirect3DDevice7 *D3DDevice,
309 DWORD Flags)
311 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
312 IDirect3DVertexBufferImpl *Src = (IDirect3DVertexBufferImpl *)SrcBuffer;
313 IDirect3DDeviceImpl *D3D = (IDirect3DDeviceImpl *)D3DDevice;
314 BOOL oldClip, doClip;
315 HRESULT hr;
317 TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n",
318 iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, D3DDevice, Flags);
320 /* Vertex operations:
321 * D3DVOP_CLIP: Clips vertices outside the viewing frustrum. Needs clipping information
322 * in the vertex buffer (Buffer may not be created with D3DVBCAPS_DONOTCLIP)
323 * D3DVOP_EXTENTS: Causes the screen extents to be updated when rendering the vertices
324 * D3DVOP_LIGHT: Lights the vertices
325 * D3DVOP_TRANSFORM: Transform the vertices. This flag is necessary
327 * WineD3D only transforms and clips the vertices by now, so EXTENTS and LIGHT
328 * are not implemented. Clipping is disabled ATM, because of unsure conditions.
330 if( !(VertexOp & D3DVOP_TRANSFORM) ) return DDERR_INVALIDPARAMS;
332 EnterCriticalSection(&ddraw_cs);
333 /* WineD3D doesn't know d3d7 vertex operation, it uses
334 * render states instead. Set the render states according to
335 * the vertex ops
337 doClip = VertexOp & D3DVOP_CLIP ? TRUE : FALSE;
338 IWineD3DDevice_GetRenderState(D3D->wineD3DDevice,
339 WINED3DRS_CLIPPING,
340 (DWORD *) &oldClip);
341 if(doClip != oldClip)
343 IWineD3DDevice_SetRenderState(D3D->wineD3DDevice,
344 WINED3DRS_CLIPPING,
345 doClip);
348 IWineD3DDevice_SetStreamSource(D3D->wineD3DDevice,
349 0, /* Stream No */
350 Src->wineD3DVertexBuffer,
351 0, /* Offset */
352 get_flexible_vertex_size(Src->fvf));
353 IWineD3DDevice_SetVertexDeclaration(D3D->wineD3DDevice,
354 Src->wineD3DVertexDeclaration);
355 hr = IWineD3DDevice_ProcessVertices(D3D->wineD3DDevice,
356 SrcIndex,
357 DestIndex,
358 Count,
359 This->wineD3DVertexBuffer,
360 NULL /* Output vdecl */,
361 Flags,
362 This->fvf);
364 /* Restore the states if needed */
365 if(doClip != oldClip)
366 IWineD3DDevice_SetRenderState(D3D->wineD3DDevice,
367 WINED3DRS_CLIPPING,
368 oldClip);
369 LeaveCriticalSection(&ddraw_cs);
370 return hr;
373 static HRESULT WINAPI IDirect3DVertexBufferImpl_1_ProcessVertices(IDirect3DVertexBuffer *iface,
374 DWORD VertexOp, DWORD DestIndex, DWORD Count, IDirect3DVertexBuffer *SrcBuffer,
375 DWORD SrcIndex, IDirect3DDevice3 *D3DDevice, DWORD Flags)
377 IDirect3DVertexBufferImpl *Src = SrcBuffer ? vb_from_vb1(SrcBuffer) : NULL;
378 IDirect3DDeviceImpl *D3D = D3DDevice ? device_from_device3(D3DDevice) : NULL;
380 TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n",
381 iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, D3DDevice, Flags);
383 return IDirect3DVertexBuffer7_ProcessVertices((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), VertexOp,
384 DestIndex, Count, (IDirect3DVertexBuffer7 *)Src, SrcIndex, (IDirect3DDevice7 *)D3D, Flags);
387 /*****************************************************************************
388 * IDirect3DVertexBuffer7::GetVertexBufferDesc
390 * Returns the description of a vertex buffer
392 * Params:
393 * Desc: Address to write the description to
395 * Returns
396 * DDERR_INVALIDPARAMS if Desc is NULL
397 * D3D_OK on success
399 *****************************************************************************/
400 static HRESULT WINAPI
401 IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface,
402 D3DVERTEXBUFFERDESC *Desc)
404 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
405 struct wined3d_resource_desc wined3d_desc;
406 struct wined3d_resource *wined3d_resource;
408 TRACE("iface %p, desc %p.\n", iface, Desc);
410 if(!Desc) return DDERR_INVALIDPARAMS;
412 EnterCriticalSection(&ddraw_cs);
413 wined3d_resource = wined3d_buffer_get_resource(This->wineD3DVertexBuffer);
414 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
415 LeaveCriticalSection(&ddraw_cs);
417 /* Now fill the Desc structure */
418 Desc->dwCaps = This->Caps;
419 Desc->dwFVF = This->fvf;
420 Desc->dwNumVertices = wined3d_desc.size / get_flexible_vertex_size(This->fvf);
422 return D3D_OK;
425 static HRESULT WINAPI IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(IDirect3DVertexBuffer *iface,
426 D3DVERTEXBUFFERDESC *Desc)
428 TRACE("iface %p, desc %p.\n", iface, Desc);
430 return IDirect3DVertexBuffer7_GetVertexBufferDesc((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), Desc);
434 /*****************************************************************************
435 * IDirect3DVertexBuffer7::Optimize
437 * Converts an unoptimized vertex buffer into an optimized buffer
439 * Params:
440 * D3DDevice: Device for which this buffer is optimized
441 * Flags: Not used, should be set to 0
443 * Returns
444 * D3D_OK, because it's a stub
446 *****************************************************************************/
447 static HRESULT WINAPI
448 IDirect3DVertexBufferImpl_Optimize(IDirect3DVertexBuffer7 *iface,
449 IDirect3DDevice7 *D3DDevice,
450 DWORD Flags)
452 IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface;
453 static BOOL hide = FALSE;
455 TRACE("iface %p, device %p, flags %#x.\n", iface, D3DDevice, Flags);
457 if (!hide)
459 FIXME("iface %p, device %p, flags %#x stub!\n", iface, D3DDevice, Flags);
460 hide = TRUE;
463 /* We could forward this call to WineD3D and take advantage
464 * of it once we use OpenGL vertex buffers
466 EnterCriticalSection(&ddraw_cs);
467 This->Caps |= D3DVBCAPS_OPTIMIZED;
468 LeaveCriticalSection(&ddraw_cs);
470 return DD_OK;
473 static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Optimize(IDirect3DVertexBuffer *iface,
474 IDirect3DDevice3 *D3DDevice, DWORD Flags)
476 IDirect3DDeviceImpl *D3D = D3DDevice ? device_from_device3(D3DDevice) : NULL;
478 TRACE("iface %p, device %p, flags %#x.\n", iface, D3DDevice, Flags);
480 return IDirect3DVertexBuffer7_Optimize((IDirect3DVertexBuffer7 *)vb_from_vb1(iface),
481 (IDirect3DDevice7 *)D3D, Flags);
484 /*****************************************************************************
485 * IDirect3DVertexBuffer7::ProcessVerticesStrided
487 * This method processes untransformed strided vertices into a processed
488 * or optimized vertex buffer.
490 * For more details on the parameters, see
491 * IDirect3DVertexBuffer7::ProcessVertices
493 * Params:
494 * VertexOp: Operations to perform
495 * DestIndex: Destination index to write the vertices to
496 * Count: Number of input vertices
497 * StrideData: Array containing the input vertices
498 * VertexTypeDesc: Vertex Description or source index?????????
499 * D3DDevice: IDirect3DDevice7 to use for processing
500 * Flags: Can be D3DPV_DONOTCOPYDATA to avoid copying unmodified vertices
502 * Returns
503 * D3D_OK on success, or DDERR_*
505 *****************************************************************************/
506 static HRESULT WINAPI
507 IDirect3DVertexBufferImpl_ProcessVerticesStrided(IDirect3DVertexBuffer7 *iface,
508 DWORD VertexOp,
509 DWORD DestIndex,
510 DWORD Count,
511 D3DDRAWPRIMITIVESTRIDEDDATA *StrideData,
512 DWORD VertexTypeDesc,
513 IDirect3DDevice7 *D3DDevice,
514 DWORD Flags)
516 FIXME("iface %p, vertex_op %#x, dst_idx %u, count %u, data %p, vertex_type %#x, device %p, flags %#x stub!\n",
517 iface, VertexOp, DestIndex, Count, StrideData, VertexTypeDesc, D3DDevice, Flags);
519 return DD_OK;
522 /*****************************************************************************
523 * The VTables
524 *****************************************************************************/
526 static const struct IDirect3DVertexBuffer7Vtbl d3d_vertex_buffer7_vtbl =
528 /*** IUnknown Methods ***/
529 IDirect3DVertexBufferImpl_QueryInterface,
530 IDirect3DVertexBufferImpl_AddRef,
531 IDirect3DVertexBufferImpl_Release,
532 /*** IDirect3DVertexBuffer Methods ***/
533 IDirect3DVertexBufferImpl_Lock,
534 IDirect3DVertexBufferImpl_Unlock,
535 IDirect3DVertexBufferImpl_ProcessVertices,
536 IDirect3DVertexBufferImpl_GetVertexBufferDesc,
537 IDirect3DVertexBufferImpl_Optimize,
538 /*** IDirect3DVertexBuffer7 Methods ***/
539 IDirect3DVertexBufferImpl_ProcessVerticesStrided
542 static const struct IDirect3DVertexBufferVtbl d3d_vertex_buffer1_vtbl =
544 /*** IUnknown Methods ***/
545 IDirect3DVertexBufferImpl_1_QueryInterface,
546 IDirect3DVertexBufferImpl_1_AddRef,
547 IDirect3DVertexBufferImpl_1_Release,
548 /*** IDirect3DVertexBuffer Methods ***/
549 IDirect3DVertexBufferImpl_1_Lock,
550 IDirect3DVertexBufferImpl_1_Unlock,
551 IDirect3DVertexBufferImpl_1_ProcessVertices,
552 IDirect3DVertexBufferImpl_1_GetVertexBufferDesc,
553 IDirect3DVertexBufferImpl_1_Optimize
556 HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
557 IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc)
559 DWORD usage;
560 HRESULT hr;
562 buffer->lpVtbl = &d3d_vertex_buffer7_vtbl;
563 buffer->IDirect3DVertexBuffer_vtbl = &d3d_vertex_buffer1_vtbl;
564 buffer->ref = 1;
566 buffer->ddraw = ddraw;
567 buffer->Caps = desc->dwCaps;
568 buffer->fvf = desc->dwFVF;
570 usage = desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0;
571 usage |= WINED3DUSAGE_STATICDECL;
573 EnterCriticalSection(&ddraw_cs);
575 hr = IWineD3DDevice_CreateVertexBuffer(ddraw->wineD3DDevice,
576 get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices,
577 usage, desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
578 buffer, &ddraw_null_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
579 if (FAILED(hr))
581 WARN("Failed to create wined3d vertex buffer, hr %#x.\n", hr);
582 LeaveCriticalSection(&ddraw_cs);
584 if (hr == WINED3DERR_INVALIDCALL)
585 return DDERR_INVALIDPARAMS;
586 else
587 return hr;
590 buffer->wineD3DVertexDeclaration = ddraw_find_decl(ddraw, desc->dwFVF);
591 if (!buffer->wineD3DVertexDeclaration)
593 ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF);
594 wined3d_buffer_decref(buffer->wineD3DVertexBuffer);
595 LeaveCriticalSection(&ddraw_cs);
597 return DDERR_INVALIDPARAMS;
599 wined3d_vertex_declaration_incref(buffer->wineD3DVertexDeclaration);
601 LeaveCriticalSection(&ddraw_cs);
603 return D3D_OK;