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);
|
|
|
|
|
2006-08-07 19:21:54 +02:00
|
|
|
static void dump_wined3dvertexelement(const WINED3DVERTEXELEMENT *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
|
|
|
}
|
|
|
|
|
2005-01-19 20:34:49 +01:00
|
|
|
/* *******************************************
|
|
|
|
IWineD3DVertexDeclaration IUnknown parts follow
|
|
|
|
******************************************* */
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DVertexDeclarationImpl_QueryInterface(IWineD3DVertexDeclaration *iface, REFIID riid, LPVOID *ppobj)
|
2005-01-19 20:34:49 +01:00
|
|
|
{
|
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
2005-03-02 14:44:58 +01:00
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2006-02-06 11:32:41 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBase)
|
2005-03-02 14:44:58 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DVertexDeclaration)){
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*ppobj = This;
|
2006-04-25 23:59:12 +02:00
|
|
|
return S_OK;
|
2005-03-02 14:44:58 +01:00
|
|
|
}
|
2006-04-25 23:59:12 +02:00
|
|
|
*ppobj = NULL;
|
2005-01-19 20:34:49 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DVertexDeclarationImpl_AddRef(IWineD3DVertexDeclaration *iface) {
|
2005-01-19 20:34:49 +01:00
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
|
2005-01-19 20:34:49 +01:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DVertexDeclarationImpl_Release(IWineD3DVertexDeclaration *iface) {
|
2005-01-19 20:34:49 +01:00
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
|
|
|
ULONG ref;
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : Releasing from %d\n", This, This->ref);
|
2005-01-19 20:34:49 +01:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
2009-09-28 10:05:01 +02:00
|
|
|
if (!ref)
|
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->elements);
|
2009-09-23 10:05:52 +02:00
|
|
|
This->parent_ops->wined3d_object_destroyed(This->parent);
|
2005-12-16 12:49:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2005-01-19 20:34:49 +01:00
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *******************************************
|
|
|
|
IWineD3DVertexDeclaration parts follow
|
|
|
|
******************************************* */
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetParent(IWineD3DVertexDeclaration *iface, IUnknown** parent){
|
2005-07-07 22:45:39 +02:00
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
|
|
|
|
2005-12-14 11:29:17 +01:00
|
|
|
*parent= This->parent;
|
2005-07-07 22:45:39 +02:00
|
|
|
IUnknown_AddRef(*parent);
|
|
|
|
TRACE("(%p) : returning %p\n", This, *parent);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-07 22:45:39 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDevice(IWineD3DVertexDeclaration *iface, IWineD3DDevice** ppDevice) {
|
2005-01-19 20:34:49 +01:00
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
|
|
|
TRACE("(%p) : returning %p\n", This, This->wineD3DDevice);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2005-01-19 20:34:49 +01:00
|
|
|
*ppDevice = (IWineD3DDevice *) This->wineD3DDevice;
|
|
|
|
IWineD3DDevice_AddRef(*ppDevice);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-19 20:34:49 +01:00
|
|
|
}
|
|
|
|
|
2008-09-18 14:57:54 +02:00
|
|
|
static BOOL declaration_element_valid_ffp(const WINED3DVERTEXELEMENT *element)
|
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
switch(element->usage)
|
2008-09-18 14:57:54 +02:00
|
|
|
{
|
|
|
|
case WINED3DDECLUSAGE_POSITION:
|
|
|
|
case WINED3DDECLUSAGE_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_BLENDWEIGHT:
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
static const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl =
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2009-09-20 20:09:24 +02:00
|
|
|
/* IUnknown */
|
|
|
|
IWineD3DVertexDeclarationImpl_QueryInterface,
|
|
|
|
IWineD3DVertexDeclarationImpl_AddRef,
|
|
|
|
IWineD3DVertexDeclarationImpl_Release,
|
|
|
|
/* IWineD3DVertexDeclaration */
|
|
|
|
IWineD3DVertexDeclarationImpl_GetParent,
|
|
|
|
IWineD3DVertexDeclarationImpl_GetDevice,
|
|
|
|
};
|
2005-07-07 22:45:39 +02:00
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *declaration, IWineD3DDeviceImpl *device,
|
2009-09-23 10:05:52 +02:00
|
|
|
const WINED3DVERTEXELEMENT *elements, UINT element_count,
|
|
|
|
IUnknown *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)
|
|
|
|
{
|
|
|
|
dump_wined3dvertexelement(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->lpVtbl = &IWineD3DVertexDeclaration_Vtbl;
|
|
|
|
declaration->ref = 1;
|
|
|
|
declaration->parent = parent;
|
2009-09-23 10:05:52 +02:00
|
|
|
declaration->parent_ops = parent_ops;
|
2009-09-20 20:09:24 +02:00
|
|
|
declaration->wineD3DDevice = device;
|
|
|
|
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
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
e->format_desc = getFormatDescEntry(elements[i].format, gl_info);
|
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
|
|
|
|
2009-09-20 20:09:24 +02:00
|
|
|
if (e->usage == WINED3DDECLUSAGE_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
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
if (!e->format_desc->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
|
|
|
}
|