Commit 4f02b52c authored by Raphael Junqueira's avatar Raphael Junqueira Committed by Alexandre Julliard

Begin support of VertexDeclaration on wined3d using d3d8 code base

(handling d3d8 and d3d9 specs).
parent 9773414d
......@@ -20,6 +20,7 @@ C_SRCS = \
texture.c \
utils.c \
vertexbuffer.c \
vertexdeclaration.c \
vertexshader.c \
volume.c \
volumetexture.c \
......
/*
* vertex declaration implementation
*
* Copyright 2002-2005 Raphael Junqueira
* Copyright 2004 Jason Edmeades
* Copyright 2004 Christian Costa
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wined3d_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl);
/**
* DirectX9 SDK download
* http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
*
* Exploring D3DX
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
*
* Using Vertex Shaders
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
*
* Dx9 New
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
*
* Dx9 Shaders
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
*
* Dx9 D3DX
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
*
* FVF
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
*
* NVIDIA: DX8 Vertex Shader to NV Vertex Program
* http://developer.nvidia.com/view.asp?IO=vstovp
*
* NVIDIA: Memory Management with VAR
* http://developer.nvidia.com/view.asp?IO=var_memory_management
*/
/** Vertex Shader Declaration 8 data types tokens */
#if 0
#define MAX_VSHADER_DECL_TYPES 8
static CONST char* VertexShader8_DeclDataTypes[] = {
"D3DVSDT_FLOAT1",
"D3DVSDT_FLOAT2",
"D3DVSDT_FLOAT3",
"D3DVSDT_FLOAT4",
"D3DVSDT_D3DCOLOR",
"D3DVSDT_UBYTE4",
"D3DVSDT_SHORT2",
"D3DVSDT_SHORT4",
NULL
};
#endif
/* *******************************************
IWineD3DVertexDeclaration IUnknown parts follow
******************************************* */
HRESULT WINAPI IWineD3DVertexDeclarationImpl_QueryInterface(IWineD3DVertexDeclaration *iface, REFIID riid, LPVOID *ppobj)
{
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
WARN("(%p)->(%s,%p) should not be called\n",This,debugstr_guid(riid),ppobj);
return E_NOINTERFACE;
}
ULONG WINAPI IWineD3DVertexDeclarationImpl_AddRef(IWineD3DVertexDeclaration *iface) {
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
return InterlockedIncrement(&This->ref);
}
ULONG WINAPI IWineD3DVertexDeclarationImpl_Release(IWineD3DVertexDeclaration *iface) {
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
ULONG ref;
TRACE("(%p) : Releasing from %ld\n", This, This->ref);
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This->pDeclaration8);
HeapFree(GetProcessHeap(), 0, This->pDeclaration9);
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
/* *******************************************
IWineD3DVertexDeclaration parts follow
******************************************* */
HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDevice(IWineD3DVertexDeclaration *iface, IWineD3DDevice** ppDevice) {
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
TRACE("(%p) : returning %p\n", This, This->wineD3DDevice);
*ppDevice = (IWineD3DDevice *) This->wineD3DDevice;
IWineD3DDevice_AddRef(*ppDevice);
return D3D_OK;
}
HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDeclaration8(IWineD3DVertexDeclaration* iface, DWORD* pData, DWORD* pSizeOfData) {
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
if (NULL == pData) {
*pSizeOfData = This->declaration8Length;
return D3D_OK;
}
if (*pSizeOfData < This->declaration8Length) {
*pSizeOfData = This->declaration8Length;
return D3DERR_MOREDATA;
}
TRACE("(%p) : GetVertexDeclaration8 copying to %p\n", This, pData);
memcpy(pData, This->pDeclaration8, This->declaration8Length);
return D3D_OK;
}
HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDeclaration9(IWineD3DVertexDeclaration* iface, D3DVERTEXELEMENT9* pData, UINT* pNumElements) {
IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
if (NULL == pData) {
*pNumElements = This->declaration9NumElements;
return D3D_OK;
}
if (*pNumElements < This->declaration9NumElements) {
*pNumElements = This->declaration9NumElements;
return D3DERR_MOREDATA;
}
TRACE("(%p) : GetVertexDeclaration9 copying to %p\n", This, pData);
memcpy(pData, This->pDeclaration9, This->declaration9NumElements);
return D3D_OK;
}
IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl =
{
IWineD3DVertexDeclarationImpl_QueryInterface,
IWineD3DVertexDeclarationImpl_AddRef,
IWineD3DVertexDeclarationImpl_Release,
IWineD3DVertexDeclarationImpl_GetDevice,
IWineD3DVertexDeclarationImpl_GetDeclaration8,
IWineD3DVertexDeclarationImpl_GetDeclaration9
};
......@@ -601,6 +601,30 @@ struct IWineD3DSurfaceImpl
extern IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
/*****************************************************************************
* IWineD3DVertexDeclaration implementation structure
*/
typedef struct IWineD3DVertexDeclarationImpl {
/* IUnknown Information */
IWineD3DVertexDeclarationVtbl *lpVtbl;
DWORD ref; /* Note: Ref counting not required */
/** precomputed fvf if simple declaration */
IWineD3DDeviceImpl *wineD3DDevice;
DWORD fvf[MAX_STREAMS];
DWORD allFVF;
/** dx8 compatible Declaration fields */
DWORD* pDeclaration8;
DWORD declaration8Length;
/** dx9+ */
D3DVERTEXELEMENT9* pDeclaration9;
UINT declaration9NumElements;
} IWineD3DVertexDeclarationImpl;
extern IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
/*****************************************************************************
* IWineD3DStateBlock implementation structure
*/
......@@ -637,10 +661,13 @@ struct IWineD3DStateBlockImpl
/* Drawing - Vertex Shader or FVF related */
DWORD fvf;
void *vertexShader; /* TODO: Replace void * with IWineD3DVertexShader * */
BOOL streamIsUP;
/* Vertex Shader Declaration */
IWineD3DVertexDeclaration* vertexDecl;
void *vertexShader; /* @TODO: Replace void * with IWineD3DVertexShader * */
/* Stream Source */
BOOL streamIsUP;
UINT stream_stride[MAX_STREAMS];
UINT stream_offset[MAX_STREAMS];
IWineD3DVertexBuffer *stream_source[MAX_STREAMS];
......@@ -755,22 +782,6 @@ GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
#if 0 /* Needs fixing during rework */
/*****************************************************************************
* IDirect3DVertexShaderDeclaration implementation structure
*/
struct IDirect3DVertexShaderDeclarationImpl {
/* The device */
/*IDirect3DDeviceImpl* device;*/
/** precomputed fvf if simple declaration */
DWORD fvf[MAX_STREAMS];
DWORD allFVF;
/** dx8 compatible Declaration fields */
DWORD* pDeclaration8;
DWORD declaration8Length;
};
/*****************************************************************************
* IDirect3DVertexShader implementation structure
......
......@@ -131,6 +131,7 @@ typedef struct IWineD3DVolumeTexture IWineD3DVolumeTexture;
typedef struct IWineD3DStateBlock IWineD3DStateBlock;
typedef struct IWineD3DSurface IWineD3DSurface;
typedef struct IWineD3DVolume IWineD3DVolume;
typedef struct IWineD3DVertexDeclaration IWineD3DVertexDeclaration;
/*****************************************************************************
* Callback functions required for predefining surfaces / stencils
......@@ -164,7 +165,7 @@ typedef HRESULT WINAPI (*D3DCB_CREATEVOLUMEFN) (IUnknown *pDevice,
HANDLE * pSharedHandle);
/*****************************************************************************
* WineD3D interface
* IWineD3D interface
*/
#define INTERFACE IWineD3D
......@@ -220,16 +221,16 @@ DECLARE_INTERFACE_(IWineD3D,IUnknown)
IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent);
/*****************************************************************************
* WineD3DDevice interface
* IWineD3DDevice interface
*/
#define INTERFACE IWineD3DDevice
DECLARE_INTERFACE_(IWineD3DDevice,IUnknown)
{
DECLARE_INTERFACE_(IWineD3DDevice,IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IWineD3D methods ***/
/*** IWineD3DDevice methods ***/
STDMETHOD(GetParent)(THIS_ IUnknown **pParent) PURE;
STDMETHOD(CreateVertexBuffer)(THIS_ UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IWineD3DVertexBuffer **ppVertexBuffer, HANDLE *sharedHandle, IUnknown *parent) PURE;
STDMETHOD(CreateIndexBuffer)(THIS_ UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IWineD3DIndexBuffer** ppIndexBuffer, HANDLE* pSharedHandle, IUnknown *parent) PURE;
......@@ -287,9 +288,9 @@ DECLARE_INTERFACE_(IWineD3DDevice,IUnknown)
#if !defined(__cplusplus) || defined(CINTERFACE)
/*** IUnknown methods ***/
#define IWineD3DDevice_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IWineD3DDevice_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IWineD3DDevice_Release(p) (p)->lpVtbl->Release(p)
#define IWineD3DDevice_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IWineD3DDevice_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IWineD3DDevice_Release(p) (p)->lpVtbl->Release(p)
/*** IWineD3DDevice methods ***/
#define IWineD3DDevice_GetParent(p,a) (p)->lpVtbl->GetParent(p,a)
#define IWineD3DDevice_CreateVertexBuffer(p,a,b,c,d,e,f,g) (p)->lpVtbl->CreateVertexBuffer(p,a,b,c,d,e,f,g)
......@@ -861,6 +862,34 @@ DECLARE_INTERFACE_(IWineD3DVolume,IUnknown)
#endif
/*****************************************************************************
* IWineD3DVertexDeclaration interface
*/
#define INTERFACE IWineD3DVertexDeclaration
DECLARE_INTERFACE_(IWineD3DVertexDeclaration,IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IWineD3DVertexDeclaration methods ***/
STDMETHOD(GetDevice)(THIS_ IWineD3DDevice ** ppDevice) PURE;
STDMETHOD(GetDeclaration8)(THIS_ DWORD*, DWORD* pSizeOfData) PURE;
STDMETHOD(GetDeclaration9)(THIS_ D3DVERTEXELEMENT9*, UINT* pNumElements) PURE;
};
#undef INTERFACE
#if !defined(__cplusplus) || defined(CINTERFACE)
/*** IUnknown methods ***/
#define IWineD3DVertexDeclaration_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IWineD3DVertexDeclaration_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IWineD3DVertexDeclaration_Release(p) (p)->lpVtbl->Release(p)
/*** IWineD3DVertexDeclaration methods ***/
#define IWineD3DVertexDeclaration_GetDevice(p,a) (p)->lpVtbl->GetDevice(p,a)
#define IWineD3DVertexDeclaration_GetDeclaration8(p,a,b) (p)->lpVtbl->GetDeclaration8(p,a,b)
#define IWineD3DVertexDeclaration_GetDeclaration9(p,a,b) (p)->lpVtbl->GetDeclaration9(p,a,b)
#endif
/*****************************************************************************
* WineD3DStateBlock interface
*/
#define INTERFACE IWineD3DStateBlock
......@@ -935,9 +964,9 @@ typedef struct IDirect3DResourceImpl IDirect3DResourceImpl;
typedef struct IDirect3DVolumeImpl IDirect3DVolumeImpl;
typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl;
typedef struct IDirect3DStateBlockImpl IDirect3DStateBlockImpl;
typedef struct IDirect3DVertexDeclarationImpl IDirect3DVertexDeclarationImpl;
typedef struct IDirect3DVertexShaderImpl IDirect3DVertexShaderImpl;
typedef struct IDirect3DPixelShaderImpl IDirect3DPixelShaderImpl;
typedef struct IDirect3DVertexShaderDeclarationImpl IDirect3DVertexShaderDeclarationImpl;
/*************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment