Commit b61b29f5 authored by hybrid's avatar hybrid

Bug fix for render state updates

Unification of d3d8 and d3d9 implementation

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4329 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 3d892c50
...@@ -18,8 +18,36 @@ namespace irr ...@@ -18,8 +18,36 @@ namespace irr
namespace video namespace video
{ {
namespace
{
D3DMATRIX UnitMatrixD3D8; D3DMATRIX UnitMatrixD3D8;
D3DMATRIX SphereMapMatrixD3D8; D3DMATRIX SphereMapMatrixD3D8;
inline void setTextureColorStage(IDirect3DDevice8* dev, DWORD i,
DWORD arg1, DWORD op, DWORD arg2)
{
dev->SetTextureStageState(i, D3DTSS_COLOROP, op);
dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1);
dev->SetTextureStageState(i, D3DTSS_COLORARG2, arg2);
}
inline void setTextureColorStage(IDirect3DDevice8* dev, DWORD i, DWORD arg1)
{
dev->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1);
}
inline void setTextureAlphaStage(IDirect3DDevice8* dev, DWORD i,
DWORD arg1, DWORD op, DWORD arg2)
{
dev->SetTextureStageState(i, D3DTSS_ALPHAOP, op);
dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1);
dev->SetTextureStageState(i, D3DTSS_ALPHAARG2, arg2);
}
inline void setTextureAlphaStage(IDirect3DDevice8* dev, DWORD i, DWORD arg1)
{
dev->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1);
}
} // anonymous namespace
//! Base class for all internal D3D8 material renderers //! Base class for all internal D3D8 material renderers
class CD3D8MaterialRenderer : public IMaterialRenderer class CD3D8MaterialRenderer : public IMaterialRenderer
...@@ -50,18 +78,16 @@ public: ...@@ -50,18 +78,16 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
} }
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -76,6 +102,8 @@ public: ...@@ -76,6 +102,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || if (material.MaterialType != lastMaterial.MaterialType ||
material.MaterialTypeParam != lastMaterial.MaterialTypeParam || material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
resetAllRenderstates) resetAllRenderstates)
...@@ -87,7 +115,9 @@ public: ...@@ -87,7 +115,9 @@ public:
unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam ); unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO) if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
else else
{ {
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
...@@ -95,43 +125,36 @@ public: ...@@ -95,43 +125,36 @@ public:
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, getD3DBlend ( dstFact ) ); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, getD3DBlend ( dstFact ) );
} }
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, getD3DModulate ( modulate ) ); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, getD3DModulate(modulate), D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
if ( alphaSource && (textureBlendFunc_hasAlpha ( srcFact ) || textureBlendFunc_hasAlpha ( dstFact ) )) if ( alphaSource && (textureBlendFunc_hasAlpha ( srcFact ) || textureBlendFunc_hasAlpha ( dstFact ) ))
{ {
if (alphaSource==EAS_VERTEX_COLOR) if (alphaSource==EAS_VERTEX_COLOR)
{ {
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
} }
else if (alphaSource==EAS_TEXTURE) else if (alphaSource==EAS_TEXTURE)
{ {
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
} }
else else
{ {
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); setTextureAlphaStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
} }
} }
else
{
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
}
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
//! Returns if the material is transparent. //! Returns if the material is transparent.
/** The scene management needs to know this for being able to sort the
materials by opaque and transparent.
The return value could be optimized, but we'd need to know the
MaterialTypeParam for it. */
virtual bool isTransparent() const virtual bool isTransparent() const
{ {
return true; return true;
...@@ -185,19 +208,17 @@ public: ...@@ -185,19 +208,17 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -213,23 +234,22 @@ public: ...@@ -213,23 +234,22 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
//! Returns if the material is transparent. //! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const virtual bool isTransparent() const
{ {
return true; return true;
...@@ -248,24 +268,23 @@ public: ...@@ -248,24 +268,23 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
//! Returns if the material is transparent. //! Returns if the material is transparent. The scene managment needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const virtual bool isTransparent() const
{ {
return true; return true;
...@@ -284,18 +303,16 @@ public: ...@@ -284,18 +303,16 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) || material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{ {
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT ); setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
...@@ -304,8 +321,6 @@ public: ...@@ -304,8 +321,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -313,7 +328,8 @@ public: ...@@ -313,7 +328,8 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
} }
//! Returns if the material is transparent. //! Returns if the material is transparent. The scene managment needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const virtual bool isTransparent() const
{ {
return true; return true;
...@@ -332,16 +348,15 @@ public: ...@@ -332,16 +348,15 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT ); setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
...@@ -350,8 +365,6 @@ public: ...@@ -350,8 +365,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -368,8 +381,7 @@ public: ...@@ -368,8 +381,7 @@ public:
}; };
//! material renderer for all kinds of lightmaps
//! material renderer for all kinds of linghtmaps
class CD3D8MaterialRenderer_LIGHTMAP : public CD3D8MaterialRenderer class CD3D8MaterialRenderer_LIGHTMAP : public CD3D8MaterialRenderer
{ {
public: public:
...@@ -380,46 +392,40 @@ public: ...@@ -380,46 +392,40 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING) if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING)
{ {
// with lighting // with lighting
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
} }
else else
{ {
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
} }
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
if (material.MaterialType == EMT_LIGHTMAP_ADD) setTextureColorStage(pID3DDevice, 1,
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD); D3DTA_TEXTURE,
else (material.MaterialType == EMT_LIGHTMAP_ADD)?
if (material.MaterialType == EMT_LIGHTMAP_M4 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M4) D3DTOP_ADD:
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE4X); (material.MaterialType == EMT_LIGHTMAP_M4 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M4)?
else D3DTOP_MODULATE4X:
if (material.MaterialType == EMT_LIGHTMAP_M2 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M2) (material.MaterialType == EMT_LIGHTMAP_M2 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M2)?
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X); D3DTOP_MODULATE2X:
else D3DTOP_MODULATE,
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); D3DTA_CURRENT);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState (1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
//! material renderer for detail maps //! material renderer for detail maps
class CD3D8MaterialRenderer_DETAIL_MAP : public CD3D8MaterialRenderer class CD3D8MaterialRenderer_DETAIL_MAP : public CD3D8MaterialRenderer
{ {
...@@ -431,23 +437,17 @@ public: ...@@ -431,23 +437,17 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); setTextureColorStage(pID3DDevice, 1,
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState (1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED);
pID3DDevice->SetTextureStageState (1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState (1, D3DTSS_COLORARG2, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState (1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -463,12 +463,12 @@ public: ...@@ -463,12 +463,12 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
...@@ -477,8 +477,6 @@ public: ...@@ -477,8 +477,6 @@ public:
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL ); pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL );
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -501,24 +499,21 @@ public: ...@@ -501,24 +499,21 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 1,
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D8 ); pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D8 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -541,38 +536,36 @@ public: ...@@ -541,38 +536,36 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); setTextureColorStage(pID3DDevice, 0,
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
setTextureAlphaStage(pID3DDevice, 1, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); pID3DDevice->SetTransform(D3DTS_TEXTURE1, &SphereMapMatrixD3D8 );
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D8 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
{ {
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetTransform( D3DTS_TEXTURE1, &UnitMatrixD3D8 ); pID3DDevice->SetTransform(D3DTS_TEXTURE1, &UnitMatrixD3D8);
} }
//! Returns if the material is transparent. //! Returns if the material is transparent. The scene managment needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const virtual bool isTransparent() const
{ {
return true; return true;
......
...@@ -63,10 +63,6 @@ public: ...@@ -63,10 +63,6 @@ public:
{ {
} }
~CD3D9MaterialRenderer()
{
}
//! sets a variable in the shader. //! sets a variable in the shader.
//! \param vertexShader: True if this should be set in the vertex shader, false if //! \param vertexShader: True if this should be set in the vertex shader, false if
//! in the pixel shader. //! in the pixel shader.
......
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