Commit 0a944ae3 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

Implement Material, Clip plane and Light support plus

MultiplyTransform.
parent 3f884c2c
......@@ -318,45 +318,8 @@ HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9 iface, D3DT
}
HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
D3DMATRIX *mat = NULL;
D3DMATRIX temp;
/* Note: Using UpdateStateBlock means it would be recorded in a state block change,
but works regardless of recording being on.
If this is found to be wrong, change to StateBlock. */
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
TRACE("(%p) : For state %u\n", This, State);
if (State < HIGHEST_TRANSFORMSTATE) {
mat = &This->UpdateStateBlock->transforms[State];
} else {
FIXME("Unhandled transform state!!\n");
}
/* Copied from ddraw code: */
temp.u.s._11 = (mat->u.s._11 * pMatrix->u.s._11) + (mat->u.s._21 * pMatrix->u.s._12) + (mat->u.s._31 * pMatrix->u.s._13) + (mat->u.s._41 * pMatrix->u.s._14);
temp.u.s._21 = (mat->u.s._11 * pMatrix->u.s._21) + (mat->u.s._21 * pMatrix->u.s._22) + (mat->u.s._31 * pMatrix->u.s._23) + (mat->u.s._41 * pMatrix->u.s._24);
temp.u.s._31 = (mat->u.s._11 * pMatrix->u.s._31) + (mat->u.s._21 * pMatrix->u.s._32) + (mat->u.s._31 * pMatrix->u.s._33) + (mat->u.s._41 * pMatrix->u.s._34);
temp.u.s._41 = (mat->u.s._11 * pMatrix->u.s._41) + (mat->u.s._21 * pMatrix->u.s._42) + (mat->u.s._31 * pMatrix->u.s._43) + (mat->u.s._41 * pMatrix->u.s._44);
temp.u.s._12 = (mat->u.s._12 * pMatrix->u.s._11) + (mat->u.s._22 * pMatrix->u.s._12) + (mat->u.s._32 * pMatrix->u.s._13) + (mat->u.s._42 * pMatrix->u.s._14);
temp.u.s._22 = (mat->u.s._12 * pMatrix->u.s._21) + (mat->u.s._22 * pMatrix->u.s._22) + (mat->u.s._32 * pMatrix->u.s._23) + (mat->u.s._42 * pMatrix->u.s._24);
temp.u.s._32 = (mat->u.s._12 * pMatrix->u.s._31) + (mat->u.s._22 * pMatrix->u.s._32) + (mat->u.s._32 * pMatrix->u.s._33) + (mat->u.s._42 * pMatrix->u.s._34);
temp.u.s._42 = (mat->u.s._12 * pMatrix->u.s._41) + (mat->u.s._22 * pMatrix->u.s._42) + (mat->u.s._32 * pMatrix->u.s._43) + (mat->u.s._42 * pMatrix->u.s._44);
temp.u.s._13 = (mat->u.s._13 * pMatrix->u.s._11) + (mat->u.s._23 * pMatrix->u.s._12) + (mat->u.s._33 * pMatrix->u.s._13) + (mat->u.s._43 * pMatrix->u.s._14);
temp.u.s._23 = (mat->u.s._13 * pMatrix->u.s._21) + (mat->u.s._23 * pMatrix->u.s._22) + (mat->u.s._33 * pMatrix->u.s._23) + (mat->u.s._43 * pMatrix->u.s._24);
temp.u.s._33 = (mat->u.s._13 * pMatrix->u.s._31) + (mat->u.s._23 * pMatrix->u.s._32) + (mat->u.s._33 * pMatrix->u.s._33) + (mat->u.s._43 * pMatrix->u.s._34);
temp.u.s._43 = (mat->u.s._13 * pMatrix->u.s._41) + (mat->u.s._23 * pMatrix->u.s._42) + (mat->u.s._33 * pMatrix->u.s._43) + (mat->u.s._43 * pMatrix->u.s._44);
temp.u.s._14 = (mat->u.s._14 * pMatrix->u.s._11) + (mat->u.s._24 * pMatrix->u.s._12) + (mat->u.s._34 * pMatrix->u.s._13) + (mat->u.s._44 * pMatrix->u.s._14);
temp.u.s._24 = (mat->u.s._14 * pMatrix->u.s._21) + (mat->u.s._24 * pMatrix->u.s._22) + (mat->u.s._34 * pMatrix->u.s._23) + (mat->u.s._44 * pMatrix->u.s._24);
temp.u.s._34 = (mat->u.s._14 * pMatrix->u.s._31) + (mat->u.s._24 * pMatrix->u.s._32) + (mat->u.s._34 * pMatrix->u.s._33) + (mat->u.s._44 * pMatrix->u.s._34);
temp.u.s._44 = (mat->u.s._14 * pMatrix->u.s._41) + (mat->u.s._24 * pMatrix->u.s._42) + (mat->u.s._34 * pMatrix->u.s._43) + (mat->u.s._44 * pMatrix->u.s._44);
/* Apply change via set transform - will reapply to eg. lights this way */
IDirect3DDevice9Impl_SetTransform(iface, State, &temp);
return D3D_OK;
return IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, pMatrix);
}
HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9 iface, CONST D3DVIEWPORT9* pViewport) {
......@@ -374,55 +337,42 @@ HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9 iface, D3DVI
HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9 iface, CONST D3DMATERIAL9* pMaterial) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_SetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
}
HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9 iface, D3DMATERIAL9* pMaterial) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
memcpy(pMaterial, &This->UpdateStateBlock->material, sizeof (D3DMATERIAL9));
TRACE("(%p) : Diffuse (%f,%f,%f,%f)\n", This, pMaterial->Diffuse.r, pMaterial->Diffuse.g, pMaterial->Diffuse.b, pMaterial->Diffuse.a);
TRACE("(%p) : Ambient (%f,%f,%f,%f)\n", This, pMaterial->Ambient.r, pMaterial->Ambient.g, pMaterial->Ambient.b, pMaterial->Ambient.a);
TRACE("(%p) : Specular (%f,%f,%f,%f)\n", This, pMaterial->Specular.r, pMaterial->Specular.g, pMaterial->Specular.b, pMaterial->Specular.a);
TRACE("(%p) : Emissive (%f,%f,%f,%f)\n", This, pMaterial->Emissive.r, pMaterial->Emissive.g, pMaterial->Emissive.b, pMaterial->Emissive.a);
TRACE("(%p) : Power (%f)\n", This, pMaterial->Power);
return D3D_OK;
return IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
}
HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST D3DLIGHT9* pLight) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
}
HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9 iface, DWORD Index,D3DLIGHT9* pLight) {
HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, D3DLIGHT9* pLight) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
}
HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9 iface, DWORD Index, BOOL Enable) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
}
HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9 iface, DWORD Index, BOOL* pEnable) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
}
HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST float* pPlane) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
}
HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9 iface, DWORD Index, float* pPlane) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
}
HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9 iface, D3DRENDERSTATETYPE State, DWORD Value) {
......@@ -440,14 +390,12 @@ HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9 iface, D3
HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9 iface, CONST D3DCLIPSTATUS9* pClipStatus) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
}
HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9 iface, D3DCLIPSTATUS9* pClipStatus) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
FIXME("(%p) : stub\n", This);
return D3D_OK;
return IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
}
HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9 iface, DWORD Stage, IDirect3DBaseTexture9** ppTexture) {
......
......@@ -24,6 +24,7 @@
#include "wined3d_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
#define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
/* *******************************************
IWineD3DIndexBuffer IUnknown parts follow
......@@ -52,7 +53,7 @@ ULONG WINAPI IWineD3DIndexBufferImpl_Release(IWineD3DIndexBuffer *iface) {
IWineD3DDevice_Release(This->resource.wineD3DDevice);
HeapFree(GetProcessHeap(), 0, This);
} else {
IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx VB */
IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
}
return ref;
}
......
......@@ -24,6 +24,7 @@
#define __WINE_WINED3D_PRIVATE_H
#include <stdarg.h>
#include <math.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#define COBJMACROS
......@@ -77,6 +78,7 @@ extern int num_lock;
/* Highest value in D3DTRANSFORMSTATETYPE */
#define WINED3D_VSHADER_MAX_CONSTANTS 96
/* Maximum number of constants provided to the shaders */
#define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
#define checkGLcall(A) \
{ \
......@@ -108,11 +110,43 @@ do {
checkGLcall("glActiveTextureARB");
#endif
/* Macro to dump out the current state of the light chain */
#define DUMP_LIGHT_CHAIN() \
{ \
PLIGHTINFOEL *el = This->stateBlock->lights;\
while (el) { \
TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
el = el->next; \
} \
}
typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
extern const float identity[16];
/*****************************************************************************
* Internal representation of a light
*/
typedef struct PLIGHTINFOEL PLIGHTINFOEL;
struct PLIGHTINFOEL {
WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
DWORD OriginalIndex;
LONG glIndex;
BOOL lightEnabled;
BOOL changed;
BOOL enabledChanged;
/* Converted parms to speed up swapping lights */
float lightPosn[4];
float lightDirn[4];
float exponent;
float cutoff;
PLIGHTINFOEL *next;
PLIGHTINFOEL *prev;
};
/*****************************************************************************
* IWineD3D implementation structure
*/
typedef struct IWineD3DImpl
......@@ -242,9 +276,11 @@ extern IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
/* Note: Very long winded but gl Lists are not flexible enough */
/* to resolve everything we need, so doing it manually for now */
typedef struct SAVEDSTATES {
BOOL material;
BOOL fvf;
BOOL stream_source[MAX_STREAMS];
BOOL transform[HIGHEST_TRANSFORMSTATE];
BOOL clipplane[MAX_CLIPPLANES];
} SAVEDSTATES;
struct IWineD3DStateBlockImpl
......@@ -273,6 +309,16 @@ struct IWineD3DStateBlockImpl
/* Transform */
D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE];
/* Lights */
PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
/* Clipping */
double clipplane[MAX_CLIPPLANES][4];
WINED3DCLIPSTATUS clip_status;
/* Material */
WINED3DMATERIAL material;
};
extern IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
......
......@@ -39,7 +39,6 @@
/*****************************************************************************
* WineD3D Structures to be used when d3d8 and d3d9 are incompatible
*/
typedef struct _WINED3DADAPTER_IDENTIFIER {
char *Driver;
char *Description;
......@@ -70,6 +69,17 @@ typedef struct _WINED3DPRESENT_PARAMETERS {
UINT *PresentationInterval;
} WINED3DPRESENT_PARAMETERS;
/* The following have differing names, but actually are the same layout */
#if defined( __WINE_D3D8_H )
#define WINED3DLIGHT D3DLIGHT8
#define WINED3DCLIPSTATUS D3DCLIPSTATUS8
#define WINED3DMATERIAL D3DMATERIAL8
#else
#define WINED3DLIGHT D3DLIGHT9
#define WINED3DCLIPSTATUS D3DCLIPSTATUS9
#define WINED3DMATERIAL D3DMATERIAL9
#endif
typedef struct IWineD3D IWineD3D;
typedef struct IWineD3DDevice IWineD3DDevice;
typedef struct IWineD3DResource IWineD3DResource;
......@@ -154,6 +164,17 @@ DECLARE_INTERFACE_(IWineD3DDevice,IUnknown)
STDMETHOD(GetStreamSource)(THIS_ UINT StreamNumber,IWineD3DVertexBuffer ** ppStreamData,UINT *pOffset, UINT * pStride) PURE;
STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX * pMatrix) PURE;
STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,D3DMATRIX * pMatrix) PURE;
STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX * pMatrix) PURE;
STDMETHOD(SetLight)(THIS_ DWORD Index,CONST WINED3DLIGHT * pLight) PURE;
STDMETHOD(GetLight)(THIS_ DWORD Index,WINED3DLIGHT * pLight) PURE;
STDMETHOD(SetLightEnable)(THIS_ DWORD Index,BOOL Enable) PURE;
STDMETHOD(GetLightEnable)(THIS_ DWORD Index,BOOL * pEnable) PURE;
STDMETHOD(SetClipPlane)(THIS_ DWORD Index,CONST float * pPlane) PURE;
STDMETHOD(GetClipPlane)(THIS_ DWORD Index,float * pPlane) PURE;
STDMETHOD(SetClipStatus)(THIS_ CONST WINED3DCLIPSTATUS * pClipStatus) PURE;
STDMETHOD(GetClipStatus)(THIS_ WINED3DCLIPSTATUS * pClipStatus) PURE;
STDMETHOD(SetMaterial)(THIS_ CONST WINED3DMATERIAL * pMaterial) PURE;
STDMETHOD(GetMaterial)(THIS_ WINED3DMATERIAL *pMaterial) PURE;
STDMETHOD(BeginScene)(THIS) PURE;
};
#undef INTERFACE
......@@ -174,6 +195,17 @@ DECLARE_INTERFACE_(IWineD3DDevice,IUnknown)
#define IWineD3DDevice_GetStreamSource(p,a,b,c,d) (p)->lpVtbl->GetStreamSource(p,a,b,c,d)
#define IWineD3DDevice_SetTransform(p,a,b) (p)->lpVtbl->SetTransform(p,a,b)
#define IWineD3DDevice_GetTransform(p,a,b) (p)->lpVtbl->GetTransform(p,a,b)
#define IWineD3DDevice_MultiplyTransform(p,a,b) (p)->lpVtbl->MultiplyTransform(p,a,b)
#define IWineD3DDevice_SetLight(p,a,b) (p)->lpVtbl->SetLight(p,a,b)
#define IWineD3DDevice_GetLight(p,a,b) (p)->lpVtbl->GetLight(p,a,b)
#define IWineD3DDevice_SetLightEnable(p,a,b) (p)->lpVtbl->SetLightEnable(p,a,b)
#define IWineD3DDevice_GetLightEnable(p,a,b) (p)->lpVtbl->GetLightEnable(p,a,b)
#define IWineD3DDevice_SetClipPlane(p,a,b) (p)->lpVtbl->SetClipPlane(p,a,b)
#define IWineD3DDevice_GetClipPlane(p,a,b) (p)->lpVtbl->GetClipPlane(p,a,b)
#define IWineD3DDevice_SetClipStatus(p,a) (p)->lpVtbl->SetClipStatus(p,a)
#define IWineD3DDevice_GetClipStatus(p,a) (p)->lpVtbl->GetClipStatus(p,a)
#define IWineD3DDevice_SetMaterial(p,a) (p)->lpVtbl->SetMaterial(p,a)
#define IWineD3DDevice_GetMaterial(p,a) (p)->lpVtbl->GetMaterial(p,a)
#define IWineD3DDevice_BeginScene(p) (p)->lpVtbl->BeginScene(p)
#endif
......
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