2007-08-17 18:29:23 +00:00
|
|
|
/*
|
|
|
|
* vertex declaration implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002-2005 Raphael Junqueira
|
|
|
|
* Copyright 2004 Jason Edmeades
|
|
|
|
* Copyright 2004 Christian Costa
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2009-09-26 11:13:40 +00:00
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
2007-08-17 18:29:23 +00: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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-03-08 12:15:18 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
2007-08-17 18:29:23 +00:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl);
|
|
|
|
|
2012-03-01 18:39:47 +00:00
|
|
|
static void dump_wined3d_vertex_element(const struct wined3d_vertex_element *element)
|
|
|
|
{
|
2015-07-21 23:40:47 +00: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);
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 15:27:19 +00:00
|
|
|
ULONG CDECL wined3d_vertex_declaration_incref(struct wined3d_vertex_declaration *declaration)
|
2007-08-17 18:29:23 +00:00
|
|
|
{
|
2011-05-30 15:27:19 +00:00
|
|
|
ULONG refcount = InterlockedIncrement(&declaration->ref);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", declaration, refcount);
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2011-05-30 15:27:19 +00:00
|
|
|
return refcount;
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 18:50:42 +00:00
|
|
|
static void wined3d_vertex_declaration_destroy_object(void *object)
|
2015-07-21 23:40:47 +00:00
|
|
|
{
|
2017-06-16 18:50:42 +00:00
|
|
|
struct wined3d_vertex_declaration *declaration = object;
|
|
|
|
|
2018-03-08 12:15:18 +00:00
|
|
|
heap_free(declaration->elements);
|
|
|
|
heap_free(declaration);
|
2015-07-21 23:40:47 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 15:27:19 +00: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)
|
2010-01-06 14:59:04 +00:00
|
|
|
{
|
2011-05-30 15:27:19 +00:00
|
|
|
declaration->parent_ops->wined3d_object_destroyed(declaration->parent);
|
2017-06-16 18:50:42 +00:00
|
|
|
wined3d_cs_destroy_object(declaration->device->cs,
|
|
|
|
wined3d_vertex_declaration_destroy_object, declaration);
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 15:27:19 +00:00
|
|
|
return refcount;
|
|
|
|
}
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2011-05-30 15:27:19 +00:00
|
|
|
void * CDECL wined3d_vertex_declaration_get_parent(const struct wined3d_vertex_declaration *declaration)
|
2010-10-11 13:56:39 +00:00
|
|
|
{
|
2011-05-30 15:27:19 +00:00
|
|
|
TRACE("declaration %p.\n", declaration);
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2011-05-30 15:27:19 +00:00
|
|
|
return declaration->parent;
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-01 18:39:47 +00:00
|
|
|
static BOOL declaration_element_valid_ffp(const struct wined3d_vertex_element *element)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2009-04-05 13:52:15 +00:00
|
|
|
switch(element->usage)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2012-08-28 19:08:01 +00:00
|
|
|
case WINED3D_DECL_USAGE_POSITION:
|
|
|
|
case WINED3D_DECL_USAGE_POSITIONT:
|
2009-04-05 13:52:15 +00:00
|
|
|
switch(element->format)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2009-04-05 13:52:15 +00: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-11-27 09:20:16 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-28 19:08:01 +00:00
|
|
|
case WINED3D_DECL_USAGE_BLEND_WEIGHT:
|
2009-04-05 13:52:15 +00:00
|
|
|
switch(element->format)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2009-04-05 13:52:15 +00:00
|
|
|
case WINED3DFMT_R32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
2009-09-26 11:13:40 +00:00
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
2009-04-05 13:52:15 +00:00
|
|
|
case WINED3DFMT_R8G8B8A8_UINT:
|
|
|
|
case WINED3DFMT_R16G16_SINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R16G16_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-11-27 09:20:16 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-08 12:15:18 +00:00
|
|
|
case WINED3D_DECL_USAGE_BLEND_INDICES:
|
|
|
|
switch(element->format)
|
|
|
|
{
|
|
|
|
case WINED3DFMT_R8G8B8A8_UINT:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-28 19:08:01 +00:00
|
|
|
case WINED3D_DECL_USAGE_NORMAL:
|
2009-04-05 13:52:15 +00:00
|
|
|
switch(element->format)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2009-04-05 13:52:15 +00:00
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2008-11-27 09:20:16 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-28 19:08:01 +00:00
|
|
|
case WINED3D_DECL_USAGE_TEXCOORD:
|
2009-04-05 13:52:15 +00:00
|
|
|
switch(element->format)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2009-04-05 13:52:15 +00: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-11-27 09:20:16 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-28 19:08:01 +00:00
|
|
|
case WINED3D_DECL_USAGE_COLOR:
|
2009-04-05 13:52:15 +00:00
|
|
|
switch(element->format)
|
2008-11-27 09:20:16 +00:00
|
|
|
{
|
2009-04-05 13:52:15 +00:00
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
2009-09-26 11:13:40 +00:00
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
2009-04-05 13:52:15 +00: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-11-27 09:20:16 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 15:27:19 +00:00
|
|
|
static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declaration,
|
2012-03-01 18:39:47 +00:00
|
|
|
struct wined3d_device *device, const struct wined3d_vertex_element *elements, UINT element_count,
|
2010-10-11 13:56:39 +00:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-09-26 11:13:40 +00:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
unsigned int i;
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2009-09-26 11:13:40 +00:00
|
|
|
if (TRACE_ON(d3d_decl))
|
|
|
|
{
|
|
|
|
for (i = 0; i < element_count; ++i)
|
|
|
|
{
|
2012-03-01 18:39:47 +00:00
|
|
|
dump_wined3d_vertex_element(elements + i);
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 11:13:40 +00:00
|
|
|
declaration->ref = 1;
|
|
|
|
declaration->parent = parent;
|
|
|
|
declaration->parent_ops = parent_ops;
|
2010-01-06 14:59:04 +00:00
|
|
|
declaration->device = device;
|
2018-03-08 12:15:18 +00:00
|
|
|
if (!(declaration->elements = heap_calloc(element_count, sizeof(*declaration->elements))))
|
2009-04-05 13:52:15 +00:00
|
|
|
{
|
2009-09-26 11:13:40 +00:00
|
|
|
ERR("Failed to allocate elements memory.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
2009-09-26 11:13:40 +00:00
|
|
|
declaration->element_count = element_count;
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2009-09-26 11:13:40 +00: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];
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2017-06-16 18:50:42 +00:00
|
|
|
e->format = wined3d_get_format(gl_info, elements[i].format, 0);
|
2009-04-05 13:52:15 +00:00
|
|
|
e->ffp_valid = declaration_element_valid_ffp(&elements[i]);
|
|
|
|
e->input_slot = elements[i].input_slot;
|
|
|
|
e->offset = elements[i].offset;
|
|
|
|
e->output_slot = elements[i].output_slot;
|
2015-07-21 23:40:47 +00:00
|
|
|
e->input_slot_class = elements[i].input_slot_class;
|
|
|
|
e->instance_data_step_rate = elements[i].instance_data_step_rate;
|
2009-04-05 13:52:15 +00:00
|
|
|
e->method = elements[i].method;
|
|
|
|
e->usage = elements[i].usage;
|
|
|
|
e->usage_idx = elements[i].usage_idx;
|
|
|
|
|
2012-08-28 19:08:01 +00:00
|
|
|
if (e->usage == WINED3D_DECL_USAGE_POSITIONT)
|
|
|
|
declaration->position_transformed = TRUE;
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2009-09-26 11:13:40 +00:00
|
|
|
/* Find the streams used in the declaration. The vertex buffers have
|
|
|
|
* to be loaded when drawing, but filter tesselation pseudo streams. */
|
2009-04-05 13:52:15 +00:00
|
|
|
if (e->input_slot >= MAX_STREAMS) continue;
|
2007-08-17 18:29:23 +00:00
|
|
|
|
2010-10-11 13:56:39 +00:00
|
|
|
if (!e->format->gl_vtx_format)
|
2009-04-05 13:52:15 +00:00
|
|
|
{
|
2009-09-26 11:13:40 +00:00
|
|
|
FIXME("The application tries to use an unsupported format (%s), returning E_FAIL.\n",
|
2009-04-05 13:52:15 +00:00
|
|
|
debug_d3dformat(elements[i].format));
|
2018-03-08 12:15:18 +00:00
|
|
|
heap_free(declaration->elements);
|
2008-09-30 12:03:48 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-02-28 10:18:41 +00:00
|
|
|
if (e->offset == WINED3D_APPEND_ALIGNED_ELEMENT)
|
|
|
|
{
|
2015-07-21 23:40:47 +00:00
|
|
|
const struct wined3d_vertex_declaration_element *prev;
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
e->offset = 0;
|
|
|
|
for (j = 1; j <= i; ++j)
|
2015-02-28 10:18:41 +00:00
|
|
|
{
|
2015-07-21 23:40:47 +00:00
|
|
|
prev = &declaration->elements[i - j];
|
|
|
|
if (prev->input_slot == e->input_slot)
|
|
|
|
{
|
|
|
|
e->offset = (prev->offset + prev->format->byte_count + 3) & ~3;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-28 10:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-05 13:52:15 +00:00
|
|
|
if (e->offset & 0x3)
|
|
|
|
{
|
2009-09-26 11:13:40 +00:00
|
|
|
WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL.\n", i, e->offset);
|
2018-03-08 12:15:18 +00:00
|
|
|
heap_free(declaration->elements);
|
2008-09-30 12:03:48 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-04-05 13:52:15 +00:00
|
|
|
if (elements[i].format == WINED3DFMT_R16G16_FLOAT || elements[i].format == WINED3DFMT_R16G16B16A16_FLOAT)
|
2009-01-18 21:09:22 +00:00
|
|
|
{
|
2009-09-26 11:13:40 +00:00
|
|
|
if (!gl_info->supported[ARB_HALF_FLOAT_VERTEX]) declaration->half_float_conv_needed = TRUE;
|
2007-11-27 11:16:57 +00:00
|
|
|
}
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
|
|
|
|
2009-09-26 11:13:40 +00:00
|
|
|
return WINED3D_OK;
|
2007-08-17 18:29:23 +00:00
|
|
|
}
|
2011-05-30 15:27:19 +00:00
|
|
|
|
|
|
|
HRESULT CDECL wined3d_vertex_declaration_create(struct wined3d_device *device,
|
2012-03-01 18:39:47 +00:00
|
|
|
const struct wined3d_vertex_element *elements, UINT element_count, void *parent,
|
2011-05-30 15:27:19 +00: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-03-08 12:15:18 +00:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2011-05-30 15:27:19 +00: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-03-08 12:15:18 +00:00
|
|
|
heap_free(object);
|
2011-05-30 15:27:19 +00:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created vertex declaration %p.\n", object);
|
|
|
|
*declaration = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wined3d_fvf_convert_state
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2012-03-01 18:39:47 +00:00
|
|
|
struct wined3d_vertex_element *elements;
|
2011-05-30 15:27:19 +00:00
|
|
|
UINT offset;
|
|
|
|
UINT idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void append_decl_element(struct wined3d_fvf_convert_state *state,
|
2012-08-28 19:08:01 +00:00
|
|
|
enum wined3d_format_id format_id, enum wined3d_decl_usage usage, UINT usage_idx)
|
2011-05-30 15:27:19 +00:00
|
|
|
{
|
2012-03-01 18:39:47 +00:00
|
|
|
struct wined3d_vertex_element *elements = state->elements;
|
2011-05-30 15:27:19 +00: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-07-21 23:40:47 +00:00
|
|
|
elements[idx].output_slot = WINED3D_OUTPUT_SLOT_SEMANTIC;
|
|
|
|
elements[idx].input_slot_class = WINED3D_INPUT_PER_VERTEX_DATA;
|
|
|
|
elements[idx].instance_data_step_rate = 0;
|
2012-08-28 19:08:01 +00:00
|
|
|
elements[idx].method = WINED3D_DECL_METHOD_DEFAULT;
|
2011-05-30 15:27:19 +00:00
|
|
|
elements[idx].usage = usage;
|
|
|
|
elements[idx].usage_idx = usage_idx;
|
|
|
|
|
2017-06-16 18:50:42 +00:00
|
|
|
format = wined3d_get_format(state->gl_info, format_id, 0);
|
|
|
|
state->offset += format->attribute_size;
|
2011-05-30 15:27:19 +00:00
|
|
|
++state->idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int convert_fvf_to_declaration(const struct wined3d_gl_info *gl_info,
|
2012-03-01 18:39:47 +00:00
|
|
|
DWORD fvf, struct wined3d_vertex_element **elements)
|
2011-05-30 15:27:19 +00: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-08-28 19:08:01 +00:00
|
|
|
DWORD texcoords = (fvf & 0xffff0000) >> 16;
|
2011-05-30 15:27:19 +00: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;
|
|
|
|
|
|
|
|
state.gl_info = gl_info;
|
2018-03-08 12:15:18 +00:00
|
|
|
if (!(state.elements = heap_calloc(size, sizeof(*state.elements))))
|
2017-06-16 18:50:42 +00:00
|
|
|
return ~0u;
|
2011-05-30 15:27:19 +00:00
|
|
|
state.offset = 0;
|
|
|
|
state.idx = 0;
|
|
|
|
|
|
|
|
if (has_pos)
|
|
|
|
{
|
|
|
|
if (!has_blend && (fvf & WINED3DFVF_XYZRHW))
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_POSITIONT, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
else if ((fvf & WINED3DFVF_XYZW) == WINED3DFVF_XYZW)
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_POSITION, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
else
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_POSITION, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_blend && (num_blends > 0))
|
|
|
|
{
|
|
|
|
if ((fvf & WINED3DFVF_XYZB5) == WINED3DFVF_XYZB2 && (fvf & WINED3DFVF_LASTBETA_D3DCOLOR))
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_B8G8R8A8_UNORM, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (num_blends)
|
|
|
|
{
|
|
|
|
case 1:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_BLEND_WEIGHT, 0);
|
2011-05-30 15:27:19 +00: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-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R8G8B8A8_UINT, WINED3D_DECL_USAGE_BLEND_INDICES, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
else if (fvf & WINED3DFVF_LASTBETA_D3DCOLOR)
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_B8G8R8A8_UNORM, WINED3D_DECL_USAGE_BLEND_INDICES, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
else
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_BLEND_INDICES, 0);
|
2011-05-30 15:27:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 19:08:01 +00: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-30 15:27:19 +00:00
|
|
|
|
|
|
|
for (idx = 0; idx < num_textures; ++idx)
|
|
|
|
{
|
|
|
|
switch ((texcoords >> (idx * 2)) & 0x03)
|
|
|
|
{
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT1:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT2:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT3:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
case WINED3DFVF_TEXTUREFORMAT4:
|
2012-08-28 19:08:01 +00:00
|
|
|
append_decl_element(&state, WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_DECL_USAGE_TEXCOORD, idx);
|
2011-05-30 15:27:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*elements = state.elements;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL wined3d_vertex_declaration_create_from_fvf(struct wined3d_device *device,
|
|
|
|
DWORD fvf, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_vertex_declaration **declaration)
|
|
|
|
{
|
2012-03-01 18:39:47 +00:00
|
|
|
struct wined3d_vertex_element *elements;
|
2011-05-30 15:27:19 +00: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);
|
|
|
|
|
|
|
|
size = convert_fvf_to_declaration(&device->adapter->gl_info, fvf, &elements);
|
|
|
|
if (size == ~0U) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = wined3d_vertex_declaration_create(device, elements, size, parent, parent_ops, declaration);
|
2018-03-08 12:15:18 +00:00
|
|
|
heap_free(elements);
|
2011-05-30 15:27:19 +00:00
|
|
|
return hr;
|
|
|
|
}
|