2006-06-09 19:36:12 +02:00
|
|
|
/* Direct3D Vertex Buffer
|
2002-11-21 22:04:16 +01:00
|
|
|
* Copyright (c) 2002 Lionel ULMER
|
2008-10-18 19:19:45 +02:00
|
|
|
* Copyright (c) 2006 Stefan DÖSINGER
|
2002-11-21 22:04:16 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-11-21 22:04:16 +01:00
|
|
|
*/
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "ddraw_private.h"
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
static inline struct d3d_vertex_buffer *impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface)
|
2011-06-15 12:48:18 +02:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_vertex_buffer, IDirect3DVertexBuffer7_iface);
|
2011-06-15 12:48:18 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IUnknown Methods
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
static HRESULT WINAPI d3d_vertex_buffer7_QueryInterface(IDirect3DVertexBuffer7 *iface, REFIID riid, void **obj)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
*obj = NULL;
|
|
|
|
|
2017-02-24 19:37:26 +01:00
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid))
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-08-27 12:27:48 +02:00
|
|
|
IDirect3DVertexBuffer7_AddRef(iface);
|
2006-06-09 19:36:12 +02:00
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2017-02-24 19:37:26 +01:00
|
|
|
if (IsEqualGUID(&IID_IDirect3DVertexBuffer7, riid) && buffer->version == 7)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-08-27 12:27:48 +02:00
|
|
|
IDirect3DVertexBuffer7_AddRef(iface);
|
2017-02-24 19:37:26 +01:00
|
|
|
*obj = iface;
|
2006-06-09 19:36:12 +02:00
|
|
|
return S_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2017-02-24 19:37:26 +01:00
|
|
|
if (IsEqualGUID(&IID_IDirect3DVertexBuffer, riid) && buffer->version == 3)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-08-27 12:27:48 +02:00
|
|
|
IDirect3DVertexBuffer7_AddRef(iface);
|
2009-01-21 09:56:13 +01:00
|
|
|
*obj = iface;
|
2006-06-09 19:36:12 +02:00
|
|
|
return S_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2012-04-11 22:52:04 +02:00
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
2006-06-09 19:36:12 +02:00
|
|
|
return E_NOINTERFACE;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
static ULONG WINAPI d3d_vertex_buffer7_AddRef(IDirect3DVertexBuffer7 *iface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&buffer->ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", buffer, ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
return ref;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
static ULONG WINAPI d3d_vertex_buffer7_Release(IDirect3DVertexBuffer7 *iface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&buffer->ref);
|
2003-01-03 22:07:22 +01:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", buffer, ref);
|
2003-01-03 20:10:48 +01:00
|
|
|
|
2017-03-08 20:45:44 +01:00
|
|
|
if (!ref)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2017-03-08 20:45:44 +01:00
|
|
|
/* 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
|
2011-05-16 23:01:21 +02:00
|
|
|
* they are destroyed. */
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2020-02-26 23:39:24 +01:00
|
|
|
if (wined3d_stateblock_get_state(buffer->ddraw->state)->streams[0].buffer == buffer->wined3d_buffer)
|
|
|
|
wined3d_stateblock_set_stream_source(buffer->ddraw->state, 0, NULL, 0, 0);
|
2007-01-06 18:26:08 +01:00
|
|
|
|
2016-08-26 13:51:23 +02:00
|
|
|
wined3d_vertex_declaration_decref(buffer->wined3d_declaration);
|
2016-08-26 13:51:22 +02:00
|
|
|
wined3d_buffer_decref(buffer->wined3d_buffer);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2017-03-08 20:45:44 +01:00
|
|
|
if (buffer->version == 7)
|
|
|
|
IDirectDraw7_Release(&buffer->ddraw->IDirectDraw7_iface);
|
|
|
|
|
2018-02-13 10:32:47 +01:00
|
|
|
heap_free(buffer);
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
2012-04-11 22:52:04 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return ref;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DVertexBuffer Methods
|
|
|
|
*****************************************************************************/
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2012-12-04 09:36:16 +01:00
|
|
|
static HRESULT d3d_vertex_buffer_create_wined3d_buffer(struct d3d_vertex_buffer *buffer, BOOL dynamic,
|
|
|
|
struct wined3d_buffer **wined3d_buffer)
|
|
|
|
{
|
2018-02-08 00:10:47 +01:00
|
|
|
struct wined3d_buffer_desc desc;
|
2012-12-04 09:36:16 +01:00
|
|
|
|
2018-02-08 00:10:47 +01:00
|
|
|
desc.byte_width = buffer->size;
|
|
|
|
desc.usage = WINED3DUSAGE_STATICDECL;
|
2012-12-04 09:36:16 +01:00
|
|
|
if (dynamic)
|
2018-02-08 00:10:47 +01:00
|
|
|
desc.usage |= WINED3DUSAGE_DYNAMIC;
|
|
|
|
desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
|
|
|
|
if (buffer->Caps & D3DVBCAPS_SYSTEMMEMORY)
|
2018-02-18 19:08:35 +01:00
|
|
|
desc.access = WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
|
2018-02-08 00:10:47 +01:00
|
|
|
else
|
2018-02-18 19:08:35 +01:00
|
|
|
desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
|
2018-02-08 00:10:47 +01:00
|
|
|
desc.misc_flags = 0;
|
|
|
|
desc.structure_byte_stride = 0;
|
2012-12-04 09:36:16 +01:00
|
|
|
|
2018-02-08 00:10:47 +01:00
|
|
|
return wined3d_buffer_create(buffer->ddraw->wined3d_device, &desc,
|
|
|
|
NULL, buffer, &ddraw_null_wined3d_parent_ops, wined3d_buffer);
|
2012-12-04 09:36:16 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DVertexBuffer7::Lock
|
|
|
|
*
|
|
|
|
* Locks the vertex buffer and returns a pointer to the vertex data
|
2006-06-23 18:18:02 +02:00
|
|
|
* Locking vertex buffers is similar to locking surfaces, because Windows
|
|
|
|
* uses surfaces to store vertex data internally (According to the DX sdk)
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-04-11 22:52:04 +02:00
|
|
|
static HRESULT WINAPI d3d_vertex_buffer7_Lock(IDirect3DVertexBuffer7 *iface,
|
|
|
|
DWORD flags, void **data, DWORD *data_size)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
2011-03-08 19:41:05 +01:00
|
|
|
struct wined3d_resource_desc wined3d_desc;
|
2011-03-10 19:07:10 +01:00
|
|
|
struct wined3d_resource *wined3d_resource;
|
2016-08-29 10:49:00 +02:00
|
|
|
struct wined3d_map_desc wined3d_map_desc;
|
2006-06-09 19:36:12 +02:00
|
|
|
HRESULT hr;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, flags, data, data_size);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2018-01-03 16:06:56 +01:00
|
|
|
if (buffer->version != 7)
|
|
|
|
flags &= ~(DDLOCK_NOOVERWRITE | DDLOCK_DISCARDCONTENTS);
|
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
if (!(flags & DDLOCK_WAIT))
|
2018-02-16 07:09:05 +01:00
|
|
|
flags |= DDLOCK_DONOTWAIT;
|
2014-03-04 10:21:33 +01:00
|
|
|
if (flags & DDLOCK_DISCARDCONTENTS)
|
2012-12-04 09:36:16 +01:00
|
|
|
{
|
|
|
|
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;
|
2016-08-26 13:51:22 +02:00
|
|
|
wined3d_buffer_decref(buffer->wined3d_buffer);
|
|
|
|
buffer->wined3d_buffer = new_buffer;
|
2012-12-04 09:36:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Failed to create a dynamic buffer\n");
|
|
|
|
}
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2012-04-11 22:52:04 +02:00
|
|
|
if (data_size)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2006-06-27 13:11:13 +02:00
|
|
|
/* Get the size, for returning it, and for locking */
|
2016-08-26 13:51:22 +02:00
|
|
|
wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
|
2011-03-10 19:07:10 +01:00
|
|
|
wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
|
2012-04-11 22:52:04 +02:00
|
|
|
*data_size = wined3d_desc.size;
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
2003-01-03 20:10:48 +01:00
|
|
|
|
2016-08-29 10:49:00 +02:00
|
|
|
hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer),
|
2018-02-16 07:09:05 +01:00
|
|
|
0, &wined3d_map_desc, NULL, wined3dmapflags_from_ddrawmapflags(flags));
|
2016-08-29 10:49:00 +02:00
|
|
|
*data = wined3d_map_desc.data;
|
2013-01-10 11:52:16 +01:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-30 16:19:10 +02:00
|
|
|
return hr;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DVertexBuffer7::Unlock
|
|
|
|
*
|
|
|
|
* Unlocks a vertex Buffer
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-04-11 22:52:04 +02:00
|
|
|
static HRESULT WINAPI d3d_vertex_buffer7_Unlock(IDirect3DVertexBuffer7 *iface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2016-08-29 10:49:01 +02:00
|
|
|
wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->wined3d_buffer), 0);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2007-05-30 16:19:10 +02:00
|
|
|
|
2010-10-15 14:35:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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
|
2018-01-08 12:43:44 +01:00
|
|
|
* unchanged vertices
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS If D3DVOP_TRANSFORM wasn't passed
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-04-11 22:52:04 +02:00
|
|
|
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)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *dst_buffer_impl = impl_from_IDirect3DVertexBuffer7(iface);
|
|
|
|
struct d3d_vertex_buffer *src_buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer7(src_buffer);
|
2017-02-24 19:37:26 +01:00
|
|
|
struct d3d_device *device_impl = dst_buffer_impl->version == 7
|
|
|
|
? unsafe_impl_from_IDirect3DDevice7(device)
|
|
|
|
: unsafe_impl_from_IDirect3DDevice3((IDirect3DDevice3 *)device);
|
2019-05-22 11:39:26 +02:00
|
|
|
BOOL old_clip, do_clip, old_lighting, do_lighting;
|
2020-02-26 23:39:24 +01:00
|
|
|
const struct wined3d_stateblock_state *state;
|
2006-06-09 19:36:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n",
|
2012-04-11 22:52:04 +02:00
|
|
|
iface, vertex_op, dst_idx, count, src_buffer, src_idx, device, flags);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2012-04-11 22:52:04 +02:00
|
|
|
if (!(vertex_op & D3DVOP_TRANSFORM))
|
|
|
|
return DDERR_INVALIDPARAMS;
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2020-02-26 23:39:24 +01:00
|
|
|
|
|
|
|
state = wined3d_stateblock_get_state(device_impl->state);
|
2011-11-13 19:52:24 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/* WineD3D doesn't know d3d7 vertex operation, it uses
|
|
|
|
* render states instead. Set the render states according to
|
|
|
|
* the vertex ops
|
|
|
|
*/
|
2019-05-22 11:39:26 +02:00
|
|
|
do_clip = !!(vertex_op & D3DVOP_CLIP);
|
2020-02-26 23:39:24 +01:00
|
|
|
old_clip = !!state->rs[WINED3D_RS_CLIPPING];
|
2019-05-22 11:39:26 +02:00
|
|
|
if (do_clip != old_clip)
|
2020-02-26 23:39:24 +01:00
|
|
|
wined3d_stateblock_set_render_state(device_impl->state, WINED3D_RS_CLIPPING, do_clip);
|
2019-05-22 11:39:26 +02:00
|
|
|
|
2020-02-26 23:39:24 +01:00
|
|
|
old_lighting = !!state->rs[WINED3D_RS_LIGHTING];
|
2019-05-22 11:39:26 +02:00
|
|
|
if (dst_buffer_impl->version == 3)
|
|
|
|
do_lighting = device_impl->material && (src_buffer_impl->fvf & D3DFVF_NORMAL)
|
|
|
|
&& (vertex_op & D3DVOP_LIGHT);
|
|
|
|
else
|
|
|
|
do_lighting = old_lighting && (vertex_op & D3DVOP_LIGHT);
|
|
|
|
|
|
|
|
if (do_lighting != old_lighting)
|
2020-02-26 23:39:24 +01:00
|
|
|
wined3d_stateblock_set_render_state(device_impl->state, WINED3D_RS_LIGHTING, do_lighting);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2020-02-26 23:39:24 +01:00
|
|
|
wined3d_stateblock_set_stream_source(device_impl->state,
|
2016-08-26 13:51:22 +02:00
|
|
|
0, src_buffer_impl->wined3d_buffer, 0, get_flexible_vertex_size(src_buffer_impl->fvf));
|
2020-02-26 23:39:24 +01:00
|
|
|
wined3d_stateblock_set_vertex_declaration(device_impl->state, src_buffer_impl->wined3d_declaration);
|
|
|
|
wined3d_device_apply_stateblock(device_impl->wined3d_device, device_impl->state);
|
2012-04-11 22:52:04 +02:00
|
|
|
hr = wined3d_device_process_vertices(device_impl->wined3d_device, src_idx, dst_idx,
|
2016-08-26 13:51:22 +02:00
|
|
|
count, dst_buffer_impl->wined3d_buffer, NULL, flags, dst_buffer_impl->fvf);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
/* Restore the states if needed */
|
2019-05-22 11:39:26 +02:00
|
|
|
if (do_clip != old_clip)
|
2020-02-26 23:39:24 +01:00
|
|
|
wined3d_stateblock_set_render_state(device_impl->state, WINED3D_RS_CLIPPING, old_clip);
|
2019-05-22 11:39:26 +02:00
|
|
|
if (do_lighting != old_lighting)
|
2020-02-26 23:39:24 +01:00
|
|
|
wined3d_stateblock_set_render_state(device_impl->state, WINED3D_RS_LIGHTING, old_lighting);
|
2011-11-13 19:52:24 +01:00
|
|
|
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return hr;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-04-11 22:52:04 +02:00
|
|
|
static HRESULT WINAPI d3d_vertex_buffer7_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface, D3DVERTEXBUFFERDESC *desc)
|
2003-01-03 22:07:22 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
2011-03-08 19:41:05 +01:00
|
|
|
struct wined3d_resource_desc wined3d_desc;
|
2011-03-10 19:07:10 +01:00
|
|
|
struct wined3d_resource *wined3d_resource;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
2003-01-03 22:07:22 +01:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
if (!desc) return DDERR_INVALIDPARAMS;
|
2003-01-03 22:07:22 +01:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2016-08-26 13:51:22 +02:00
|
|
|
wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
|
2011-03-10 19:07:10 +01:00
|
|
|
wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2003-01-03 22:07:22 +01:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
/* Now fill the desc structure */
|
|
|
|
desc->dwCaps = buffer->Caps;
|
|
|
|
desc->dwFVF = buffer->fvf;
|
|
|
|
desc->dwNumVertices = wined3d_desc.size / get_flexible_vertex_size(buffer->fvf);
|
2003-01-03 22:07:22 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-04-11 22:52:04 +02:00
|
|
|
static HRESULT WINAPI d3d_vertex_buffer7_Optimize(IDirect3DVertexBuffer7 *iface,
|
|
|
|
IDirect3DDevice7 *device, DWORD flags)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer = impl_from_IDirect3DVertexBuffer7(iface);
|
2008-12-24 11:22:29 +01:00
|
|
|
static BOOL hide = FALSE;
|
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
TRACE("iface %p, device %p, flags %#x.\n", iface, device, flags);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2008-12-24 11:22:29 +01:00
|
|
|
if (!hide)
|
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
FIXME("iface %p, device %p, flags %#x stub!\n", iface, device, flags);
|
2008-12-24 11:22:29 +01:00
|
|
|
hide = TRUE;
|
|
|
|
}
|
2003-01-03 22:07:22 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/* We could forward this call to WineD3D and take advantage
|
|
|
|
* of it once we use OpenGL vertex buffers
|
|
|
|
*/
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2012-04-11 22:52:04 +02:00
|
|
|
buffer->Caps |= D3DVBCAPS_OPTIMIZED;
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DVertexBuffer7::ProcessVerticesStrided
|
|
|
|
*
|
|
|
|
* This method processes untransformed strided vertices into a processed
|
|
|
|
* or optimized vertex buffer.
|
|
|
|
*
|
|
|
|
* For more details on the parameters, see
|
|
|
|
* IDirect3DVertexBuffer7::ProcessVertices
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* VertexOp: Operations to perform
|
|
|
|
* DestIndex: Destination index to write the vertices to
|
|
|
|
* Count: Number of input vertices
|
|
|
|
* StrideData: Array containing the input vertices
|
|
|
|
* VertexTypeDesc: Vertex Description or source index?????????
|
|
|
|
* D3DDevice: IDirect3DDevice7 to use for processing
|
|
|
|
* Flags: Can be D3DPV_DONOTCOPYDATA to avoid copying unmodified vertices
|
|
|
|
*
|
|
|
|
* Returns
|
|
|
|
* D3D_OK on success, or DDERR_*
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-04-11 22:52:04 +02:00
|
|
|
static HRESULT WINAPI d3d_vertex_buffer7_ProcessVerticesStrided(IDirect3DVertexBuffer7 *iface,
|
|
|
|
DWORD vertex_op, DWORD dst_idx, DWORD count, D3DDRAWPRIMITIVESTRIDEDDATA *data,
|
|
|
|
DWORD fvf, IDirect3DDevice7 *device, DWORD flags)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
FIXME("iface %p, vertex_op %#x, dst_idx %u, count %u, data %p, fvf %#x, device %p, flags %#x stub!\n",
|
|
|
|
iface, vertex_op, dst_idx, count, data, fvf, device, flags);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DD_OK;
|
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* The VTables
|
|
|
|
*****************************************************************************/
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2010-08-19 18:57:47 +02:00
|
|
|
static const struct IDirect3DVertexBuffer7Vtbl d3d_vertex_buffer7_vtbl =
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
d3d_vertex_buffer7_QueryInterface,
|
|
|
|
d3d_vertex_buffer7_AddRef,
|
|
|
|
d3d_vertex_buffer7_Release,
|
|
|
|
d3d_vertex_buffer7_Lock,
|
|
|
|
d3d_vertex_buffer7_Unlock,
|
|
|
|
d3d_vertex_buffer7_ProcessVertices,
|
|
|
|
d3d_vertex_buffer7_GetVertexBufferDesc,
|
|
|
|
d3d_vertex_buffer7_Optimize,
|
|
|
|
d3d_vertex_buffer7_ProcessVerticesStrided,
|
2002-11-21 22:04:16 +01:00
|
|
|
};
|
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
HRESULT d3d_vertex_buffer_create(struct d3d_vertex_buffer **vertex_buf,
|
|
|
|
struct ddraw *ddraw, D3DVERTEXBUFFERDESC *desc)
|
2010-08-19 18:57:47 +02:00
|
|
|
{
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *buffer;
|
2011-06-15 12:36:49 +02:00
|
|
|
HRESULT hr = D3D_OK;
|
|
|
|
|
|
|
|
TRACE("Vertex buffer description:\n");
|
|
|
|
TRACE(" dwSize %u\n", desc->dwSize);
|
|
|
|
TRACE(" dwCaps %#x\n", desc->dwCaps);
|
|
|
|
TRACE(" FVF %#x\n", desc->dwFVF);
|
|
|
|
TRACE(" dwNumVertices %u\n", desc->dwNumVertices);
|
|
|
|
|
2018-02-13 10:32:47 +01:00
|
|
|
if (!(buffer = heap_alloc_zero(sizeof(*buffer))))
|
2011-06-15 12:36:49 +02:00
|
|
|
return DDERR_OUTOFMEMORY;
|
2010-08-19 18:57:47 +02:00
|
|
|
|
2011-06-15 12:48:18 +02:00
|
|
|
buffer->IDirect3DVertexBuffer7_iface.lpVtbl = &d3d_vertex_buffer7_vtbl;
|
2010-08-19 18:57:47 +02:00
|
|
|
buffer->ref = 1;
|
2017-02-24 19:37:26 +01:00
|
|
|
buffer->version = ddraw->d3dversion;
|
2017-03-08 20:45:44 +01:00
|
|
|
if (buffer->version == 7)
|
|
|
|
IDirectDraw7_AddRef(&ddraw->IDirectDraw7_iface);
|
2010-08-19 18:57:47 +02:00
|
|
|
buffer->ddraw = ddraw;
|
|
|
|
buffer->Caps = desc->dwCaps;
|
|
|
|
buffer->fvf = desc->dwFVF;
|
2012-12-04 09:36:16 +01:00
|
|
|
buffer->size = get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices;
|
2010-08-19 18:57:47 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2010-08-19 18:57:47 +02:00
|
|
|
|
2016-08-26 13:51:22 +02:00
|
|
|
if (FAILED(hr = d3d_vertex_buffer_create_wined3d_buffer(buffer, FALSE, &buffer->wined3d_buffer)))
|
2010-08-19 18:57:47 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d vertex buffer, hr %#x.\n", hr);
|
|
|
|
if (hr == WINED3DERR_INVALIDCALL)
|
2011-06-15 12:36:49 +02:00
|
|
|
hr = DDERR_INVALIDPARAMS;
|
|
|
|
goto end;
|
2010-08-19 18:57:47 +02:00
|
|
|
}
|
|
|
|
|
2016-08-26 13:51:23 +02:00
|
|
|
if (!(buffer->wined3d_declaration = ddraw_find_decl(ddraw, desc->dwFVF)))
|
2010-08-19 18:57:47 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF);
|
2016-08-26 13:51:22 +02:00
|
|
|
wined3d_buffer_decref(buffer->wined3d_buffer);
|
2011-06-15 12:36:49 +02:00
|
|
|
hr = DDERR_INVALIDPARAMS;
|
|
|
|
goto end;
|
2010-08-19 18:57:47 +02:00
|
|
|
}
|
2016-08-26 13:51:23 +02:00
|
|
|
wined3d_vertex_declaration_incref(buffer->wined3d_declaration);
|
2010-08-19 18:57:47 +02:00
|
|
|
|
2011-06-15 12:36:49 +02:00
|
|
|
end:
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2011-06-15 12:36:49 +02:00
|
|
|
if (hr == D3D_OK)
|
|
|
|
*vertex_buf = buffer;
|
|
|
|
else
|
2018-02-13 10:32:47 +01:00
|
|
|
heap_free(buffer);
|
2010-08-19 18:57:47 +02:00
|
|
|
|
2011-06-15 12:36:49 +02:00
|
|
|
return hr;
|
2010-08-19 18:57:47 +02:00
|
|
|
}
|
2011-06-15 12:40:44 +02:00
|
|
|
|
2012-04-11 22:52:04 +02:00
|
|
|
struct d3d_vertex_buffer *unsafe_impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface)
|
2011-06-15 12:40:44 +02:00
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d_vertex_buffer7_vtbl);
|
|
|
|
|
2011-06-15 12:48:18 +02:00
|
|
|
return impl_from_IDirect3DVertexBuffer7(iface);
|
2011-06-15 12:40:44 +02:00
|
|
|
}
|