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
|
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);
|
|
|
|
|
2007-12-20 01:34:22 +01:00
|
|
|
#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
|
|
|
|
|
2006-08-07 19:21:54 +02:00
|
|
|
static void dump_wined3dvertexelement(const WINED3DVERTEXELEMENT *element) {
|
|
|
|
TRACE(" Stream: %d\n", element->Stream);
|
|
|
|
TRACE(" Offset: %d\n", element->Offset);
|
|
|
|
TRACE(" Type: %s (%#x)\n", debug_d3ddecltype(element->Type), element->Type);
|
|
|
|
TRACE(" Method: %s (%#x)\n", debug_d3ddeclmethod(element->Method), element->Method);
|
|
|
|
TRACE(" Usage: %s (%#x)\n", debug_d3ddeclusage(element->Usage), element->Usage);
|
|
|
|
TRACE("Usage index: %d\n", element->UsageIndex);
|
|
|
|
TRACE(" Register: %d\n", element->Reg);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (ref == 0) {
|
2007-04-11 14:02:38 +02:00
|
|
|
if(iface == This->wineD3DDevice->stateBlock->vertexDecl) {
|
|
|
|
/* See comment in PixelShader::Release */
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(This->wineD3DDevice, STATE_VDECL);
|
|
|
|
}
|
|
|
|
|
2005-12-16 12:49:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->pDeclarationWine);
|
2008-09-18 14:57:54 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->ffp_valid);
|
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
|
|
|
}
|
|
|
|
|
2007-02-13 23:12:36 +01:00
|
|
|
static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDeclaration(IWineD3DVertexDeclaration *iface,
|
2008-01-07 17:17:04 +01:00
|
|
|
WINED3DVERTEXELEMENT *elements, UINT *element_count) {
|
2005-07-28 12:15:35 +02:00
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
2007-02-13 23:12:36 +01:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2005-07-28 12:15:35 +02:00
|
|
|
|
2007-02-13 23:12:36 +01:00
|
|
|
TRACE("(%p) : d3d version %d, elements %p, element_count %p\n",
|
|
|
|
This, ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion, elements, element_count);
|
2006-02-07 12:26:34 +01:00
|
|
|
|
2007-02-13 23:12:45 +01:00
|
|
|
*element_count = This->declarationWNumElements;
|
|
|
|
if (elements) {
|
|
|
|
CopyMemory(elements, This->pDeclarationWine, This->declarationWNumElements * sizeof(WINED3DVERTEXELEMENT));
|
2005-07-28 12:15:35 +02:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:45:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-09-18 14:57:54 +02:00
|
|
|
static BOOL declaration_element_valid_ffp(const WINED3DVERTEXELEMENT *element)
|
|
|
|
{
|
|
|
|
switch(element->Usage)
|
|
|
|
{
|
|
|
|
case WINED3DDECLUSAGE_POSITION:
|
|
|
|
case WINED3DDECLUSAGE_POSITIONT:
|
|
|
|
switch(element->Type)
|
|
|
|
{
|
|
|
|
case WINED3DDECLTYPE_FLOAT2:
|
|
|
|
case WINED3DDECLTYPE_FLOAT3:
|
|
|
|
case WINED3DDECLTYPE_FLOAT4:
|
|
|
|
case WINED3DDECLTYPE_SHORT2:
|
|
|
|
case WINED3DDECLTYPE_SHORT4:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_2:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_4:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_BLENDWEIGHT:
|
|
|
|
switch(element->Type)
|
|
|
|
{
|
|
|
|
case WINED3DDECLTYPE_D3DCOLOR:
|
|
|
|
case WINED3DDECLTYPE_UBYTE4:
|
|
|
|
case WINED3DDECLTYPE_SHORT2:
|
|
|
|
case WINED3DDECLTYPE_SHORT4:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_2:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_4:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_NORMAL:
|
|
|
|
switch(element->Type)
|
|
|
|
{
|
|
|
|
case WINED3DDECLTYPE_FLOAT3:
|
|
|
|
case WINED3DDECLTYPE_FLOAT4:
|
|
|
|
case WINED3DDECLTYPE_SHORT4:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_4:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_TEXCOORD:
|
|
|
|
switch(element->Type)
|
|
|
|
{
|
|
|
|
case WINED3DDECLTYPE_FLOAT1:
|
|
|
|
case WINED3DDECLTYPE_FLOAT2:
|
|
|
|
case WINED3DDECLTYPE_FLOAT3:
|
|
|
|
case WINED3DDECLTYPE_FLOAT4:
|
|
|
|
case WINED3DDECLTYPE_SHORT2:
|
|
|
|
case WINED3DDECLTYPE_SHORT4:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_2:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_4:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_COLOR:
|
|
|
|
switch(element->Type)
|
|
|
|
{
|
|
|
|
case WINED3DDECLTYPE_FLOAT3:
|
|
|
|
case WINED3DDECLTYPE_FLOAT4:
|
|
|
|
case WINED3DDECLTYPE_D3DCOLOR:
|
|
|
|
case WINED3DDECLTYPE_UBYTE4:
|
|
|
|
case WINED3DDECLTYPE_SHORT4:
|
|
|
|
case WINED3DDECLTYPE_UBYTE4N:
|
|
|
|
case WINED3DDECLTYPE_SHORT4N:
|
|
|
|
case WINED3DDECLTYPE_USHORT4N:
|
|
|
|
case WINED3DDECLTYPE_FLOAT16_4:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-13 23:12:36 +01:00
|
|
|
static HRESULT WINAPI IWineD3DVertexDeclarationImpl_SetDeclaration(IWineD3DVertexDeclaration *iface,
|
2008-01-07 17:17:04 +01:00
|
|
|
const WINED3DVERTEXELEMENT *elements, UINT element_count) {
|
2005-07-07 22:45:39 +02:00
|
|
|
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
|
2006-04-07 12:51:12 +02:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2009-01-08 10:19:17 +01:00
|
|
|
int i;
|
2007-08-03 19:53:25 +02:00
|
|
|
char isPreLoaded[MAX_STREAMS];
|
2005-07-07 22:45:39 +02:00
|
|
|
|
|
|
|
TRACE("(%p) : d3d version %d\n", This, ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion);
|
2007-08-03 19:53:25 +02:00
|
|
|
memset(isPreLoaded, 0, sizeof(isPreLoaded));
|
2007-02-13 23:12:36 +01:00
|
|
|
|
2007-02-13 23:12:45 +01: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
|
|
|
|
|
|
|
This->declarationWNumElements = element_count;
|
|
|
|
This->pDeclarationWine = HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DVERTEXELEMENT) * element_count);
|
2008-09-18 14:57:54 +02:00
|
|
|
This->ffp_valid = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->ffp_valid) * element_count);
|
|
|
|
if (!This->pDeclarationWine || !This->ffp_valid) {
|
2007-02-13 23:12:45 +01:00
|
|
|
ERR("Memory allocation failed\n");
|
2007-08-21 17:13:55 +02:00
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
2007-02-13 23:12:45 +01:00
|
|
|
} else {
|
|
|
|
CopyMemory(This->pDeclarationWine, elements, sizeof(WINED3DVERTEXELEMENT) * element_count);
|
|
|
|
}
|
|
|
|
|
2007-08-03 19:53:25 +02:00
|
|
|
/* Do some static analysis on the elements to make reading the declaration more comfortable
|
|
|
|
* for the drawing code
|
|
|
|
*/
|
|
|
|
This->num_streams = 0;
|
2007-07-30 12:35:33 +02:00
|
|
|
This->position_transformed = FALSE;
|
2007-08-03 19:53:25 +02:00
|
|
|
for (i = 0; i < element_count; ++i) {
|
2008-09-18 14:57:54 +02:00
|
|
|
This->ffp_valid[i] = declaration_element_valid_ffp(&This->pDeclarationWine[i]);
|
2007-08-03 19:53:25 +02:00
|
|
|
|
2007-07-30 12:35:33 +02:00
|
|
|
if(This->pDeclarationWine[i].Usage == WINED3DDECLUSAGE_POSITIONT) {
|
|
|
|
This->position_transformed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the Streams used in the declaration. The vertex buffers have to be loaded
|
|
|
|
* when drawing, but filter tesselation pseudo streams
|
|
|
|
*/
|
2007-08-03 19:53:25 +02:00
|
|
|
if(This->pDeclarationWine[i].Stream >= MAX_STREAMS) continue;
|
|
|
|
|
2008-07-18 01:00:21 +02:00
|
|
|
if(This->pDeclarationWine[i].Type == WINED3DDECLTYPE_UNUSED) {
|
|
|
|
WARN("The application tries to use WINED3DDECLTYPE_UNUSED, returning E_FAIL\n");
|
|
|
|
/* The caller will release the vdecl, which will free This->pDeclarationWine */
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2007-12-20 20:48:03 +01:00
|
|
|
if(This->pDeclarationWine[i].Offset & 0x3) {
|
|
|
|
WARN("Declaration element %d is not 4 byte aligned(%d), returning E_FAIL\n", i, This->pDeclarationWine[i].Offset);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2007-08-03 19:53:25 +02:00
|
|
|
if(!isPreLoaded[This->pDeclarationWine[i].Stream]) {
|
|
|
|
This->streams[This->num_streams] = This->pDeclarationWine[i].Stream;
|
|
|
|
This->num_streams++;
|
|
|
|
isPreLoaded[This->pDeclarationWine[i].Stream] = 1;
|
|
|
|
}
|
2007-11-20 21:14:10 +01:00
|
|
|
|
2009-01-08 10:19:17 +01:00
|
|
|
if (This->pDeclarationWine[i].Type == WINED3DDECLTYPE_FLOAT16_2
|
|
|
|
|| This->pDeclarationWine[i].Type == WINED3DDECLTYPE_FLOAT16_4)
|
|
|
|
{
|
|
|
|
if (!GL_SUPPORT(NV_HALF_FLOAT)) This->half_float_conv_needed = TRUE;
|
2007-11-20 21:14:10 +01:00
|
|
|
}
|
2007-08-03 19:53:25 +02:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:45:39 +02:00
|
|
|
TRACE("Returning\n");
|
|
|
|
return hr;
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl =
|
2005-01-19 20:34:49 +01:00
|
|
|
{
|
2005-07-07 22:45:39 +02:00
|
|
|
/* IUnknown */
|
2005-01-19 20:34:49 +01:00
|
|
|
IWineD3DVertexDeclarationImpl_QueryInterface,
|
|
|
|
IWineD3DVertexDeclarationImpl_AddRef,
|
|
|
|
IWineD3DVertexDeclarationImpl_Release,
|
2005-07-07 22:45:39 +02:00
|
|
|
/* IWineD3DVertexDeclaration */
|
|
|
|
IWineD3DVertexDeclarationImpl_GetParent,
|
2005-01-19 20:34:49 +01:00
|
|
|
IWineD3DVertexDeclarationImpl_GetDevice,
|
2005-01-26 21:54:00 +01:00
|
|
|
IWineD3DVertexDeclarationImpl_GetDeclaration,
|
2005-07-07 22:45:39 +02:00
|
|
|
IWineD3DVertexDeclarationImpl_SetDeclaration
|
2005-01-19 20:34:49 +01:00
|
|
|
};
|