2005-01-19 20:34:49 +01:00
|
|
|
/*
|
|
|
|
* vertex declaration implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002-2005 Raphael Junqueira
|
|
|
|
* Copyright 2004 Jason Edmeades
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-07 22:45:39 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2009-09-25 13:31:49 +02:00
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
2005-01-19 20:34:49 +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
|
2005-01-19 20:34:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl);
|
|
|
|
|
2011-11-24 22:52:36 +01:00
|
|
|
static void dump_wined3d_vertex_element(const struct wined3d_vertex_element *element)
|
|
|
|
{
|
2015-03-24 09:38:23 +01:00
|
|
|
TRACE(" format: %s (%#x)\n", debug_d3dformat(element->format), element->format);
|
|
|
|
TRACE(" input_slot: %u\n", element->input_slot);
|
|
|
|
TRACE(" offset: %u\n", element->offset);
|
|
|
|
TRACE(" output_slot: %u\n", element->output_slot);
|
|
|
|
TRACE(" input slot class: %s\n", debug_d3dinput_classification(element->input_slot_class));
|
|
|
|
TRACE("instance data step rate: %u\n", element->instance_data_step_rate);
|
|
|
|
TRACE(" method: %s (%#x)\n", debug_d3ddeclmethod(element->method), element->method);
|
|
|
|
TRACE(" usage: %s (%#x)\n", debug_d3ddeclusage(element->usage), element->usage);
|
|
|
|
TRACE(" usage_idx: %u\n", element->usage_idx);
|
2006-08-07 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 20:22:50 +01:00
|
|
|
ULONG CDECL wined3d_vertex_declaration_incref(struct wined3d_vertex_declaration *declaration)
|
2005-01-19 20:34:49 +01:00
|
|
|
{
|
2011-02-02 20:22:50 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&declaration->ref);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", declaration, refcount);
|
2005-01-19 20:34:49 +01:00
|
|
|
|
2011-02-02 20:22:50 +01:00
|
|
|
return refcount;
|
2005-01-19 20:34:49 +01:00
|
|
|
}
|
|
|
|
|
2016-06-22 10:39:02 +02:00
|
|
|
static void wined3d_vertex_declaration_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
struct wined3d_vertex_declaration *declaration = object;
|
|
|
|
|
2021-02-11 11:52:16 +01:00
|
|
|
TRACE("declaration %p.\n", declaration);
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(declaration->elements);
|
|
|
|
heap_free(declaration);
|
2016-06-22 10:39:02 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 20:22:50 +01:00
|
|
|
ULONG CDECL wined3d_vertex_declaration_decref(struct wined3d_vertex_declaration *declaration)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&declaration->ref);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", declaration, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
2009-09-28 10:05:01 +02:00
|
|
|
{
|
2021-10-15 14:25:57 +02:00
|
|
|
wined3d_mutex_lock();
|
2011-02-02 20:22:50 +01:00
|
|
|
declaration->parent_ops->wined3d_object_destroyed(declaration->parent);
|
2017-02-16 00:58:53 +01:00
|
|
|
wined3d_cs_destroy_object(declaration->device->cs,
|
2016-06-22 10:39:02 +02:00
|
|
|
wined3d_vertex_declaration_destroy_object, declaration);
|
2021-10-15 14:25:57 +02:00
|
|
|
wined3d_mutex_unlock();
|
2005-01-19 20:34:49 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 20:22:50 +01:00
|
|
|
return refcount;
|
|
|
|
}
|
2005-01-19 20:34:49 +01:00
|
|
|
|
2011-02-02 20:22:50 +01:00
|
|
|
void * CDECL wined3d_vertex_declaration_get_parent(const struct wined3d_vertex_declaration *declaration)
|
2010-08-31 18:41:40 +02:00
|
|
|
{
|
2011-02-02 20:22:50 +01:00
|
|
|
TRACE("declaration %p.\n", declaration);
|
2005-07-07 22:45:39 +02:00
|
|
|
|
2011-02-02 20:22:50 +01:00
|
|
|
return declaration->parent;
|
2005-07-07 22:45:39 +02:00
|
|
|
}
|
|
|
|
|
2011-11-24 22:52:36 +01:00
|
|
|
static BOOL declaration_element_valid_ffp(const struct wined3d_vertex_element *element)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->usage)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2012-01-18 21:46:22 +01:00
|
|
|
case WINED3D_DECL_USAGE_POSITION:
|
|
|
|
case WINED3D_DECL_USAGE_POSITIONT:
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->format)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16_SINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R16G16_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-09-18 14:57:54 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-18 21:46:22 +01:00
|
|
|
case WINED3D_DECL_USAGE_BLEND_WEIGHT:
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->format)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R8G8B8A8_UINT:
|
|
|
|
case WINED3DFMT_R16G16_SINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R16G16_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-09-18 14:57:54 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-18 21:46:22 +01:00
|
|
|
case WINED3D_DECL_USAGE_NORMAL:
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->format)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-09-18 14:57:54 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-18 21:46:22 +01:00
|
|
|
case WINED3D_DECL_USAGE_TEXCOORD:
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->format)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16_SINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R16G16_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-09-18 14:57:54 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-18 21:46:22 +01:00
|
|
|
case WINED3D_DECL_USAGE_COLOR:
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->format)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R8G8B8A8_UINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R8G8B8A8_UNORM:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SNORM:
|
|
|
|
case WINED3DFMT_R16G16B16A16_UNORM:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-09-18 14:57:54 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declaration,
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_device *device, const struct wined3d_vertex_element *elements, UINT element_count,
|
2010-08-31 18:41:40 +02:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-09-20 20:09:24 +02:00
|
|
|
{
|
2018-08-23 14:34:03 +02:00
|
|
|
const struct wined3d_adapter *adapter = device->adapter;
|
2009-09-20 20:09:24 +02:00
|
|
|
unsigned int i;
|
2007-02-13 23:12:36 +01:00
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
if (TRACE_ON(d3d_decl))
|
|
|
|
{
|
|
|
|
for (i = 0; i < element_count; ++i)
|
|
|
|
{
|
2011-11-24 22:52:36 +01:00
|
|
|
dump_wined3d_vertex_element(elements + i);
|
2007-02-13 23:12:36 +01:00
|
|
|
}
|
2005-07-07 22:45:39 +02:00
|
|
|
}
|
2007-02-13 23:12:45 +01:00
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
declaration->ref = 1;
|
|
|
|
declaration->parent = parent;
|
2009-09-23 10:05:52 +02:00
|
|
|
declaration->parent_ops = parent_ops;
|
2009-12-09 20:32:08 +01:00
|
|
|
declaration->device = device;
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(declaration->elements = heap_calloc(element_count, sizeof(*declaration->elements))))
|
2009-03-27 10:25:56 +01:00
|
|
|
{
|
2009-09-20 20:09:24 +02:00
|
|
|
ERR("Failed to allocate elements memory.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2007-02-13 23:12:45 +01:00
|
|
|
}
|
2009-09-20 20:09:24 +02:00
|
|
|
declaration->element_count = element_count;
|
2007-02-13 23:12:45 +01:00
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
/* Do some static analysis on the elements to make reading the
|
|
|
|
* declaration more comfortable for the drawing code. */
|
|
|
|
for (i = 0; i < element_count; ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_vertex_declaration_element *e = &declaration->elements[i];
|
2021-02-08 18:50:37 +01:00
|
|
|
unsigned int alignment;
|
2007-08-03 19:53:25 +02:00
|
|
|
|
2018-08-23 14:34:03 +02:00
|
|
|
e->format = wined3d_get_format(adapter, elements[i].format, 0);
|
2009-03-27 10:25:56 +01:00
|
|
|
e->ffp_valid = declaration_element_valid_ffp(&elements[i]);
|
2009-03-27 10:25:56 +01:00
|
|
|
e->input_slot = elements[i].input_slot;
|
|
|
|
e->offset = elements[i].offset;
|
|
|
|
e->output_slot = elements[i].output_slot;
|
2015-03-24 09:38:23 +01:00
|
|
|
e->input_slot_class = elements[i].input_slot_class;
|
|
|
|
e->instance_data_step_rate = elements[i].instance_data_step_rate;
|
2009-03-27 10:25:56 +01:00
|
|
|
e->method = elements[i].method;
|
|
|
|
e->usage = elements[i].usage;
|
|
|
|
e->usage_idx = elements[i].usage_idx;
|
2009-03-27 10:25:56 +01:00
|
|
|
|
2021-02-08 18:50:37 +01:00
|
|
|
if ((alignment = e->format->byte_count) > 4)
|
|
|
|
alignment = 4;
|
|
|
|
|
2012-01-18 21:46:22 +01:00
|
|
|
if (e->usage == WINED3D_DECL_USAGE_POSITIONT)
|
|
|
|
declaration->position_transformed = TRUE;
|
2007-07-30 12:35:33 +02:00
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
/* Find the streams used in the declaration. The vertex buffers have
|
2019-12-12 11:20:53 +01:00
|
|
|
* to be loaded when drawing, but filter tessellation pseudo streams. */
|
2019-02-20 21:53:56 +01:00
|
|
|
if (e->input_slot >= WINED3D_MAX_STREAMS)
|
2018-08-24 15:44:05 +02:00
|
|
|
continue;
|
2007-08-03 19:53:25 +02:00
|
|
|
|
2018-09-13 23:07:49 +02:00
|
|
|
if (!(e->format->flags[WINED3D_GL_RES_TYPE_BUFFER] & WINED3DFMT_FLAG_VERTEX_ATTRIBUTE))
|
2009-03-27 10:25:56 +01:00
|
|
|
{
|
2021-02-08 18:50:38 +01:00
|
|
|
FIXME("The application tries to use an unsupported format (%s).\n",
|
2009-03-27 10:25:56 +01:00
|
|
|
debug_d3dformat(elements[i].format));
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(declaration->elements);
|
2021-02-08 18:50:38 +01:00
|
|
|
return E_INVALIDARG;
|
2008-07-18 01:00:21 +02:00
|
|
|
}
|
|
|
|
|
2015-02-13 10:40:48 +01:00
|
|
|
if (e->offset == WINED3D_APPEND_ALIGNED_ELEMENT)
|
|
|
|
{
|
2015-03-23 09:17:15 +01:00
|
|
|
const struct wined3d_vertex_declaration_element *prev;
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
e->offset = 0;
|
|
|
|
for (j = 1; j <= i; ++j)
|
2015-02-13 10:40:48 +01:00
|
|
|
{
|
2015-03-23 09:17:15 +01:00
|
|
|
prev = &declaration->elements[i - j];
|
|
|
|
if (prev->input_slot == e->input_slot)
|
|
|
|
{
|
2021-02-08 18:50:37 +01:00
|
|
|
e->offset = (prev->offset + prev->format->byte_count + alignment - 1) & ~(alignment - 1);
|
2015-03-23 09:17:15 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-02-13 10:40:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 18:50:37 +01:00
|
|
|
if (e->offset & (alignment - 1))
|
2009-03-27 10:25:56 +01:00
|
|
|
{
|
2021-02-08 18:50:37 +01:00
|
|
|
WARN("Declaration element %u with format %s and offset %u is not %u byte aligned.\n",
|
|
|
|
i, debug_d3dformat(elements[i].format), e->offset, alignment);
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(declaration->elements);
|
2021-02-08 18:50:38 +01:00
|
|
|
return E_INVALIDARG;
|
2007-12-20 20:48:03 +01:00
|
|
|
}
|
2007-08-03 19:53:25 +02:00
|
|
|
}
|
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_vertex_declaration_create(struct wined3d_device *device,
|
2011-11-24 22:52:36 +01:00
|
|
|
const struct wined3d_vertex_element *elements, UINT element_count, void *parent,
|
2011-05-10 21:18:47 +02:00
|
|
|
const struct wined3d_parent_ops *parent_ops, struct wined3d_vertex_declaration **declaration)
|
|
|
|
{
|
|
|
|
struct wined3d_vertex_declaration *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("device %p, elements %p, element_count %u, parent %p, parent_ops %p, declaration %p.\n",
|
|
|
|
device, elements, element_count, parent, parent_ops, declaration);
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2011-05-10 21:18:47 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = vertexdeclaration_init(object, device, elements, element_count, parent, parent_ops);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(object);
|
2011-05-10 21:18:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created vertex declaration %p.\n", object);
|
|
|
|
*declaration = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wined3d_fvf_convert_state
|
|
|
|
{
|
2018-08-23 14:34:03 +02:00
|
|
|
const struct wined3d_adapter *adapter;
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element *elements;
|
2018-08-23 14:34:03 +02:00
|
|
|
unsigned int offset;
|
|
|
|
unsigned int idx;
|
2011-05-10 21:18:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void append_decl_element(struct wined3d_fvf_convert_state *state,
|
2012-01-18 21:46:22 +01:00
|
|
|
enum wined3d_format_id format_id, enum wined3d_decl_usage usage, UINT usage_idx)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element *elements = state->elements;
|
2011-05-10 21:18:47 +02:00
|
|
|
const struct wined3d_format *format;
|
|
|
|
UINT offset = state->offset;
|
|
|
|
UINT idx = state->idx;
|
|
|
|
|
|
|
|
elements[idx].format = format_id;
|
|
|
|
elements[idx].input_slot = 0;
|
|
|
|
elements[idx].offset = offset;
|
2015-03-23 09:17:16 +01:00
|
|
|
elements[idx].output_slot = WINED3D_OUTPUT_SLOT_SEMANTIC;
|
2015-03-24 09:38:23 +01:00
|
|
|
elements[idx].input_slot_class = WINED3D_INPUT_PER_VERTEX_DATA;
|
|
|
|
elements[idx].instance_data_step_rate = 0;
|
2012-01-18 21:46:21 +01:00
|
|
|
elements[idx].method = WINED3D_DECL_METHOD_DEFAULT;
|
2011-05-10 21:18:47 +02:00
|
|
|
elements[idx].usage = usage;
|
|
|
|
elements[idx].usage_idx = usage_idx;
|
|
|
|
|
2018-08-23 14:34:03 +02:00
|
|
|
format = wined3d_get_format(state->adapter, format_id, 0);
|
2018-09-09 22:32:45 +02:00
|
|
|
state->offset += format->byte_count;
|
2011-05-10 21:18:47 +02:00
|
|
|
++state->idx;
|
|
|
|
}
|
|
|
|
|
2018-08-23 14:34:03 +02:00
|
|
|
static unsigned int convert_fvf_to_declaration(const struct wined3d_adapter *adapter,
|
2011-11-24 22:52:36 +01:00
|
|
|
DWORD fvf, struct wined3d_vertex_element **elements)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
BOOL has_pos = !!(fvf & WINED3DFVF_POSITION_MASK);
|
|
|
|
BOOL has_blend = (fvf & WINED3DFVF_XYZB5) > WINED3DFVF_XYZRHW;
|
|
|
|
BOOL has_blend_idx = has_blend &&
|
|
|
|
(((fvf & WINED3DFVF_XYZB5) == WINED3DFVF_XYZB5) ||
|
|
|
|
(fvf & WINED3DFVF_LASTBETA_D3DCOLOR) ||
|
|
|
|
(fvf & WINED3DFVF_LASTBETA_UBYTE4));
|
|
|
|
BOOL has_normal = !!(fvf & WINED3DFVF_NORMAL);
|
|
|
|
BOOL has_psize = !!(fvf & WINED3DFVF_PSIZE);
|
|
|
|
BOOL has_diffuse = !!(fvf & WINED3DFVF_DIFFUSE);
|
|
|
|
BOOL has_specular = !!(fvf & WINED3DFVF_SPECULAR);
|
|
|
|
|
|
|
|
DWORD num_textures = (fvf & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
|
2012-07-20 00:24:27 +02:00
|
|
|
DWORD texcoords = (fvf & 0xffff0000) >> 16;
|
2011-05-10 21:18:47 +02:00
|
|
|
struct wined3d_fvf_convert_state state;
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int idx;
|
|
|
|
DWORD num_blends = 1 + (((fvf & WINED3DFVF_XYZB5) - WINED3DFVF_XYZB1) >> 1);
|
|
|
|
if (has_blend_idx) num_blends--;
|
|
|
|
|
|
|
|
/* Compute declaration size */
|
|
|
|
size = has_pos + (has_blend && num_blends > 0) + has_blend_idx + has_normal +
|
|
|
|
has_psize + has_diffuse + has_specular + num_textures;
|
|
|
|
|
2018-08-23 14:34:03 +02:00
|
|
|
state.adapter = adapter;
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(state.elements = heap_calloc(size, sizeof(*state.elements))))
|
2016-05-23 18:06:27 +02:00
|
|
|
return ~0u;
|
2011-05-10 21:18:47 +02:00
|
|
|
state.offset = 0;
|
|
|
|
state.idx = 0;
|
|
|
|
|
|
|
|
if (has_pos)
|
|
|
|
{
|
|
|
|
if (!has_blend && (fvf & WINED3DFVF_XYZRHW))
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_POSITIONT, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
else if ((fvf & WINED3DFVF_XYZW) == WINED3DFVF_XYZW)
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_POSITION, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
else
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_POSITION, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_blend && (num_blends > 0))
|
|
|
|
{
|
|
|
|
if ((fvf & WINED3DFVF_XYZB5) == WINED3DFVF_XYZB2 && (fvf & WINED3DFVF_LASTBETA_D3DCOLOR))
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_B8G8R8A8_UNORM, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (num_blends)
|
|
|
|
{
|
|
|
|
case 1:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unexpected amount of blend values: %u\n", num_blends);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_blend_idx)
|
|
|
|
{
|
|
|
|
if ((fvf & WINED3DFVF_LASTBETA_UBYTE4)
|
|
|
|
|| ((fvf & WINED3DFVF_XYZB5) == WINED3DFVF_XYZB2 && (fvf & WINED3DFVF_LASTBETA_D3DCOLOR)))
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R8G8B8A8_UINT, WINED3D_DECL_USAGE_BLEND_INDICES, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
else if (fvf & WINED3DFVF_LASTBETA_D3DCOLOR)
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_B8G8R8A8_UNORM, WINED3D_DECL_USAGE_BLEND_INDICES, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
else
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_BLEND_INDICES, 0);
|
2011-05-10 21:18:47 +02:00
|
|
|
}
|
|
|
|
|
2012-01-18 21:46:22 +01:00
|
|
|
if (has_normal)
|
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_NORMAL, 0);
|
|
|
|
if (has_psize)
|
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_PSIZE, 0);
|
|
|
|
if (has_diffuse)
|
|
|
|
append_decl_element(&state, WINED3DFMT_B8G8R8A8_UNORM, WINED3D_DECL_USAGE_COLOR, 0);
|
|
|
|
if (has_specular)
|
|
|
|
append_decl_element(&state, WINED3DFMT_B8G8R8A8_UNORM, WINED3D_DECL_USAGE_COLOR, 1);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
for (idx = 0; idx < num_textures; ++idx)
|
|
|
|
{
|
|
|
|
switch ((texcoords >> (idx * 2)) & 0x03)
|
|
|
|
{
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT1:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT2:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT3:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT4:
|
2012-01-18 21:46:22 +01:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-10 21:18:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*elements = state.elements;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_vertex_declaration_create_from_fvf(struct wined3d_device *device,
|
2011-05-10 21:18:47 +02:00
|
|
|
DWORD fvf, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_vertex_declaration **declaration)
|
|
|
|
{
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element *elements;
|
2011-05-10 21:18:47 +02:00
|
|
|
unsigned int size;
|
|
|
|
DWORD hr;
|
|
|
|
|
|
|
|
TRACE("device %p, fvf %#x, parent %p, parent_ops %p, declaration %p.\n",
|
|
|
|
device, fvf, parent, parent_ops, declaration);
|
|
|
|
|
2018-08-23 14:34:03 +02:00
|
|
|
size = convert_fvf_to_declaration(device->adapter, fvf, &elements);
|
|
|
|
if (size == ~0u)
|
|
|
|
return E_OUTOFMEMORY;
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_vertex_declaration_create(device, elements, size, parent, parent_ops, declaration);
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(elements);
|
2011-05-10 21:18:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|