/***************************************************************************** * IDirect3DVertexBuffer7::QueryInterface * * The QueryInterface Method for Vertex Buffers * For a link to QueryInterface rules, see IDirectDraw7::QueryInterface * * Params * riid: Queried Interface id * obj: Address to return the interface pointer * * Returns: * S_OK on success * E_NOINTERFACE if the interface wasn't found * *****************************************************************************/ static HRESULT WINAPI d3d_vertex_buffer7_QueryInterface(IDirect3DVertexBuffer7 *iface, REFIID riid, void **obj) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); /* By default, set the object pointer to NULL */ *obj = NULL; if ( IsEqualGUID( &IID_IUnknown, riid ) ) { IDirect3DVertexBuffer7_AddRef(iface); *obj = iface; TRACE(" Creating IUnknown interface at %p.\n", *obj); return S_OK; } if ( IsEqualGUID( &IID_IDirect3DVertexBuffer, riid ) ) { IDirect3DVertexBuffer7_AddRef(iface); *obj = &buffer->IDirect3DVertexBuffer_iface; TRACE(" Creating IDirect3DVertexBuffer interface %p\n", *obj); return S_OK; } if ( IsEqualGUID( &IID_IDirect3DVertexBuffer7, riid ) ) { IDirect3DVertexBuffer7_AddRef(iface); *obj = iface; TRACE(" Creating IDirect3DVertexBuffer7 interface %p\n", *obj); return S_OK; } WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); return E_NOINTERFACE; }
/***************************************************************************** * IDirect3DVertexBuffer7::Release * * Release for Vertex Buffers * * Returns: * The new refcount * *****************************************************************************/ static ULONG WINAPI d3d_vertex_buffer7_Release(IDirect3DVertexBuffer7 *iface) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); ULONG ref = InterlockedDecrement(&buffer->ref); TRACE("%p decreasing refcount to %u.\n", buffer, ref); if (ref == 0) { struct wined3d_buffer *curVB = NULL; UINT offset, stride; /* D3D7 Vertex buffers don't stay bound in the device, they are passed * as a parameter to drawPrimitiveVB. DrawPrimitiveVB sets them as the * stream source in wined3d, and they should get unset there before * they are destroyed. */ wined3d_mutex_lock(); wined3d_device_get_stream_source(buffer->ddraw->wined3d_device, 0, &curVB, &offset, &stride); if (curVB == buffer->wineD3DVertexBuffer) wined3d_device_set_stream_source(buffer->ddraw->wined3d_device, 0, NULL, 0, 0); wined3d_vertex_declaration_decref(buffer->wineD3DVertexDeclaration); wined3d_buffer_decref(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); HeapFree(GetProcessHeap(), 0, buffer); } return ref; }
/***************************************************************************** * IDirect3DVertexBuffer7::QueryInterface * * The QueryInterface Method for Vertex Buffers * For a link to QueryInterface rules, see IDirectDraw7::QueryInterface * * Params * riid: Queried Interface id * obj: Address to return the interface pointer * * Returns: * S_OK on success * E_NOINTERFACE if the interface wasn't found * *****************************************************************************/ static HRESULT WINAPI IDirect3DVertexBufferImpl_QueryInterface(IDirect3DVertexBuffer7 *iface, REFIID riid, void **obj) { IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); /* By default, set the object pointer to NULL */ *obj = NULL; if ( IsEqualGUID( &IID_IUnknown, riid ) ) { IUnknown_AddRef(iface); *obj = iface; TRACE(" Creating IUnknown interface at %p.\n", *obj); return S_OK; } if ( IsEqualGUID( &IID_IDirect3DVertexBuffer, riid ) ) { IUnknown_AddRef(iface); *obj = &This->IDirect3DVertexBuffer_iface; TRACE(" Creating IDirect3DVertexBuffer interface %p\n", *obj); return S_OK; } if ( IsEqualGUID( &IID_IDirect3DVertexBuffer7, riid ) ) { IUnknown_AddRef(iface); *obj = iface; TRACE(" Creating IDirect3DVertexBuffer7 interface %p\n", *obj); return S_OK; } FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid)); return E_NOINTERFACE; }
/***************************************************************************** * IDirect3DVertexBuffer7::Lock * * Locks the vertex buffer and returns a pointer to the vertex data * Locking vertex buffers is similar to locking surfaces, because Windows * uses surfaces to store vertex data internally (According to the DX sdk) * * Params: * Flags: Locking flags. Relevant here are DDLOCK_READONLY, DDLOCK_WRITEONLY, * DDLOCK_DISCARDCONTENTS and DDLOCK_NOOVERWRITE. * Data: Returns a pointer to the vertex data * Size: Returns the size of the buffer if not NULL * * Returns: * D3D_OK on success * DDERR_INVALIDPARAMS if Data is NULL * D3DERR_VERTEXBUFFEROPTIMIZED if called on an optimized buffer(WineD3D) * *****************************************************************************/ static HRESULT WINAPI IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface, DWORD Flags, void **Data, DWORD *Size) { IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; HRESULT hr; DWORD wined3d_flags = 0; TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, Flags, Data, Size); /* Writeonly: Pointless. Event: Unsupported by native according to the sdk * nosyslock: Not applicable */ if(!(Flags & DDLOCK_WAIT)) wined3d_flags |= WINED3DLOCK_DONOTWAIT; if(Flags & DDLOCK_READONLY) wined3d_flags |= WINED3DLOCK_READONLY; if(Flags & DDLOCK_NOOVERWRITE) wined3d_flags |= WINED3DLOCK_NOOVERWRITE; if(Flags & DDLOCK_DISCARDCONTENTS) wined3d_flags |= WINED3DLOCK_DISCARD; wined3d_mutex_lock(); if(Size) { /* Get the size, for returning it, and for locking */ wined3d_resource = wined3d_buffer_get_resource(This->wineD3DVertexBuffer); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); *Size = wined3d_desc.size; } hr = wined3d_buffer_map(This->wineD3DVertexBuffer, 0, 0, (BYTE **)Data, wined3d_flags); wined3d_mutex_unlock(); return hr; }
struct d3d_vertex_buffer *unsafe_impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface) { if (!iface) return NULL; assert(iface->lpVtbl == &d3d_vertex_buffer7_vtbl); return impl_from_IDirect3DVertexBuffer7(iface); }
/***************************************************************************** * IDirect3DVertexBuffer7::Lock * * Locks the vertex buffer and returns a pointer to the vertex data * Locking vertex buffers is similar to locking surfaces, because Windows * uses surfaces to store vertex data internally (According to the DX sdk) * * Params: * Flags: Locking flags. Relevant here are DDLOCK_READONLY, DDLOCK_WRITEONLY, * DDLOCK_DISCARDCONTENTS and DDLOCK_NOOVERWRITE. * Data: Returns a pointer to the vertex data * Size: Returns the size of the buffer if not NULL * * Returns: * D3D_OK on success * DDERR_INVALIDPARAMS if Data is NULL * D3DERR_VERTEXBUFFEROPTIMIZED if called on an optimized buffer(WineD3D) * *****************************************************************************/ static HRESULT WINAPI d3d_vertex_buffer7_Lock(IDirect3DVertexBuffer7 *iface, DWORD flags, void **data, DWORD *data_size) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; HRESULT hr; DWORD wined3d_flags = 0; TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, flags, data, data_size); /* Writeonly: Pointless. Event: Unsupported by native according to the sdk * nosyslock: Not applicable */ if (!(flags & DDLOCK_WAIT)) wined3d_flags |= WINED3D_MAP_DONOTWAIT; if (flags & DDLOCK_READONLY) wined3d_flags |= WINED3D_MAP_READONLY; if (flags & DDLOCK_NOOVERWRITE) wined3d_flags |= WINED3D_MAP_NOOVERWRITE; if (flags & DDLOCK_DISCARDCONTENTS) { wined3d_flags |= WINED3D_MAP_DISCARD; if (!buffer->dynamic) { struct wined3d_buffer *new_buffer; wined3d_mutex_lock(); hr = d3d_vertex_buffer_create_wined3d_buffer(buffer, TRUE, &new_buffer); if (SUCCEEDED(hr)) { buffer->dynamic = TRUE; wined3d_buffer_decref(buffer->wineD3DVertexBuffer); buffer->wineD3DVertexBuffer = new_buffer; } else { WARN("Failed to create a dynamic buffer\n"); } wined3d_mutex_unlock(); } } wined3d_mutex_lock(); if (data_size) { /* Get the size, for returning it, and for locking */ wined3d_resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); *data_size = wined3d_desc.size; } hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, 0, 0, (BYTE **)data, wined3d_flags); wined3d_mutex_unlock(); return hr; }
/***************************************************************************** * IDirect3DVertexBuffer7::AddRef * * AddRef for Vertex Buffers * * Returns: * The new refcount * *****************************************************************************/ static ULONG WINAPI d3d_vertex_buffer7_AddRef(IDirect3DVertexBuffer7 *iface) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); ULONG ref = InterlockedIncrement(&buffer->ref); TRACE("%p increasing refcount to %u.\n", buffer, ref); return ref; }
/***************************************************************************** * IDirect3DVertexBuffer7::AddRef * * AddRef for Vertex Buffers * * Returns: * The new refcount * *****************************************************************************/ static ULONG WINAPI IDirect3DVertexBufferImpl_AddRef(IDirect3DVertexBuffer7 *iface) { IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); return ref; }
/***************************************************************************** * IDirect3DVertexBuffer7::Unlock * * Unlocks a vertex Buffer * * Returns: * D3D_OK on success * *****************************************************************************/ static HRESULT WINAPI d3d_vertex_buffer7_Unlock(IDirect3DVertexBuffer7 *iface) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); TRACE("iface %p.\n", iface); wined3d_mutex_lock(); wined3d_buffer_unmap(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); return D3D_OK; }
/***************************************************************************** * IDirect3DVertexBuffer7::Unlock * * Unlocks a vertex Buffer * * Returns: * D3D_OK on success * *****************************************************************************/ static HRESULT WINAPI IDirect3DVertexBufferImpl_Unlock(IDirect3DVertexBuffer7 *iface) { IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); TRACE("iface %p.\n", iface); wined3d_mutex_lock(); wined3d_buffer_unmap(This->wineD3DVertexBuffer); wined3d_mutex_unlock(); return D3D_OK; }
/***************************************************************************** * IDirect3DVertexBuffer7::ProcessVertices * * Processes untransformed Vertices into a transformed or optimized vertex * buffer. It can also perform other operations, such as lighting or clipping * * Params * VertexOp: Operation(s) to perform: D3DVOP_CLIP, _EXTENTS, _LIGHT, _TRANSFORM * DestIndex: Index in the destination buffer(This), where the vertices are * placed * Count: Number of Vertices in the Source buffer to process * SrcBuffer: Source vertex buffer * SrcIndex: Index of the first vertex in the src buffer to process * D3DDevice: Device to use for transformation * Flags: 0 for default, D3DPV_DONOTCOPYDATA to prevent copying * unchaned vertices * * Returns: * D3D_OK on success * DDERR_INVALIDPARAMS If D3DVOP_TRANSFORM wasn't passed * *****************************************************************************/ static HRESULT WINAPI d3d_vertex_buffer7_ProcessVertices(IDirect3DVertexBuffer7 *iface, DWORD vertex_op, DWORD dst_idx, DWORD count, IDirect3DVertexBuffer7 *src_buffer, DWORD src_idx, IDirect3DDevice7 *device, DWORD flags) { struct d3d_vertex_buffer *dst_buffer_impl = impl_from_IDirect3DVertexBuffer7(iface); struct d3d_vertex_buffer *src_buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer7(src_buffer); struct d3d_device *device_impl = unsafe_impl_from_IDirect3DDevice7(device); BOOL oldClip, doClip; HRESULT hr; TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n", iface, vertex_op, dst_idx, count, src_buffer, src_idx, device, flags); /* Vertex operations: * D3DVOP_CLIP: Clips vertices outside the viewing frustrum. Needs clipping information * in the vertex buffer (Buffer may not be created with D3DVBCAPS_DONOTCLIP) * D3DVOP_EXTENTS: Causes the screen extents to be updated when rendering the vertices * D3DVOP_LIGHT: Lights the vertices * D3DVOP_TRANSFORM: Transform the vertices. This flag is necessary * * WineD3D only transforms and clips the vertices by now, so EXTENTS and LIGHT * are not implemented. Clipping is disabled ATM, because of unsure conditions. */ if (!(vertex_op & D3DVOP_TRANSFORM)) return DDERR_INVALIDPARAMS; wined3d_mutex_lock(); /* WineD3D doesn't know d3d7 vertex operation, it uses * render states instead. Set the render states according to * the vertex ops */ doClip = !!(vertex_op & D3DVOP_CLIP); oldClip = wined3d_device_get_render_state(device_impl->wined3d_device, WINED3D_RS_CLIPPING); if (doClip != oldClip) wined3d_device_set_render_state(device_impl->wined3d_device, WINED3D_RS_CLIPPING, doClip); wined3d_device_set_stream_source(device_impl->wined3d_device, 0, src_buffer_impl->wineD3DVertexBuffer, 0, get_flexible_vertex_size(src_buffer_impl->fvf)); wined3d_device_set_vertex_declaration(device_impl->wined3d_device, src_buffer_impl->wineD3DVertexDeclaration); hr = wined3d_device_process_vertices(device_impl->wined3d_device, src_idx, dst_idx, count, dst_buffer_impl->wineD3DVertexBuffer, NULL, flags, dst_buffer_impl->fvf); /* Restore the states if needed */ if (doClip != oldClip) wined3d_device_set_render_state(device_impl->wined3d_device, WINED3D_RS_CLIPPING, oldClip); wined3d_mutex_unlock(); return hr; }
/***************************************************************************** * IDirect3DVertexBuffer7::GetVertexBufferDesc * * Returns the description of a vertex buffer * * Params: * Desc: Address to write the description to * * Returns * DDERR_INVALIDPARAMS if Desc is NULL * D3D_OK on success * *****************************************************************************/ static HRESULT WINAPI d3d_vertex_buffer7_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface, D3DVERTEXBUFFERDESC *desc) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; TRACE("iface %p, desc %p.\n", iface, desc); if (!desc) return DDERR_INVALIDPARAMS; wined3d_mutex_lock(); wined3d_resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); wined3d_mutex_unlock(); /* Now fill the desc structure */ desc->dwCaps = buffer->Caps; desc->dwFVF = buffer->fvf; desc->dwNumVertices = wined3d_desc.size / get_flexible_vertex_size(buffer->fvf); return D3D_OK; }
/***************************************************************************** * IDirect3DVertexBuffer7::Optimize * * Converts an unoptimized vertex buffer into an optimized buffer * * Params: * D3DDevice: Device for which this buffer is optimized * Flags: Not used, should be set to 0 * * Returns * D3D_OK, because it's a stub * *****************************************************************************/ static HRESULT WINAPI d3d_vertex_buffer7_Optimize(IDirect3DVertexBuffer7 *iface, IDirect3DDevice7 *device, DWORD flags) { struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface); static BOOL hide = FALSE; TRACE("iface %p, device %p, flags %#x.\n", iface, device, flags); if (!hide) { FIXME("iface %p, device %p, flags %#x stub!\n", iface, device, flags); hide = TRUE; } /* We could forward this call to WineD3D and take advantage * of it once we use OpenGL vertex buffers */ wined3d_mutex_lock(); buffer->Caps |= D3DVBCAPS_OPTIMIZED; wined3d_mutex_unlock(); return DD_OK; }