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"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2005-01-19 20:34:49 +01:00
|
|
|
#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)
|
|
|
|
{
|
2009-03-27 10:25:56 +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(" 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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-02-02 20:22:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, declaration->elements);
|
|
|
|
declaration->parent_ops->wined3d_object_destroyed(declaration->parent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, declaration);
|
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
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
WORD preloaded = 0; /* MAX_STREAMS, 16 */
|
|
|
|
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;
|
2009-09-20 20:09:24 +02:00
|
|
|
declaration->elements = HeapAlloc(GetProcessHeap(), 0, sizeof(*declaration->elements) * element_count);
|
|
|
|
if (!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];
|
2007-08-03 19:53:25 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
e->format = wined3d_get_format(gl_info, elements[i].format);
|
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;
|
|
|
|
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
|
|
|
|
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
|
|
|
|
* to be loaded when drawing, but filter tesselation pseudo streams. */
|
2009-03-27 10:25:56 +01:00
|
|
|
if (e->input_slot >= MAX_STREAMS) continue;
|
2007-08-03 19:53:25 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (!e->format->gl_vtx_format)
|
2009-03-27 10:25:56 +01:00
|
|
|
{
|
2009-09-20 20:09:24 +02:00
|
|
|
FIXME("The application tries to use an unsupported format (%s), returning E_FAIL.\n",
|
2009-03-27 10:25:56 +01:00
|
|
|
debug_d3dformat(elements[i].format));
|
2009-09-20 20:09:24 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, declaration->elements);
|
2008-07-18 01:00:21 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
if (e->offset & 0x3)
|
|
|
|
{
|
2009-09-20 20:09:24 +02:00
|
|
|
WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL.\n", i, e->offset);
|
|
|
|
HeapFree(GetProcessHeap(), 0, declaration->elements);
|
2007-12-20 20:48:03 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
if (!(preloaded & (1 << e->input_slot)))
|
2009-03-27 10:25:56 +01:00
|
|
|
{
|
2009-09-20 20:09:24 +02:00
|
|
|
declaration->streams[declaration->num_streams] = e->input_slot;
|
|
|
|
++declaration->num_streams;
|
|
|
|
preloaded |= 1 << e->input_slot;
|
2007-08-03 19:53:25 +02:00
|
|
|
}
|
2007-11-20 21:14:10 +01:00
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
if (elements[i].format == WINED3DFMT_R16G16_FLOAT || elements[i].format == WINED3DFMT_R16G16B16A16_FLOAT)
|
2009-01-08 10:19:17 +01:00
|
|
|
{
|
2009-09-20 20:09:24 +02:00
|
|
|
if (!gl_info->supported[ARB_HALF_FLOAT_VERTEX]) declaration->half_float_conv_needed = TRUE;
|
2007-11-20 21:14:10 +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);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if(!object)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate vertex declaration memory.\n");
|
|
|
|
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);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
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;
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element *elements;
|
2011-05-10 21:18:47 +02:00
|
|
|
UINT offset;
|
|
|
|
UINT idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
elements[idx].output_slot = 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;
|
|
|
|
|
|
|
|
format = wined3d_get_format(state->gl_info, format_id);
|
|
|
|
state->offset += format->component_count * format->component_size;
|
|
|
|
++state->idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int convert_fvf_to_declaration(const struct wined3d_gl_info *gl_info,
|
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;
|
|
|
|
|
|
|
|
state.gl_info = gl_info;
|
|
|
|
state.elements = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*state.elements));
|
|
|
|
if (!state.elements) return ~0U;
|
|
|
|
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);
|
|
|
|
|
|
|
|
size = convert_fvf_to_declaration(&device->adapter->gl_info, fvf, &elements);
|
|
|
|
if (size == ~0U) return E_OUTOFMEMORY;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_vertex_declaration_create(device, elements, size, parent, parent_ops, declaration);
|
2011-05-10 21:18:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, elements);
|
|
|
|
return hr;
|
|
|
|
}
|