Commit ea41a914 authored by nadro's avatar nadro

- Remove force blending mechanism and improve blending handling in material renderers.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4775 dfc29bdd-3216-0410-991c-e03cc46cb475
parent de6df498
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Fixed issue with wrongly enabled Z-writing for transparent shader materials. Thanks Hendu for this fix.
- Allow more control over particle behavior. This also changed the default behavior. - Allow more control over particle behavior. This also changed the default behavior.
- ISceneNodeAnimators can now be disabled and paused. - ISceneNodeAnimators can now be disabled and paused.
- Maya camera no longer get's stuck in "rotating" state when a mouse-up event is lost (thx @ JLouisB for reporting). - Maya camera no longer get's stuck in "rotating" state when a mouse-up event is lost (thx @ JLouisB for reporting).
...@@ -22,14 +23,14 @@ Changes in 1.9 (not yet released) ...@@ -22,14 +23,14 @@ Changes in 1.9 (not yet released)
- CGUICheckBox no longer gives up focus on EMIE_LMOUSE_LEFT_UP (thx @Demre and @REDDemon for reporting) - CGUICheckBox no longer gives up focus on EMIE_LMOUSE_LEFT_UP (thx @Demre and @REDDemon for reporting)
- Bugfix: IGUIElement::addChild now prevents setting an element as it's own child. - Bugfix: IGUIElement::addChild now prevents setting an element as it's own child.
- GUI editor improvements (prevent crash, improve UI) - GUI editor improvements (prevent crash, improve UI)
- Add IrrlichtDevice::setWindowSize. - Add IrrlichtDevice::setWindowSize.
- Bugfix: getFont for xml-fonts now also works for fonts inside archives (thx @Neirdan for bugreport) - Bugfix: getFont for xml-fonts now also works for fonts inside archives (thx @Neirdan for bugreport)
- Added function irr::core::mergeFilename - Added function irr::core::mergeFilename
- Add ISceneNodeAnimator::setStartTime/getStartTime to allow resetting movement animators. - Add ISceneNodeAnimator::setStartTime/getStartTime to allow resetting movement animators.
- Improve speed for finalizing skinned meshes (removal of unnecessary frames after loading) (thx @ichtyander for the testmodel) - Improve speed for finalizing skinned meshes (removal of unnecessary frames after loading) (thx @ichtyander for the testmodel)
- Collada loader now instantiates camera nodes which had been ignore so far (thx @NemoStein for the test .dae) - Collada loader now instantiates camera nodes which had been ignore so far (thx @NemoStein for the test .dae)
- line2d::intersectWith has a new parameter to allow ignoring intersections with coincident lines - line2d::intersectWith has a new parameter to allow ignoring intersections with coincident lines
- vector2d::equals now has an tolerance parameter for passing the epsilon (like vector3d had). Note that this changes the default - vector2d::equals now has an tolerance parameter for passing the epsilon (like vector3d had). Note that this changes the default
behavior of vector2d::equals as well as functions using it like the operators for ==, !=, <, >, <=, >= when using vector2d with f64 behavior of vector2d::equals as well as functions using it like the operators for ==, !=, <, >, <=, >= when using vector2d with f64
as the tolerance is increased in that case (for f32 and integer values it shouldn't make any difference). as the tolerance is increased in that case (for f32 and integer values it shouldn't make any difference).
- Material renderers which offers blending feature (eg. EMT_TRANSPARENT_ALPHA_CHANNEL, EMT_ONETEXTURE_BLEND etc.) require SMaterial::BlendOperation set to other value than EBO_NONE. - Material renderers which offers blending feature (eg. EMT_TRANSPARENT_ALPHA_CHANNEL, EMT_ONETEXTURE_BLEND etc.) require SMaterial::BlendOperation set to other value than EBO_NONE.
...@@ -69,9 +70,9 @@ Changes in 1.8.1 (17.11.2013) ...@@ -69,9 +70,9 @@ Changes in 1.8.1 (17.11.2013)
- Improved OpenGL performance under OSX (Thanks devonsoft for reporting). - Improved OpenGL performance under OSX (Thanks devonsoft for reporting).
- Fixed OSX compilation issues. - Fixed OSX compilation issues.
- [KNOWN BUG] Software driver doesn't work properly under OSX 10.9. - [KNOWN BUG] Software driver doesn't work properly under OSX 10.9.
- For speed improvement the following attributes accessible by ISceneManager::getParameters() are no longer updated in release: - For speed improvement the following attributes accessible by ISceneManager::getParameters() are no longer updated in release:
"culled", "calls", "drawn_solid", "drawn_transparent", "drawn_transparent_effect". "culled", "calls", "drawn_solid", "drawn_transparent", "drawn_transparent_effect".
They can be enabled by compiling Irrlicht with the define _IRR_SCENEMANAGER_DEBUG. They can be enabled by compiling Irrlicht with the define _IRR_SCENEMANAGER_DEBUG.
Thanks @hendu for reporting, see http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=48211 for the discussion. Thanks @hendu for reporting, see http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=48211 for the discussion.
- Fix compile problem with CIrrDeviceSDL on VS2008 (and maybe other systems). Thanks @HellFlip for reporting. - Fix compile problem with CIrrDeviceSDL on VS2008 (and maybe other systems). Thanks @HellFlip for reporting.
- Fix quaternion::rotationFromTo() (Thanks @takamoto for reporting) - Fix quaternion::rotationFromTo() (Thanks @takamoto for reporting)
......
...@@ -35,7 +35,7 @@ namespace video ...@@ -35,7 +35,7 @@ namespace video
EBF_SRC_ALPHA_SATURATE //!< src (min(srcA, 1-destA), idem, ...) EBF_SRC_ALPHA_SATURATE //!< src (min(srcA, 1-destA), idem, ...)
}; };
//! Values defining the blend operation used when blend is enabled //! Values defining the blend operation
enum E_BLEND_OPERATION enum E_BLEND_OPERATION
{ {
EBO_NONE = 0, //!< No blending happens EBO_NONE = 0, //!< No blending happens
......
...@@ -1370,14 +1370,8 @@ bool CD3D8Driver::setRenderStates3DMode() ...@@ -1370,14 +1370,8 @@ bool CD3D8Driver::setRenderStates3DMode()
// set new material. // set new material.
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
// force blending if necessary
if (Material.BlendOperation == EBO_NONE && MaterialRenderers[Material.MaterialType].Renderer->isTransparent())
Material.BlendOperation = EBO_ADD;
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
Material, LastMaterial, ResetRenderStates, this); Material, LastMaterial, ResetRenderStates, this);
}
} }
bool shaderOK = true; bool shaderOK = true;
......
...@@ -87,7 +87,6 @@ public: ...@@ -87,7 +87,6 @@ public:
} }
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
}; };
...@@ -104,9 +103,9 @@ public: ...@@ -104,9 +103,9 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); 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)
{ {
E_BLEND_FACTOR srcFact,dstFact; E_BLEND_FACTOR srcFact,dstFact;
...@@ -150,6 +149,11 @@ public: ...@@ -150,6 +149,11 @@ public:
} }
} }
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
//! 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 /** The scene management needs to know this for being able to sort the
materials by opaque and transparent. materials by opaque and transparent.
...@@ -216,8 +220,6 @@ public: ...@@ -216,8 +220,6 @@ public:
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);
} }
} }
}; };
...@@ -236,18 +238,24 @@ public: ...@@ -236,18 +238,24 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
} }
} }
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
//! Returns if the material is transparent. The scene management needs to know this //! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent. //! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_ virtual bool isTransparent() const _IRR_OVERRIDE_
...@@ -270,6 +278,10 @@ public: ...@@ -270,6 +278,10 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -277,12 +289,14 @@ public: ...@@ -277,12 +289,14 @@ public:
setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
} }
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
//! for being able to sort the materials by opaque and transparent. //! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_ virtual bool isTransparent() const _IRR_OVERRIDE_
...@@ -305,6 +319,10 @@ public: ...@@ -305,6 +319,10 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) || material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{ {
...@@ -313,9 +331,6 @@ public: ...@@ -313,9 +331,6 @@ public:
setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f)); pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f));
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
...@@ -326,6 +341,7 @@ public: ...@@ -326,6 +341,7 @@ public:
virtual void OnUnsetMaterial() _IRR_OVERRIDE_ virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{ {
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
...@@ -358,8 +374,6 @@ public: ...@@ -358,8 +374,6 @@ public:
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF // 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127); pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127);
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
...@@ -419,8 +433,6 @@ public: ...@@ -419,8 +433,6 @@ public:
D3DTOP_MODULATE2X: D3DTOP_MODULATE2X:
D3DTOP_MODULATE, D3DTOP_MODULATE,
D3DTA_CURRENT); D3DTA_CURRENT);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
} }
}; };
...@@ -446,7 +458,6 @@ public: ...@@ -446,7 +458,6 @@ public:
setTextureColorStage(pID3DDevice, 1, setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT); D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
} }
}; };
...@@ -471,7 +482,6 @@ public: ...@@ -471,7 +482,6 @@ public:
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D8 ); pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D8 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
...@@ -512,7 +522,6 @@ public: ...@@ -512,7 +522,6 @@ public:
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);
} }
} }
...@@ -538,6 +547,10 @@ public: ...@@ -538,6 +547,10 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -550,10 +563,6 @@ public: ...@@ -550,10 +563,6 @@ public:
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, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
} }
...@@ -562,6 +571,7 @@ public: ...@@ -562,6 +571,7 @@ public:
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);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
......
...@@ -112,8 +112,6 @@ bool CD3D8ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E ...@@ -112,8 +112,6 @@ bool CD3D8ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E
void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services) bool resetAllRenderstates, video::IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (VertexShader) if (VertexShader)
...@@ -134,11 +132,13 @@ void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material ...@@ -134,11 +132,13 @@ void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material
if (FAILED(pID3DDevice->SetPixelShader(PixelShader))) if (FAILED(pID3DDevice->SetPixelShader(PixelShader)))
os::Printer::log("Could not set pixel shader.", ELL_ERROR); os::Printer::log("Could not set pixel shader.", ELL_ERROR);
} }
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, material, true, services);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
} }
......
...@@ -75,10 +75,6 @@ bool CD3D9CgMaterialRenderer::isTransparent() const ...@@ -75,10 +75,6 @@ bool CD3D9CgMaterialRenderer::isTransparent() const
void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Material = material;
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (VertexProgram) if (VertexProgram)
...@@ -86,13 +82,17 @@ void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMa ...@@ -86,13 +82,17 @@ void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMa
if (FragmentProgram) if (FragmentProgram)
cgD3D9BindProgram(FragmentProgram); cgD3D9BindProgram(FragmentProgram);
}
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, material, true, this); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, lastMaterial, resetAllRenderstates, this);
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
Material = material;
} }
bool CD3D9CgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) bool CD3D9CgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype)
...@@ -115,7 +115,7 @@ void CD3D9CgMaterialRenderer::OnUnsetMaterial() ...@@ -115,7 +115,7 @@ void CD3D9CgMaterialRenderer::OnUnsetMaterial()
if (BaseMaterial) if (BaseMaterial)
BaseMaterial->OnUnsetMaterial(); BaseMaterial->OnUnsetMaterial();
Material = IdentityMaterial;; Material = IdentityMaterial;
} }
void CD3D9CgMaterialRenderer::setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) void CD3D9CgMaterialRenderer::setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates)
......
...@@ -2076,14 +2076,8 @@ bool CD3D9Driver::setRenderStates3DMode() ...@@ -2076,14 +2076,8 @@ bool CD3D9Driver::setRenderStates3DMode()
// set new material. // set new material.
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
// force blending if necessary
if (Material.BlendOperation == EBO_NONE && MaterialRenderers[Material.MaterialType].Renderer->isTransparent())
Material.BlendOperation = EBO_ADD;
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
Material, LastMaterial, ResetRenderStates, this); Material, LastMaterial, ResetRenderStates, this);
}
} }
bool shaderOK = true; bool shaderOK = true;
......
...@@ -115,7 +115,6 @@ public: ...@@ -115,7 +115,6 @@ public:
} }
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
}; };
...@@ -132,9 +131,9 @@ public: ...@@ -132,9 +131,9 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); 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)
{ {
E_BLEND_FACTOR srcFact,dstFact; E_BLEND_FACTOR srcFact,dstFact;
...@@ -178,6 +177,11 @@ public: ...@@ -178,6 +177,11 @@ public:
} }
} }
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
//! 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 /** The scene management needs to know this for being able to sort the
materials by opaque and transparent. materials by opaque and transparent.
...@@ -246,8 +250,6 @@ public: ...@@ -246,8 +250,6 @@ public:
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);
} }
} }
}; };
...@@ -266,18 +268,24 @@ public: ...@@ -266,18 +268,24 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
} }
} }
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
//! Returns if the material is transparent. The scene management needs to know this //! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent. //! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_ virtual bool isTransparent() const _IRR_OVERRIDE_
...@@ -300,6 +308,10 @@ public: ...@@ -300,6 +308,10 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -307,12 +319,14 @@ public: ...@@ -307,12 +319,14 @@ public:
setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
} }
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
//! for being able to sort the materials by opaque and transparent. //! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_ virtual bool isTransparent() const _IRR_OVERRIDE_
...@@ -335,6 +349,10 @@ public: ...@@ -335,6 +349,10 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) || material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{ {
...@@ -343,9 +361,6 @@ public: ...@@ -343,9 +361,6 @@ public:
setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f)); pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f));
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
...@@ -356,6 +371,7 @@ public: ...@@ -356,6 +371,7 @@ public:
virtual void OnUnsetMaterial() _IRR_OVERRIDE_ virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{ {
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
...@@ -389,8 +405,6 @@ public: ...@@ -389,8 +405,6 @@ public:
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF // 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127); pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127);
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
...@@ -450,8 +464,6 @@ public: ...@@ -450,8 +464,6 @@ public:
D3DTOP_MODULATE2X: D3DTOP_MODULATE2X:
D3DTOP_MODULATE, D3DTOP_MODULATE,
D3DTA_CURRENT); D3DTA_CURRENT);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
} }
}; };
...@@ -478,7 +490,6 @@ public: ...@@ -478,7 +490,6 @@ public:
setTextureColorStage(pID3DDevice, 1, setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT); D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
} }
}; };
...@@ -503,7 +514,6 @@ public: ...@@ -503,7 +514,6 @@ public:
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D9 ); pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D9 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
...@@ -544,7 +554,6 @@ public: ...@@ -544,7 +554,6 @@ public:
pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D9 ); pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D9 );
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);
} }
} }
...@@ -570,6 +579,10 @@ public: ...@@ -570,6 +579,10 @@ public:
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -582,10 +595,6 @@ public: ...@@ -582,10 +595,6 @@ public:
pID3DDevice->SetTransform(D3DTS_TEXTURE1, &SphereMapMatrixD3D9 ); pID3DDevice->SetTransform(D3DTS_TEXTURE1, &SphereMapMatrixD3D9 );
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, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
} }
...@@ -594,6 +603,7 @@ public: ...@@ -594,6 +603,7 @@ public:
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, &UnitMatrixD3D9); pID3DDevice->SetTransform(D3DTS_TEXTURE1, &UnitMatrixD3D9);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
......
...@@ -112,8 +112,6 @@ bool CD3D9ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E ...@@ -112,8 +112,6 @@ bool CD3D9ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E
void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services) bool resetAllRenderstates, video::IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (VertexShader) if (VertexShader)
...@@ -132,11 +130,13 @@ void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material ...@@ -132,11 +130,13 @@ void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material
if (FAILED(pID3DDevice->SetPixelShader(PixelShader))) if (FAILED(pID3DDevice->SetPixelShader(PixelShader)))
os::Printer::log("Could not set pixel shader.", ELL_WARNING); os::Printer::log("Could not set pixel shader.", ELL_WARNING);
} }
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, material, true, services);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
} }
......
...@@ -93,10 +93,6 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S ...@@ -93,10 +93,6 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S
else else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Material = material;
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (VertexProgram) if (VertexProgram)
...@@ -116,13 +112,17 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S ...@@ -116,13 +112,17 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S
cgGLEnableProfile(GeometryProfile); cgGLEnableProfile(GeometryProfile);
cgGLBindProgram(GeometryProgram); cgGLBindProgram(GeometryProgram);
} }
if (BaseMaterial)
BaseMaterial->OnSetBaseMaterial(material);
} }
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (BaseMaterial)
BaseMaterial->OnSetBaseMaterial(material);
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
Material = material;
} }
bool COpenGLCgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) bool COpenGLCgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype)
...@@ -154,9 +154,9 @@ void COpenGLCgMaterialRenderer::OnUnsetMaterial() ...@@ -154,9 +154,9 @@ void COpenGLCgMaterialRenderer::OnUnsetMaterial()
} }
if (BaseMaterial) if (BaseMaterial)
BaseMaterial->OnUnsetMaterial(); BaseMaterial->OnUnsetBaseMaterial();
Material = IdentityMaterial;; Material = IdentityMaterial;
} }
void COpenGLCgMaterialRenderer::setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) void COpenGLCgMaterialRenderer::setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates)
......
...@@ -2722,14 +2722,8 @@ void COpenGLDriver::setRenderStates3DMode() ...@@ -2722,14 +2722,8 @@ void COpenGLDriver::setRenderStates3DMode()
// set new material. // set new material.
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size()) if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
{
// force blending if necessary
if (Material.BlendOperation == EBO_NONE && MaterialRenderers[Material.MaterialType].Renderer->isTransparent())
Material.BlendOperation = EBO_ADD;
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
Material, LastMaterial, ResetRenderStates, this); Material, LastMaterial, ResetRenderStates, this);
}
LastMaterial = Material; LastMaterial = Material;
ResetRenderStates = false; ResetRenderStates = false;
......
...@@ -291,12 +291,11 @@ public: ...@@ -291,12 +291,11 @@ public:
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
Driver->getBridgeCalls()->setBlend(true);
if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates) if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates)
{
Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Driver->getBridgeCalls()->setBlend(true);
}
} }
virtual void OnSetBaseMaterial(const SMaterial& material) _IRR_OVERRIDE_ virtual void OnSetBaseMaterial(const SMaterial& material) _IRR_OVERRIDE_
...@@ -342,6 +341,9 @@ public: ...@@ -342,6 +341,9 @@ public:
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
#ifdef GL_ARB_texture_env_combine #ifdef GL_ARB_texture_env_combine
...@@ -359,8 +361,6 @@ public: ...@@ -359,8 +361,6 @@ public:
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
#endif #endif
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
} }
} }
...@@ -416,6 +416,11 @@ public: ...@@ -416,6 +416,11 @@ public:
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setAlphaTest(true);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) || material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{ {
...@@ -434,11 +439,6 @@ public: ...@@ -434,11 +439,6 @@ public:
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
#endif #endif
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setAlphaTest(true);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam);
} }
} }
...@@ -822,6 +822,9 @@ public: ...@@ -822,6 +822,9 @@ public:
Driver->disableTextures(2); Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
#ifdef GL_ARB_texture_env_combine #ifdef GL_ARB_texture_env_combine
...@@ -862,9 +865,6 @@ public: ...@@ -862,9 +865,6 @@ public:
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_T);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
} }
} }
......
...@@ -212,19 +212,19 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material, ...@@ -212,19 +212,19 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
else else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (Program2) if (Program2)
Driver->extGlUseProgram(Program2); Driver->extGlUseProgram(Program2);
else if (Program) else if (Program)
Driver->extGlUseProgramObject(Program); Driver->extGlUseProgramObject(Program);
if (BaseMaterial)
BaseMaterial->OnSetBaseMaterial(material);
} }
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (BaseMaterial)
BaseMaterial->OnSetBaseMaterial(material);
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
} }
......
...@@ -138,8 +138,6 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi ...@@ -138,8 +138,6 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi
else else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (VertexShader) if (VertexShader)
...@@ -179,11 +177,13 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi ...@@ -179,11 +177,13 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi
glEnable(GL_FRAGMENT_PROGRAM_NV); glEnable(GL_FRAGMENT_PROGRAM_NV);
#endif #endif
} }
if (BaseMaterial)
BaseMaterial->OnSetBaseMaterial(material);
} }
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (BaseMaterial)
BaseMaterial->OnSetBaseMaterial(material);
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
} }
......
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